Actual write to pin
This commit is contained in:
parent
619a0e8b9a
commit
8780c44ff0
|
@ -13,11 +13,15 @@
|
|||
|
||||
#include <linux/seccomp.h>
|
||||
|
||||
#include <bcm2835.h>
|
||||
|
||||
#define LOGF(x, ...) do { logf_impl(x, __FILE__, __LINE__, __func__, __VA_ARGS__); } while(0);
|
||||
#define LOG(x) do { log_impl(x, __FILE__, __LINE__, __func__); } while(0);
|
||||
#define DEFAULT_PORT 9305
|
||||
#define MBUF_SIZE 2048
|
||||
|
||||
#define TROMMEL_PIN 17
|
||||
|
||||
const char *SOCKET_ERROR = "Socket-fout";
|
||||
|
||||
typedef struct mbuf {
|
||||
|
@ -147,6 +151,9 @@ int do_command_loop(mbuf_t *mbuf) {
|
|||
if (len == 0) return 0;
|
||||
LOGF("COMMANDO: %s", buf);
|
||||
if (strcmp(buf, "trommel") == 0) {
|
||||
bcm2835_gpio_write(TROMMEL_PIN, HIGH);
|
||||
bcm2835_delay(250);
|
||||
bcm2835_gpio_write(TROMMEL_PIN, LOW);
|
||||
const char *ok = "oké\n";
|
||||
write(mbuf->sock, ok, strlen(ok) * sizeof(char));
|
||||
} else if (strcmp(buf, "ping") == 0) {
|
||||
|
@ -192,6 +199,10 @@ int main(int argc, char *argv[]) {
|
|||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
|
||||
bcm2835_init();
|
||||
bcm2835_gpio_fsel(TROMMEL_PIN, BCM2835_GPIO_FSEL_OUTP);
|
||||
|
||||
if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT) < 0) {
|
||||
LOGF("Kon seccomp niet aanroepen: %s", strerror(errno));
|
||||
}
|
||||
|
@ -242,5 +253,6 @@ int main(int argc, char *argv[]) {
|
|||
(void) quit_if_fail(do_command_loop(buf), "Fout");
|
||||
LOG("De andere kant heeft de verbinding verbroken");
|
||||
free(buf);
|
||||
bcm2835_close();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue