add batteryStatus info and allow access to it through the interface.
Change-Id: Ieb748b1478d532f52ffff9edc783de3cbcf9f303
This commit is contained in:
parent
b09d4f7331
commit
a0a46f729f
4 changed files with 45 additions and 28 deletions
|
@ -1,30 +1,29 @@
|
|||
#pragma once
|
||||
#include "HardwareAbstractionInterface.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class HardwareSimulator :
|
||||
public HardwareAbstractionInterface
|
||||
{
|
||||
public:
|
||||
class HardwareSimulator : public HardwareAbstractionInterface {
|
||||
public:
|
||||
HardwareSimulator() = default;
|
||||
|
||||
HardwareSimulator() = default;
|
||||
virtual void debugPrint(std::string message) override {
|
||||
std::cout << message;
|
||||
}
|
||||
|
||||
virtual void debugPrint(std::string message) override {
|
||||
std::cout << message;
|
||||
}
|
||||
virtual void sendIR() override {}
|
||||
|
||||
virtual void sendIR() override {
|
||||
|
||||
}
|
||||
virtual void MQTTPublish(const char *topic, const char *payload) override{
|
||||
|
||||
virtual void MQTTPublish(const char* topic, const char* payload) override {
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
virtual void init() override {
|
||||
lv_init();
|
||||
}
|
||||
virtual void init() override { lv_init(); }
|
||||
|
||||
virtual batteryStatus getBatteryPercentage() {
|
||||
batteryStatus fakeStatus;
|
||||
fakeStatus.isCharging = false;
|
||||
fakeStatus.percentage = 100;
|
||||
fakeStatus.voltage = 4200;
|
||||
return fakeStatus;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -7,10 +7,21 @@
|
|||
|
||||
class HardwareAbstractionInterface {
|
||||
public:
|
||||
struct batteryStatus{
|
||||
/// @brief Percent of battery remaining (0-100]
|
||||
int percentage;
|
||||
/// @brief Voltage of battery in millivolts
|
||||
int voltage;
|
||||
/// @brief True - Battery is Charging
|
||||
/// False - Battery discharging
|
||||
bool isCharging;
|
||||
};
|
||||
|
||||
HardwareAbstractionInterface() = default;
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void sendIR() = 0;
|
||||
virtual void MQTTPublish(const char *topic, const char *payload) = 0;
|
||||
virtual batteryStatus getBatteryPercentage() = 0;
|
||||
virtual void debugPrint(std::string message) = 0;
|
||||
};
|
||||
|
|
|
@ -99,6 +99,10 @@ void HardwareRevX::MQTTPublish(const char *topic, const char *payload) {
|
|||
#endif
|
||||
}
|
||||
|
||||
HardwareAbstractionInterface::batteryStatus HardwareRevX::getBatteryPercentage(){
|
||||
return battery;
|
||||
}
|
||||
|
||||
void HardwareRevX::initLVGL() {
|
||||
lv_init();
|
||||
|
||||
|
@ -424,11 +428,11 @@ void HardwareRevX::startTasks() {
|
|||
|
||||
void HardwareRevX::updateBatteryTask([[maybe_unused]] void *aData) {
|
||||
while (true) {
|
||||
mInstance->battery_voltage =
|
||||
mInstance->battery.voltage =
|
||||
analogRead(ADC_BAT) * 2 * 3300 / 4095 + 350; // 350mV ADC offset
|
||||
mInstance->battery_percentage =
|
||||
constrain(map(mInstance->battery_voltage, 3700, 4200, 0, 100), 0, 100);
|
||||
mInstance->battery_ischarging = !digitalRead(CRG_STAT);
|
||||
mInstance->battery.percentage =
|
||||
constrain(map(mInstance->battery.voltage, 3700, 4200, 0, 100), 0, 100);
|
||||
mInstance->battery.isCharging = !digitalRead(CRG_STAT);
|
||||
// Check if battery is charging, fully charged or disconnected
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
// Update battery at 1Hz
|
||||
|
@ -436,6 +440,9 @@ void HardwareRevX::updateBatteryTask([[maybe_unused]] void *aData) {
|
|||
}
|
||||
|
||||
void HardwareRevX::loopHandler() {
|
||||
|
||||
// TODO Move the backlight handling into task that spawns when the backlight
|
||||
// setting changes and then gets deleted when the setting is achieved.
|
||||
// Update Backlight brightness
|
||||
static int fadeInTimer = millis(); // fadeInTimer = time after setup
|
||||
if (millis() <
|
||||
|
@ -448,6 +455,7 @@ void HardwareRevX::loopHandler() {
|
|||
ledcWrite(5, backlight_brightness); // Backlight on
|
||||
}
|
||||
|
||||
// TODO move to debug task
|
||||
// Blink debug LED at 1 Hz
|
||||
digitalWrite(USER_LED, millis() % 1000 > 500);
|
||||
|
||||
|
|
|
@ -34,12 +34,13 @@ public:
|
|||
}
|
||||
|
||||
HardwareRevX() : HardwareAbstractionInterface(){};
|
||||
// HardwareAbstractionInterface
|
||||
// HardwareAbstractionInterface
|
||||
virtual void init() override;
|
||||
virtual void sendIR() override;
|
||||
virtual void MQTTPublish(const char *topic, const char *payload) override;
|
||||
virtual batteryStatus getBatteryPercentage() override;
|
||||
virtual void debugPrint(std::string aDebugMessage) override;
|
||||
|
||||
|
||||
void loopHandler();
|
||||
|
||||
protected:
|
||||
|
@ -114,9 +115,7 @@ private:
|
|||
IRsend IrSender = IRsend(IR_LED, true);
|
||||
IRrecv IrReceiver = IRrecv(IR_RX);
|
||||
|
||||
int battery_voltage = 0;
|
||||
int battery_percentage = 100;
|
||||
bool battery_ischarging = false;
|
||||
HardwareAbstractionInterface::batteryStatus battery;
|
||||
|
||||
// LVGL Screen Buffers
|
||||
lv_disp_draw_buf_t mdraw_buf;
|
||||
|
|
Loading…
Add table
Reference in a new issue