]> git.tnoah.ca Git - lora-radio.git/commitdiff
Added battery status and console support to Heltec V3
authorMark Qvist <mark@unsigned.io>
Thu, 26 Sep 2024 22:28:37 +0000 (00:28 +0200)
committerMark Qvist <mark@unsigned.io>
Thu, 26 Sep 2024 22:28:37 +0000 (00:28 +0200)
Boards.h
Makefile
Power.h

index 0eb5c2b7538e13d5367ccc48e32072eb394a7e0a..b43da3c167aa66ce2485833a135b3ebca2affc85 100644 (file)
--- a/Boards.h
+++ b/Boards.h
       #define HAS_DISPLAY true
       #define HAS_BLUETOOTH false
       #define HAS_BLE true
-      #define HAS_CONSOLE false
+      #define HAS_PMU true
+      #define HAS_CONSOLE true
       #define HAS_EEPROM true
       #define HAS_INPUT true
       #define HAS_SLEEP true
index 8e0f1541d5a334bb8e7bcb27defe07f9fbfb297c..16d1eee81b814fe3136f1b7d179f339225ebd8f1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -158,11 +158,11 @@ upload-heltec32_v2:
        python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyUSB1 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
 
 upload-heltec32_v3:
-       arduino-cli upload -p /dev/ttyUSB1 --fqbn esp32:esp32:heltec_wifi_lora_32_V3
+       arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:heltec_wifi_lora_32_V3
        @sleep 1
-       rnodeconf /dev/ttyUSB1 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.bin)
+       rnodeconf /dev/ttyUSB0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.bin)
        @sleep 3
-       python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyUSB1 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
+       python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
 
 upload-rnode_ng_20:
        arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:ttgo-lora32
diff --git a/Power.h b/Power.h
index 07eef084c052048a09d9a522c4c646cf7d276633..faf98f24e333d4865c51a81ccd507a8fc10480bb 100644 (file)
--- a/Power.h
+++ b/Power.h
   int bat_charged_samples = 0;
   bool bat_voltage_dropping = false;
   float bat_delay_v = 0;
+#elif BOARD_MODEL == BOARD_HELTEC32_V3
+  #define BAT_C_SAMPLES   7
+  #define BAT_D_SAMPLES   2
+  #define BAT_V_MIN       3.15
+  #define BAT_V_MAX       4.3
+  #define BAT_V_CHG       4.48
+  #define BAT_V_FLOAT     4.33
+  #define BAT_SAMPLES     5
+  const uint8_t pin_vbat = 1;
+  const uint8_t pin_ctrl = 37;
+  float bat_p_samples[BAT_SAMPLES];
+  float bat_v_samples[BAT_SAMPLES];
+  uint8_t bat_samples_count = 0;
+  int bat_discharging_samples = 0;
+  int bat_charging_samples = 0;
+  int bat_charged_samples = 0;
+  bool bat_voltage_dropping = false;
+  float bat_delay_v = 0;
 #endif
 
 uint32_t last_pmu_update = 0;
@@ -54,10 +72,17 @@ uint8_t pmu_rc = 0;
 void kiss_indicate_battery();
 
 void measure_battery() {
-  #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1
+  #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 || BOARD_MODEL == BOARD_HELTEC32_V3
     battery_installed = true;
     battery_indeterminate = true;
-    bat_v_samples[bat_samples_count%BAT_SAMPLES] = (float)(analogRead(pin_vbat)) / 4095*2*3.3*1.1;
+
+    #if BOARD_MODEL == BOARD_HELTEC32_V3
+      float battery_measurement = (float)(analogRead(pin_vbat)) * 0.0041;
+    #else
+      float battery_measurement = (float)(analogRead(pin_vbat)) / 4095.0*2.0*3.3*1.1;
+    #endif
+
+    bat_v_samples[bat_samples_count%BAT_SAMPLES] = battery_measurement;
     bat_p_samples[bat_samples_count%BAT_SAMPLES] = ((battery_voltage-BAT_V_MIN) / (BAT_V_MAX-BAT_V_MIN))*100.0;
     
     bat_samples_count++;
@@ -95,11 +120,7 @@ void measure_battery() {
       if (bat_voltage_dropping && battery_voltage < BAT_V_FLOAT) {
         battery_state = BATTERY_STATE_DISCHARGING;
       } else {
-        #if BOARD_MODEL == BOARD_RNODE_NG_21
           battery_state = BATTERY_STATE_CHARGING;
-        #else
-          battery_state = BATTERY_STATE_DISCHARGING;
-        #endif
       }
 
 
@@ -214,6 +235,10 @@ bool init_pmu() {
   #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1
     pinMode(pin_vbat, INPUT);
     return true;
+  #elif BOARD_MODEL == BOARD_HELTEC32_V3
+    pinMode(pin_ctrl,OUTPUT);
+    digitalWrite(pin_ctrl, LOW);
+    return true;
   #elif BOARD_MODEL == BOARD_TBEAM
     Wire.begin(I2C_SDA, I2C_SCL);