Skip to content

Commit

Permalink
Merge pull request #279 from kike-canaries/batt_disable_flag
Browse files Browse the repository at this point in the history
Added general flag for enable/disable battery feature
  • Loading branch information
hpsaturn authored Jun 14, 2024
2 parents 1b897eb + 4326283 commit 3c8ba21
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 23 deletions.
2 changes: 2 additions & 0 deletions lib/batterylib/Batterylib.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef DISABLE_BATT
#ifndef Batterylib_hpp
#define Batterylib_hpp

Expand All @@ -16,3 +17,4 @@
#endif

#endif
#endif
2 changes: 1 addition & 1 deletion lib/batterylib/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ class Battery {
}
return (int)percentage;
}
};
};
2 changes: 1 addition & 1 deletion lib/batterylib/battery_m5stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ void Battery_M5STACK::printValues() {
Battery_M5STACK battery;
#endif

#endif
#endif
6 changes: 6 additions & 0 deletions lib/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ void wcli_debug(char *args, Stream *response) {
debugEnable(dbgmode);
devmode = dbgmode;
sensors.setDebugMode(dbgmode);
#ifndef DISABLE_BATT
battery.debug = dbgmode;
#endif
}

void wcli_klist(char *args, Stream *response) {
Expand Down Expand Up @@ -72,6 +74,7 @@ bool validBattLimits(float min, float max){
}

void wcli_battvLimits(char *args, Stream *response) {
#ifndef DISABLE_BATT
Pair<String, String> operands = wcli.parseCommand(args);
float battMin = operands.first().toFloat();
float battMax = operands.second().toFloat();
Expand All @@ -85,9 +88,11 @@ void wcli_battvLimits(char *args, Stream *response) {
response->println("-->[BATT] !invalid battery value! Current values:");
battery.printLimits();
}
#endif
}

void wcli_chargLimits(char *args, Stream *response) {
#ifndef DISABLE_BATT
Pair<String, String> operands = wcli.parseCommand(args);
float battMin = operands.first().toFloat();
float battMax = operands.second().toFloat();
Expand All @@ -101,6 +106,7 @@ void wcli_chargLimits(char *args, Stream *response) {
response->println("-->[BATT] !invalid battery value! Current values:");
battery.printLimits();
}
#endif
}

void wcli_stime(char *args, Stream *response) {
Expand Down
4 changes: 4 additions & 0 deletions lib/power/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

void prepairShutdown() {
#ifndef M5STICKCPLUS
#ifndef DISABLE_BATT
digitalWrite(ADC_EN, LOW);
#endif
delay(10);
//rtc_gpio_init(GPIO_NUM_14);
//rtc_gpio_set_direction(GPIO_NUM_14, RTC_GPIO_MODE_OUTPUT_ONLY);
Expand Down Expand Up @@ -106,6 +108,7 @@ float powerESP32TempRead(){
}

void powerLoop() {
#ifndef DISABLE_BATT
static uint32_t powerTimeStamp = 0; // timestamp for check low power
if ((millis() - powerTimeStamp > 30 * 1000)) { // check it every 5 seconds
powerTimeStamp = millis();
Expand All @@ -122,4 +125,5 @@ void powerLoop() {
#endif
log_i("[HEAP] Min:%d Max:%d\t: %d\r\n", ESP.getMinFreeHeap(), ESP.getMaxAllocHeap(), ESP.getFreeHeap());
}
#endif
}
2 changes: 2 additions & 0 deletions lib/wifi/cloud_anaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ void anairePublish() {
doc["cpm"] = String(sensors.getGeigerCPM());
doc["usvh"] = String(sensors.getGeigerMicroSievertHour());
doc["geo"] = geo;
#ifndef DISABLE_BATT
doc["battery"] = String(battery.getCharge());
doc["VBat"] = String(battery.getVoltage());
#endif
doc["co"] = String(sensors.getCO());
doc["nh3"] = String(sensors.getNH3());
doc["no2"] = String(sensors.getNO2());
Expand Down
2 changes: 2 additions & 0 deletions lib/wifi/cloud_hass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ void hassPubSensorPayload() {
doc["pm4"] = String(sensors.getPM4());
doc["pm10"] = String(sensors.getPM10());
doc["signal_strength"] = String(getWifiRSSI());
#ifndef DISABLE_BATT
doc["battery"] = String(battery.getCharge());
doc["voltage"] = String(battery.getVoltage());
#endif
doc["cpm"] = String(sensors.getGeigerCPM());
doc["usvh"] = String(sensors.getGeigerMicroSievertHour());
doc["co"] = String(sensors.getCO());
Expand Down
2 changes: 2 additions & 0 deletions lib/wifi/cloud_influxdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ void influxDbParseFields() {
sensor.addField("alt",sensors.getAltitude());
sensor.addField("cpm",sensors.getGeigerCPM());
sensor.addField("usvh",sensors.getGeigerMicroSievertHour());
#ifndef DISABLE_BATT
sensor.addField("bat",battery.getCharge());
sensor.addField("vbat",battery.getVoltage());
#endif
sensor.addField("rssi",getWifiRSSI());
sensor.addField("heap",ESP.getFreeHeap());
sensor.addField("name",getStationName().c_str());
Expand Down
2 changes: 2 additions & 0 deletions lib/wifi/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ String getDeviceInfo() {
#ifdef CONFIG_IDF_TARGET_ESP32S3
info = info + "CPU: " + String(powerESP32TempRead()) + "°C\r\n";
#endif
#ifndef DISABLE_BATT
info = info + "BAT: " + String(battery.getVoltage()) + "v "+String(battery.getCharge()) +"%\r\n";
#endif
return info;
}

Expand Down
20 changes: 11 additions & 9 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ build_flags =
-D WAIT_FOR_PM_SENSOR=25 # time of stabilization of PM sensors in seconds
-D ARDUINO_ESP32_DEV=1 # compatibilty for DFRobot NH3/CO library
-D DISABLE_ALL_LIBRARY_WARNINGS=1
-D WCLI_MAX_CMDS=16
-D SHELLMINATOR_BUFF_LEN=70
-D SHELLMINATOR_BUFF_DIM=70
-D COMMANDER_MAX_COMMAND_SIZE=70
-D SHELLMINATOR_LOGO_COLOR=YELLOW
-D DISABLE_BLE=1 # disable/enable Bluetooth
; -D DISABLE_CLI_TELNET=1 # disable remote access via telnet.
; -D DISABLE_CLI # uncomment to only have Bluetooth config via
; -D ENABLE_OTA # disable for memory saving, we have FOTA enable
-D COMMANDER_MAX_COMMAND_SIZE=70
-D WCLI_MAX_CMDS=16
; -D DISABLE_BLE=1 # removed Bluetooth module
; -D DISABLE_BATT=1 # removed battery module
; -D DISABLE_CLI_TELNET=1 # disable remote access via telnet. It needs CLI
; -D DISABLE_CLI=1 # removed CLI module. Config via Bluetooth only
; -D ENABLE_OTA # disable for memory saving. We have FOTA enable
lib_deps =
bblanchon/ArduinoJson @ 6.21.2
; hpsaturn/EasyPreferences@^0.1.0
Expand All @@ -49,9 +50,8 @@ lib_deps =
https://github.com/rlogiacco/CircularBuffer.git#f29cf01
https://github.com/256dpi/arduino-mqtt.git#7afcfb1
https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino.git#8e5f051

; hpsaturn/CanAirIO Air Quality Sensors Library @ 0.7.4
; https://github.com/kike-canaries/canairio_sensorlib.git#devel
https://github.com/kike-canaries/canairio_sensorlib.git#devel
; ${commonlibs.lib_deps} ; only for local tests of sensorslib

[esp32_common]
Expand Down Expand Up @@ -150,12 +150,14 @@ board = lolin_c3_mini
extends = esp32c3_common
board = seeed_xiao_esp32c3

[env:ESP32C3_AIRGRADIENT]
[env:AG_OPENAIR]
extends = esp32c3_common
build_flags =
${esp32c3_common.build_flags}
-D ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_USB_MODE=1
-D DISABLE_BLE=1 # removed Bluetooth module
-D DISABLE_BATT=1 # removed battery module

[esp32s3_common]
extends = oled_common
Expand Down
2 changes: 1 addition & 1 deletion prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

chipFamily = "ESP32"

if flavor == "ESP32C3" or flavor == "ESP32C3OIPLUS" or flavor == "ESP32C3LOLIN" or flavor == "ESP32C3SEEDX" or flavor == "ESP32C3_AIRGRADIENT":
if flavor == "ESP32C3" or flavor == "ESP32C3OIPLUS" or flavor == "ESP32C3LOLIN" or flavor == "ESP32C3SEEDX" or flavor == "AG_OPENAIR":
chipFamily = "ESP32-C3"

if flavor == "ESP32S3" or flavor == "TTGO_T7S3":
Expand Down
28 changes: 17 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ class MyRemoteConfigCallBacks : public RemoteConfigCallbacks {
}
};

#ifndef DISABLE_BATT
class MyBatteryUpdateCallbacks : public BatteryUpdateCallbacks {
void onBatteryUpdate(float voltage, int charge, bool charging) {
gui.setBatteryStatus(voltage, charge, charging);
};
};
#endif

/// sensors data callback
void onSensorDataOk() {
Expand Down Expand Up @@ -249,18 +251,20 @@ void startingSensors() {
}

void initBattery() {
#ifndef DISABLE_BATT
if (FAMILY != "ESP32-C3") {
battery.setUpdateCallbacks(new MyBatteryUpdateCallbacks());
battery.init(devmode);
if(cfg.isKey(CONFKEYS::KBATVMX)) {
battery.setBattLimits(cfg.getFloat(CONFKEYS::KBATVMI),cfg.getFloat(CONFKEYS::KBATVMX));
}
if(cfg.isKey(CONFKEYS::KCHRVMX)) {
battery.setChargLimits(cfg.getFloat(CONFKEYS::KCHRVMI),cfg.getFloat(CONFKEYS::KCHRVMX));
}
if(devmode) battery.printLimits();
battery.update();
battery.setUpdateCallbacks(new MyBatteryUpdateCallbacks());
battery.init(devmode);
if (cfg.isKey(CONFKEYS::KBATVMX)) {
battery.setBattLimits(cfg.getFloat(CONFKEYS::KBATVMI), cfg.getFloat(CONFKEYS::KBATVMX));
}
if (cfg.isKey(CONFKEYS::KCHRVMX)) {
battery.setChargLimits(cfg.getFloat(CONFKEYS::KCHRVMI), cfg.getFloat(CONFKEYS::KCHRVMX));
}
if (devmode) battery.printLimits();
battery.update();
}
#endif
}

void initCLIFailsafe() {
Expand Down Expand Up @@ -395,7 +399,9 @@ void loop() {
#endif
gui.setGUIStatusFlags(WiFi.isConnected(), true, false);
gui.loop(); // Only for OLED
battery.loop(); // refresh battery level and voltage
#ifndef DISABLE_BATT
battery.loop(); // refresh battery level and voltage
#endif
#ifdef LORADEVKIT
os_runloop_once();
#endif
Expand Down

0 comments on commit 3c8ba21

Please sign in to comment.