Auto time calibration

This commit is contained in:
mamutcho 2019-12-23 11:29:09 +02:00
parent 8cc5ed04cd
commit 57df6ec703
7 changed files with 116 additions and 90 deletions

View File

@ -52,7 +52,7 @@ public final class WatchXPlusConstants extends LenovoWatchConstants {
public static final String PREF_LONGSIT_PERIOD = "pref_watchxplus_longsit_period"; public static final String PREF_LONGSIT_PERIOD = "pref_watchxplus_longsit_period";
public static final String PREF_WXP_LANGUAGE = "pref_wxp_language"; public static final String PREF_WXP_LANGUAGE = "pref_wxp_language";
public static final String PREF_POWER_MODE = "pref_wxp_power"; public static final String PREF_POWER_MODE = "pref_wxp_power";
public static final String PREF_ONLY_DIGITAL = "pref_wxp_only_digital";
// time format constants // time format constants
public static final byte ARG_SET_TIMEMODE_24H = 0x00; public static final byte ARG_SET_TIMEMODE_24H = 0x00;
@ -74,10 +74,9 @@ public final class WatchXPlusConstants extends LenovoWatchConstants {
public static final byte[] CMD_NOTIFICATION_TEXT_TASK = new byte[]{0x03, 0x06}; public static final byte[] CMD_NOTIFICATION_TEXT_TASK = new byte[]{0x03, 0x06};
public static final byte[] CMD_NOTIFICATION_CANCEL = new byte[]{0x03, 0x04}; public static final byte[] CMD_NOTIFICATION_CANCEL = new byte[]{0x03, 0x04};
public static final byte[] CMD_NOTIFICATION_SETTINGS = new byte[]{0x03, 0x02}; public static final byte[] CMD_NOTIFICATION_SETTINGS = new byte[]{0x03, 0x02};
public static final byte[] CMD_DO_NOT_DISTURB_SETTINGS = new byte[]{0x03, 0x61};
public static final byte[] CMD_POWER_MODE = new byte[]{0x03, -0x7F}; public static final byte[] CMD_POWER_MODE = new byte[]{0x03, -0x7F};
public static final byte[] CMD_SET_QUITE_HOURS_TIME = new byte[]{0x03, 0x62}; public static final byte[] CMD_SET_DND_HOURS_TIME = new byte[]{0x03, 0x62};
public static final byte[] CMD_SET_QUITE_HOURS_SWITCH = new byte[]{0x03, 0x61}; public static final byte[] CMD_SET_DND_HOURS_SWITCH = new byte[]{0x03, 0x61};
public static final byte[] CMD_SET_PERSONAL_INFO = new byte[]{0x01, 0x0E}; 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_SWITCH = new byte[]{0x03, 0x51};
public static final byte[] CMD_INACTIVITY_REMINDER_SET = new byte[]{0x03, 0x52}; public static final byte[] CMD_INACTIVITY_REMINDER_SET = new byte[]{0x03, 0x52};

View File

@ -249,9 +249,9 @@ Prefs from device settings on main page
/** /**
* @param startOut out Only hour/minute are used. * @param startOut out Only hour/minute are used.
* @param endOut out Only hour/minute are used. * @param endOut out Only hour/minute are used.
* @return True if quite hours are enabled. * @return True if DND hours are enabled.
*/ */
public static boolean getQuiteHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) { public static boolean getDNDHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) {
String doNotDisturb = sharedPrefs.getString(WatchXPlusConstants.PREF_DO_NOT_DISTURB, getContext().getString(R.string.p_off)); String doNotDisturb = sharedPrefs.getString(WatchXPlusConstants.PREF_DO_NOT_DISTURB, getContext().getString(R.string.p_off));
assert doNotDisturb != null; assert doNotDisturb != null;
@ -278,7 +278,7 @@ Prefs from device settings on main page
/** /**
* @param startOut out Only hour/minute are used. * @param startOut out Only hour/minute are used.
* @param endOut out Only hour/minute are used. * @param endOut out Only hour/minute are used.
* @return True if quite hours are enabled. * @return True if DND hours are enabled.
*/ */
public static boolean getLongSitHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) { public static boolean getLongSitHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) {
boolean enabled = prefs.getBoolean(WatchXPlusConstants.PREF_LONGSIT_SWITCH, false); boolean enabled = prefs.getBoolean(WatchXPlusConstants.PREF_LONGSIT_SWITCH, false);

View File

@ -814,7 +814,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
} }
if (mAutoConnectInvervalReceiver != null) { if (mAutoConnectInvervalReceiver != null) {
unregisterReceiver(mAutoConnectInvervalReceiver); unregisterReceiver(mAutoConnectInvervalReceiver);
mAutoConnectIntervalReceiver.destroy(); mAutoConnectInvervalReceiver.destroy();
mAutoConnectInvervalReceiver = null; mAutoConnectInvervalReceiver = null;
} }
} }

