mirror of
https://github.com/DanielPollithy/bluetooth_drone.git
synced 2025-10-16 11:45:38 +00:00
change
This commit is contained in:
parent
e6b2137a72
commit
01eaec7b41
7
hikey_control/Makefile
Normal file
7
hikey_control/Makefile
Normal 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
20
hikey_control/README.txt
Normal 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
|
||||
44
hikey_control/temp_touch_switch.cpp
Normal file
44
hikey_control/temp_touch_switch.cpp
Normal 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
BIN
hikey_control/touch_switch
Executable file
Binary file not shown.
29
hikey_control/touch_switch.cpp
Normal file
29
hikey_control/touch_switch.cpp
Normal 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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user