1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

TLW64: Add basic settings

* inactivity warnings
* activate display on lift
* timeformat
* TODO: screen timeout, find-my-device,...
This commit is contained in:
115ek 2020-07-30 15:00:34 +02:00
parent 81956143de
commit 58711ff2d2
4 changed files with 52 additions and 8 deletions

View File

@ -43,5 +43,6 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_ALTITUDE_CALIBRATE = "pref_sensors_altitude"; public static final String PREF_ALTITUDE_CALIBRATE = "pref_sensors_altitude";
public static final String PREF_LONGSIT_PERIOD = "pref_longsit_period"; public static final String PREF_LONGSIT_PERIOD = "pref_longsit_period";
public static final String PREF_LONGSIT_SWITCH = "pref_longsit_switch"; public static final String PREF_LONGSIT_SWITCH = "pref_longsit_switch";
public static final String PREF_LONGSIT_SWITCH_NOSHED = "screen_longsit_noshed";
public static final String PREF_DO_NOT_DISTURB_NOAUTO = "do_not_disturb_no_auto"; public static final String PREF_DO_NOT_DISTURB_NOAUTO = "do_not_disturb_no_auto";
} }

View File

@ -26,6 +26,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
@ -138,4 +139,13 @@ public class TLW64Coordinator extends AbstractDeviceCoordinator {
public boolean supportsFindDevice() { public boolean supportsFindDevice() {
return true; return true;
} }
}
@Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{
R.xml.devicesettings_liftwrist_display_noshed,
R.xml.devicesettings_longsit_noshed,
R.xml.devicesettings_timeformat
};
}
}

View File

@ -39,6 +39,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity; import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
@ -468,11 +469,24 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
} else { } else {
displayBytes[1] = 2; displayBytes[1] = 2;
} }
if (DateFormat.is24HourFormat(getContext())) {
displayBytes[2] = 1; String timeformat = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, "auto");
} else { switch (timeformat) {
displayBytes[2] = 2; case "24h":
displayBytes[2] = 1;
break;
case "am/pm":
displayBytes[2] = 2;
break;
case "auto":
default:
if (DateFormat.is24HourFormat(getContext())) {
displayBytes[2] = 1;
} else {
displayBytes[2] = 2;
}
} }
transaction.write(ctrlCharacteristic, displayBytes); transaction.write(ctrlCharacteristic, displayBytes);
return; return;
} }
@ -493,7 +507,7 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
(byte) 0x00, // unknown (byte) 0x00, // unknown
(byte) (activityUser.getStepsGoal() / 256), (byte) (activityUser.getStepsGoal() / 256),
(byte) (activityUser.getStepsGoal() % 256), (byte) (activityUser.getStepsGoal() % 256),
(byte) 0x01, // raise hand to turn on screen, ON = 1, OFF = 0 (byte) 0x00, // raise hand to turn on screen, ON = 1, OFF = 0
(byte) 0xff, // unknown (byte) 0xff, // unknown
(byte) 0x00, // unknown (byte) 0x00, // unknown
(byte) activityUser.getAge(), (byte) activityUser.getAge(),
@ -502,6 +516,10 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
(byte) 0x02 // unknown (byte) 0x02 // unknown
}; };
if (GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREF_LIFTWRIST_NOSHED, false)) {
userBytes[10] = (byte) 0x01;
}
if (activityUser.getGender() == ActivityUser.GENDER_FEMALE) { if (activityUser.getGender() == ActivityUser.GENDER_FEMALE) {
userBytes[14] = 2; // female userBytes[14] = 2; // female
// default and factor from https://livehealthy.chron.com/determine-stride-pedometer-height-weight-4518.html // default and factor from https://livehealthy.chron.com/determine-stride-pedometer-height-weight-4518.html
@ -520,7 +538,7 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
builder.write(ctrlCharacteristic, userBytes); builder.write(ctrlCharacteristic, userBytes);
// device settings // device settings
builder.write(ctrlCharacteristic, new byte[]{ byte[] deviceBytes = new byte[]{
TLW64Constants.CMD_DEVICE_SETTINGS, TLW64Constants.CMD_DEVICE_SETTINGS,
(byte) 0x00, // 1 - turns on inactivity alarm (byte) 0x00, // 1 - turns on inactivity alarm
(byte) 0x3c, // unknown, sniffed by original app (byte) 0x3c, // unknown, sniffed by original app
@ -528,7 +546,13 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
(byte) 0x03, // unknown, sniffed by original app (byte) 0x03, // unknown, sniffed by original app
(byte) 0x01, // unknown, sniffed by original app (byte) 0x01, // unknown, sniffed by original app
(byte) 0x00 // unknown, sniffed by original app (byte) 0x00 // unknown, sniffed by original app
}); };
if (GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREF_LONGSIT_SWITCH_NOSHED, false)) {
deviceBytes[1] = (byte) 0x01;
}
builder.write(ctrlCharacteristic, deviceBytes);
} }
private void showIcon(int iconId) { private void showIcon(int iconId) {

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:icon="@drawable/ic_activity_sleep"
android:defaultValue="false"
android:key="screen_longsit_noshed"
android:title="@string/mi2_prefs_inactivity_warnings"
android:summary="@string/mi2_prefs_inactivity_warnings_summary"/>
</androidx.preference.PreferenceScreen>