Skip to content

Instantly share code, notes, and snippets.

@lptr
Created December 6, 2023 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lptr/7bd7252dba1349ec83468c98bf17dd9a to your computer and use it in GitHub Desktop.
Save lptr/7bd7252dba1349ec83468c98bf17dd9a to your computer and use it in GitHub Desktop.
diff --git a/platformio.ini b/platformio.ini
index dd73415..bdb058f 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -25,6 +25,7 @@ build_flags =
monitor_filters = esp32_exception_decoder
monitor_speed = 115200
+monitor_raw = true
lib_deps =
256dpi/MQTT@^2.5.1
bblanchon/ArduinoJson@^6.21.3
diff --git a/src/kernel/Application.hpp b/src/kernel/Application.hpp
index 8cedd6d..6f0a483 100644
--- a/src/kernel/Application.hpp
+++ b/src/kernel/Application.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <optional>
+
#include <freertos/FreeRTOS.h>
#include <kernel/Command.hpp>
diff --git a/src/main.cpp b/src/main.cpp
index 7c9f78e..318cf6b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,14 +3,16 @@
#include <kernel/Application.hpp>
#include <kernel/FileSystem.hpp>
#include <kernel/Task.hpp>
+#include <kernel/drivers/BatteryDriver.hpp>
using namespace farmhub::kernel;
using namespace farmhub::kernel::drivers;
class ConsolePrinter : IntermittentLoopTask {
public:
- ConsolePrinter()
- : IntermittentLoopTask("Console printer", 32768, 1) {
+ ConsolePrinter(BatteryDriver& batteryDriver)
+ : IntermittentLoopTask("Console printer", 32768, 1)
+ , batteryDriver(batteryDriver) {
}
protected:
@@ -31,7 +33,10 @@ protected:
Serial.printf(", now: \033[33m%d\033[0m", now);
Serial.print(&timeinfo, ", UTC: \033[33m%A, %B %d %Y %H:%M:%S\033[0m");
- Serial.print(" ");
+ Serial.printf(", battery: \033[33m%.2f V\033[0m", batteryDriver.getVoltage());
+
+ Serial.println(" ");
+ Serial.flush();
return milliseconds(100);
}
@@ -61,6 +66,8 @@ private:
int counter;
const String spinner { "-\\|/" };
+
+ BatteryDriver& batteryDriver;
};
class SampleDeviceConfiguration
@@ -79,7 +86,8 @@ public:
}
private:
- ConsolePrinter consolePrinter;
+ BatteryDriver batteryDriver { GPIO_NUM_1, 1.0 };
+ ConsolePrinter consolePrinter { batteryDriver };
};
SampleDeviceConfiguration* deviceConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment