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

Committer:
ansond
Date:
Mon Nov 11 20:35:49 2013 +0000
Revision:
5:3ab657317bfa
Parent:
1:3faa003ad6e6
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:26c48388f725 1 /* Thermostat-BaseUtils.h */
ansond 0:26c48388f725 2 /* Copyright (C) 2013 mbed.org, MIT License
ansond 0:26c48388f725 3 *
ansond 0:26c48388f725 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:26c48388f725 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
ansond 0:26c48388f725 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:26c48388f725 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:26c48388f725 8 * furnished to do so, subject to the following conditions:
ansond 0:26c48388f725 9 *
ansond 0:26c48388f725 10 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:26c48388f725 11 * substantial portions of the Software.
ansond 0:26c48388f725 12 *
ansond 0:26c48388f725 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:26c48388f725 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:26c48388f725 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:26c48388f725 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:26c48388f725 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:26c48388f725 18 */
ansond 0:26c48388f725 19
ansond 0:26c48388f725 20 #ifndef THERMOSTAT_BASEUTILS_H_
ansond 0:26c48388f725 21 #define THERMOSTAT_BASEUTILS_H_
ansond 0:26c48388f725 22
ansond 0:26c48388f725 23 // AppBoard LCD Support
ansond 0:26c48388f725 24 #include "C12832_lcd.h"
ansond 0:26c48388f725 25 C12832_LCD lcd;
ansond 0:26c48388f725 26
ansond 0:26c48388f725 27 // Serial Console Support (main.cpp)
ansond 0:26c48388f725 28 extern Serial pc;
ansond 0:26c48388f725 29
ansond 0:26c48388f725 30 // log messages to appropriate outputs
ansond 0:26c48388f725 31 void Thermostat::logMessage(bool do_lcd) {
ansond 0:26c48388f725 32 // print to LCD panel
ansond 0:26c48388f725 33 if (do_lcd) {
ansond 0:26c48388f725 34 lcd.cls();
ansond 0:26c48388f725 35 lcd.locate(0,0);
ansond 0:26c48388f725 36 lcd.printf(this->m_display_message);
ansond 0:26c48388f725 37 }
ansond 0:26c48388f725 38 else {
ansond 0:26c48388f725 39 // print to serial console
ansond 0:26c48388f725 40 pc.printf(this->m_display_message);
ansond 0:26c48388f725 41 pc.printf("\r\n");
ansond 0:26c48388f725 42 }
ansond 0:26c48388f725 43
ansond 0:26c48388f725 44 // wait a bit so that the message can be read
ansond 0:26c48388f725 45 wait(0.5);
ansond 0:26c48388f725 46 }
ansond 0:26c48388f725 47
ansond 0:26c48388f725 48 // display output
ansond 0:26c48388f725 49 void Thermostat::display(const char *format, ...) {
ansond 0:26c48388f725 50 memset(this->m_display_message,'\0',MAX_MESSAGE_LENGTH+1);
ansond 0:26c48388f725 51 va_list args;
ansond 0:26c48388f725 52 va_start(args, format);
ansond 0:26c48388f725 53 vsprintf(this->m_display_message, format, args);
ansond 0:26c48388f725 54 va_end(args);
ansond 0:26c48388f725 55 this->logMessage(false);
ansond 0:26c48388f725 56 }
ansond 0:26c48388f725 57
ansond 0:26c48388f725 58 // display output
ansond 0:26c48388f725 59 void Thermostat::display_lcd(const char *format, ...) {
ansond 0:26c48388f725 60 memset(this->m_display_message,'\0',MAX_MESSAGE_LENGTH+1);
ansond 0:26c48388f725 61 va_list args;
ansond 0:26c48388f725 62 va_start(args, format);
ansond 0:26c48388f725 63 vsprintf(this->m_display_message, format, args);
ansond 0:26c48388f725 64 va_end(args);
ansond 0:26c48388f725 65 this->logMessage(true);
ansond 0:26c48388f725 66 }
ansond 0:26c48388f725 67
ansond 1:3faa003ad6e6 68 // display text message output
ansond 1:3faa003ad6e6 69 void Thermostat::displayTextMessage(const char *format, ...) {
ansond 1:3faa003ad6e6 70 memset(this->m_display_message,'\0',MAX_MESSAGE_LENGTH+1);
ansond 1:3faa003ad6e6 71 va_list args;
ansond 1:3faa003ad6e6 72 va_start(args, format);
ansond 1:3faa003ad6e6 73 vsprintf(this->m_display_message, format, args);
ansond 1:3faa003ad6e6 74 va_end(args);
ansond 1:3faa003ad6e6 75 this->logMessage(true);
ansond 1:3faa003ad6e6 76 wait_ms(3000); // add wait state so that we can see the message!
ansond 1:3faa003ad6e6 77 }
ansond 1:3faa003ad6e6 78
ansond 0:26c48388f725 79 #endif // THERMOSTAT_BASEUTILS_H_