From 555fab59a3935f3a8f05fc66c8f389a64c4a8e6f Mon Sep 17 00:00:00 2001 From: dak664 Date: Sat, 18 Dec 2010 20:35:58 +0000 Subject: [PATCH] Add SLEEP and DOZE functions to the menu. Give serial commands the same defines as in the 1284p for grepping. --- platform/avr-ravenlcd/main.h | 3 ++ platform/avr-ravenlcd/menu.c | 90 ++++++++++++++++++++++++------- platform/avr-ravenlcd/menu.h | 2 + platform/avr-ravenlcd/raven3290.c | 42 +++++++++++---- platform/avr-ravenlcd/sleep.c | 82 +++++++++++++++++++++------- platform/avr-ravenlcd/sleep.h | 2 +- platform/avr-ravenlcd/temp.h | 2 +- platform/avr-ravenlcd/uart.c | 20 ++++--- platform/avr-ravenlcd/uart.h | 19 +------ 9 files changed, 185 insertions(+), 77 deletions(-) diff --git a/platform/avr-ravenlcd/main.h b/platform/avr-ravenlcd/main.h index e1f4dd3c3..e41ec464f 100644 --- a/platform/avr-ravenlcd/main.h +++ b/platform/avr-ravenlcd/main.h @@ -57,6 +57,8 @@ #define SEND_TEMP (0x80) #define SEND_PING (0x81) #define SEND_ADC2 (0x82) +#define SEND_SLEEP (0x83) +#define SEND_WAKE (0x84) /** \} */ /** \name These are the Radio to GUI binary commands. */ @@ -64,6 +66,7 @@ #define REPORT_PING (0xC0) #define REPORT_PING_BEEP (0xC1) #define REPORT_TEXT_MSG (0xC2) +#define REPORT_WAKE (0xC3) /** \} */ diff --git a/platform/avr-ravenlcd/menu.c b/platform/avr-ravenlcd/menu.c index 79a19e48a..843d254a6 100644 --- a/platform/avr-ravenlcd/menu.c +++ b/platform/avr-ravenlcd/menu.c @@ -40,6 +40,7 @@ */ #include +#include #include "menu.h" #include "main.h" #include "lcd.h" @@ -47,7 +48,9 @@ #include "uart.h" #include "sleep.h" #include "temp.h" +#include "beep.h" +uint8_t sleep_count; uint8_t ping_count; uint8_t ping_response; bool ping_mode; @@ -156,40 +159,43 @@ eeprom_init(void) /** * \brief This will start a sleep operation. * - * \param val Used for rembering the new menu to display after a wakeup. + * \param val Used for remembering the new menu to display after a wakeup. */ void menu_run_sleep(uint8_t *val) { - /* Turn off LED */ + /* Turn off LED, LCD, ADC, Timer 1, SPI */ led_off(); - - /* Turn off Timer 1, SPI, uart */ + lcd_deinit(); + key_deinit(); PRR |= (1 << PRTIM1) | (1 << PRSPI); - /* Turn off the LCD display for sleeping */ - lcd_deinit(); + /* Tell the 1284P to turn off the radio and sleep */ + sleep_count=0; + uart_serial_send_frame(SEND_SLEEP, 1, (uint8_t *)&sleep_count); - /* Turn off A/D converter */ - key_deinit(); + /* Turn off UART when transmission is complete */ + while(!(UCSR0A & (1 << TXC0))); + _delay_us(10000); //deinit trash clears done flag on 1284p + uart_deinit(); - /* Go to sleep now */ - sleep_now(); + /* Go to sleep until button is pushed */ + sleep_now(0); - /* Wake up LCD Display */ + /* Yawn, waking up, turn on LCD with Raven Logo */ lcd_init(); - - /* Tell user we're waking up */ - lcd_puts_P(PSTR("WAKE---")); - - /* Turn on Raven logo */ lcd_symbol_set(LCD_SYMBOL_RAVEN); - /* Wake up ADC */ + /* Disable interrupts before powering everything up */ + cli(); key_init(); + PRR &= ~((1 << PRTIM1) | (1 << PRSPI)); + uart_init(); - /* Wake up radio */ + /* Enable interrupts, Wake up 1284p and radio */ + sei(); sleep_wakeup(); +// uart_init();//flush receive buffer /* Wait for buttons up */ while (key_state_get() != KEY_NO_KEY) @@ -197,9 +203,53 @@ menu_run_sleep(uint8_t *val) if (is_button()){ get_button(); } +} +/*---------------------------------------------------------------------------*/ - /* Print last menu tex */ - lcd_puts_P((char *)&val); +/** + * \brief This will start a sleep with wakes for temperature measurement and web requests. + * + * \param val Used for remembering the new menu to display after a wakeup. +*/ +void +menu_run_doze(uint8_t *val) +{ + /* Turn off LED, LCD */ + led_off(); + lcd_deinit(); + + /* Debounce */ + while (key_state_get() != KEY_NO_KEY) ; + + /* Stay in doze loop until button is pressed*/ + while (ENTER_PORT & (1<SEND_TEMP - (0x80) * -# SEND_PING - (0x81) + *...-# SEND_SLEEP- (0x82) + *...-# SEND_WAKE - (0x83) * * The following commands are used to update the 3290p. - * -# REPORT_PING - (0xC0) + * -# REPORT_PING - (0xC0) * -# REPORT_PING_BEEP - (0xC1) - * -# REPORT_TEXT_MSG - (0xC2) + * -# REPORT_TEXT_MSG - (0xC2) + * -# REPORT_WAKE - (0xC3) */ /* * Copyright (c) 2008 Swedish Institute of Computer Science @@ -170,7 +173,9 @@ const char menu_text12[]; const char menu_text13[]; const char menu_text14[]; const char menu_text15[]; -const tmenu_item menu_items[16]; +const char menu_text16[]; +const char menu_text17[]; +const tmenu_item menu_items[18]; #else /* !DOXYGEN */ /** \brief This is the menu text in Flash. See menu_items[] for menu operation. */ const char menu_text0[] PROGMEM = "CONTIKI"; @@ -189,6 +194,8 @@ const char menu_text12[] PROGMEM = "DBG ON"; const char menu_text13[] PROGMEM = "DBG OFF"; const char menu_text14[] PROGMEM = "SENT"; const char menu_text15[] PROGMEM = "SENDING"; +const char menu_text16[] PROGMEM = "SLEEP"; +const char menu_text17[] PROGMEM = "DOZE"; /*---------------------------------------------------------------------------*/ @@ -200,10 +207,10 @@ const char menu_text15[] PROGMEM = "SENDING"; * * { text, left, right, up, down, *state, tmenufunc enter_func} */ -const PROGMEM tmenu_item menu_items[16] = { +const PROGMEM tmenu_item menu_items[18] = { {menu_text0, 0, 2, 0, 0, 0, 0 }, {menu_text1, 0, 2, 0, 0, 0, 0 }, - {menu_text2, 0, 3, 11, 4, 0, menu_ping_request }, + {menu_text2, 0, 3, 17, 4, 0, menu_ping_request }, {menu_text3, 2, 2, 2, 2, 0, 0 }, {menu_text4, 0, 5, 2, 11, 0, 0 }, {menu_text5, 4, 6, 8, 8, 0, 0 }, @@ -212,11 +219,15 @@ const PROGMEM tmenu_item menu_items[16] = { {menu_text8, 4, 9, 5, 5, 0, 0 }, {menu_text9, 8, 14, 10, 10, (uint8_t*)0, menu_prepare_temp }, {menu_text10, 8, 15, 9, 9, (uint8_t*)1, menu_prepare_temp }, - {menu_text11, 0, 12, 4, 2, 0, 0 }, + {menu_text11, 0, 12, 4, 16, 0, 0 }, {menu_text12, 11, 11, 13, 13, (uint8_t*)1, menu_debug_mode }, {menu_text13, 11, 11, 12, 12, (uint8_t*)0, menu_debug_mode }, {menu_text14, 9, 14, 14, 14, 0, 0 }, {menu_text15, 10, 15, 15, 15, 0, 0 }, + // {menu_text16, 0, 16, 11, 17, (uint8_t*)&menu_text16, menu_run_sleep }, + // {menu_text17, 0, 17, 16, 2, (uint8_t*)&menu_text17, menu_run_doze }, + {menu_text16, 0, 16, 11, 17, (uint8_t*)1, menu_run_sleep },//display "sleep" on wake + {menu_text17, 0, 17, 16, 2, (uint8_t*)1, menu_run_doze },//display "doze" on wake }; #endif /* !DOXYGEN */ @@ -248,20 +259,31 @@ read_menu(uint8_t ndx) /*---------------------------------------------------------------------------*/ /** - * \brief This will toggle the CONTIKI and 6LOWPAN LCD menus only in the main - * menu position. + * \brief This will toggle the CONTIKI and 6LOWPAN LCD menus in the main + * menu position, unless alternate text has been sent from the 1284p. + * The other menus will display normally. */ +char top_menu_text[20]; void check_main_menu(void) { +uint8_t showtop=0; + if(menu.text == menu_text0){ read_menu(1); - lcd_puts_P(menu.text); + showtop=1; } else if(menu.text == menu_text1){ read_menu(0); - lcd_puts_P(menu.text); + showtop=1; } + if (showtop) { + if (top_menu_text[0]) { + lcd_puts(top_menu_text); + return; + } + } + lcd_puts_P(menu.text); } /*---------------------------------------------------------------------------*/ diff --git a/platform/avr-ravenlcd/sleep.c b/platform/avr-ravenlcd/sleep.c index c9d07106b..ecdec7df6 100644 --- a/platform/avr-ravenlcd/sleep.c +++ b/platform/avr-ravenlcd/sleep.c @@ -41,9 +41,14 @@ #include #include #include +#include #include +#include "main.h" #include "sleep.h" #include "uart.h" +#include "key.h" +#include "timer.h" +#include "lcd.h" //temp /** * \addtogroup lcd @@ -55,53 +60,79 @@ /** * \brief Prepares for and executes sleep. This function sets up the * processor to enter sleep mode, and to wake up when the joystick - * button (PE2/PCINT2) is pressed. + * button (PE2/PCINT2) is pressed or after the specified interval. + * + * \param howlong Seconds to sleep, 0=until button pushed */ void -sleep_now(void) +sleep_now(int howlong) { - /* Disable watchdog */ + /* Disable watchdog (not currently used elsewhere) */ wdt_disable(); /* Setup sleep mode */ - set_sleep_mode(SLEEP_MODE_PWR_DOWN); + if (howlong==0) { + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + MCUCR |= (1< 10){ + if (length > sizeof(payload)){ /* invalid length */ return; } @@ -402,7 +405,7 @@ uart_serial_rcv_frame(uint8_t wait_for_ack) return uart_timeout_msg(7); } - /* Now print something based on rx'd frame */ + /* Process the received command */ switch (cmd){ case REPORT_PING: /* @@ -431,15 +434,18 @@ uart_serial_rcv_frame(uint8_t wait_for_ack) beep(); lcd_symbol_clr(LCD_SYMBOL_BELL); break; + case REPORT_TEXT_MSG: + /* Copy text message to menu buffer and fall through to beep */ + /* Prezero in case no string terminator in command */ + for (i=0;i