Dreamforce 2013 MiniHack Thermostat Challenge - completed code

Dependencies:   C12832_lcd EthernetInterface-ansond-patched HTTPClient-thermostat-remotes LM75B MMA7660 SocketIO WebSocketClient-ThermostatDemo mbed-rtos mbed picojson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Thermostat-BaseUtils.h Source File

Thermostat-BaseUtils.h

00001 /* Thermostat-BaseUtils.h */
00002 /* Copyright (C) 2013 mbed.org, MIT License
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00005  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00006  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00007  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in all copies or
00011  * substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00014  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00015  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019  
00020 #ifndef THERMOSTAT_BASEUTILS_H_
00021 #define THERMOSTAT_BASEUTILS_H_
00022 
00023 // AppBoard LCD Support
00024 #include "C12832_lcd.h"
00025 C12832_LCD lcd;
00026 
00027 // Serial Console Support (main.cpp)
00028 extern Serial pc;
00029 
00030 // log messages to appropriate outputs
00031 void Thermostat::logMessage(bool do_lcd) {    
00032     // print to LCD panel
00033     if (do_lcd) {
00034         lcd.cls();
00035         lcd.locate(0,0);
00036         lcd.printf(this->m_display_message);
00037     }
00038     else {
00039         // print to serial console
00040         pc.printf(this->m_display_message);
00041         pc.printf("\r\n");
00042     }
00043     
00044     // wait a bit so that the message can be read
00045     wait(0.5);
00046 }
00047 
00048 // display output
00049 void Thermostat::display(const char *format, ...) {   
00050     memset(this->m_display_message,'\0',MAX_MESSAGE_LENGTH+1);
00051     va_list args;
00052     va_start(args, format);
00053     vsprintf(this->m_display_message, format, args);
00054     va_end(args);
00055     this->logMessage(false);
00056 }
00057 
00058 // display output
00059 void Thermostat::display_lcd(const char *format, ...) {
00060     memset(this->m_display_message,'\0',MAX_MESSAGE_LENGTH+1);
00061     va_list args;
00062     va_start(args, format);
00063     vsprintf(this->m_display_message, format, args);
00064     va_end(args);
00065     this->logMessage(true);
00066 }
00067 
00068 // display text message output
00069 void Thermostat::displayTextMessage(const char *format, ...) {
00070     memset(this->m_display_message,'\0',MAX_MESSAGE_LENGTH+1);
00071     va_list args;
00072     va_start(args, format);
00073     vsprintf(this->m_display_message, format, args);
00074     va_end(args);
00075     this->logMessage(true);
00076     wait_ms(3000);              // add wait state so that we can see the message!
00077 }
00078 
00079 #endif // THERMOSTAT_BASEUTILS_H_