add master mode
This commit is contained in:
parent
eaa3447fad
commit
90925ea959
27
main.c
27
main.c
|
@ -285,6 +285,8 @@ static void nec_transmit(uint32_t code)
|
|||
|
||||
void main(void)
|
||||
{
|
||||
bool master = false; // if we are not a slave badge, but master controller
|
||||
|
||||
sim(); // disable interrupts (while we reconfigure them)
|
||||
|
||||
CLK->CKDIVR.fields.HSIDIV = CLK_CKDIVR_HSIDIV_DIV0; // don't divide internal 16 MHz clock
|
||||
|
@ -454,7 +456,7 @@ void main(void)
|
|||
putc('t');
|
||||
action = true; // redo main loop
|
||||
}
|
||||
if (time_count > 488UL * REST_TIME) {
|
||||
if (time_count > 488UL * REST_TIME && !master) {
|
||||
puts("rest\r\n");
|
||||
time_count = 0; // reset counter
|
||||
LED_UV_PORT->ODR.reg &= ~LED_UV_PIN; // switch UV LED off
|
||||
|
@ -484,6 +486,29 @@ void main(void)
|
|||
timer_ir_in(); // go back to IR capture
|
||||
puts("\r\ncode transmitted\r\n");
|
||||
}
|
||||
} else if (uart_used >= 7 && 'M' == uart_cmd[0]) { // switch to master
|
||||
bool code_valid = true; // verify it it's really a hex string
|
||||
uint32_t code = 0x02000000; // parsed master code
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
uint32_t n = a2n(uart_cmd[1 + i]);
|
||||
if (n > 0xf) {
|
||||
code_valid = false;
|
||||
break;
|
||||
} else {
|
||||
code |= (n << ((i + 1) * 4));
|
||||
}
|
||||
}
|
||||
if (code_valid) {
|
||||
rgb[0] = code >> 8; // save color
|
||||
rgb[1] = code >> 16; // save color
|
||||
rgb[2] = code >> 24; // save color
|
||||
led_rgb(rgb); // set color
|
||||
nec_transmit(code); // transmit code
|
||||
if (!master) {
|
||||
master = true; // switch to master mode
|
||||
puts("\r\nmaster set\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
uart_used = 0; // reset buffer
|
||||
} else if (uart_used < ARRAY_LENGTH(uart_cmd)) {
|
||||
|
|
Loading…
Reference in New Issue