1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-25 22:40:05 +02:00

TLW64: Beautify code

This commit is contained in:
115ek 2020-06-30 22:11:30 +02:00
parent 8a3174dabd
commit 4f5e2d0730
2 changed files with 36 additions and 40 deletions

View File

@ -28,25 +28,25 @@ public final class TLW64Constants {
// Command bytes
public static final byte CMD_DISPLAY_SETTINGS = (byte) 0xa0;
public static final byte CMD_FIRMWARE_VERSION = (byte) 0xa1;
public static final byte CMD_BATTERY = (byte) 0xa2;
public static final byte CMD_DATETIME = (byte) 0xa3;
public static final byte CMD_USER_DATA = (byte) 0xa9;
public static final byte CMD_ALARM = (byte) 0xab;
public static final byte CMD_FACTORY_RESET = (byte) 0xad;
public static final byte CMD_NOTIFICATION = (byte) 0xc1;
public static final byte CMD_ICON = (byte) 0xc3;
public static final byte CMD_DEVICE_SETTINGS = (byte) 0xd3;
public static final byte CMD_BATTERY = (byte) 0xa2;
public static final byte CMD_DATETIME = (byte) 0xa3;
public static final byte CMD_USER_DATA = (byte) 0xa9;
public static final byte CMD_ALARM = (byte) 0xab;
public static final byte CMD_FACTORY_RESET = (byte) 0xad;
public static final byte CMD_NOTIFICATION = (byte) 0xc1;
public static final byte CMD_ICON = (byte) 0xc3;
public static final byte CMD_DEVICE_SETTINGS = (byte) 0xd3;
// Notifications
public static final byte NOTIFICATION_HEADER = (byte) 0x01;
public static final byte NOTIFICATION_CALL = (byte) 0x02; // displays "call" on screen
public static final byte NOTIFICATION_SMS = (byte) 0x03; // displays "mms" on screen
public static final byte NOTIFICATION_STOP = (byte) 0x04; // to stop showing incoming call
public static final byte NOTIFICATION_CALL = (byte) 0x02; // displays "call" on screen
public static final byte NOTIFICATION_SMS = (byte) 0x03; // displays "mms" on screen
public static final byte NOTIFICATION_STOP = (byte) 0x04; // to stop showing incoming call
// Icons
public static final byte ICON_QQ = (byte) 0x01;
public static final byte ICON_QQ = (byte) 0x01;
public static final byte ICON_WECHAT = (byte) 0x02;
public static final byte ICON_MAIL = (byte) 0x04;
public static final byte ICON_MAIL = (byte) 0x04;
// Alarm arguments
public static final byte ARG_SET_ALARM_REMINDER_REPEAT_SUNDAY = (byte) 0x01;

View File

@ -266,7 +266,7 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
(byte) (alarm.getEnabled() ? 2 : 0), // vibration duration
(byte) (alarm.getEnabled() ? 10 : 0), // vibration count
(byte) (alarm.getEnabled() ? 2 : 0), // unknown
(byte) 0,
(byte) 0x00,
(byte) (alarm.getPosition() + 1)
};
builder.write(ctrlCharacteristic, alarmMessage);
@ -350,7 +350,7 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
@Override
public void onReset(int flags) {
if (flags == GBDeviceProtocol.RESET_FLAGS_FACTORY_RESET){
if (flags == GBDeviceProtocol.RESET_FLAGS_FACTORY_RESET) {
try {
TransactionBuilder builder = performInitialized("factoryReset");
byte[] msg = new byte[]{
@ -436,13 +436,13 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
TransactionBuilder builder = performInitialized("vibrate");
byte[] msg = new byte[]{
TLW64Constants.CMD_ALARM,
0,
0,
0,
(byte) 0x00,
(byte) 0x00,
(byte) 0x00,
(byte) duration,
(byte) count,
7, // unknown, sniffed by original app
1
(byte) 0x07, // unknown, sniffed by original app
(byte) 0x01
};
builder.write(ctrlCharacteristic, msg);
builder.queue(getQueue());
@ -469,8 +469,8 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
private void setDisplaySettings(TransactionBuilder transaction) {
byte[] displayBytes = new byte[]{
TLW64Constants.CMD_DISPLAY_SETTINGS,
0x00, // 1 - display distance in kilometers, 2 - in miles
0x00 // 1 - display 24-hour clock, 2 - for 12-hour with AM/PM
(byte) 0x00, // 1 - display distance in kilometers, 2 - in miles
(byte) 0x00 // 1 - display 24-hour clock, 2 - for 12-hour with AM/PM
};
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, getContext().getString(R.string.p_unit_metric));
if (units.equals(getContext().getString(R.string.p_unit_metric))) {
@ -494,36 +494,32 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
ActivityUser activityUser = new ActivityUser();
byte[] userBytes = new byte[]{
TLW64Constants.CMD_USER_DATA,
0, // unknown
0, // step length [cm]
0, // unknown
(byte) 0x00, // unknown
(byte) 0x00, // step length [cm]
(byte) 0x00, // unknown
(byte) activityUser.getWeightKg(),
5, // screen on time / display timeout
0, // unknown
0, // unknown
(byte) 0x05, // screen on time / display timeout
(byte) 0x00, // unknown
(byte) 0x00, // unknown
(byte) (activityUser.getStepsGoal() / 256),
(byte) (activityUser.getStepsGoal() % 256),
1, // raise hand to turn on screen, ON = 1, OFF = 0
(byte) 0xff, // unknown
0, // unknown
(byte) 0x01, // raise hand to turn on screen, ON = 1, OFF = 0
(byte) 0xff, // unknown
(byte) 0x00, // unknown
(byte) activityUser.getAge(),
0, // gender
0, // lost function, ON = 1, OFF = 0 TODO: find out what this does
2 // unknown
(byte) 0x00, // gender
(byte) 0x00, // lost function, ON = 1, OFF = 0 TODO: find out what this does
(byte) 0x02 // unknown
};
if (activityUser.getGender() == ActivityUser.GENDER_FEMALE)
{
if (activityUser.getGender() == ActivityUser.GENDER_FEMALE) {
userBytes[14] = 2; // female
// default and factor from https://livehealthy.chron.com/determine-stride-pedometer-height-weight-4518.html
if (activityUser.getHeightCm() != 0)
userBytes[2] = (byte) Math.ceil(activityUser.getHeightCm() * 0.413);
else
userBytes[2] = 70; // default
}
else
{
} else {
userBytes[14] = 1; // male
if (activityUser.getHeightCm() != 0)
userBytes[2] = (byte) Math.ceil(activityUser.getHeightCm() * 0.415);