soc-2
Dependencies: PinDetect libmDot mbed-rtos mbed
Fork of thermostat_fan_demo--sensor by
Revision 5:838b35b0a3c3, committed 2015-10-24
- Comitter:
- socie123
- Date:
- Sat Oct 24 06:03:09 2015 +0000
- Parent:
- 4:d823cd66d8f8
- Commit message:
- soc-2
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed-rtos.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 23 21:24:35 2015 +0000
+++ b/main.cpp Sat Oct 24 06:03:09 2015 +0000
@@ -13,34 +13,34 @@
#include "PinDetect.h"
mDot* dot;
-Ticker ledTick;
-Ticker temperatureMonitorTick;
+//Ticker ledTick;
+//Ticker temperatureMonitorTick;
Ticker periodicSendTick;
-PinDetect up_button(PB_1); //A0 on Arduino base shield
-PinDetect down_button(PB_0); //A1 on Arduino base shield
+//PinDetect up_button(PB_1); //A0 on Arduino base shield
+//PinDetect down_button(PB_0); //A1 on Arduino base shield
AnalogIn temperatureSensor(PC_1); //A2 on Arduino base shield
-DigitalOut transmitLED(LED1);
-DigitalOut buttonPressLED(PA_1); //D6 on Arduino base shield
+//DigitalOut transmitLED(LED1);
+//DigitalOut buttonPressLED(PA_1); //D6 on Arduino base shield
// Configuration variables
-static std::string config_network_name = "your_name_here";
-static std::string config_network_pass = "your_key_here";
+static std::string config_network_name = "watchlink";
+static std::string config_network_pass = "watchlink";
static uint8_t config_frequency_sub_band = 1;
//Global Variables
-static uint16_t setPoint = 21; //21 C is standard room temp
+//static uint16_t setPoint = 21; //21 C is standard room temp
static volatile bool timeToReadTemperature = true;
static volatile bool dataChanged = true;
-static volatile bool thermostatActivated = false;
-static uint16_t sentSetPoint;
+//static volatile bool thermostatActivated = false;
+//static uint16_t sentSetPoint;
//Function prototypes
-void ledTock();
+//void ledTock();
void periodicSendTock();
-void temperatureMonitorTock();
-void up_button_callback();
-void down_button_callback();
+//void temperatureMonitorTock();
+//void up_button_callback();
+//void down_button_callback();
void printError(mDot* dot, int32_t returnCode);
void printVersion();
bool setFrequencySubBand(uint8_t subBand);
@@ -55,7 +55,7 @@
int main()
{
//Start LED startup sequence
- ledTick.attach(&ledTock, 0.1);
+ //ledTick.attach(&ledTock, 0.1);
printf("\r\n\r\n");
printf("=====================================\r\n");
@@ -79,27 +79,27 @@
while (!joinNetwork()) { wait(2); dot->resetNetworkSession(); }
- // Stop LED startup sequence & configure them for operation
- ledTick.detach();
- transmitLED = 1;
- buttonPressLED = 1;
+ //Stop LED startup sequence & configure them for operation
+ //ledTick.detach();
+ //transmitLED = 1;
+ //buttonPressLED = 1;
// Configure timers
- periodicSendTick.attach(&periodicSendTock, 5*60);
- temperatureMonitorTick.attach(&temperatureMonitorTock, 0.15);
+ periodicSendTick.attach(&periodicSendTock, 1*60);
+ //temperatureMonitorTick.attach(&temperatureMonitorTock, 0.15);
// Setup Interrupt callback function
- up_button.attach_deasserted(&up_button_callback);
- down_button.attach_deasserted(&down_button_callback);
+ //up_button.attach_deasserted(&up_button_callback);
+ //down_button.attach_deasserted(&down_button_callback);
// Start sampling buttons using interrupts
- up_button.setSampleFrequency();
- down_button.setSampleFrequency();
+ //up_button.setSampleFrequency();
+ //down_button.setSampleFrequency();
uint16_t temperature = 0;
- while (1) {
- if (timeToReadTemperature) {
- uint16_t B = 4250; //B value of the thermistor
+ //while (1) {
+ //if (timeToReadTemperature) {
+ uint16_t B = 4100; //B value of the thermistor
uint16_t analogReading;
float resistance;
@@ -111,73 +111,47 @@
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;
//printf("read: %d, res: %d, temp: %d,set: %d\r\n", analogReading, (uint16_t)resistance, temperature, setPoint);
- if (!thermostatActivated && temperature > setPoint) {
- thermostatActivated = true;
- dataChanged = true;
- }
- else if (thermostatActivated && temperature < setPoint) {
- thermostatActivated = false;
- dataChanged = true;
- }
+ //if (!thermostatActivated && temperature > setPoint) {
+ //thermostatActivated = true;
+ //dataChanged = true;
+ //}
+ //else if (thermostatActivated && temperature < setPoint) {
+ //thermostatActivated = false;
+ //dataChanged = true;
+ //}
- timeToReadTemperature = false;
- }
+ //timeToReadTemperature = false;
+ //}
+
+ dataChanged = true;
+
if (dataChanged) {
+
char latestData[100];
- transmitLED = 1;
- sentSetPoint = setPoint;
- sprintf(latestData, "temp: %d,set: %d", temperature, sentSetPoint);
+ //transmitLED = 1;
+ // sentSetPoint = setPoint;
+ sprintf(latestData, "temp: %d", temperature);
printf("%s\r\n", latestData);
if (send(latestData)) {
dataChanged = false;
}
- transmitLED = 0;
+ //transmitLED = 0;
}
- }
+ //}
+ //return true;
}
-
-void ledTock() {
- transmitLED = !transmitLED;
- buttonPressLED = !buttonPressLED;
+void printVersion()
+{
+ printf("%s\r\n\r\n", dot->getId().c_str());
}
void periodicSendTock() {
dataChanged = true;
}
-void temperatureMonitorTock() {
- timeToReadTemperature = true;
-
- if (sentSetPoint != setPoint) {
- dataChanged = true;
- }
-}
-
-void up_button_callback() {
- if (setPoint < 51) {
- setPoint += 1;
- buttonPressLED = !buttonPressLED;
- dataChanged = true;
- }
-}
-
-void down_button_callback() {
- if (setPoint > 0) {
- setPoint -= 1;
- buttonPressLED = !buttonPressLED;
- dataChanged = true;
- }
-}
-
-
-void printVersion()
-{
- printf("%s\r\n\r\n", dot->getId().c_str());
-}
-
bool setFrequencySubBand(uint8_t subBand)
{
int32_t returnCode;
@@ -273,5 +247,5 @@
{
std::string error = mDot::getReturnCodeString(returnCode) + " - " + dot->getLastError();
printf("%s\r\n", error.c_str());
-}
+ }
--- a/mbed-rtos.lib Fri Oct 23 21:24:35 2015 +0000 +++ b/mbed-rtos.lib Sat Oct 24 06:03:09 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#ef0a22cdf839 +http://mbed.org/users/mbed_official/code/mbed-rtos/#12552ef4e980
