RocketLogger  1.1.4
rl_deamon.c
Go to the documentation of this file.
1 
32 #include "gpio.h"
33 
35 #define GPIO_BUTTON 26
36 #define MIN_INTERVAL 1
38 
43 int gpio_setup(void) {
44 
45  int ret1 = gpio_export(GPIO_BUTTON);
46  int ret2 = gpio_dir(GPIO_BUTTON, IN);
47  int ret3 = gpio_interrupt(GPIO_BUTTON, FALLING);
48 
49  if (ret1 == FAILURE || ret2 == FAILURE || ret3 == FAILURE) {
50  return FAILURE;
51  }
52 
53  return SUCCESS;
54 }
55 
60 void interrupt_handler(int value) {
61 
62  if (value == 0) { // only react if button pressed enough long
63 
64  // get RL status
65  int status = system("rocketlogger status > /dev/null");
66 
67  if (status > 0) {
68  system("rocketlogger stop > /dev/null");
69  } else {
70  system("rocketlogger cont > /dev/null");
71  }
72 
73  // debouncing
74  sleep(MIN_INTERVAL);
75  }
76 }
77 
85 int main(void) {
86 
87  int timeout = -1; // infinite timeout
88  if (gpio_setup() == FAILURE) {
89  exit(EXIT_FAILURE);
90  }
91 
92  while (1) {
93  int val = gpio_wait_interrupt(GPIO_BUTTON, timeout);
94  interrupt_handler(val);
95  }
96 
97  exit(EXIT_SUCCESS);
98 }
int main(void)
Definition: rl_deamon.c:85
#define MIN_INTERVAL
Minimal time interval between two interrupts (in seconds)
Definition: rl_deamon.c:37
#define FAILURE
Definition: types.h:78
#define SUCCESS
Definition: types.h:75
struct rl_status status
Current status of RocketLogger.
Definition: rl_server.c:71
int gpio_export(int num)
Definition: gpio.c:63
#define GPIO_BUTTON
Linux GPIO number of start/stop button.
Definition: rl_deamon.c:35
Interrupt on falling edge.
Definition: gpio.h:64
int gpio_interrupt(int num, rl_edge edge)
Definition: gpio.c:117
GPIO read mode.
Definition: gpio.h:54
int gpio_wait_interrupt(int num, int timeout)
Definition: gpio.c:212
void interrupt_handler(int value)
Definition: rl_deamon.c:60
int gpio_dir(int num, rl_direction dir)
Definition: gpio.c:88
int gpio_setup(void)
Definition: rl_deamon.c:43