[switch_uart] retrieve status

This commit is contained in:
Christophe De Wagter
2016-10-28 20:59:32 +02:00
parent aa3294cd4e
commit b2d836a2eb
3 changed files with 25 additions and 6 deletions

View File

@@ -15,12 +15,15 @@
<strip_button name="3" value="3" group="switching"/>
<strip_button name="4" value="4" group="switching"/>
</dl_setting>
<dl_setting var="switch_uart_status" min="0" step="1" max="255" module="switching/switch_uart">
</dl_setting>
</dl_settings>
</dl_settings>
</settings>
<header>
<file name="switch_uart.h"/>
</header>
<periodic fun="periodic_switch_uart()" period="0.05" autorun="TRUE"/>
<makefile>
<file name="switch_uart.c"/>
<configure name="SWITCH_UART_PORT" default="uart1" case="upper|lower"/>

View File

@@ -27,26 +27,39 @@
#include "mcu_periph/uart.h"
uint8_t switch_uart_channel = 0;
uint8_t switch_uart_status = 0;
static uint8_t drop_string[] = "<Drop_Paintball_Now";
#define DROP_STRINGLEN 19
void drop_ball(uint8_t number) {
for(uint8_t i = 0; i < DROP_STRINGLEN; i++)
void periodic_switch_uart(void)
{
while (uart_char_available(&SWITCH_UART_PORT)) {
uint8_t r = uart_getch(&SWITCH_UART_PORT);
switch_uart_status = r;
}
}
void drop_ball(uint8_t number)
{
for (uint8_t i = 0; i < DROP_STRINGLEN; i++) {
uart_put_byte(&SWITCH_UART_PORT, 0, drop_string[i]);
}
// Drop next ball
uint8_t last = '>';
// Or Drop a specific ball
if(number == 1) {
if (number == 1) {
last = '1';
} else if(number == 2) {
} else if (number == 2) {
last = '2';
} else if(number == 3) {
} else if (number == 3) {
last = '3';
} else if(number == 4) {
} else if (number == 4) {
last = '4';
}
uart_put_byte(&SWITCH_UART_PORT, 0, last);
}

View File

@@ -31,8 +31,11 @@
#define switch_uart_SwitchUartChannel(X) ({switch_uart_channel=X;drop_ball(switch_uart_channel); false;})
extern uint8_t switch_uart_channel;
extern uint8_t switch_uart_status;
extern void drop_ball(uint8_t number);
extern void periodic_switch_uart(void);
#endif