summaryrefslogtreecommitdiff
path: root/src/components/battery
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2021-08-14 21:18:11 +0300
committerRiku Isokoski <riksu9000@gmail.com>2021-08-14 21:18:11 +0300
commit23bde0d18e99a344b95b5f1507350e186659eec2 (patch)
treef243992efa5ebd0dc1a8870ab062a0e119a02ab9 /src/components/battery
parent643077341b14a52819cbaf02abbd5fb56cdeb802 (diff)
Make battery reading periodic. Add events. Disable pullup
Diffstat (limited to 'src/components/battery')
-rw-r--r--src/components/battery/BatteryController.cpp11
-rw-r--r--src/components/battery/BatteryController.h7
2 files changed, 11 insertions, 7 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index f8a64ecd..aa038c5d 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -9,10 +9,7 @@ Battery* Battery::instance = nullptr;
Battery::Battery() {
instance = this;
-}
-
-void Battery::Init() {
- nrf_gpio_cfg_input(chargingPin, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Pullup);
+ nrf_gpio_cfg_input(chargingPin, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled);
}
void Battery::Update() {
@@ -75,5 +72,11 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
nrfx_saadc_uninit();
isReading = false;
+
+ systemTask->PushMessage(System::Messages::BatteryMeasurementDone);
}
}
+
+void Battery::Register(Pinetime::System::SystemTask* systemTask) {
+ this->systemTask = systemTask;
+}
diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h
index 6f09b737..ad304eba 100644
--- a/src/components/battery/BatteryController.h
+++ b/src/components/battery/BatteryController.h
@@ -1,8 +1,7 @@
#pragma once
#include <cstdint>
#include <drivers/include/nrfx_saadc.h>
-#include <array>
-#include <numeric>
+#include <systemtask/SystemTask.h>
namespace Pinetime {
namespace Controllers {
@@ -11,8 +10,8 @@ namespace Pinetime {
public:
Battery();
- void Init();
void Update();
+ void Register(System::SystemTask* systemTask);
uint8_t PercentRemaining() const {
return percentRemaining;
@@ -49,6 +48,8 @@ namespace Pinetime {
static void AdcCallbackStatic(nrfx_saadc_evt_t const* event);
bool isReading = false;
+
+ Pinetime::System::SystemTask* systemTask = nullptr;
};
}
}