/* * Copyright (c) 2008 Swedish Institute of Computer Science * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of the copyright holders nor the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** * \file * * \brief * This file operates the menu flow chart described in the readme * notes. This will create the proper commands needed to control the 1284p. * * \author * Mike Vidales mavida404@gmail.com * */ #include #include #include "menu.h" #include "main.h" #include "lcd.h" #include "key.h" #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; bool timeout_flag; bool temp_flag; bool temp_mode; bool auto_temp=true; /** * \addtogroup lcd * \{ */ /*---------------------------------------------------------------------------*/ /** * \brief This function will convert decimal to ascii. * * \param val Decimal value to convert. * \param str Address location to store converted value. */ void dectoascii(uint8_t val, char *str) { *(str+1) = (val % 10) + '0'; *str = (val / 10) + '0'; } /*---------------------------------------------------------------------------*/ /** * \brief This will convert a signed decimal number to ASCII. * * \param n Signed number * \param str Pointer to store converted value. * * \return *p Address of stored conversion. */ uint8_t *signed_dectoascii(int16_t n, uint8_t *str) { uint8_t * p = str; uint8_t neg = 0; if(n < 0){ neg = 1; n = -n; } *p-- = 0x00; /* Determine the unit of conversion. */ if(temp_mode == TEMP_UNIT_CELCIUS){ /* Add ASCII C to string. */ *p-- = 'C'; } else{ /* Add ASCII F to string. */ *p-- = 'F'; } /* Add a space before unit symbol. */ *p-- = ' '; /* For zero, just print zero. */ if (!n){ *p = '0'; return p; } while (n){ *p-- = (n%10) + '0'; n/= 10; } if (neg){ *p-- = '-'; } return ++p; } /*---------------------------------------------------------------------------*/ /** * \brief This will check for DEBUG mode after power up. */ void eeprom_init(void) { uint8_t val; if(0xFF == eeprom_read_byte(EEPROM_DEBUG_ADDR)){ /* Disable - Reverse logic. */ val = 1; menu_debug_mode(&val); } else{ /* Enable - Reverse logic. */ val = 0; menu_debug_mode(&val); } } /*---------------------------------------------------------------------------*/ /** * \brief This will start a sleep operation. * * \param val Used for remembering the new menu to display after a wakeup. */ void menu_run_sleep(uint8_t *val) { /* Turn off LED, LCD, ADC, Timer 1, SPI */ led_off(); lcd_deinit(); key_deinit(); PRR |= (1 << PRTIM1) | (1 << PRSPI); /* 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 UART when transmission is complete */ while(!(UCSR0A & (1 << TXC0))); _delay_us(10000); //deinit trash clears done flag on 1284p uart_deinit(); /* Go to sleep until button is pushed */ sleep_now(0); /* Yawn, waking up, turn on LCD with Raven Logo */ lcd_init(); lcd_symbol_set(LCD_SYMBOL_RAVEN); /* Disable interrupts before powering everything up */ cli(); key_init(); PRR &= ~((1 << PRTIM1) | (1 << PRSPI)); uart_init(); /* 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) ; if (is_button()){ get_button(); } } /*---------------------------------------------------------------------------*/ /** * \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<