From 9c07c2b85d908f699f8ba590b1d60232157eca90 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Wed, 23 Oct 2024 22:57:18 -0400 Subject: test_fw: read veml and bme --- test_fw/src/main.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 test_fw/src/main.cpp (limited to 'test_fw/src/main.cpp') diff --git a/test_fw/src/main.cpp b/test_fw/src/main.cpp new file mode 100644 index 0000000..c6d3834 --- /dev/null +++ b/test_fw/src/main.cpp @@ -0,0 +1,103 @@ +#include +#include + +#include + +#include + +#include "i2c_scan.h" +#include "veml.h" + +constexpr auto SDA = 6; +constexpr auto SCL = 23; + +constexpr auto BME_ADDR = 0x76; + +static TwoWire wire(SDA, SCL); + +static Adafruit_BME680 bme(&wire); +static ocularium::VEML veml(wire); + +struct init_check +{ + const String name; + bool (*f)(); + bool succeeded; +}; + +static init_check STARTUP_CHECKS[] = { + { + .name = String("bme680"), + .f = [] { return bme.begin(BME_ADDR); }, + .succeeded = false, + }, + { + .name = String("veml7700"), + .f = []{ return veml.init(ocularium::veml::Config { + .gain = ocularium::veml::AmbientLightGain::Quarter, + }); }, + .succeeded = false, + } +}; + +void startup_checks() +{ + auto success = true; + + do + { + success = true; + + for (auto & check : STARTUP_CHECKS) + { + if (check.succeeded) + continue; + + Serial.print("checking " + check.name + "... "); + + check.succeeded = check.f(); + success = success && check.succeeded; + + if (check.succeeded) Serial.println("ok"); + else Serial.println("bad"); + } + + if (!success) delay(10); + } while (!success); +} + +void setup() { + Serial.begin(115200); + delay(2000); + + Serial.println("boot"); + wire.begin(); + + ocularium::scan(wire); + startup_checks(); + + Serial.println("sensors initialized"); +} + +void loop() { + static uint32_t bme_target_millis = 0; + + if (millis() >= bme_target_millis) + { + if (bme_target_millis != 0 && !bme.endReading()) + { + Serial.println("bme read error!"); + } + + bme_target_millis = bme.beginReading(); + } + + Serial.print("lux: " + String(veml.lux())); + Serial.print(", temp: " + String(bme.temperature)); + Serial.print(", hum: " + String(bme.humidity)); + Serial.print(", pres: " + String(bme.pressure)); + Serial.print(", gas: " + String(bme.gas_resistance)); + Serial.println(); + + delay(100); +} \ No newline at end of file -- cgit v1.3.1