mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-23 08:07:33 +01:00
HPlus: Improve initial configuration process and refactor constants
This commit is contained in:
parent
fed5638782
commit
a135f51d31
@ -14,35 +14,33 @@ public final class HPlusConstants {
|
||||
public static final UUID UUID_SERVICE_HP = UUID.fromString("14701820-620a-3973-7c78-9cfff0876abd");
|
||||
|
||||
|
||||
public static final byte COUNTRY_CN = 1;
|
||||
public static final byte COUNTRY_OTHER = 2;
|
||||
public static final byte PREF_VALUE_COUNTRY_CN = 1;
|
||||
public static final byte PREF_VALUE_COUNTRY_OTHER = 2;
|
||||
|
||||
public static final byte CLOCK_24H = 0;
|
||||
public static final byte CLOCK_12H = 1;
|
||||
public static final byte PREF_VALUE_CLOCK_24H = 0;
|
||||
public static final byte PREF_VALUE_CLOCK_12H = 1;
|
||||
|
||||
public static final byte UNIT_METRIC = 0;
|
||||
public static final byte UNIT_IMPERIAL = 1;
|
||||
public static final byte PREF_VALUE_UNIT_METRIC = 0;
|
||||
public static final byte PREF_VALUE_UNIT_IMPERIAL = 1;
|
||||
|
||||
public static final byte PREF_VALUE_GENDER_MALE = 0;
|
||||
public static final byte PREF_VALUE_GENDER_FEMALE = 1;
|
||||
|
||||
public static final byte HEARTRATE_MEASURE_ON = 11;
|
||||
public static final byte HEARTRATE_MEASURE_OFF = 22;
|
||||
public static final byte PREF_VALUE_HEARTRATE_MEASURE_ON = 11;
|
||||
public static final byte PREF_VALUE_HEARTRATE_MEASURE_OFF = 22;
|
||||
|
||||
public static final byte HEARTRATE_ALLDAY_ON = 10;
|
||||
public static final byte HEARTRATE_ALLDAY_OFF = -1;
|
||||
public static final byte PREF_VALUE_HEARTRATE_ALLDAY_ON = 10;
|
||||
public static final byte PREF_VALUE_HEARTRATE_ALLDAY_OFF = -1;
|
||||
|
||||
public static final byte[] COMMAND_SET_INIT1 = new byte[]{0x50,0x00,0x25,(byte) 0xb1,0x4a,0x00,0x00,0x27,0x10,0x05,0x02,0x00,(byte) 0xff,0x0a,(byte) 0xff,0x00,(byte) 0xff,(byte) 0xff,0x00,0x01};
|
||||
public static final byte[] COMMAND_SET_INIT2 = new byte[]{0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,(byte) 0xe0,0x0c,0x12,0x16,0x0a,0x10,0x00,0x00,0x00,0x00};
|
||||
public static final byte INCOMING_CALL_STATE_DISABLED_THRESHOLD = 0x7B;
|
||||
public static final byte INCOMING_CALL_STATE_ENABLED = (byte) 0xAA;
|
||||
|
||||
public static final byte[] COMMAND_SET_PREF_START = new byte[]{0x4f, 0x5a};
|
||||
public static final byte[] COMMAND_SET_PREF_START1 = new byte[]{0x4d};
|
||||
|
||||
public static final byte COMMAND_SET_PREF_COUNTRY = 0x22;
|
||||
public static final byte COMMAND_SET_PREF_TIMEMODE = 0x47;
|
||||
public static final byte COMMAND_SET_PREF_UNIT = 0x48;
|
||||
public static final byte COMMAND_SET_PREF_SEX = 0x2d;
|
||||
|
||||
public static final byte COMMAND_SET_PREF_DATE = 0x08;
|
||||
public static final byte COMMAND_SET_PREF_TIME = 0x09;
|
||||
public static final byte COMMAND_SET_PREF_WEEK = 0x2a;
|
||||
@ -58,23 +56,16 @@ public final class HPlusConstants {
|
||||
public static final byte COMMAND_SET_PREF_END = 0x4f;
|
||||
public static final byte COMMAND_SET_DISPLAY_ALERT = 0x23;
|
||||
public static final byte COMMAND_SET_PREF_ALLDAYHR = 53;
|
||||
|
||||
public static final byte COMMAND_SET_INCOMING_CALL = 0x41;
|
||||
public static final byte[] COMMAND_FACTORY_RESET = new byte[] {-74, 90};
|
||||
|
||||
public static final byte COMMAND_SET_CONF_SAVE = 0x17;
|
||||
public static final byte COMMAND_SET_CONF_END = 0x4f;
|
||||
|
||||
public static final byte COMMAND_SET_PREFS = 0x50;
|
||||
public static final byte COMMAND_SET_SIT_INTERVAL = 0x51;
|
||||
|
||||
public static final byte[] COMMAND_FACTORY_RESET = new byte[] {-74, 90};
|
||||
|
||||
|
||||
public static final byte DATA_STATS = 0x33;
|
||||
public static final byte DATA_STEPS = 0x36;
|
||||
|
||||
public static final byte DATA_SLEEP = 0x1A;
|
||||
|
||||
//Actions to device
|
||||
public static final byte COMMAND_ACTION_INCOMING_SOCIAL = 0x31;
|
||||
public static final byte COMMAND_ACTION_INCOMING_SMS = 0x40;
|
||||
public static final byte COMMAND_ACTION_DISPLAY_TEXT = 0x43;
|
||||
@ -84,6 +75,15 @@ public final class HPlusConstants {
|
||||
public static final byte COMMAND_ACTION_DISPLAY_TEXT_NAME_CN = 0x3E; //Text in GB2312?
|
||||
|
||||
|
||||
//Incoming Messages
|
||||
public static final byte DATA_STATS = 0x33;
|
||||
public static final byte DATA_STEPS = 0x36;
|
||||
public static final byte DATA_DAY_SUMMARY = 0x38;
|
||||
public static final byte DATA_DAY_SUMMARY_ALT = 0x39;
|
||||
public static final byte DATA_SLEEP = 0x1A;
|
||||
public static final byte DATA_INCOMING_CALL_STATE = 0x18;
|
||||
|
||||
|
||||
|
||||
public static final String PREF_HPLUS_SCREENTIME = "hplus_screentime";
|
||||
public static final String PREF_HPLUS_ALLDAYHR = "hplus_alldayhr";
|
||||
|
@ -107,10 +107,10 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
getDevice().setFirmwareVersion2("0");
|
||||
|
||||
//Initialize device
|
||||
setInitValues(builder);
|
||||
setCurrentDate(builder);
|
||||
setCurrentTime(builder);
|
||||
syncPreferences(builder);
|
||||
syncPreferences(builder); //Sync preferences
|
||||
setSIT(builder); //Sync SIT Interval
|
||||
setCurrentDate(builder); // Sync Current Date
|
||||
setCurrentTime(builder); // Sync Current Time
|
||||
|
||||
builder.notify(getCharacteristic(HPlusConstants.UUID_CHARACTERISTIC_MEASURE), true);
|
||||
|
||||
@ -121,14 +121,6 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
return builder;
|
||||
}
|
||||
|
||||
private HPlusSupport setInitValues(TransactionBuilder builder) {
|
||||
LOG.debug("Set Init Values");
|
||||
|
||||
builder.write(ctrlCharacteristic, HPlusConstants.COMMAND_SET_INIT1);
|
||||
builder.write(ctrlCharacteristic, HPlusConstants.COMMAND_SET_INIT2);
|
||||
return this;
|
||||
}
|
||||
|
||||
private HPlusSupport sendUserInfo(TransactionBuilder builder) {
|
||||
builder.write(ctrlCharacteristic, HPlusConstants.COMMAND_SET_PREF_START);
|
||||
builder.write(ctrlCharacteristic, HPlusConstants.COMMAND_SET_PREF_START1);
|
||||
@ -553,9 +545,9 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
byte state;
|
||||
|
||||
if (enable)
|
||||
state = HPlusConstants.HEARTRATE_ALLDAY_ON;
|
||||
state = HPlusConstants.PREF_VALUE_HEARTRATE_ALLDAY_ON;
|
||||
else
|
||||
state = HPlusConstants.HEARTRATE_ALLDAY_OFF;
|
||||
state = HPlusConstants.PREF_VALUE_HEARTRATE_ALLDAY_OFF;
|
||||
|
||||
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.COMMAND_SET_PREF_ALLDAYHR, state});
|
||||
builder.queue(getQueue());
|
||||
@ -813,7 +805,11 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
return processSleepStats(data);
|
||||
case HPlusConstants.DATA_STEPS:
|
||||
return processStepStats(data);
|
||||
|
||||
case HPlusConstants.DATA_DAY_SUMMARY:
|
||||
case HPlusConstants.DATA_DAY_SUMMARY_ALT:
|
||||
return processDaySummary(data);
|
||||
case HPlusConstants.DATA_INCOMING_CALL_STATE:
|
||||
return processIncomingCallState(data);
|
||||
default:
|
||||
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
|
||||
|
||||
@ -821,18 +817,25 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean processIncomingCallState(byte[] data){
|
||||
LOG.debug("Process Incoming Call State");
|
||||
//Disabled now
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
Receives a message containing the status of the day.
|
||||
*/
|
||||
private boolean processDayStats(byte[] data) {
|
||||
private boolean processDaySummary(byte[] data) {
|
||||
LOG.debug("Process Day Summary");
|
||||
|
||||
int a = data[4] * 256 + data[5];
|
||||
if (a < 144) {
|
||||
int slot = a * 2; // 10 minute slots as an offset from 0:00 AM
|
||||
int avgHR = data[1]; //Average Heart Rate
|
||||
int avgHR = data[1]; //Average Heart Rate ?
|
||||
int steps = data[2] * 256 + data[3]; // Steps in this period
|
||||
|
||||
//?? data[6];
|
||||
int timeInactive = data[7];
|
||||
int timeInactive = data[7]; // ?
|
||||
|
||||
LOG.debug("Day Stats: Slot: " + slot + " HR: " + avgHR + " Steps: " + steps + " TimeInactive: " + timeInactive);
|
||||
|
||||
@ -997,6 +1000,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public HPlusHealthActivitySample createActivitySample(Device device, User user, int timestampInSeconds, SampleProvider provider) {
|
||||
HPlusHealthActivitySample sample = new HPlusHealthActivitySample();
|
||||
sample.setDevice(device);
|
||||
|
Loading…
x
Reference in New Issue
Block a user