-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (37 loc) · 972 Bytes
/
main.cpp
File metadata and controls
38 lines (37 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "emergencybutton.h"
#include <stdio.h>
#include <unistd.h>
#include <vector>
int main(void) {
button_state last_state = (button_state)-1;
close(2);
while(1) {
emergencybutton_handle* dev = emergencybutton_open();
usleep(1000);
button_state state = emergencybutton_poll(dev);
if (state != last_state) {
if (last_state == BUTTON_PRESSED && state == BUTTON_ARMED) {
last_state = state;
continue;
}
last_state = state;
switch(state) {
case BUTTON_CLOSED:
printf("Button is closed\n");
break;
case BUTTON_ARMED:
printf("Button is armed\n");
system("say OMG Button is armed!");
break;
case BUTTON_PRESSED:
printf("Button is pressed OH NO!\n");
system("cd noises; ./button_push.sh &");
system("cd crazytown; ./simple &");
system("cd irc; python yell_in_irc.py '#si' 'si_e SI IS TAKING DOWN THE SITE NOW'&");
break;
}
}
emergencybutton_close(dev);
}
return 0;
}