Sentinel
Loading...
Searching...
No Matches
battery.h
Go to the documentation of this file.
1
16
17#ifndef BATTERY_H
18#define BATTERY_H
19
20#include "utilities.h"
21#include "config.h"
22#include <Arduino.h>
23#include <TinyGsmClient.h>
24#include <esp32-hal-adc.h>
25#include <vector>
26#include <algorithm>
27#include <numeric>
28
29// Voltage thresholds
30#define LOW_VOLTAGE_LEVEL 3600 // Sleep shutdown voltage (mV)
31#define WARN_VOLTAGE_LEVEL 3700 // Warning voltage (mV)
32#define SLEEP_MINUTE 60 // Sleep time, unit / minute
33
35{
36private:
37 static uint32_t getBatteryVoltageAverage(); // Static method for accurate voltage reading
38
39public:
40 // Functions for monitoring battery status
41 void begin();
42 float getBatteryStatus(); // Returns percentage as float
43 int percent(); // Returns percentage as int (for batteryTask compatibility)
44 uint32_t getBatteryVoltage(); // Returns voltage in mV
45 float readVoltage(); // Returns voltage in volts (for batteryTask compatibility)
46 void getUpdate();
47
48 // Functions for power management
49 void powerSaveMode();
50 void deepSleep(uint32_t ms);
51 bool isPowerOn(int pin);
52 void turnOnPower(int pin);
53 void turnOffPower(int pin);
54 void safetyShutdown(); // Fixed to use actual voltage reading
55 void setRGB(int percent);
56};
57
58#endif
Definition battery.h:35
void turnOffPower(int pin)
Turns off the power pin.
Definition battery.cpp:185
void turnOnPower(int pin)
Turns on the power pin.
Definition battery.cpp:173
void deepSleep(uint32_t ms)
Puts the device into deep sleep mode for a specified duration.
Definition battery.cpp:224
void getUpdate()
Gets the battery update every 10 seconds.
Definition battery.cpp:155
bool isPowerOn(int pin)
Checks if the power pin is on.
Definition battery.cpp:199
float readVoltage()
Reads the battery voltage in volts.
Definition battery.cpp:108
void setRGB(int percent)
Sets the RGB LED color based on battery percentage.
Definition battery.cpp:248
int percent()
Gets the battery percentage based on the voltage.
Definition battery.cpp:119
float getBatteryStatus()
Gets the battery status as a percentage based on the voltage.
Definition battery.cpp:130
uint32_t getBatteryVoltage()
Gets the current battery voltage in millivolts.
Definition battery.cpp:98
void safetyShutdown()
Initiates a safety shutdown due to low battery voltage.
Definition battery.cpp:212
void powerSaveMode()
Enters power save mode by putting the device into deep sleep for a short duration.
Definition battery.cpp:235
void begin()
Initializes the battery monitoring system.
Definition battery.cpp:26
Configuration Header File.