1 files modified
1 files deleted
| | |
| | | #include <stdio.h> |
| | | #include <unistd.h> |
| | | #include <libgen.h> |
| | | |
| | | #include <string.h> |
| | | |
| | | #include <wiringPi.h> |
| | | #include "relay.h" |
| | | #include <gpiod.h> |
| | | |
| | | #define ON 1 |
| | | #define OFF 0 |
| | | |
| | | /* Relay #Pin(29) BCM(5) */ |
| | | #define relay_pin 5 |
| | | |
| | | int turn_relay(int cmd); |
| | | |
| | | int main (int argc, char **argv) |
| | | { |
| | |
| | | printf("Usage: %s [on/off]\n", basename(argv[0])); |
| | | return -1; |
| | | } |
| | | |
| | | wiringPiSetup(); |
| | | relay_init(); |
| | | |
| | | if( !strstr(argv[1], "on") || !strstr(argv[1], "on") ) |
| | | { |
| | |
| | | return 0; |
| | | } |
| | | |
| | | void relay_init(void) |
| | | static void gpiod_ctxless_cb(void *data) |
| | | { |
| | | pinMode(RELAY_PIN, OUTPUT); |
| | | sleep(3); |
| | | } |
| | | |
| | | |
| | | void turn_relay(int cmd) |
| | | int turn_relay(int cmd) |
| | | { |
| | | if( OFF == cmd ) |
| | | { |
| | | digitalWrite ( RELAY_PIN, HIGH ); |
| | | } |
| | | gpiod_ctxless_set_value("gpiochip0", relay_pin, 0, false, "relay", gpiod_ctxless_cb, NULL); |
| | | else |
| | | { |
| | | digitalWrite ( RELAY_PIN, LOW ); |
| | | } |
| | | gpiod_ctxless_set_value("gpiochip0", relay_pin, 1, false, "relay", gpiod_ctxless_cb, NULL); |
| | | } |
| | | |