Some fixes

This commit is contained in:
mamutcho 2019-11-18 19:10:56 +02:00
parent 4ff17153b6
commit 71ff71cb2c
3 changed files with 62 additions and 9 deletions

View File

@ -79,6 +79,7 @@ public final class WatchXPlusConstants extends LenovoWatchConstants {
public static final byte[] CMD_SET_PERSONAL_INFO = new byte[]{0x01, 0x0E};
public static final byte[] CMD_INACTIVITY_REMINDER_SWITCH = new byte[]{0x03, 0x51};
public static final byte[] CMD_INACTIVITY_REMINDER_SET = new byte[]{0x03, 0x52};
public static final byte[] CMD_SET_UNITS = new byte[]{0x03, -0x6D};
public static final byte[] CMD_FITNESS_GOAL_SETTINGS = new byte[]{0x10, 0x02};
public static final byte[] CMD_DAY_STEPS_INFO = new byte[]{0x10, 0x03};

View File

@ -1,8 +1,6 @@
NEED TO BE DONE
Watch settings
- Set watch units (metric/imperial)
- Implement temperature alarm on watch
- switch, lowTemp, highTemp
- Implement temperature alarm on watch //tried to implement with no luck
- Implement continuous blood pressure measurement (on, off, scheduled)
Add feature to initiate button press event on watch
@ -14,9 +12,6 @@ NEED TO BE DONE
- Disconnect reminder scheduler (inApp, not supported by watch)
- Continuous blood pressure measurement (supported by watch, there are command for that, but not tested)
Refine send weather to watch
- Send weather icon
Refine get activity data
- Fix get sleep data
@ -69,6 +64,7 @@ WORK PROGRESS
- Send User details to watch [height, weight, age, gender] (10.11.2019) (need more testing)
- Implemented long sit reminder (inactivity reminder)[on, off, period] (17.11.2019)
- Set watch language [English, Chinese] (17.11.2019)
- Set watch units (metric/imperial) (17.11.2019)
Activity data
- get steps per day
@ -76,6 +72,8 @@ WORK PROGRESS
- get sleep data
- set user goal for steps
Send weather
- Send weather icon (17.11.2019)
Changed in app device icon (02.11.2019)
Get blood pressure measurement result (work only if blood pressure is calibrated)
Pairing activity

View File

@ -50,11 +50,14 @@ import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.DebugActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
@ -94,9 +97,12 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
protected static Prefs prefs = GBApplication.getPrefs();
private boolean needsAuth;
private int sequenceNumber = 0;
private boolean isCalibrationActive = false;
@ -412,6 +418,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
.enableNotificationChannels(builder)
.setFitnessGoal(builder) // set steps per day
.getBloodPressureCalibrationStatus(builder) // request blood pressure calibration
//.setUnitsSettings() // set metric/imperial units
.syncPreferences(builder); // read preferences from app and set them to watch
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
builder.setGattCallback(this);
@ -825,6 +832,9 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
case "WXP_LANGUAGE":
setLanguageAndTimeFormat(builder, sharedPreferences);
break;
case "measurement_system":
setUnitsSettings();
break;
}
builder.queue(getQueue());
} catch (IOException e) {
@ -999,6 +1009,50 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
return this;
}
/** request watch units
* for testing purposes only
*/
private WatchXPlusDeviceSupport getUnitsSettings() {
LOG.info(" Get units from watch... ");
try {
TransactionBuilder builder = performInitialized("getUnits");
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_SET_UNITS,
WatchXPlusConstants.READ_VALUE));
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn("Unable to get units", e);
}
return this;
}
/** set watch units
*
*/
private WatchXPlusDeviceSupport setUnitsSettings() {
int units = 0;
if (getContext().getString(R.string.p_unit_metric).equals(units)) {
LOG.info(" Changed units: metric");
} else {
LOG.info(" Changed units: imperial");
}
byte[] bArr = new byte[3];
bArr[0] = (byte) units; // metric - 0/imperial - 1
bArr[1] = (byte) 0x00; //time unit 12/24h (there are separate command for this)
bArr[2] = (byte) 0x00; // temperature unit (do nothing)
try {
TransactionBuilder builder = performInitialized("setUnits");
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_SET_UNITS,
WatchXPlusConstants.WRITE_VALUE,
bArr));
builder.queue(getQueue());
} catch (IOException e) {
LOG.warn("Unable to set units", e);
}
return this;
}
/** request status of blood pressure calibration
* @param builder
*/
@ -1725,11 +1779,11 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
private void syncPreferences(TransactionBuilder transaction) {
SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(this.getDevice().getAddress());
this.setHeadsUpScreen(transaction, sharedPreferences); // lift wirst to screen on
this.setQuiteHours(transaction, sharedPreferences); // DND
this.setQuiteHours(transaction, sharedPreferences); // DND
this.setDisconnectReminder(transaction, sharedPreferences); // disconnect reminder
this.setLanguageAndTimeFormat(transaction, sharedPreferences); // set time mode 12/24h
this.setLanguageAndTimeFormat(transaction, sharedPreferences); // set time mode 12/24h
this.setAltitude(transaction); // set altitude calibration
this.setLongSitHours(transaction, sharedPreferences); // set Long sit reminder
this.setLongSitHours(transaction, sharedPreferences); // set Long sit reminder
ActivityUser activityUser = new ActivityUser();
this.setPersonalInformation(transaction, activityUser.getHeightCm(), activityUser.getWeightKg(),
activityUser.getAge(),activityUser.getGender());