1eae8fedd062db2482304f9eb0b6a498db7e2983
[wsn-p.git] / exercise_remotecontrol / rime / led_remote_control.c
1 #include <contiki.h>
2 #include <stdio.h>
3 #include <dev/leds.h>
4 #include <dev/button-sensor.h>
5 #include <net/rime.h>
6
7 PROCESS(led_remote_control_rime, "binary LED counter via button over Rime");
8 AUTOSTART_PROCESSES(&led_remote_control_rime);
9
10 void recv(struct broadcast_conn *ptr, const rimeaddr_t * sender) {
11 char * val = (char *) packetbuf_dataptr();
12 printf("node %d: recv from %d: %d\n", rimeaddr_node_addr, *sender, *val);
13 // FIXME
14 if(*val % 2) {
15 leds_toggle(LEDS_GREEN);
16 }
17 leds_toggle(LEDS_YELLOW);
18 printf("toggled LEDs\n");
19 }
20
21 static struct broadcast_conn bc;
22 static const struct broadcast_callbacks bccb = { recv };
23
24 PROCESS_THREAD(led_remote_control_rime, ev, data) {
25 PROCESS_EXITHANDLER(broadcast_close(&bc));
26
27 PROCESS_BEGIN();
28
29 leds_init();
30 leds_off(LEDS_ALL);
31
32 SENSORS_ACTIVATE(button_sensor);
33
34 broadcast_open(&bc, 129, &bccb);
35
36 static struct etimer timer;
37 static char i;
38 for(i = 0; 1; i++) {
39 PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
40
41 // debounce for 250 ms
42 etimer_set(&timer, CLOCK_SECOND * 0.25);
43 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
44
45 packetbuf_copyfrom(&i, sizeof(i));
46 broadcast_send(&bc);
47 printf("node %d: broadcast sent: %d\n", rimeaddr_node_addr, i);
48 }
49
50 PROCESS_END();
51 }
This page took 0.063527 seconds and 3 git commands to generate.