diff --git a/firmware/main.c b/firmware/main.c index 8cb8ce1..2ba1cd8 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -62,6 +62,8 @@ volatile bool power_flag = false; /* a change in the power or fan */ volatile bool ir_flag = false; /* to process a burst */ volatile bool pwm_flag = false; /* to trigger a PWM tick */ volatile bool channel_flag = false; /* indicate a change in the channel PWM values */ +volatile bool learn_flag = false; /* learn an IR command for an action */ +enum IR_ACTIONS to_learn = IR_ACTION_END; /* IR action to learn */ /* UART receive interrupt */ ISR(USART_RX_vect) { @@ -208,6 +210,115 @@ void ioinit(void) sei(); /* enable interrupts */ } +void help(void) +{ + printf("commands:\n"\ + "\thelp display this help\n"\ + "\tpower show power state\n"\ + "\tpower on switch power on\n"\ + "\tpower off switch power off\n"\ + "\tfan show fan speed\n"\ + "\tch X Y show channel [1-2].[1-5] brightness\n"\ + "\tch X Y Z set channel [1-2].[1-5] brightness [0-255]\n"\ + "\tir learn power learn the IR command to power on/off\n"\ + "\tir learn mode learn the IR command to change between modes\n"\ + "\tir learn brightness up learn the IR command to increase brightness\n"\ + "\tir learn brightness down learn the IR command to decrease brightness\n"\ + "\tir learn channel next learn the IR command to select next channel\n"\ + "\tir learn channel previous learn the IR command to select previous channel\n"\ + ); +} + +void uart_action(char* str) +{ + const char* delimiter = " "; + char* word = strtok(str,delimiter); + if (!word) { + goto error; + } + if (0==strcmp(word,"help")) { + help(); + } else if (0==strcmp(word,"power")) { + word = strtok(NULL,delimiter); + if (!word) { + if (PINB&(1<1) { + input[command_i-1] = '\0'; + uart_action(input); + } + input_i = command_i = 0; + } uart_flag = false; } /* handle power state */ @@ -308,7 +431,18 @@ int main(void) ir_repeat = 0; } if (ir_repeat==0 || ir_repeat>3) { - ir_action(ir_data.address,ir_data.command); + if (learn_flag) { + if (to_learn0) { - OCR0A--; - } - printf("decreasing LED: %u\n",OCR0A); - break; - case '+': - if (OCR0A<0xff) { - OCR0A++; - } - printf("increasing LED: %u\n",OCR0A); - break; - case 't': - if (tachometer) { - uint16_t prescale = TIMER2_PRESCALE[TCCR2B&((1<