mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-26 00:21:45 +01:00
Auto time calibration
This commit is contained in:
parent
8cc5ed04cd
commit
57df6ec703
@ -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_WXP_LANGUAGE = "pref_wxp_language";
|
||||
public static final String PREF_POWER_MODE = "pref_wxp_power";
|
||||
|
||||
public static final String PREF_ONLY_DIGITAL = "pref_wxp_only_digital";
|
||||
|
||||
// time format constants
|
||||
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_CANCEL = new byte[]{0x03, 0x04};
|
||||
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_SET_QUITE_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_TIME = new byte[]{0x03, 0x62};
|
||||
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_INACTIVITY_REMINDER_SWITCH = new byte[]{0x03, 0x51};
|
||||
public static final byte[] CMD_INACTIVITY_REMINDER_SET = new byte[]{0x03, 0x52};
|
||||
|
@ -249,9 +249,9 @@ Prefs from device settings on main page
|
||||
/**
|
||||
* @param startOut 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));
|
||||
|
||||
assert doNotDisturb != null;
|
||||
@ -278,7 +278,7 @@ Prefs from device settings on main page
|
||||
/**
|
||||
* @param startOut 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) {
|
||||
boolean enabled = prefs.getBoolean(WatchXPlusConstants.PREF_LONGSIT_SWITCH, false);
|
||||
|
@ -814,7 +814,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
}
|
||||
if (mAutoConnectInvervalReceiver != null) {
|
||||
unregisterReceiver(mAutoConnectInvervalReceiver);
|
||||
mAutoConnectIntervalReceiver.destroy();
|
||||
mAutoConnectInvervalReceiver.destroy();
|
||||
mAutoConnectInvervalReceiver = null;
|
||||
}
|
||||
}
|
||||
|
@ -90,9 +90,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
|
||||
public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
private static final Prefs prefs = GBApplication.getPrefs();
|
||||
|
||||
@ -323,6 +320,14 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("getTime");
|
||||
@ -348,13 +353,26 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
nowDevice.set(Calendar.DAY_OF_WEEK, Conversion.fromBcd8(time[16]) + 1);
|
||||
|
||||
long timeDiff = (Math.abs(now.getTimeInMillis() - nowDevice.getTimeInMillis())) / 1000;
|
||||
LOG.info(" Time diff: " + timeDiff);
|
||||
if (10 < timeDiff && timeDiff < 120) {
|
||||
LOG.info(" Set new time ");
|
||||
boolean onlyDigital = prefs.getBoolean(WatchXPlusConstants.PREF_ONLY_DIGITAL, true);
|
||||
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) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("setTime");
|
||||
@ -412,6 +430,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
.setFitnessGoal(builder) // set steps per day
|
||||
.getBloodPressureCalibrationStatus(builder) // request blood pressure calibration
|
||||
//.setUnitsSettings() // set metric/imperial units
|
||||
.checkInitTime(builder)
|
||||
.syncPreferences(builder); // read preferences from app and set them to watch
|
||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||
builder.setGattCallback(this);
|
||||
@ -426,6 +445,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
LOG.info(" Get time ");
|
||||
getTime();
|
||||
}
|
||||
|
||||
@ -649,7 +669,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
* @param gender - user age
|
||||
*/
|
||||
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[] bArr = new byte[4];
|
||||
@ -852,7 +872,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
case WatchXPlusConstants.PREF_DO_NOT_DISTURB:
|
||||
case WatchXPlusConstants.PREF_DO_NOT_DISTURB_START:
|
||||
case WatchXPlusConstants.PREF_DO_NOT_DISTURB_END:
|
||||
setQuiteHours(builder, sharedPreferences);
|
||||
setDNDHours(builder, sharedPreferences);
|
||||
break;
|
||||
}
|
||||
builder.queue(getQueue());
|
||||
@ -881,9 +901,9 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
* @param minuteEnd - end minute
|
||||
*/
|
||||
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.warn(" 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 reminder... Enabled:"+enable+" Period:"+period);
|
||||
LOG.info(" Setting Long sit time... Hs:"+hourEnd+" Ms:"+minuteEnd+" He:"+hourStart+" Me:"+minuteStart);
|
||||
LOG.info(" Setting Long sit DND time... Hs:"+hourStart+" Ms:"+minuteStart+" He:"+hourEnd+" Me:"+minuteEnd);
|
||||
// set Long Sit reminder time
|
||||
byte[] command = WatchXPlusConstants.CMD_INACTIVITY_REMINDER_SET;
|
||||
|
||||
@ -931,7 +951,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
* @param enable - true or false
|
||||
*/
|
||||
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),
|
||||
buildCommand(WatchXPlusConstants.CMD_INACTIVITY_REMINDER_SWITCH,
|
||||
WatchXPlusConstants.WRITE_VALUE,
|
||||
@ -948,10 +968,10 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
* @param hourEnd - end hour
|
||||
* @param minuteEnd - end minute
|
||||
*/
|
||||
private void setQuiteHours(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);
|
||||
private void setDNDHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd) {
|
||||
LOG.info(" Setting DND time... Hs:"+hourStart+" Ms:"+minuteStart+" He:"+hourEnd+" Me:"+minuteEnd);
|
||||
// set DND time
|
||||
byte[] command = WatchXPlusConstants.CMD_SET_QUITE_HOURS_TIME;
|
||||
byte[] command = WatchXPlusConstants.CMD_SET_DND_HOURS_TIME;
|
||||
|
||||
byte[] bArr = new byte[4];
|
||||
bArr[0] = (byte) hourStart; // byte[08]
|
||||
@ -961,17 +981,17 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
|
||||
buildCommand(command, WatchXPlusConstants.WRITE_VALUE, bArr));
|
||||
// set DND state (enabled, disabled)
|
||||
setQuiteHoursSwitch(builder, enable);
|
||||
setDNDHoursSwitch(builder, enable);
|
||||
}
|
||||
|
||||
/** set do not disturb switch
|
||||
* @param tbuilder - transaction builder
|
||||
* @param enable - true or false
|
||||
*/
|
||||
private void setQuiteHoursSwitch(TransactionBuilder tbuilder, boolean enable) {
|
||||
LOG.warn("Setting DND switch to" + enable);
|
||||
private void setDNDHoursSwitch(TransactionBuilder tbuilder, boolean enable) {
|
||||
LOG.info(" Setting DND switch to: " + enable);
|
||||
tbuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
|
||||
buildCommand(WatchXPlusConstants.CMD_SET_QUITE_HOURS_SWITCH,
|
||||
buildCommand(WatchXPlusConstants.CMD_SET_DND_HOURS_SWITCH,
|
||||
WatchXPlusConstants.WRITE_VALUE,
|
||||
new byte[]{(byte) (enable ? 0x01 : 0x00)}));
|
||||
}
|
||||
@ -980,18 +1000,18 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
* @param builder - transaction builder
|
||||
* @param sharedPreferences - shared preferences
|
||||
*/
|
||||
private void setQuiteHours(TransactionBuilder builder, SharedPreferences sharedPreferences) {
|
||||
private void setDNDHours(TransactionBuilder builder, SharedPreferences sharedPreferences) {
|
||||
Calendar start = new GregorianCalendar();
|
||||
Calendar end = new GregorianCalendar();
|
||||
boolean enable = WatchXPlusDeviceCoordinator.getQuiteHours(sharedPreferences, start, end);
|
||||
boolean enable = WatchXPlusDeviceCoordinator.getDNDHours(sharedPreferences, start, end);
|
||||
if (enable) {
|
||||
this.setQuiteHours(builder, enable,
|
||||
this.setDNDHours(builder, enable,
|
||||
start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE),
|
||||
end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE));
|
||||
} else {
|
||||
// disable DND
|
||||
LOG.info(" Quiet hours are disabled ");
|
||||
this.setQuiteHoursSwitch(builder, enable);
|
||||
this.setDNDHoursSwitch(builder, enable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1078,7 +1098,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
try {
|
||||
int beginCalibration = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_SWITCH, 0);
|
||||
if (beginCalibration == 1) {
|
||||
LOG.warn(" Calibrating BP - cancel " + beginCalibration);
|
||||
LOG.info(" Calibrating BP - cancel " + beginCalibration);
|
||||
return;
|
||||
}
|
||||
int mLowP = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_LOW, 80);
|
||||
@ -1136,7 +1156,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
*/
|
||||
private void requestBloodPressureMeasurement() {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@ -1172,7 +1192,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Unable to request HR Measure", e);
|
||||
LOG.warn(" Unable to request new command ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1327,7 +1347,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if (todayMaxTemp < 0) {
|
||||
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
|
||||
weatherInfo[0] = (byte )(currentConditionCode >> 8);
|
||||
weatherInfo[1] = (byte )currentConditionCode;
|
||||
@ -1623,7 +1643,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
LOG.warn(" Got unsupported data package type: " + type);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.info((ex.getMessage()));
|
||||
LOG.warn((ex.getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1700,12 +1720,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
*/
|
||||
private void handleSportAimStatus(byte[] value) {
|
||||
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) {
|
||||
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
|
||||
Calendar date = GregorianCalendar.getInstance();
|
||||
@ -1717,7 +1737,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
int newSteps = (steps - dayStepCount);
|
||||
|
||||
if (newSteps > 0) {
|
||||
LOG.debug("adding " + newSteps + " steps");
|
||||
LOG.info("adding " + newSteps + " steps");
|
||||
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
WatchXPlusSampleProvider provider = new WatchXPlusSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||
@ -1736,7 +1756,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sample.setProvider(provider);
|
||||
provider.addGBActivitySample(sample);
|
||||
} catch (Exception ex) {
|
||||
LOG.info((ex.getMessage()));
|
||||
LOG.warn(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1767,7 +1787,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
return totalSteps;
|
||||
|
||||
} catch (Exception ex) {
|
||||
LOG.error(ex.getMessage());
|
||||
LOG.warn(ex.getMessage());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1886,7 +1906,7 @@ 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.setDNDHours(transaction, sharedPreferences); // DND
|
||||
this.setDisconnectReminder(transaction, sharedPreferences); // disconnect reminder
|
||||
this.setLanguageAndTimeFormat(transaction, sharedPreferences); // set time mode 12/24h
|
||||
this.setAltitude(transaction); // set altitude calibration
|
||||
|
@ -291,10 +291,7 @@
|
||||
<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="prefs_wxp_continious">Известявай докато телефона звъни</string>
|
||||
<string name="prefs_wxp_missed">Известие за пропуснато обаждане</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="prefs_wxp_reject">Бутона заглушава/отказва повикване</string>
|
||||
<string name="pref_wxp_title_shake_reject_summary">Повтаря действието на бутона</string>
|
||||
@ -319,6 +316,8 @@
|
||||
<string name="prefs_wxp_longsit_switch">Включи напомняне за активност</string>
|
||||
<string name="pref_wxp_title_longsit">Период на неактивност (минути)</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="title_activity_sleepmonitor">Наблюдение/анализ на съня</string>
|
||||
|
@ -222,6 +222,8 @@
|
||||
<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="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>
|
||||
|
||||
<!-- Makibes HR3 Preferences -->
|
||||
|
@ -89,6 +89,12 @@
|
||||
android:summary="@string/pref_wxp_longsit_switch_summary"
|
||||
android:title="@string/prefs_wxp_longsit_switch" />
|
||||
</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
|
||||
android:key="pref_category_watchxplus_calibration"
|
||||
|
Loading…
Reference in New Issue
Block a user