battery monitor
This commit is contained in:
parent
7cd5ff8398
commit
4649c796b9
@ -89,7 +89,7 @@ void init_display(const char *Productname, const char *Version) {
|
||||
|
||||
} // init_display
|
||||
|
||||
void refreshDisplay() {
|
||||
void refreshtheDisplay() {
|
||||
|
||||
// set display on/off according to current device configuration
|
||||
if (DisplayState != cfg.screenon) {
|
||||
@ -109,13 +109,11 @@ void refreshDisplay() {
|
||||
u8x8.draw2x2String(0, 0,
|
||||
buff); // display number on unique macs total Wifi + BLE
|
||||
|
||||
/*
|
||||
// update Battery status (line 2)
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
u8x8.setCursor(0, 2);
|
||||
u8x8.printf("B:%.1fV", read_voltage() / 1000.0);
|
||||
u8x8.printf("B:%.1fV", batt_voltage / 1000.0);
|
||||
#endif
|
||||
*/
|
||||
|
||||
// update GPS status (line 2)
|
||||
#ifdef HAS_GPS
|
||||
|
@ -6,7 +6,7 @@
|
||||
extern uint8_t DisplayState;
|
||||
|
||||
void init_display(const char *Productname, const char *Version);
|
||||
void refreshDisplay(void);
|
||||
void refreshtheDisplay(void);
|
||||
void DisplayKey(const uint8_t *key, uint8_t len, bool lsb);
|
||||
|
||||
#endif
|
@ -40,8 +40,8 @@ typedef struct {
|
||||
extern configData_t cfg; // current device configuration
|
||||
extern char display_line6[], display_line7[]; // screen buffers
|
||||
extern uint8_t channel; // wifi channel rotation counter
|
||||
extern uint16_t macs_total, macs_wifi, macs_ble; // display values
|
||||
extern std::set<uint16_t> macs; // temp storage for MACs
|
||||
extern uint16_t macs_total, macs_wifi, macs_ble, batt_voltage; // display values
|
||||
extern std::set<uint16_t> macs; // temp storage for MACs
|
||||
extern hw_timer_t *channelSwitch, *sendCycle;
|
||||
extern portMUX_TYPE timerMux;
|
||||
|
||||
|
48
src/main.cpp
48
src/main.cpp
@ -30,13 +30,16 @@ licenses. Refer to LICENSE.txt file in repository for more details.
|
||||
configData_t cfg; // struct holds current device configuration
|
||||
char display_line6[16], display_line7[16]; // display buffers
|
||||
uint8_t channel = 0; // channel rotation counter
|
||||
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0; // globals for display
|
||||
hw_timer_t *channelSwitch = NULL, *displaytimer = NULL,
|
||||
*sendCycle = NULL; // configure hardware timer for cyclic tasks
|
||||
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
||||
batt_voltage = 0; // globals for display
|
||||
|
||||
// hardware timer for cyclic tasks
|
||||
hw_timer_t *channelSwitch = NULL, *displaytimer = NULL, *sendCycle = NULL,
|
||||
*battCycle = NULL;
|
||||
|
||||
// this variables will be changed in the ISR, and read in main loop
|
||||
static volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0,
|
||||
SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0;
|
||||
SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0, BattReadIRQ = 0;
|
||||
|
||||
portMUX_TYPE timerMux =
|
||||
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
|
||||
@ -116,17 +119,30 @@ void IRAM_ATTR DisplayIRQ() {
|
||||
DisplayTimerIRQ++;
|
||||
portEXIT_CRITICAL_ISR(&timerMux);
|
||||
}
|
||||
|
||||
void updateDisplay() {
|
||||
// refresh display according to refresh cycle setting
|
||||
if (DisplayTimerIRQ) {
|
||||
portENTER_CRITICAL(&timerMux);
|
||||
DisplayTimerIRQ = 0;
|
||||
portEXIT_CRITICAL(&timerMux);
|
||||
refreshDisplay();
|
||||
refreshtheDisplay();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
void IRAM_ATTR BattCycleIRQ() {
|
||||
portENTER_CRITICAL(&timerMux);
|
||||
BattReadIRQ++;
|
||||
portEXIT_CRITICAL(&timerMux);
|
||||
}
|
||||
void readBattery() {
|
||||
if (BattReadIRQ) {
|
||||
portENTER_CRITICAL(&timerMux);
|
||||
BattReadIRQ = 0;
|
||||
portEXIT_CRITICAL(&timerMux);
|
||||
batt_voltage = read_voltage();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BUTTON
|
||||
@ -313,6 +329,12 @@ void setup() {
|
||||
strcat_P(features, " GPS");
|
||||
#endif
|
||||
|
||||
// initialize battery status if present
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
strcat_P(features, " BATT");
|
||||
batt_voltage = read_voltage();
|
||||
#endif
|
||||
|
||||
// initialize display if present
|
||||
#ifdef HAS_DISPLAY
|
||||
strcat_P(features, " OLED");
|
||||
@ -344,6 +366,14 @@ void setup() {
|
||||
timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true);
|
||||
timerAlarmEnable(sendCycle);
|
||||
|
||||
// setup battery read cycle trigger IRQ using esp32 hardware timer 3
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
battCycle = timerBegin(3, 8000, true);
|
||||
timerAttachInterrupt(battCycle, &BattCycleIRQ, true);
|
||||
timerAlarmWrite(battCycle, 60 * 100, true);
|
||||
timerAlarmEnable(battCycle);
|
||||
#endif
|
||||
|
||||
// show payload encoder
|
||||
#if PAYLOAD_ENCODER == 1
|
||||
strcat_P(features, " PAYLOAD_PLAIN");
|
||||
@ -431,6 +461,10 @@ void loop() {
|
||||
readButton();
|
||||
#endif
|
||||
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
readBattery();
|
||||
#endif
|
||||
|
||||
#ifdef HAS_DISPLAY
|
||||
updateDisplay();
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user