From 786fedc74f1fe45a811da388140dd129b6f253fa Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 2 Jun 2016 01:28:16 +0200 Subject: [PATCH] Same return value for every sensor after Setup() --- WifiControlSensor/BMP180.h | 3 --- WifiControlSensor/BMP180.ino | 8 +++++++- WifiControlSensor/WifiControlSensor.ino | 8 ++++---- WifiControlSensor/sensor_DHT.h | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/WifiControlSensor/BMP180.h b/WifiControlSensor/BMP180.h index c340396..1222735 100644 --- a/WifiControlSensor/BMP180.h +++ b/WifiControlSensor/BMP180.h @@ -5,9 +5,6 @@ // Get Current altitude with http://fr.mygeoposition.com/ #define ALTITUDE 130 -SFE_BMP180 bmp180; -int bmp180Connected = 0; - int BMP180GetTemperature(double &t); int BMP180GetTempAndPressure(double &t, double &p); int BMP180Setup(int sda, int scl); diff --git a/WifiControlSensor/BMP180.ino b/WifiControlSensor/BMP180.ino index cc55ae9..7c60b2c 100644 --- a/WifiControlSensor/BMP180.ino +++ b/WifiControlSensor/BMP180.ino @@ -1,12 +1,18 @@ #ifdef CONFIG_ENABLE_BMP180 #include "BMP180.h" +SFE_BMP180 bmp180; +int bmp180Connected = 0; + int BMP180Setup(int sda, int scl) { //Use BMP fork at https://github.com/mmaret/BMP180_Breakout_Arduino_Library/archive/master.zip bmp180Connected = bmp180.begin(sda, scl); if (!bmp180Connected){ SKETCH_DEBUG_PRINTLN("Cannot connect to BMP180"); + goto err; } - return bmp180Connected; + return 0; +err: + return -1; } bool BMP180IsConnected() { diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index 471640a..3112558 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -228,10 +228,10 @@ void setup() { if (mode == BOOTMODE_OTA) { OTASetup(); } else { - if (BMP180Setup(CONFIG_BMP180_SDA, CONFIG_BMP180_SCL)){ + if (!BMP180Setup(CONFIG_BMP180_SDA, CONFIG_BMP180_SCL)){ SKETCH_DEBUG_PRINTLN("BMP180 init success"); } - if (DHTSetup(CONFIG_DHT_PIN)){ + if (!DHTSetup(CONFIG_DHT_PIN)){ SKETCH_DEBUG_PRINTLN("DHT init success"); } WebSetupServer(mode); @@ -252,14 +252,14 @@ void loop() { nbCycle++; if (nbCycle > CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS) { - if (BMP180GetTempAndPressure(temp, pressure) == 0) { + if (!BMP180GetTempAndPressure(temp, pressure)) { SKETCH_DEBUG_PRINT("Current T°C "); SKETCH_DEBUG_PRINT(temp); SKETCH_DEBUG_PRINT(" Pressure mB "); SKETCH_DEBUG_PRINTLN(pressure); MqttPublish(temp, pressure); } - if (DHTGetTempAndHumidity(dhtTemp, dhtHumidity) == 0) { + if (!DHTGetTempAndHumidity(dhtTemp, dhtHumidity)) { SKETCH_DEBUG_PRINT("Current T°C "); SKETCH_DEBUG_PRINT(dhtTemp); SKETCH_DEBUG_PRINT(" Humidity "); diff --git a/WifiControlSensor/sensor_DHT.h b/WifiControlSensor/sensor_DHT.h index 011b652..cacb2ac 100644 --- a/WifiControlSensor/sensor_DHT.h +++ b/WifiControlSensor/sensor_DHT.h @@ -8,7 +8,7 @@ int DHTGetTempAndHumidity(float &t, float &h); bool DHTIsConnected(); #else //CONFIG_ENABLE_DHT -int DHTSetup(int pin){SKETCH_DEBUG_PRINTLN("DHT is disabled at build time"); return 0}; +int DHTSetup(int pin){SKETCH_DEBUG_PRINTLN("DHT is disabled at build time"); return -1}; int DHTGetTempAndHumidity(float &t, float &h){return -1;}; bool DHTIsConnected(){return false;}; #endif