1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-30 14:02:56 +01:00

Fossil Hybrid HR: Support setting metric/imperial mode

Fixes #2355
This commit is contained in:
Andreas Shimokawa 2021-08-09 16:32:42 +02:00
parent e6ae5e357e
commit 5fb674f9ae
2 changed files with 40 additions and 9 deletions

View File

@ -16,6 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil_hr; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil_hr;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.UnitsConfigItem;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.VibrationStrengthConfigItem;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.MUSIC_PHONE_REQUEST;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.MUSIC_WATCH_REQUEST;
import static nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil.convertDrawableToBitmap;
import static nodomain.freeyourgadget.gadgetbridge.util.StringUtils.shortenPackageName;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -61,6 +68,7 @@ import java.util.regex.Pattern;
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.devicesettings.DeviceSettingsPreferenceConst; 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;
@ -137,11 +145,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import nodomain.freeyourgadget.gadgetbridge.util.UriHelper; import nodomain.freeyourgadget.gadgetbridge.util.UriHelper;
import nodomain.freeyourgadget.gadgetbridge.util.Version; import nodomain.freeyourgadget.gadgetbridge.util.Version;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.MUSIC_PHONE_REQUEST;
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.MUSIC_WATCH_REQUEST;
import static nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil.convertDrawableToBitmap;
import static nodomain.freeyourgadget.gadgetbridge.util.StringUtils.shortenPackageName;
public class FossilHRWatchAdapter extends FossilWatchAdapter { public class FossilHRWatchAdapter extends FossilWatchAdapter {
private byte[] phoneRandomNumber; private byte[] phoneRandomNumber;
private byte[] watchRandomNumber; private byte[] watchRandomNumber;
@ -216,6 +219,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
if (authenticated) { if (authenticated) {
setVibrationStrength(); setVibrationStrength();
setUnitsConfig();
syncSettings(); syncSettings();
setTime(); setTime();
} }
@ -261,6 +265,19 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
setVibrationStrength((short) (vibrationStrengh)); setVibrationStrength((short) (vibrationStrengh));
} }
private void setUnitsConfig() {
Prefs prefs = GBApplication.getPrefs();
String unit = prefs.getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
int value = 8; // dont know what this bit means but it was set for me before tampering
if (!unit.equals("metric")) {
value |= (4 | 1); // temperature and distance
}
queueWrite(
(FileEncryptedInterface) new ConfigurationPutRequest(new UnitsConfigItem(value), this)
);
}
@Override @Override
public void setVibrationStrength(short strength) { public void setVibrationStrength(short strength) {
if (connectionMode == CONNECTION_MODE.NOT_AUTHENTICATED) { if (connectionMode == CONNECTION_MODE.NOT_AUTHENTICATED) {
@ -269,7 +286,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
} }
queueWrite( queueWrite(
(FileEncryptedInterface) new ConfigurationPutRequest(new nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.VibrationStrengthConfigItem((byte) strength), this) (FileEncryptedInterface) new ConfigurationPutRequest(new VibrationStrengthConfigItem((byte) strength), this)
); );
} }
@ -1362,6 +1379,9 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
saveRawActivityFiles = getDeviceSpecificPreferences().getBoolean("save_raw_activity_files", false); saveRawActivityFiles = getDeviceSpecificPreferences().getBoolean("save_raw_activity_files", false);
break; break;
} }
case SettingsActivity.PREF_MEASUREMENT_SYSTEM:
setUnitsConfig();
break;
} }
} }

View File

@ -35,7 +35,8 @@ public class ConfigurationPutRequest extends FilePutRequest {
itemsById.put((short)0x0A, VibrationStrengthConfigItem.class); itemsById.put((short)0x0A, VibrationStrengthConfigItem.class);
itemsById.put((short)0x0C, TimeConfigItem.class); itemsById.put((short)0x0C, TimeConfigItem.class);
itemsById.put((short)0x0D, BatteryConfigItem.class); itemsById.put((short)0x0D, BatteryConfigItem.class);
itemsById.put((short)0x0E, HeartRateMeasurementModeItem.class); itemsById.put((short) 0x0E, HeartRateMeasurementModeItem.class);
itemsById.put((short) 0x10, UnitsConfigItem.class);
} }
public static ConfigItem[] parsePayload(byte[] data) { public static ConfigItem[] parsePayload(byte[] data) {
@ -264,7 +265,7 @@ public class ConfigurationPutRequest extends FilePutRequest {
} }
static public class CurrentStepCountConfigItem extends GenericConfigItem<Integer> { static public class CurrentStepCountConfigItem extends GenericConfigItem<Integer> {
public CurrentStepCountConfigItem(){ public CurrentStepCountConfigItem() {
this(-1); this(-1);
} }
@ -273,11 +274,21 @@ public class ConfigurationPutRequest extends FilePutRequest {
} }
} }
static public class UnitsConfigItem extends GenericConfigItem<Integer> {
public UnitsConfigItem() {
this(-1);
}
public UnitsConfigItem(Integer value) {
super((short) 16, value);
}
}
static public class TimeConfigItem extends ConfigItem { static public class TimeConfigItem extends ConfigItem {
private int epochSeconds; private int epochSeconds;
private short millis, offsetMinutes; private short millis, offsetMinutes;
public TimeConfigItem(){ public TimeConfigItem() {
this(-1, (short) -1, (short) -1); this(-1, (short) -1, (short) -1);
} }