This commit is contained in:
Daniel Pollithy 2017-08-29 20:07:46 +02:00
parent e6b2137a72
commit 01eaec7b41
5 changed files with 100 additions and 0 deletions

7
hikey_control/Makefile Normal file
View File

@ -0,0 +1,7 @@
LDFLAGS=-lmraa
CXXFLAGS=-Wall -g
TARGETS=touch_switch
all: ${TARGETS}
clean:
rm -f ${TARGETS}

20
hikey_control/README.txt Normal file
View File

@ -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

View File

@ -0,0 +1,44 @@
#include <signal.h>
#include <unistd.h>
#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;
}

BIN
hikey_control/touch_switch Executable file

Binary file not shown.

View File

@ -0,0 +1,29 @@
#include <string>
#include <unistd.h>
#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;
}