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.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_H_
ansond 0:26c48388f725 21 #define THERMOSTAT_H_
ansond 0:26c48388f725 22
ansond 0:26c48388f725 23 // platform support
ansond 0:26c48388f725 24 #include "mbed.h"
ansond 0:26c48388f725 25
ansond 0:26c48388f725 26 // Support for std args
ansond 0:26c48388f725 27 #include <stdarg.h>
ansond 0:26c48388f725 28
ansond 0:26c48388f725 29 // maximum size of a displayed message
ansond 0:26c48388f725 30 #define MAX_MESSAGE_LENGTH 100
ansond 0:26c48388f725 31
ansond 0:26c48388f725 32 class Thermostat {
ansond 0:26c48388f725 33 public:
ansond 0:26c48388f725 34 // Default Constructor
ansond 0:26c48388f725 35 Thermostat();
ansond 0:26c48388f725 36
ansond 0:26c48388f725 37 // Destructor
ansond 0:26c48388f725 38 ~Thermostat();
ansond 0:26c48388f725 39
ansond 0:26c48388f725 40 // invoke the demo
ansond 0:26c48388f725 41 void runDemo();
ansond 0:26c48388f725 42
ansond 0:26c48388f725 43 private:
ansond 0:26c48388f725 44 int getErrorState();
ansond 0:26c48388f725 45 char *createDeregisterJSON(char *buffer);
ansond 0:26c48388f725 46 char *createJSON(char *buffer, float temp, float latitude, float longitude, float bat);
ansond 0:26c48388f725 47
ansond 0:26c48388f725 48 float getTemperature();
ansond 0:26c48388f725 49 float getBatteryLevel();
ansond 0:26c48388f725 50
ansond 0:26c48388f725 51 void resetDeviceStatus();
ansond 0:26c48388f725 52 int translateLEDStatus(const char *status, int current);
ansond 0:26c48388f725 53 void parseAndActOnControlMessage(char *json);
ansond 0:26c48388f725 54 void processControlMessage();
ansond 0:26c48388f725 55 void sendDeregisterMessage();
ansond 0:26c48388f725 56 void sendStatus();
ansond 0:26c48388f725 57 void sendStatus(float temp, int battery);
ansond 0:26c48388f725 58 void sendStatus(float temp, float latitude, float longitude, float bat);
ansond 0:26c48388f725 59
ansond 0:26c48388f725 60 char *receiveFromWSService(char *buffer);
ansond 0:26c48388f725 61
ansond 0:26c48388f725 62 void parseSessionKey(char *response, char *sessionkey);
ansond 0:26c48388f725 63 char *performSocketIOHandshake(char *sessionkey);
ansond 0:26c48388f725 64 bool connectWebSocketService();
ansond 0:26c48388f725 65 bool connectEthernet();
ansond 0:26c48388f725 66
ansond 0:26c48388f725 67 void gracefullyDisconnect();
ansond 0:26c48388f725 68 void mainLoop();
ansond 0:26c48388f725 69
ansond 0:26c48388f725 70 // Thermostat-LEDUtils.cpp
ansond 0:26c48388f725 71 void setAllLEDs(int state);
ansond 0:26c48388f725 72 void resetAllLEDs();
ansond 0:26c48388f725 73 void blinkAllLEDs();
ansond 0:26c48388f725 74 void updateRGBLED(float H,float S, float V);
ansond 0:26c48388f725 75 void setRGBLED(double color, double bright);
ansond 0:26c48388f725 76 void turnRGBLEDRed();
ansond 0:26c48388f725 77 void turnRGBLEDGreen();
ansond 0:26c48388f725 78 void turnRGBLEDBlue();
ansond 0:26c48388f725 79 void blinkLED(DigitalOut led);
ansond 0:26c48388f725 80 void blinkTransportTxLED();
ansond 0:26c48388f725 81 void blinkTransportRxLED();
ansond 0:26c48388f725 82
ansond 0:26c48388f725 83 // Thermostat-BaseUtils.cpp
ansond 0:26c48388f725 84 void logMessage(bool do_lcd);
ansond 0:26c48388f725 85 void display(const char *format, ...);
ansond 0:26c48388f725 86 void display_lcd(const char *format, ...);
ansond 1:3faa003ad6e6 87 void displayTextMessage(const char *format, ...);
ansond 0:26c48388f725 88
ansond 0:26c48388f725 89 // Stubs
ansond 0:26c48388f725 90 void updateCoordinates();
ansond 0:26c48388f725 91 void initLocation();
ansond 0:26c48388f725 92
ansond 0:26c48388f725 93 // private members
ansond 0:26c48388f725 94 float m_latitude;
ansond 0:26c48388f725 95 float m_longitude;
ansond 0:26c48388f725 96 float m_temperature;
ansond 0:26c48388f725 97 float m_battery;
ansond 0:26c48388f725 98 char *m_status;
ansond 0:26c48388f725 99 bool m_error_state;
ansond 0:26c48388f725 100 double m_rgbLEDColor;
ansond 0:26c48388f725 101 double m_rgbLEDBright;
ansond 0:26c48388f725 102 char m_display_message[MAX_MESSAGE_LENGTH+1];
ansond 0:26c48388f725 103 };
ansond 0:26c48388f725 104
ansond 0:26c48388f725 105 #endif /* THERMOSTAT_H_ */