diff --git a/include/bmp.h b/include/bmp.h new file mode 100644 index 0000000..06264a4 --- /dev/null +++ b/include/bmp.h @@ -0,0 +1,40 @@ +#include + +namespace Bmp { + + Adafruit_BMP280 bmp; // I2C Interface + + void setup() { + Serial.begin(9600); + Serial.println(F("BMP280 test")); + + if (!bmp.begin(0x76)) { + Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); + while (1); + } + + /* Default settings from datasheet. */ + bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ + Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ + Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ + Adafruit_BMP280::FILTER_X16, /* Filtering. */ + Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ + } + + void loop() { + Serial.print(F("Temperature = ")); + Serial.print(bmp.readTemperature()); + Serial.println(" *C"); + + Serial.print(F("Pressure = ")); + Serial.print(bmp.readPressure() / 100); //displaying the Pressure in hPa, you can change the unit + Serial.println(" hPa"); + + Serial.print(F("Approx altitude = ")); + Serial.print(bmp.readAltitude(1019.66)); //The "1019.66" is the pressure(hPa) at sea level in day in your region + Serial.println(" m"); //If you don't know it, modify it until you get your current altitude + + Serial.println(); + delay(2000); + } +} \ No newline at end of file diff --git a/include/display.h b/include/display.h index cad554f..150b47e 100644 --- a/include/display.h +++ b/include/display.h @@ -80,6 +80,15 @@ namespace Display { colonOn = !colonOn; } + void displayFloat(float value) { + tDisplay.disable(); + displayColon(false); + clockDisplay.print(value); + clockDisplay.writeDisplay(); + adjustTime(); + tDisplay.enableDelayed(1000); + } + void displayValue(uint8_t value) { tDisplay.disable(); displayColon(false); diff --git a/include/ir.h b/include/ir.h index 353c8c4..d21bdb8 100644 --- a/include/ir.h +++ b/include/ir.h @@ -55,38 +55,34 @@ namespace Ir { case 0x12: command("Slp"); break; + case 0xC1: + Display::displayText("Mute"); + break; case 0xC4: command("Play"); break; + case 0xC7: + avrOn ? Display::displayText(" Up") : Display::changeBrightness(true); + Mqtt::commands.pop(); + break; + case 0xC8: + avrOn ? Display::displayText(" Dn") : Display::changeBrightness(false); + Mqtt::commands.pop(); + break; case 0xD0: - command("Fire"); + command("Stop"); break; case 0xC0: command("On"); break; + case 0x84: + Display::displayFloat(Bmp::bmp.readTemperature()); + break; default: Display::displayValue(lastCommand); break; } } - if (Mqtt::commands.getCurrent() == 0xC7) { - if (!avrOn) { - Display::displayText("B Up"); - Display::changeBrightness(true); - } else { - Display::displayText(" Up"); - } - Mqtt::commands.pop(); - } - if (Mqtt::commands.getCurrent() == 0xC8) { - if (!avrOn) { - Display::displayText("B Dn"); - Display::changeBrightness(false); - } else { - Display::displayText(" Dn"); - } - Mqtt::commands.pop(); - } } void setup() { diff --git a/platformio.ini b/platformio.ini index a2fdefd..9530ec0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,6 +21,8 @@ lib_deps = ottowinter/AsyncMqttClient-esphome@^0.8.5 crankyoldgit/IRremoteESP8266@^2.7.18 arkhipenko/TaskScheduler@^3.4.0 + adafruit/Adafruit Unified Sensor @ ^1.1.4 + adafruit/Adafruit BMP280 Library@^2.5.0 build_flags = -D IR=1 [env:laptop_home] diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index 40bee75..da74a3e 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -13,12 +13,13 @@ Task tWifiConnected(onWifiConnected, &ts); #include "wifi.h" #include "display.h" +#include "bmp.h" #include "ntp_time.h" #include "mqtt.h" #include "ota.h" #include "ir.h" -#define STAY_CONNECTED_AFTER_BOOT 5*60 +#define STAY_CONNECTED_AFTER_BOOT 30*60 void setup() { Serial.begin(9600); @@ -28,6 +29,7 @@ void setup() { Ntp::setup(); Ir::setup(); Mqtt::setup(); + Bmp::setup(); hourChanged.setWaiting(); wifiConnected.setWaiting();