Merge pull request #230 from tbowmo/development

Development
This commit is contained in:
Henrik Ekblad
2015-10-22 15:48:29 +02:00
@@ -31,10 +31,15 @@
*
*
* Version 1.3 - Thomas Bowman Mørch
* Improved transmission logic, eliminating spurious transmissions (when temperatuere / humidity fluctuates 1 up and down between measurements)
*
* Improved transmission logic, eliminating spurious transmissions (when temperatuere / humidity fluctuates 1 up and down between measurements)
* Added OTA boot mode, need to hold A1 low while applying power. (uses slightly more power as it's waiting for bootloader messages)
*
* Version 1.4 - Thomas Bowman Mørch
*
* Corrected division in the code deciding whether to transmit or not, that resulted in generating an integer. Now it's generating floats as expected.
* Simplified detection for OTA bootloader, now detecting if MY_OTA_FIRMWARE_FEATURE is defined. If this is defined sensebender automaticly waits 300mS after each transmission
* Moved Battery status messages, so they are transmitted together with normal sensor updates (but only every 60th minute)
*
*/
// Enable debug prints to serial monitor
@@ -61,7 +66,7 @@
// Uncomment the line below, to transmit battery voltage as a normal sensor value
//#define BATT_SENSOR 199
#define RELEASE "1.3"
#define RELEASE "1.4"
#define AVERAGES 2
@@ -88,7 +93,6 @@
// Pin definitions
#define TEST_PIN A0
#define OTA_ENABLE A1
#define LED_PIN A2
#define ATSHA204_PIN 17 // A3
@@ -111,7 +115,6 @@ int measureCount = 0;
int sendBattery = 0;
boolean isMetric = true;
boolean highfreq = true;
boolean ota_enabled = false;
boolean transmission_occured = false;
// Storage of old measurements
@@ -142,18 +145,11 @@ void setup() {
digitalWrite(TEST_PIN, HIGH); // Enable pullup
if (!digitalRead(TEST_PIN)) testMode();
pinMode(OTA_ENABLE, INPUT);
digitalWrite(OTA_ENABLE, HIGH);
if (!digitalRead(OTA_ENABLE)) {
ota_enabled = true;
}
// Make sure that ATSHA204 is not floating
pinMode(ATSHA204_PIN, INPUT);
digitalWrite(ATSHA204_PIN, HIGH);
digitalWrite(TEST_PIN,LOW);
digitalWrite(OTA_ENABLE, LOW); // remove pullup, save some power.
digitalWrite(LED_PIN, HIGH);
@@ -169,7 +165,10 @@ void setup() {
raHum.clear();
sendTempHumidityMeasurements(false);
sendBattLevel(false);
if (ota_enabled) Serial.println("OTA FW update enabled");
#ifdef MY_OTA_FIRMWARE_FEATURE
Serial.println("OTA FW update enabled");
#endif
}
@@ -196,11 +195,13 @@ void loop() {
sendBattery ++;
bool forceTransmit = false;
transmission_occured = false;
#ifndef MY_OTA_FIRMWARE_FEATURE
if ((measureCount == 5) && highfreq)
{
if (!ota_enabled) clock_prescale_set(clock_div_8); // Switch to 1Mhz for the reminder of the sketch, save power.
clock_prescale_set(clock_div_8); // Switch to 1Mhz for the reminder of the sketch, save power.
highfreq = false;
}
#endif
if (measureCount > FORCE_TRANSMIT_INTERVAL) { // force a transmission
forceTransmit = true;
@@ -208,15 +209,16 @@ void loop() {
}
sendTempHumidityMeasurements(forceTransmit);
if (sendBattery > 60)
/* if (sendBattery > 60)
{
sendBattLevel(forceTransmit); // Not needed to send battery info that often
sendBattery = 0;
}
if (ota_enabled & transmission_occured) {
}*/
#ifdef MY_OTA_FIRMWARE_FEATURE
if (transmission_occured) {
wait(OTA_WAIT_PERIOD);
}
#endif
sleep(MEASURE_INTERVAL);
}
@@ -238,7 +240,7 @@ void sendTempHumidityMeasurements(bool force)
raHum.addValue(data.humidityPercent);
float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100);
float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0);
float diffHum = abs(lastHumidity - raHum.getAverage());
Serial.print(F("TempDiff :"));Serial.println(diffTemp);
@@ -261,6 +263,10 @@ void sendTempHumidityMeasurements(bool force)
lastTemperature = temperature;
lastHumidity = humidity;
transmission_occured = true;
if (sendBattery > 60) {
sendBattLevel(true); // Not needed to send battery info that often
sendBattery = 0;
}
}
}