diff --git a/hikey_control/Makefile b/hikey_control/Makefile new file mode 100644 index 0000000..1ab5289 --- /dev/null +++ b/hikey_control/Makefile @@ -0,0 +1,7 @@ +LDFLAGS=-lmraa +CXXFLAGS=-Wall -g +TARGETS=touch_switch + +all: ${TARGETS} +clean: + rm -f ${TARGETS} diff --git a/hikey_control/README.txt b/hikey_control/README.txt new file mode 100644 index 0000000..91b6e2e --- /dev/null +++ b/hikey_control/README.txt @@ -0,0 +1,20 @@ +Hello, my dear! + +This folder contains the hikey control as binary and the c++ ressources. + + + +Take a look at this: + +https://github.com/96boards/Sensor_Mezzanine_Getting_Started#step-7-configure-the-software + + +This is for setting up the board +--------------------------------- + + +sudo apt-get install arduino-mk arduino git build-essential autoconf libtool swig3.0 python-dev nodejs-dev cmake pkg-config libpcre3-dev + +sudo apt-get clean + +sudo apt-get install libmraa-dev diff --git a/hikey_control/temp_touch_switch.cpp b/hikey_control/temp_touch_switch.cpp new file mode 100644 index 0000000..6d4e811 --- /dev/null +++ b/hikey_control/temp_touch_switch.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "mraa.hpp" + +bool running = true; +bool relay_state = false; +int last_touch; +void sig_handler(int signo) +{ + if (signo == SIGINT) + running = false; +} +int main(int argc, char* argv[]) +{ + mraa::Gpio* touch_gpio = new mraa::Gpio(29); + mraa::Gpio* relay_gpio = new mraa::Gpio(27); + mraa::Result response; + int touch; + + signal(SIGINT, sig_handler); + + response = touch_gpio->dir(mraa::DIR_IN); + if (response != mraa::SUCCESS) + return 1; + response = relay_gpio->dir(mraa::DIR_OUT); + if (response != mraa::SUCCESS) + return 1; + + relay_gpio->write(relay_state); + + while (running) { + touch = touch_gpio->read(); + if (touch == 1 && last_touch == 0) { + relay_state = !relay_state; + response = relay_gpio->write(relay_state); + usleep(100000); + } + last_touch = touch; + } + delete relay_gpio; + delete touch_gpio; + return response; +} + diff --git a/hikey_control/touch_switch b/hikey_control/touch_switch new file mode 100755 index 0000000..62d1af5 Binary files /dev/null and b/hikey_control/touch_switch differ diff --git a/hikey_control/touch_switch.cpp b/hikey_control/touch_switch.cpp new file mode 100644 index 0000000..b53cb39 --- /dev/null +++ b/hikey_control/touch_switch.cpp @@ -0,0 +1,29 @@ +#include +#include +#include "mraa.hpp" + +int main(int argc, char* argv[]) +{ + if (argc != 2) { + return 1; + } + + std::string new_state = argv[1]; + + mraa::Gpio* relay_gpio = new mraa::Gpio(27); + mraa::Result response; + + response = relay_gpio->dir(mraa::DIR_OUT); + if (response != mraa::SUCCESS) { + return 1; + } + + if (new_state == "on") { + relay_gpio->write(true); + } else { + relay_gpio->write(false); + } + + delete relay_gpio; + return response; +}