From 0d2784f3b4e79a8c10ef3ceae9a9957aaac803f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 19 Oct 2013 22:52:50 +0200 Subject: [PATCH] mode added to uart actions --- firmware/main.c | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 3cc9ab8..f162d1e 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -42,14 +42,16 @@ const char help_03[] PROGMEM = "\tpower show power state\n" const char help_04[] PROGMEM = "\tpower on switch power on\n"; const char help_05[] PROGMEM = "\tpower off switch power off\n"; const char help_06[] PROGMEM = "\tfan show fan speed\n"; -const char help_07[] PROGMEM = "\tch X Y show channel [1-2].[1-5] brightness\n"; -const char help_08[] PROGMEM = "\tch X Y Z set channel [1-2].[1-5] brightness [0-255]\n"; -const char help_09[] PROGMEM = "\tir learn power learn the IR command to power on/off\n"; -const char help_10[] PROGMEM = "\tir learn mode learn the IR command to change between modes\n"; -const char help_11[] PROGMEM = "\tir learn brightness up learn the IR command to increase brightness\n"; -const char help_12[] PROGMEM = "\tir learn brightness down learn the IR command to decrease brightness\n"; -const char help_13[] PROGMEM = "\tir learn channel next learn the IR command to select next channel\n"; -const char help_14[] PROGMEM = "\tir learn channel previous learn the IR command to select previous channel\n"; +const char help_07[] PROGMEM = "\tmode show current mode\n"; +const char help_08[] PROGMEM = "\tmode N select mode\n"; +const char help_09[] PROGMEM = "\tch X Y show channel [1-2].[1-5] brightness\n"; +const char help_10[] PROGMEM = "\tch X Y Z set channel [1-2].[1-5] brightness [0-255]\n"; +const char help_11[] PROGMEM = "\tir learn power learn the IR command to power on/off\n"; +const char help_12[] PROGMEM = "\tir learn mode learn the IR command to change between modes\n"; +const char help_13[] PROGMEM = "\tir learn brightness up learn the IR command to increase brightness\n"; +const char help_14[] PROGMEM = "\tir learn brightness down learn the IR command to decrease brightness\n"; +const char help_15[] PROGMEM = "\tir learn channel next learn the IR command to select next channel\n"; +const char help_16[] PROGMEM = "\tir learn channel previous learn the IR command to select previous channel\n"; PGM_P const help_table[] PROGMEM = { help_00, help_01, @@ -66,6 +68,8 @@ PGM_P const help_table[] PROGMEM = { help_12, help_13, help_14, + help_15, + help_16 }; volatile uint8_t* PORTS[CHANNELS_1+CHANNELS_2] = {&PORTC,&PORTC,&PORTC,&PORTC,&PORTC,&PORTD,&PORTD,&PORTD,&PORTD,&PORTD}; @@ -456,6 +460,32 @@ void uart_action(char* str) } else { printf("fan is off (or not detected)\n"); } + reset_settings(); + /* reset using watchdog */ + do { + wdt_enable(WDTO_15MS); + for(;;) {} + } while(0); + } else if (0==strcmp(word,"mode")) { + word = strtok(NULL,delimiter); + if (!word) { + printf("%u/%u\n",mode+1,MODES); + } else { + /* expecting one digit mode N */ + if (strlen(word)!=1) { + goto error; + } + /* expecting mode 1-MODES */ + if (word[0]<'1') { + goto error; + } + uint8_t mode_temp = word[0]-'1'; + if (mode_temp>MODES) { + goto error; + } + mode = mode_temp; + channel_flag = true; + } } else if (0==strcmp(word,"ir")) { word = strtok(NULL,delimiter); if (0==strcmp(word,"learn")) {