Remove unnecessary comments, clean up code
This commit is contained in:
@@ -13,7 +13,7 @@ void initBatteryADC() {
|
||||
pinMode(PIN_VBAT_ENABLE, OUTPUT); digitalWrite(PIN_VBAT_ENABLE, LOW);
|
||||
pinMode(PIN_VBAT_READ, INPUT);
|
||||
analogReference(AR_INTERNAL_3_0); analogReadResolution(12);
|
||||
// Warm up with a few reads (no delay — just discard results)
|
||||
// Warm up with a few reads (no delay - just discard results)
|
||||
for (int i=0; i<8; i++) analogRead(PIN_VBAT_READ);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ void updateBattery() {
|
||||
float v = readBatteryVoltage(); int pct = batteryPercent(v);
|
||||
bool chg = (digitalRead(PIN_CHG) == LOW);
|
||||
ChargeStatus status = chg ? (pct >= 99 ? CHGSTAT_FULL : CHGSTAT_CHARGING) : CHGSTAT_DISCHARGING;
|
||||
// Only write BLE Battery Service when connected — blebas.write() blocks on the
|
||||
// Only write BLE Battery Service when connected - blebas.write() blocks on the
|
||||
// SoftDevice ATT layer and causes 30-40ms loop stalls when called during advertising.
|
||||
if (Bluefruit.connected()) blebas.write(pct);
|
||||
lastChargeStatus = status;
|
||||
@@ -44,7 +44,7 @@ void updateBattery() {
|
||||
const char* st[] = {"discharging","charging","full"};
|
||||
Serial.print("[BATT] "); Serial.print(v,2); Serial.print("V ");
|
||||
Serial.print(pct); Serial.print("% "); Serial.println(st[status]);
|
||||
// Critical battery alert — only blink when not connected to avoid blocking BLE scheduler.
|
||||
// Critical battery alert - only blink when not connected to avoid blocking BLE scheduler.
|
||||
// 6 × 160ms = 960ms hard block; skip during active connection.
|
||||
if (status == CHGSTAT_DISCHARGING && v < BATT_CRITICAL && !Bluefruit.connected())
|
||||
for (int i=0; i<6; i++) { digitalWrite(LED_RED,LOW); delay(80); digitalWrite(LED_RED,HIGH); delay(80); }
|
||||
|
||||
Reference in New Issue
Block a user