Dreamforce Heroku Sample mbed application for the FRDM-K64F. This application uses SocketIO to connect and communicate with Heroku.

Dependencies:   BufferedSerial C12832 EthernetInterface HTTPClient-SSL LM75B MMA7660 SocketIO-k64f WebSocketClient-ThermostatDemo mbed-rtos mbed picojson

Fork of df-2013-minihack-thermostat-complete by MBED_DEMOS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Thermostat.h Source File

Thermostat.h

00001 /* Thermostat.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_H_
00021 #define THERMOSTAT_H_
00022 
00023 // platform support
00024 #include "mbed.h"
00025 
00026 // Support for std args
00027 #include <stdarg.h>
00028 
00029 // maximum size of a displayed message
00030 #define MAX_MESSAGE_LENGTH  256
00031 
00032 class Thermostat {
00033     public:
00034         // Default Constructor
00035         Thermostat();
00036         
00037         // Destructor
00038         ~Thermostat();
00039         
00040         // invoke the demo
00041         void runDemo();
00042               
00043     private: 
00044         int getErrorState();
00045         char *createDeregisterJSON(char *buffer);
00046         char *createJSON(char *buffer, float temp, float latitude, float longitude, float bat);
00047        
00048         float getTemperature();
00049         float getBatteryLevel();
00050         
00051         void resetDeviceStatus();
00052         int translateLEDStatus(const char *status, int current);
00053         void parseAndActOnControlMessage(char *json);
00054         void processControlMessage();
00055         void sendDeregisterMessage();
00056         void sendStatus();
00057         void sendStatus(float temp, int battery);
00058         void sendStatus(float temp, float latitude, float longitude, float bat);
00059         
00060         char *receiveFromWSService(char *buffer);
00061          
00062         void parseSessionKey(char *response, char *sessionkey);
00063         char *performSocketIOHandshake(char *sessionkey);
00064         bool connectWebSocketService();
00065         bool connectEthernet();
00066         
00067         void gracefullyDisconnect();
00068         void mainLoop();
00069         
00070         // Thermostat-LEDUtils.cpp
00071         void setAllLEDs(int state);
00072         void resetAllLEDs();
00073         void blinkAllLEDs();
00074         void updateRGBLED(float H,float S, float V);
00075         void setRGBLED(double color, double bright);       
00076         void turnRGBLEDRed();
00077         void turnRGBLEDGreen();
00078         void turnRGBLEDBlue();
00079         void blinkLED(DigitalOut led);
00080         void blinkTransportTxLED();
00081         void blinkTransportRxLED();
00082         
00083         // Thermostat-BaseUtils.cpp
00084         void logMessage(bool do_lcd);
00085         void display(const char *format, ...);
00086         void display_lcd(const char *format, ...);
00087         void displayTextMessage(const char *format, ...);
00088         
00089         // Stubs
00090         void updateCoordinates();
00091         void initLocation();
00092         
00093         // private members
00094         float  m_latitude;
00095         float  m_longitude;
00096         float  m_temperature;
00097         float  m_battery;
00098         char  *m_status;
00099         bool   m_error_state;
00100         double m_rgbLEDColor;
00101         double m_rgbLEDBright;
00102         char   m_display_message[MAX_MESSAGE_LENGTH+1];
00103 };
00104 
00105 #endif /* THERMOSTAT_H_ */