View File

@ -90,9 +90,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import static android.content.Context.MODE_PRIVATE;
public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
private static final Prefs prefs = GBApplication.getPrefs(); private static final Prefs prefs = GBApplication.getPrefs();
@ -212,7 +209,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
bArr)); bArr));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to cancel notification", e); LOG.warn(" Unable to cancel notification ", e);
} }
} }
@ -256,7 +253,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to send notification", e); LOG.warn(" Unable to send notification ", e);
} }
} }
@ -291,7 +288,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
new byte[]{(byte) (enable ? 0x01 : 0x00)})); new byte[]{(byte) (enable ? 0x01 : 0x00)}));
performImmediately(builder); performImmediately(builder);
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to start/stop calibration mode", e); LOG.warn(" Unable to start/stop calibration mode ", e);
} }
} }
@ -303,7 +300,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
WatchXPlusConstants.KEEP_ALIVE)); WatchXPlusConstants.KEEP_ALIVE));
performImmediately(builder); performImmediately(builder);
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to keep calibration mode alive", e); LOG.warn(" Unable to keep calibration mode alive ", e);
} }
} }
@ -319,10 +316,18 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
performImmediately(builder); performImmediately(builder);
} catch (IOException e) { } catch (IOException e) {
isCalibrationActive = false; isCalibrationActive = false;
LOG.warn("Unable to send calibration data", e); LOG.warn(" Unable to send calibration data ", e);
} }
} }
private WatchXPlusDeviceSupport checkInitTime(TransactionBuilder builder) {
LOG.info(" Check init time ");
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_TIME_SETTINGS,
WatchXPlusConstants.READ_VALUE));
return this;
}
private void getTime() { private void getTime() {
try { try {
TransactionBuilder builder = performInitialized("getTime"); TransactionBuilder builder = performInitialized("getTime");
@ -331,7 +336,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
WatchXPlusConstants.READ_VALUE)); WatchXPlusConstants.READ_VALUE));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to get device time", e); LOG.warn(" Unable to get device time ", e);
} }
} }
@ -348,13 +353,26 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
nowDevice.set(Calendar.DAY_OF_WEEK, Conversion.fromBcd8(time[16]) + 1); nowDevice.set(Calendar.DAY_OF_WEEK, Conversion.fromBcd8(time[16]) + 1);
long timeDiff = (Math.abs(now.getTimeInMillis() - nowDevice.getTimeInMillis())) / 1000; long timeDiff = (Math.abs(now.getTimeInMillis() - nowDevice.getTimeInMillis())) / 1000;
LOG.info(" Time diff: " + timeDiff);
if (10 < timeDiff && timeDiff < 120) { if (10 < timeDiff && timeDiff < 120) {
enableCalibration(true); LOG.info(" Set new time ");
setTime(BLETypeConversions.createCalendar()); boolean onlyDigital = prefs.getBoolean(WatchXPlusConstants.PREF_ONLY_DIGITAL, true);
enableCalibration(false); if (onlyDigital) {
LOG.info(" Auto set time ");
enableCalibration(true);
setTime(BLETypeConversions.createCalendar());
enableCalibration(false);
} else {
LOG.info(" Auto set time is OFF ");
}
} else if (timeDiff > 120) {
LOG.info(" Time diff is too big ");
GB.toast("Manual time calibration needed!", Toast.LENGTH_LONG, GB.WARN);
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_DEFAULT, "Calibrate time");
} }
} }
// set only digytal time
private void setTime(Calendar calendar) { private void setTime(Calendar calendar) {
try { try {
TransactionBuilder builder = performInitialized("setTime"); TransactionBuilder builder = performInitialized("setTime");
@ -376,7 +394,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
time)); time));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set time", e); LOG.warn(" Unable to set time ", e);
} }
} }
@ -412,6 +430,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
.setFitnessGoal(builder) // set steps per day .setFitnessGoal(builder) // set steps per day
.getBloodPressureCalibrationStatus(builder) // request blood pressure calibration .getBloodPressureCalibrationStatus(builder) // request blood pressure calibration
//.setUnitsSettings() // set metric/imperial units //.setUnitsSettings() // set metric/imperial units
.checkInitTime(builder)
.syncPreferences(builder); // read preferences from app and set them to watch .syncPreferences(builder); // read preferences from app and set them to watch
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext())); builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
builder.setGattCallback(this); builder.setGattCallback(this);
@ -426,6 +445,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSetTime() { public void onSetTime() {
LOG.info(" Get time ");
getTime(); getTime();
} }
@ -438,7 +458,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set alarms", e); LOG.warn(" Unable to set alarms ", e);
} }
} }
@ -649,7 +669,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
* @param gender - user age * @param gender - user age
*/ */
private void setPersonalInformation(TransactionBuilder builder, int height, int weight, int age, int gender) { private void setPersonalInformation(TransactionBuilder builder, int height, int weight, int age, int gender) {
LOG.warn(" Setting Personal Information... height:"+height+" weight:"+weight+" age:"+age+" gender:"+gender); LOG.info(" Setting Personal Information... height:"+height+" weight:"+weight+" age:"+age+" gender:"+gender);
byte[] command = WatchXPlusConstants.CMD_SET_PERSONAL_INFO; byte[] command = WatchXPlusConstants.CMD_SET_PERSONAL_INFO;
byte[] bArr = new byte[4]; byte[] bArr = new byte[4];
@ -737,7 +757,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
WatchXPlusConstants.READ_VALUE)); WatchXPlusConstants.READ_VALUE));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to retrieve battery data", e); LOG.warn(" Unable to retrieve battery data ", e);
} }
try { try {
@ -752,7 +772,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to retrieve recorded data", e); LOG.warn(" Unable to retrieve recorded data ", e);
} }
} }
@ -852,7 +872,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
case WatchXPlusConstants.PREF_DO_NOT_DISTURB: case WatchXPlusConstants.PREF_DO_NOT_DISTURB:
case WatchXPlusConstants.PREF_DO_NOT_DISTURB_START: case WatchXPlusConstants.PREF_DO_NOT_DISTURB_START:
case WatchXPlusConstants.PREF_DO_NOT_DISTURB_END: case WatchXPlusConstants.PREF_DO_NOT_DISTURB_END:
setQuiteHours(builder, sharedPreferences); setDNDHours(builder, sharedPreferences);
break; break;
} }
builder.queue(getQueue()); builder.queue(getQueue());
@ -881,9 +901,9 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
* @param minuteEnd - end minute * @param minuteEnd - end minute
*/ */
private void setLongSitHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd, int period) { private void setLongSitHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd, int period) {
LOG.warn(" Setting Long sit reminder... Enabled:"+enable+" Period:"+period); LOG.info(" Setting Long sit reminder... Enabled:"+enable+" Period:"+period);
LOG.warn(" Setting Long sit time... Hs:"+hourEnd+" Ms:"+minuteEnd+" He:"+hourStart+" Me:"+minuteStart); LOG.info(" Setting Long sit time... Hs:"+hourEnd+" Ms:"+minuteEnd+" He:"+hourStart+" Me:"+minuteStart);
LOG.warn(" Setting Long sit DND time... Hs:"+hourStart+" Ms:"+minuteStart+" He:"+hourEnd+" Me:"+minuteEnd); LOG.info(" Setting Long sit DND time... Hs:"+hourStart+" Ms:"+minuteStart+" He:"+hourEnd+" Me:"+minuteEnd);
// set Long Sit reminder time // set Long Sit reminder time
byte[] command = WatchXPlusConstants.CMD_INACTIVITY_REMINDER_SET; byte[] command = WatchXPlusConstants.CMD_INACTIVITY_REMINDER_SET;
@ -921,7 +941,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
period); period);
} else { } else {
// disable Long sit reminder // disable Long sit reminder
LOG.info(" Long sit reminder are disabled"); LOG.info(" Long sit reminder are disabled ");
this.setLongSitSwitch(builder, enable); this.setLongSitSwitch(builder, enable);
} }
} }
@ -931,7 +951,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
* @param enable - true or false * @param enable - true or false
*/ */
private void setLongSitSwitch(TransactionBuilder tbuilder, boolean enable) { private void setLongSitSwitch(TransactionBuilder tbuilder, boolean enable) {
LOG.warn("Setting Long sit reminder switch to" + enable); LOG.info(" Setting Long sit reminder switch to: " + enable);
tbuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), tbuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_INACTIVITY_REMINDER_SWITCH, buildCommand(WatchXPlusConstants.CMD_INACTIVITY_REMINDER_SWITCH,
WatchXPlusConstants.WRITE_VALUE, WatchXPlusConstants.WRITE_VALUE,
@ -948,10 +968,10 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
* @param hourEnd - end hour * @param hourEnd - end hour
* @param minuteEnd - end minute * @param minuteEnd - end minute
*/ */
private void setQuiteHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd) { private void setDNDHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd) {
LOG.warn(" Setting DND time... Hs:"+hourStart+" Ms:"+minuteStart+" He:"+hourEnd+" Me:"+minuteEnd); LOG.info(" Setting DND time... Hs:"+hourStart+" Ms:"+minuteStart+" He:"+hourEnd+" Me:"+minuteEnd);
// set DND time // set DND time
byte[] command = WatchXPlusConstants.CMD_SET_QUITE_HOURS_TIME; byte[] command = WatchXPlusConstants.CMD_SET_DND_HOURS_TIME;
byte[] bArr = new byte[4]; byte[] bArr = new byte[4];
bArr[0] = (byte) hourStart; // byte[08] bArr[0] = (byte) hourStart; // byte[08]
@ -961,17 +981,17 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(command, WatchXPlusConstants.WRITE_VALUE, bArr)); buildCommand(command, WatchXPlusConstants.WRITE_VALUE, bArr));
// set DND state (enabled, disabled) // set DND state (enabled, disabled)
setQuiteHoursSwitch(builder, enable); setDNDHoursSwitch(builder, enable);
} }
/** set do not disturb switch /** set do not disturb switch
* @param tbuilder - transaction builder * @param tbuilder - transaction builder
* @param enable - true or false * @param enable - true or false
*/ */
private void setQuiteHoursSwitch(TransactionBuilder tbuilder, boolean enable) { private void setDNDHoursSwitch(TransactionBuilder tbuilder, boolean enable) {
LOG.warn("Setting DND switch to" + enable); LOG.info(" Setting DND switch to: " + enable);
tbuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), tbuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_SET_QUITE_HOURS_SWITCH, buildCommand(WatchXPlusConstants.CMD_SET_DND_HOURS_SWITCH,
WatchXPlusConstants.WRITE_VALUE, WatchXPlusConstants.WRITE_VALUE,
new byte[]{(byte) (enable ? 0x01 : 0x00)})); new byte[]{(byte) (enable ? 0x01 : 0x00)}));
} }
@ -980,18 +1000,18 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
* @param builder - transaction builder * @param builder - transaction builder
* @param sharedPreferences - shared preferences * @param sharedPreferences - shared preferences
*/ */
private void setQuiteHours(TransactionBuilder builder, SharedPreferences sharedPreferences) { private void setDNDHours(TransactionBuilder builder, SharedPreferences sharedPreferences) {
Calendar start = new GregorianCalendar(); Calendar start = new GregorianCalendar();
Calendar end = new GregorianCalendar(); Calendar end = new GregorianCalendar();
boolean enable = WatchXPlusDeviceCoordinator.getQuiteHours(sharedPreferences, start, end); boolean enable = WatchXPlusDeviceCoordinator.getDNDHours(sharedPreferences, start, end);
if (enable) { if (enable) {
this.setQuiteHours(builder, enable, this.setDNDHours(builder, enable,
start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE), start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE),
end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE)); end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE));
} else { } else {
// disable DND // disable DND
LOG.info(" Quiet hours are disabled"); LOG.info(" Quiet hours are disabled ");
this.setQuiteHoursSwitch(builder, enable); this.setDNDHoursSwitch(builder, enable);
} }
} }
@ -1012,7 +1032,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
bArr)); bArr));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set power mode", e); LOG.warn(" Unable to set power mode ", e);
} }
//prefs.getPreferences().edit().putInt("PREF_POWER_MODE", 0).apply(); //prefs.getPreferences().edit().putInt("PREF_POWER_MODE", 0).apply();
} }
@ -1029,7 +1049,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
WatchXPlusConstants.READ_VALUE)); WatchXPlusConstants.READ_VALUE));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to get units", e); LOG.warn(" Unable to get units ", e);
} }
return this; return this;
} }
@ -1040,9 +1060,9 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
private void setUnitsSettings() { private void setUnitsSettings() {
int units = 0; int units = 0;
if (getContext().getString(R.string.p_unit_metric).equals(units)) { if (getContext().getString(R.string.p_unit_metric).equals(units)) {
LOG.info(" Changed units: metric"); LOG.info(" Changed units: metric ");
} else { } else {
LOG.info(" Changed units: imperial"); LOG.info(" Changed units: imperial ");
} }
byte[] bArr = new byte[3]; byte[] bArr = new byte[3];
bArr[0] = (byte) units; // metric - 0/imperial - 1 bArr[0] = (byte) units; // metric - 0/imperial - 1
@ -1056,7 +1076,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
bArr)); bArr));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set units", e); LOG.warn(" Unable to set units ", e);
} }
} }
@ -1078,7 +1098,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
try { try {
int beginCalibration = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_SWITCH, 0); int beginCalibration = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_SWITCH, 0);
if (beginCalibration == 1) { if (beginCalibration == 1) {
LOG.warn(" Calibrating BP - cancel " + beginCalibration); LOG.info(" Calibrating BP - cancel " + beginCalibration);
return; return;
} }
int mLowP = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_LOW, 80); int mLowP = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_LOW, 80);
@ -1104,7 +1124,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
bArr)); bArr));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to send BP Calibration", e); LOG.warn(" Unable to send BP Calibration ", e);
} }
} }
@ -1122,7 +1142,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
private void handleBloodPressureCalibrationResult(byte[] value) { private void handleBloodPressureCalibrationResult(byte[] value) {
if (Conversion.fromByteArr16(value[8]) != 0x00) { if (Conversion.fromByteArr16(value[8]) != 0x00) {
WatchXPlusDeviceCoordinator.isBPCalibrated = false; WatchXPlusDeviceCoordinator.isBPCalibrated = false;
GB.toast("Calibrating BP fail", Toast.LENGTH_LONG, GB.ERROR); GB.toast(" Calibrating BP fail ", Toast.LENGTH_LONG, GB.ERROR);
} else { } else {
WatchXPlusDeviceCoordinator.isBPCalibrated = true; WatchXPlusDeviceCoordinator.isBPCalibrated = true;
int high = Conversion.fromByteArr16(value[9], value[10]); int high = Conversion.fromByteArr16(value[9], value[10]);
@ -1136,7 +1156,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
*/ */
private void requestBloodPressureMeasurement() { private void requestBloodPressureMeasurement() {
if (!WatchXPlusDeviceCoordinator.isBPCalibrated) { if (!WatchXPlusDeviceCoordinator.isBPCalibrated) {
LOG.warn("BP is NOT calibrated"); LOG.info(" BP is NOT calibrated ");
GB.toast("BP is not calibrated", Toast.LENGTH_LONG, GB.WARN); GB.toast("BP is not calibrated", Toast.LENGTH_LONG, GB.WARN);
return; return;
} }
@ -1150,7 +1170,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
WatchXPlusConstants.TASK, new byte[]{0x01})); WatchXPlusConstants.TASK, new byte[]{0x01}));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to request BP Measure", e); LOG.warn(" Unable to request BP Measure ", e);
} }
} }
@ -1165,14 +1185,14 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
int second = prefs.getInt("wxp_newcmd_second", 0); int second = prefs.getInt("wxp_newcmd_second", 0);
byte[] command = new byte[]{(byte) first, (byte) second}; byte[] command = new byte[]{(byte) first, (byte) second};
LOG.info("testing new command " + Arrays.toString(command)); LOG.info(" testing new command " + Arrays.toString(command));
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(command, buildCommand(command,
WatchXPlusConstants.READ_VALUE)); WatchXPlusConstants.READ_VALUE));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to request HR Measure", e); LOG.warn(" Unable to request new command ", e);
} }
} }
@ -1313,7 +1333,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
currentConditionCode = 261; currentConditionCode = 261;
break; break;
} }
LOG.info( "Weather cond: " + currentCondition + " icon: " + currentConditionCode); LOG.info( " Weather cond: " + currentCondition + " icon: " + currentConditionCode);
// calculate for temps under 0 // calculate for temps under 0
currentTemp = (Math.abs(weatherSpec.currentTemp)) - 273; currentTemp = (Math.abs(weatherSpec.currentTemp)) - 273;
if (currentTemp < 0) { if (currentTemp < 0) {
@ -1327,7 +1347,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
if (todayMaxTemp < 0) { if (todayMaxTemp < 0) {
todayMaxTemp = (Math.abs(todayMaxTemp) ^ 255) + 1; todayMaxTemp = (Math.abs(todayMaxTemp) ^ 255) + 1;
} }
LOG.warn(" Set weather min: " + todayMinTemp + " max: " + todayMaxTemp + " current: " + currentTemp + " icon: " + currentCondition); LOG.info(" Set weather min: " + todayMinTemp + " max: " + todayMaxTemp + " current: " + currentTemp + " icon: " + currentCondition);
// First two bytes are controlling the icon // First two bytes are controlling the icon
weatherInfo[0] = (byte )(currentConditionCode >> 8); weatherInfo[0] = (byte )(currentConditionCode >> 8);
weatherInfo[1] = (byte )currentConditionCode; weatherInfo[1] = (byte )currentConditionCode;
@ -1340,7 +1360,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
weatherInfo)); weatherInfo));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set weather", e); LOG.warn(" Unable to set weather ", e);
} }
} }
@ -1376,7 +1396,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
this.onReverseFindDevice(true); this.onReverseFindDevice(true);
// It looks like WatchXPlus doesn't send this action // It looks like WatchXPlus doesn't send this action
// WRONG: WatchXPlus send this on find phone // WRONG: WatchXPlus send this on find phone
LOG.info(" Unhandled action: Button pressed"); LOG.info(" Unhandled action: Button pressed ");
} else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_ALARM_INDICATOR, 5)) { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_ALARM_INDICATOR, 5)) {
LOG.info(" Alarm active: id=" + value[8]); LOG.info(" Alarm active: id=" + value[8]);
} else if (isCalibrationActive && value.length == 7 && value[4] == ACK_CALIBRATION) { } else if (isCalibrationActive && value.length == 7 && value[4] == ACK_CALIBRATION) {
@ -1385,24 +1405,24 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DAY_STEPS_INDICATOR, 5)) { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DAY_STEPS_INDICATOR, 5)) {
handleStepsInfo(value); handleStepsInfo(value);
} else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DATA_COUNT, 5)) { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DATA_COUNT, 5)) {
LOG.info(" Received data count"); LOG.info(" Received data count ");
handleDataCount(value); handleDataCount(value);
} else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DATA_DETAILS, 5)) { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DATA_DETAILS, 5)) {
LOG.info(" Received data details"); LOG.info(" Received data details ");
handleDataDetails(value); handleDataDetails(value);
} else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DATA_CONTENT, 5)) { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DATA_CONTENT, 5)) {
LOG.info(" Received data content"); LOG.info(" Received data content ");
handleDataContentAck(value); handleDataContentAck(value);
} else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_BP_MEASURE_STARTED, 5)) { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_BP_MEASURE_STARTED, 5)) {
handleBpMeasureResult(value); handleBpMeasureResult(value);
} else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DATA_CONTENT_REMOVE, 5)) { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DATA_CONTENT_REMOVE, 5)) {
handleDataContentRemove(value); handleDataContentRemove(value);
} else if (value.length == 7 && value[5] == 0) { } else if (value.length == 7 && value[5] == 0) {
LOG.info(" Received ACK"); LOG.info(" Received ACK ");
// Not sure if that's necessary. There is no response for ACK in original app logs // Not sure if that's necessary. There is no response for ACK in original app logs
// handleAck(); // handleAck();
} else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_NOTIFICATION_SETTINGS, 5)) { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_NOTIFICATION_SETTINGS, 5)) {
LOG.info(" Received notification settings status"); LOG.info(" Received notification settings status ");
} else { } else {
LOG.info(" Unhandled value change for characteristic: " + characteristicUUID); LOG.info(" Unhandled value change for characteristic: " + characteristicUUID);
logMessageContent(characteristic.getValue()); logMessageContent(characteristic.getValue());
@ -1458,7 +1478,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to send request to retrieve recorded data", e); LOG.warn(" Unable to send request to retrieve recorded data ", e);
} }
} }
@ -1468,7 +1488,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
int dataCount = Conversion.fromByteArr16(value[10], value[11]); int dataCount = Conversion.fromByteArr16(value[10], value[11]);
DataType type = DataType.getType(dataType); DataType type = DataType.getType(dataType);
LOG.info("Watch contains " + dataCount + " " + type + " entries"); LOG.info(" Watch contains " + dataCount + " " + type + " entries");
dataSlots = dataCount; dataSlots = dataCount;
dataToFetch.clear(); dataToFetch.clear();
if (dataCount != 0) { if (dataCount != 0) {
@ -1491,12 +1511,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to request data details", e); LOG.warn( "Unable to request data details ", e);
} }
} }
private void handleDataDetails(byte[] value) { private void handleDataDetails(byte[] value) {
LOG.info("Got data details"); LOG.info(" Got data details ");
int timestamp = Conversion.fromByteArr16(value[8], value[9], value[10], value[11]); int timestamp = Conversion.fromByteArr16(value[8], value[9], value[10], value[11]);
int dataLength = Conversion.fromByteArr16(value[12], value[13]); int dataLength = Conversion.fromByteArr16(value[12], value[13]);
int samplingInterval = (int) onSamplingInterval(value[14] >> 4, Conversion.fromByteArr16((byte) (value[14] & 15), value[15])); int samplingInterval = (int) onSamplingInterval(value[14] >> 4, Conversion.fromByteArr16((byte) (value[14] & 15), value[15]));
@ -1506,12 +1526,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
parts++; parts++;
} }
LOG.info("timestamp (UTC): " + timestamp); LOG.info(" timestamp (UTC): " + timestamp);
LOG.info("timestamp (UTC): " + new Date((long) timestamp * 1000)); LOG.info(" timestamp (UTC): " + new Date((long) timestamp * 1000));
LOG.info("dataLength (data length): " + dataLength); LOG.info(" dataLength (data length): " + dataLength);
LOG.info("samplingInterval (per time): " + samplingInterval); LOG.info(" samplingInterval (per time): " + samplingInterval);
LOG.info("mtu (mtu): " + mtu); LOG.info(" mtu (mtu): " + mtu);
LOG.info("parts: " + parts); LOG.info(" parts: " + parts);
dataToFetch.put(timestamp, parts); dataToFetch.put(timestamp, parts);
@ -1539,7 +1559,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
req)); req));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to request data content", e); LOG.warn(" Unable to request data content ", e);
} }
} }
@ -1556,12 +1576,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
req)); req));
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to remove data content", e); LOG.warn(" Unable to remove data content ", e);
} }
} }
private void handleDataContentAck(byte[] value) { private void handleDataContentAck(byte[] value) {
LOG.info(" Received data content start"); LOG.info(" Received data content start ");
// To verify: Chunks are sent if value[8] == 0, if value[8] == 1 they are not sent by watch // To verify: Chunks are sent if value[8] == 0, if value[8] == 1 they are not sent by watch
} }
@ -1623,7 +1643,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
LOG.warn(" Got unsupported data package type: " + type); LOG.warn(" Got unsupported data package type: " + type);
} }
} catch (Exception ex) { } catch (Exception ex) {
LOG.info((ex.getMessage())); LOG.warn((ex.getMessage()));
} }
} }
@ -1656,10 +1676,10 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
private void handleBpMeasureResult(byte[] value) { private void handleBpMeasureResult(byte[] value) {
if (value.length < 11) { if (value.length < 11) {
LOG.info(" BP Measure started. Waiting for result"); LOG.info(" BP Measure started. Waiting for result ");
GB.toast("BP Measure started. Waiting for result...", Toast.LENGTH_LONG, GB.INFO); GB.toast("BP Measure started. Waiting for result...", Toast.LENGTH_LONG, GB.INFO);
} else { } else {
LOG.info(" Received BP live data"); LOG.info(" Received BP live data ");
int high = Conversion.fromByteArr16(value[8], value[9]); int high = Conversion.fromByteArr16(value[8], value[9]);
int low = Conversion.fromByteArr16(value[10], value[11]); int low = Conversion.fromByteArr16(value[10], value[11]);
int timestamp = Conversion.fromByteArr16(value[12], value[13], value[14], value[15]); int timestamp = Conversion.fromByteArr16(value[12], value[13], value[14], value[15]);
@ -1676,7 +1696,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
buildCommand()); buildCommand());
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to response to ACK", e); LOG.warn(" Unable to response to ACK ", e);
} }
} }
@ -1700,12 +1720,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
*/ */
private void handleSportAimStatus(byte[] value) { private void handleSportAimStatus(byte[] value) {
int stepsAim = Conversion.fromByteArr16(value[8], value[9]); int stepsAim = Conversion.fromByteArr16(value[8], value[9]);
LOG.debug(" Received goal stepsAim: " + stepsAim); LOG.info(" Received goal stepsAim: " + stepsAim);
} }
private void handleStepsInfo(byte[] value) { private void handleStepsInfo(byte[] value) {
int steps = Conversion.fromByteArr16(value[8], value[9]); int steps = Conversion.fromByteArr16(value[8], value[9]);
LOG.debug(" Received steps count: " + steps); LOG.info(" Received steps count: " + steps);
// This code is from MakibesHR3DeviceSupport // This code is from MakibesHR3DeviceSupport
Calendar date = GregorianCalendar.getInstance(); Calendar date = GregorianCalendar.getInstance();
@ -1717,7 +1737,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
int newSteps = (steps - dayStepCount); int newSteps = (steps - dayStepCount);
if (newSteps > 0) { if (newSteps > 0) {
LOG.debug("adding " + newSteps + " steps"); LOG.info("adding " + newSteps + " steps");
try (DBHandler dbHandler = GBApplication.acquireDB()) { try (DBHandler dbHandler = GBApplication.acquireDB()) {
WatchXPlusSampleProvider provider = new WatchXPlusSampleProvider(getDevice(), dbHandler.getDaoSession()); WatchXPlusSampleProvider provider = new WatchXPlusSampleProvider(getDevice(), dbHandler.getDaoSession());
@ -1736,7 +1756,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
sample.setProvider(provider); sample.setProvider(provider);
provider.addGBActivitySample(sample); provider.addGBActivitySample(sample);
} catch (Exception ex) { } catch (Exception ex) {
LOG.info((ex.getMessage())); LOG.warn(ex.getMessage());
} }
} }
} }
@ -1767,7 +1787,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
return totalSteps; return totalSteps;
} catch (Exception ex) { } catch (Exception ex) {
LOG.error(ex.getMessage()); LOG.warn(ex.getMessage());
return 0; return 0;
} }
@ -1886,7 +1906,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
private void syncPreferences(TransactionBuilder transaction) { private void syncPreferences(TransactionBuilder transaction) {
SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(this.getDevice().getAddress()); SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(this.getDevice().getAddress());
this.setHeadsUpScreen(transaction, sharedPreferences); // lift wirst to screen on this.setHeadsUpScreen(transaction, sharedPreferences); // lift wirst to screen on
this.setQuiteHours(transaction, sharedPreferences); // DND this.setDNDHours(transaction, sharedPreferences); // DND
this.setDisconnectReminder(transaction, sharedPreferences); // disconnect reminder 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.setAltitude(transaction); // set altitude calibration

View File

@ -291,10 +291,7 @@
<string name="pref_wxp_title_repeat_on_call">Повтаряй известие за позвъняване</string> <string name="pref_wxp_title_repeat_on_call">Повтаряй известие за позвъняване</string>
<string name="pref_wxp_title_repeat_on_call_summary">Възможни стойности min=0, max=10</string> <string name="pref_wxp_title_repeat_on_call_summary">Възможни стойности min=0, max=10</string>
<string name="prefs_wxp_continious">Известявай докато телефона звъни</string> <string name="prefs_wxp_continious">Известявай докато телефона звъни</string>
<string name="prefs_wxp_missed">Известие за пропуснато обаждане</string>
<string name="preferences_watchxplus_settings">Watch X Plus настройки</string> <string name="preferences_watchxplus_settings">Watch X Plus настройки</string>
<string name="pref_header_wxp_notification_call">Известия при обаждане</string>
<string name="pref_header_wxp_notification_misscall">Известия при пропуснато обаждане</string>
<string name="pref_wxp_title_reject_summary">Изкл. - заглуши, Вкл. - откажи</string> <string name="pref_wxp_title_reject_summary">Изкл. - заглуши, Вкл. - откажи</string>
<string name="prefs_wxp_reject">Бутона заглушава/отказва повикване</string> <string name="prefs_wxp_reject">Бутона заглушава/отказва повикване</string>
<string name="pref_wxp_title_shake_reject_summary">Повтаря действието на бутона</string> <string name="pref_wxp_title_shake_reject_summary">Повтаря действието на бутона</string>
@ -319,6 +316,8 @@
<string name="prefs_wxp_longsit_switch">Включи напомняне за активност</string> <string name="prefs_wxp_longsit_switch">Включи напомняне за активност</string>
<string name="pref_wxp_title_longsit">Период на неактивност (минути)</string> <string name="pref_wxp_title_longsit">Период на неактивност (минути)</string>
<string name="wxp_language_title">Език</string> <string name="wxp_language_title">Език</string>
<string name="pref_wxp_title_only_digital">Синхронизирай часа</string>
<string name="pref_wxp_title_only_digital_sum">Синхронизирай дата и час при свързване</string>
<string name="pref_header_wxp_call_notification">Известия и Обаждания</string> <string name="pref_header_wxp_call_notification">Известия и Обаждания</string>
<string name="title_activity_sleepmonitor">Наблюдение/анализ на съня</string> <string name="title_activity_sleepmonitor">Наблюдение/анализ на съня</string>

View File

@ -222,6 +222,8 @@
<string name="pref_wxp_longsit_switch_summary">Inactivity time interval is from DND setting</string> <string name="pref_wxp_longsit_switch_summary">Inactivity time interval is from DND setting</string>
<string name="prefs_wxp_longsit_switch">Enable inactivity reminder</string> <string name="prefs_wxp_longsit_switch">Enable inactivity reminder</string>
<string name="pref_wxp_title_longsit">Inactivity period (minutes)</string> <string name="pref_wxp_title_longsit">Inactivity period (minutes)</string>
<string name="pref_wxp_title_only_digital">Synchronize time</string>
<string name="pref_wxp_title_only_digital_sum">On reconnect auto synchronize time</string>
<string name="wxp_language_title">Language</string> <string name="wxp_language_title">Language</string>
<!-- Makibes HR3 Preferences --> <!-- Makibes HR3 Preferences -->

View File

@ -89,6 +89,12 @@
android:summary="@string/pref_wxp_longsit_switch_summary" android:summary="@string/pref_wxp_longsit_switch_summary"
android:title="@string/prefs_wxp_longsit_switch" /> android:title="@string/prefs_wxp_longsit_switch" />
</PreferenceScreen> </PreferenceScreen>
<CheckBoxPreference
android:layout="@layout/preference_checkbox"
android:defaultValue="true"
android:key="pref_wxp_only_digital"
android:summary="@string/pref_wxp_title_only_digital_sum"
android:title="@string/pref_wxp_title_only_digital" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="pref_category_watchxplus_calibration" android:key="pref_category_watchxplus_calibration"