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