-
Notifications
You must be signed in to change notification settings - Fork 0
/
zag_bridge.c
58 lines (49 loc) · 1.37 KB
/
zag_bridge.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Based on ZigbeeRadioBridge (https://github.com/Frans-Willem/ZigbeeRadioBridge)
*
* Copyright (c) 2019, Frans-Willem Hardijzer <fw@hardijzer.nl>
* Copyright (c) 2020, Jeff Kent <jeff@jkent.net>
*/
#include "commands.h"
#include "contiki.h"
#include "dev/button-sensor.h"
#include "dev/io-arch.h"
#include "dev/leds.h"
#include "lib/ringbuf.h"
#include "net/netstack.h"
#include "serial_protocol.h"
#include "sys/process.h"
#include <stdbool.h>
PROCESS(packetbridge_process, "packet bridge process");
AUTOSTART_PROCESSES(&packetbridge_process);
static uint8_t receive_ringbuf_buffer[128];
static struct ringbuf receive_ringbuf;
static int on_serial_byte(uint8_t c) {
ringbuf_put(&receive_ringbuf, c);
process_poll(&packetbridge_process);
return 1;
}
PROCESS_THREAD(packetbridge_process, ev, data) {
PROCESS_BEGIN();
(void)data; // Stop whining
ringbuf_init(&receive_ringbuf, receive_ringbuf_buffer,
sizeof(receive_ringbuf_buffer));
io_arch_set_input(on_serial_byte);
while (true) {
PROCESS_YIELD();
if (ev == PROCESS_EVENT_POLL) {
serial_process_input(&receive_ringbuf);
} else if (ev == sensors_event) {
if (data == &button_1_sensor) {
commands_send_event_on_button(0);
} else if (data == &button_2_sensor) {
commands_send_event_on_button(1);
}
}
}
PROCESS_END();
}
void netstack_init(void) {
NETSTACK_RADIO.init();
NETSTACK_RDC.init();
}