Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ char bt_devname[11];
// start device information service
bledis.begin();
blebas.begin();
blebas.write(battery_percent);

// Guard to ensure SerialBT service is not duplicated through BT being power cycled
if (!SerialBT_init) {
Expand All @@ -569,6 +570,9 @@ char bt_devname[11];

// Include bleuart 128-bit uuid
Bluefruit.Advertising.addService(SerialBT);

// Include blebas 16-bit uuid for battery status
Bluefruit.Advertising.addService(blebas);

// There is no room for Name in Advertising packet
// Use Scan response for Name
Expand Down
17 changes: 11 additions & 6 deletions Power.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void measure_battery() {

bat_v_samples[bat_samples_count%BAT_SAMPLES] = battery_measurement;
bat_p_samples[bat_samples_count%BAT_SAMPLES] = ((battery_measurement-BAT_V_MIN) / (BAT_V_MAX-BAT_V_MIN))*100.0;

bat_samples_count++;
if (!battery_ready && bat_samples_count >= BAT_SAMPLES) {
battery_ready = true;
Expand All @@ -277,13 +277,13 @@ void measure_battery() {
battery_percent += bat_p_samples[bi];
}
battery_percent = battery_percent/BAT_SAMPLES;

battery_voltage = 0;
for (uint8_t bi = 0; bi < BAT_SAMPLES; bi++) {
battery_voltage += bat_v_samples[bi];
}
battery_voltage = battery_voltage/BAT_SAMPLES;

if (bat_delay_v == 0) bat_delay_v = battery_voltage;
if (bat_state_change_v == 0) bat_state_change_v = battery_voltage;
if (battery_percent > 100.0) battery_percent = 100.0;
Expand Down Expand Up @@ -332,7 +332,12 @@ void measure_battery() {
}

#if MCU_VARIANT == MCU_NRF52
if (bt_state != BT_STATE_OFF) { blebas.write(battery_percent); }
if (bt_state != BT_STATE_OFF) {
blebas.write(battery_percent);
if (bt_state == BT_STATE_CONNECTED) {
blebas.notify(battery_percent);
}
}
#endif

// if (bt_state == BT_STATE_CONNECTED) {
Expand Down Expand Up @@ -611,7 +616,7 @@ bool init_pmu() {
// Set the time of pressing the button to turn off
PMU->setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S);

return true;
return true;
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
Wire1.begin(I2C_SDA, I2C_SCL);

Expand Down Expand Up @@ -691,7 +696,7 @@ bool init_pmu() {
PMU->enableBattVoltageMeasure();


return true;
return true;
#else
return false;
#endif
Expand Down