Boboter
Loading...
Searching...
No Matches
battery.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <esp_adc/adc_oneshot.h>
11
12class Robot;
13
14namespace Device {
15 class Battery {
16 private:
17 static constexpr const char* TAG = "Device::Battery";
18
19 static constexpr adc_channel_t ADC_CHANNEL = ADC_CHANNEL_3; // GPIO 39
20 static constexpr uint8_t NUM_SAMPLES = 50;
21
22 Robot& robot;
23
24 int8_t percentage;
25 uint16_t voltage;
26
27 public:
28 explicit Battery(Robot& robot);
29 ~Battery();
30
34 void initialize();
35
39 void update();
40
47 [[nodiscard]] int8_t get_percentage() const { return percentage; }
48
54 [[nodiscard]] uint16_t get_millivolts() const { return voltage; }
55 };
56}
~Battery()
Definition battery.cpp:23
void initialize()
Configures the needed ADC channel.
Definition battery.cpp:27
void update()
Read and calculate current battery state.
Definition battery.cpp:32
int8_t get_percentage() const
Returns the current battery percentage in percent.
Definition battery.h:47
uint16_t get_millivolts() const
Returns the current battery voltage.
Definition battery.h:54
Battery(Robot &robot)
Definition battery.cpp:15
Class containing all the components of the robot.
Definition robot.h:24
Definition battery.cpp:14