-
Notifications
You must be signed in to change notification settings - Fork 12
/
comm.c
executable file
·100 lines (90 loc) · 2.15 KB
/
comm.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "comm.h"
#include "comm_can.h"
#include "comm_i2c.h"
#include "comm_uart.h"
#include "comm_nunchuk.h"
#include "comm_usb.h"
#include "ch.h"
#include "hal.h"
#include "config.h"
static volatile Config *config;
static volatile bool usb_override = false;
static THD_WORKING_AREA(comm_update_wa, 1024);
static THD_FUNCTION(comm_update, arg) {
(void)arg;
chRegSetThreadName("Comm update");
/*comm_can_init();*/
switch(config->commInterface) {
case CAN:
break;
case I2C:
comm_i2c_init();
break;
case UART:
comm_uart_init();
break;
case PPM:
break;
case NUNCHUK:
comm_nunchuk_init();
break;
case NRF24:
break;
case CUSTOM:
break;
default:
break;
}
for(;;) {
if (!usb_override)
{
switch(config->commInterface) {
case CAN:
comm_can_update();
break;
case I2C:
comm_i2c_update();
break;
case UART:
comm_uart_update();
break;
case PPM:
break;
case NUNCHUK:
comm_nunchuk_update();
break;
case NRF24:
break;
case CUSTOM:
break;
default:
break;
}
}
if (!comm_usb_serial_is_active())
{
usb_override = false;
}
if (config->forwardCAN && config->commInterface != CAN)
{
comm_can_forward_commands();
}
if (usb_override)
{
chThdSleepMilliseconds(10);
}
}
}
void comm_init(void)
{
config = config_get_configuration();
chThdCreateStatic(comm_update_wa, sizeof(comm_update_wa), NORMALPRIO, comm_update, NULL);
}
void comm_set_usb_override(bool enable)
{
usb_override = enable;
}
bool comm_get_usb_override(void)
{
return usb_override;
}