From 3a0c42f9240eedfbc6a1e94ad3a59c52664fb5b5 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 28 Aug 2023 13:26:53 +1000 Subject: Move battery measurement to its own class --- src/drivers/include/adc.hpp | 37 +++++++++++++++++++++++++++++++++++++ src/drivers/include/battery.hpp | 39 --------------------------------------- 2 files changed, 37 insertions(+), 39 deletions(-) create mode 100644 src/drivers/include/adc.hpp delete mode 100644 src/drivers/include/battery.hpp (limited to 'src/drivers/include') diff --git a/src/drivers/include/adc.hpp b/src/drivers/include/adc.hpp new file mode 100644 index 00000000..3e94a9ee --- /dev/null +++ b/src/drivers/include/adc.hpp @@ -0,0 +1,37 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include + +#include "esp_adc/adc_cali.h" +#include "esp_adc/adc_oneshot.h" +#include "esp_err.h" +#include "result.hpp" + +namespace drivers { + +/* + * Handles measuring the battery's current voltage. + */ +class AdcBattery { + public: + static auto Create() -> AdcBattery* { return new AdcBattery(); } + AdcBattery(); + ~AdcBattery(); + + /** + * Returns the current battery level in millivolts. + */ + auto Millivolts() -> uint32_t; + + private: + adc_oneshot_unit_handle_t adc_handle_; + adc_cali_handle_t adc_calibration_handle_; +}; + +} // namespace drivers diff --git a/src/drivers/include/battery.hpp b/src/drivers/include/battery.hpp deleted file mode 100644 index 64a00135..00000000 --- a/src/drivers/include/battery.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include - -#include "esp_adc/adc_cali.h" -#include "esp_adc/adc_oneshot.h" -#include "esp_err.h" -#include "result.hpp" - -namespace drivers { - -class Battery { - public: - static auto Create() -> Battery* { return new Battery(); } - Battery(); - ~Battery(); - - /** - * Returns the current battery level in millivolts. - */ - auto Millivolts() -> uint32_t; - - auto UpdatePercent() -> bool; - auto Percent() -> uint_fast8_t { return percent_; } - - private: - adc_oneshot_unit_handle_t adc_handle_; - adc_cali_handle_t adc_calibration_handle_; - - uint_fast8_t percent_; -}; - -} // namespace drivers -- cgit v1.2.3