Fossil/Skagen Hybrids: Implement inactivity warnings

This commit is contained in:
Arjan Schrijver 2023-02-06 14:26:26 +01:00
parent 5ea68cad3b
commit 810cc91e8e
3 changed files with 84 additions and 0 deletions

View File

@ -250,6 +250,7 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
//Settings applicable to all firmware versions
int[] supportedSettings = new int[]{
R.xml.devicesettings_fossilhybridhr,
R.xml.devicesettings_inactivity,
R.xml.devicesettings_autoremove_notifications,
R.xml.devicesettings_canned_dismisscall_16,
R.xml.devicesettings_transliteration

View File

@ -1615,6 +1615,25 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
queueWrite((FileEncryptedInterface) new ConfigurationPutRequest(fitnessConfigItem, this));
}
private void setInactivityWarning(){
SharedPreferences prefs = getDeviceSpecificPreferences();
boolean enabled = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE, false);
int threshold = Integer.parseInt(prefs.getString(DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD, "60"));
String start = prefs.getString(DeviceSettingsPreferenceConst.PREF_INACTIVITY_START, "06:00");
String end = prefs.getString(DeviceSettingsPreferenceConst.PREF_INACTIVITY_END, "22:00");
int startHour = Integer.parseInt(start.split(":")[0]);
int startMinute = Integer.parseInt(start.split(":")[1]);
int endHour = Integer.parseInt(end.split(":")[0]);
int endMinute = Integer.parseInt(end.split(":")[1]);
InactivityWarningItem inactivityWarningItem = new InactivityWarningItem(
startHour, startMinute, endHour, endMinute, threshold, enabled
);
queueWrite((FileEncryptedInterface) new ConfigurationPutRequest(inactivityWarningItem, this));
}
@Override
public void onSendConfiguration(String config) {
switch (config) {
@ -1660,6 +1679,12 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
case DeviceSettingsPreferenceConst.PREF_HYBRID_HR_ACTIVITY_RECOGNITION_ROWING_MINUTES:
setActivityRecognition();
break;
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_START:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_END:
setInactivityWarning();
break;
}
}

View File

@ -34,6 +34,7 @@ public class ConfigurationPutRequest extends FilePutRequest {
static {
itemsById.put((short) 0x02, CurrentStepCountConfigItem.class);
itemsById.put((short) 0x03, DailyStepGoalConfigItem.class);
itemsById.put((short) 0x09, InactivityWarningItem.class);
itemsById.put((short) 0x0A, VibrationStrengthConfigItem.class);
itemsById.put((short) 0x0C, TimeConfigItem.class);
itemsById.put((short) 0x0D, BatteryConfigItem.class);
@ -466,5 +467,62 @@ public class ConfigurationPutRequest extends FilePutRequest {
"recognizeRowing: " + recognizeRowing + " askRowing: " + askRowing + " minutesRowing: " + minutesRowing;
}
}
static public class InactivityWarningItem extends ConfigItem {
private int fromTimeHour, fromTimeMinute, untilTimeHour, untilTimeMinute, inactiveMinutes;
boolean enabled;
public InactivityWarningItem() {
this(0, 0, 0, 0, 0, false);
}
public InactivityWarningItem(int fromTimeHour, int fromTimeMinute, int untilTimeHour, int untilTimeMinute, int inactiveMinutes, boolean enabled) {
this.fromTimeHour = fromTimeHour;
this.fromTimeMinute = fromTimeMinute;
this.untilTimeHour = untilTimeHour;
this.untilTimeMinute = untilTimeMinute;
this.inactiveMinutes = inactiveMinutes;
this.enabled = enabled;
}
@Override
public int getItemSize() {
return 6;
}
@Override
public short getId() {
return (short) 9;
}
@Override
public byte[] getContent() {
ByteBuffer buffer = ByteBuffer.allocate(getItemSize());
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put((byte) this.fromTimeHour);
buffer.put((byte) this.fromTimeMinute);
buffer.put((byte) this.untilTimeHour);
buffer.put((byte) this.untilTimeMinute);
buffer.put((byte) this.inactiveMinutes);
buffer.put((byte) (this.enabled ? 1 : 0));
return buffer.array();
}
@Override
public void parseData(byte[] data) {
if (data.length != getItemSize()) throw new RuntimeException("wrong data");
ByteBuffer buffer = ByteBuffer.wrap(data);
buffer.order(ByteOrder.LITTLE_ENDIAN);
this.fromTimeHour = buffer.get();
this.fromTimeMinute = buffer.get();
this.untilTimeHour = buffer.get();
this.untilTimeMinute = buffer.get();
this.inactiveMinutes = buffer.get();
this.enabled = buffer.get() == 0x01;
}
}
}