Even Realities G1: Remove baterry polling

The glasses periodically transmit their battery state, since that is
supported now, use that instead of requesting the battery info
periodically.
This commit is contained in:
jrthomas270
2025-10-04 09:53:59 -07:00
parent f01f7f7537
commit e8f7a1fad3
3 changed files with 8 additions and 31 deletions
@@ -1,6 +1,8 @@
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
import androidx.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,6 +30,12 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
private final UpdateType updateType;
@NonNull
@Override
public String toString() {
return super.toString() + ", state: " + state + ", " + updateType;
}
public GBDeviceEventBatteryIncrementalInfo(int batteryIndex, GregorianCalendar lastChargeTime) {
super();
super.batteryIndex = batteryIndex;
@@ -42,7 +50,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
super.state = state;
super.level = GBDevice.BATTERY_UNKNOWN;
this.updateType = UpdateType.STATE;
}
public GBDeviceEventBatteryIncrementalInfo(int batteryIndex, int level) {
@@ -152,11 +152,6 @@ public class G1DeviceCoordinator extends AbstractBLEDeviceCoordinator {
}
}
@Override
public boolean addBatteryPollingSettings() {
return true;
}
@Override
public int getBatteryCount(final GBDevice device) {
return 3;
@@ -51,7 +51,6 @@ public class G1SideManager {
private final BiFunction<String, Integer, TransactionBuilder> createTransactionBuilder;
private final BluetoothGattCharacteristic rx;
private final BluetoothGattCharacteristic tx;
private final Runnable batteryRunner;
private final Runnable heartBeatRunner;
private final Runnable displaySettingsPreviewCloserRunner;
private final Set<G1Communications.CommandHandler> commandHandlers;
@@ -75,10 +74,6 @@ public class G1SideManager {
this.createTransactionBuilder = createTransactionBuilder;
this.rx = rx;
this.tx = tx;
this.batteryRunner = () -> {
send(new G1Communications.CommandGetBatteryInfo(this::handleBatteryPayload));
scheduleBatteryPolling();
};
this.heartBeatRunner = () -> {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -161,9 +156,6 @@ public class G1SideManager {
// useless to the user.
scheduleHeatBeat();
// Schedule the battery polling.
scheduleBatteryPolling();
connectingState = GBDevice.State.INITIALIZED;
}
@@ -212,11 +204,6 @@ public class G1SideManager {
public void onSendConfiguration(String config) {
DevicePrefs prefs = getDevicePrefs();
switch (config) {
// Reschedule battery polling. The new schedule may be disabled.
case DeviceSettingsPreferenceConst.PREF_BATTERY_POLLING_ENABLE:
case DeviceSettingsPreferenceConst.PREF_BATTERY_POLLING_INTERVAL:
scheduleBatteryPolling();
break;
case DeviceSettingsPreferenceConst.PREF_EVEN_REALITIES_SCREEN_HEIGHT:
case DeviceSettingsPreferenceConst.PREF_EVEN_REALITIES_SCREEN_DEPTH:
sendDisplaySettings(prefs);
@@ -259,18 +246,6 @@ public class G1SideManager {
backgroundTasksHandler.postDelayed(heartBeatRunner, G1Constants.HEART_BEAT_DELAY_MS);
}
private void scheduleBatteryPolling() {
backgroundTasksHandler.removeCallbacksAndMessages(batteryRunner);
DevicePrefs prefs = getDevicePrefs();
if (prefs.getBatteryPollingEnabled()) {
int interval_minutes = prefs.getBatteryPollingIntervalMinutes();
int interval = interval_minutes * 60 * 1000;
LOG.debug("Starting battery runner delayed by {} ({} minutes)", interval,
interval_minutes);
backgroundTasksHandler.postDelayed(batteryRunner, interval);
}
}
private synchronized byte getNextSequence() {
// Synchronized so the sequence increments atomically.
// This number will eventually overflow, and that is fine. The sequence number is just to