aboutsummaryrefslogtreecommitdiff
path: root/test_fw/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test_fw/src/main.cpp')
-rw-r--r--test_fw/src/main.cpp103
1 files changed, 103 insertions, 0 deletions
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 <Arduino.h>
+#include <Wire.h>
+
+#include <Adafruit_BME680.h>
+
+#include <hardware/pio.h>
+
+#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