1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 18:15:49 +01:00

Mi Band 2/Bip/Cor: allow to set a period when the display/background light gets enabled when lifting the wrist

Closes #1013
This commit is contained in:
Andreas Shimokawa 2018-03-23 23:27:03 +01:00
parent 6be7ee4a96
commit e26dbc6812
10 changed files with 181 additions and 21 deletions

View File

@ -0,0 +1,23 @@
/* Copyright (C) 2017-2018 José Rebelo
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.huami;
public enum ActivateDisplayOnLift {
ON,
OFF,
SCHEDULED
}

View File

@ -52,7 +52,6 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
@ -133,9 +132,30 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
return DateTimeDisplay.DATE_TIME;
}
public static boolean getActivateDisplayOnLiftWrist() {
public static ActivateDisplayOnLift getActivateDisplayOnLiftWrist(Context context) {
Prefs prefs = GBApplication.getPrefs();
return prefs.getBoolean(MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT, true);
String liftOff = context.getString(R.string.p_off);
String liftOn = context.getString(R.string.p_on);
String liftScheduled = context.getString(R.string.p_scheduled);
String pref = prefs.getString(MiBandConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, liftOff);
if (liftOn.equals(pref)) {
return ActivateDisplayOnLift.ON;
} else if (liftScheduled.equals(pref)) {
return ActivateDisplayOnLift.SCHEDULED;
}
return ActivateDisplayOnLift.OFF;
}
public static Date getDisplayOnLiftStart() {
return getTimePreference( MiBandConst.PREF_DISPLAY_ON_LIFT_START, "00:00");
}
public static Date getDisplayOnLiftEnd() {
return getTimePreference( MiBandConst.PREF_DISPLAY_ON_LIFT_END, "00:00");
}
public static Set<String> getDisplayItems() {

View File

@ -134,8 +134,8 @@ public class MiBand2Service {
public static final byte[] DATEFORMAT_TIME = new byte[] {ENDPOINT_DISPLAY, 0x0a, 0x0, 0x0 };
public static final byte[] DATEFORMAT_TIME_12_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x0 };
public static final byte[] DATEFORMAT_TIME_24_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x1 };
public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01};
public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x00};
public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
public static final byte[] COMMAND_ENABLE_GOAL_NOTIFICATION = new byte[]{ENDPOINT_DISPLAY, 0x06, 0x00, 0x01};
public static final byte[] COMMAND_DISABLE_GOAL_NOTIFICATION = new byte[]{ENDPOINT_DISPLAY, 0x06, 0x00, 0x00};
public static final byte[] COMMAND_ENABLE_ROTATE_WRIST_TO_SWITCH_INFO = new byte[]{ENDPOINT_DISPLAY, 0x0d, 0x00, 0x01};

View File

@ -49,7 +49,9 @@ public final class MiBandConst {
public static final String PREF_MI2_DISPLAY_ITEM_CALORIES = "calories";
public static final String PREF_MI2_DISPLAY_ITEM_HEART_RATE = "heart_rate";
public static final String PREF_MI2_DISPLAY_ITEM_BATTERY = "battery";
public static final String PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist";
public static final String PREF_ACTIVATE_DISPLAY_ON_LIFT = "activate_display_on_lift_wrist";
public static final String PREF_DISPLAY_ON_LIFT_START = "display_on_lift_start";
public static final String PREF_DISPLAY_ON_LIFT_END = "display_on_lift_end";
public static final String PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO = "mi2_rotate_wrist_to_switch_info";
public static final String PREF_MI2_ENABLE_TEXT_NOTIFICATIONS = "mi2_enable_text_notifications";
public static final String PREF_MI2_DO_NOT_DISTURB = "mi2_do_not_disturb";

View File

@ -38,7 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_ALARM_CLOCK;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_INCOMING_CALL;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_ACTIVATE_DISPLAY_ON_LIFT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DISPLAY_ON_LIFT_END;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DISPLAY_ON_LIFT_START;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DISPLAY_ITEMS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DO_NOT_DISTURB;
@ -135,14 +137,14 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
}
});
final Preference activateDisplayOnLift = findPreference(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
final Preference activateDisplayOnLift = findPreference(PREF_ACTIVATE_DISPLAY_ON_LIFT);
activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
GBApplication.deviceService().onSendConfiguration(PREF_ACTIVATE_DISPLAY_ON_LIFT);
}
});
return true;
@ -313,6 +315,60 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
}
});
String displayOnLiftState = prefs.getString(MiBandConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_MI2_DO_NOT_DISTURB_OFF);
boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_MI2_DO_NOT_DISTURB_SCHEDULED);
final Preference displayOnLiftStart = findPreference(PREF_DISPLAY_ON_LIFT_START);
displayOnLiftStart.setEnabled(displayOnLiftScheduled);
displayOnLiftStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_DISPLAY_ON_LIFT_START);
}
});
return true;
}
});
final Preference displayOnLiftEnd = findPreference(PREF_DISPLAY_ON_LIFT_END);
displayOnLiftEnd.setEnabled(displayOnLiftScheduled);
displayOnLiftEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_DISPLAY_ON_LIFT_END);
}
});
return true;
}
});
final Preference displayOnLift = findPreference(PREF_ACTIVATE_DISPLAY_ON_LIFT);
displayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
final boolean scheduled = PREF_MI2_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
displayOnLiftStart.setEnabled(scheduled);
displayOnLiftEnd.setEnabled(scheduled);
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_ACTIVATE_DISPLAY_ON_LIFT);
}
});
return true;
}
});
final Preference fitnessGoal = findPreference(ActivityUser.PREF_USER_STEPS_GOAL);
fitnessGoal.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override

View File

@ -56,6 +56,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallContro
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.ActivateDisplayOnLift;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService;
@ -1330,7 +1331,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
case MiBandConst.PREF_MI2_GOAL_NOTIFICATION:
setGoalNotification(builder);
break;
case MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT:
case MiBandConst.PREF_ACTIVATE_DISPLAY_ON_LIFT:
case MiBandConst.PREF_DISPLAY_ON_LIFT_START:
case MiBandConst.PREF_DISPLAY_ON_LIFT_END:
setActivateDisplayOnLiftWrist(builder);
break;
case MiBandConst.PREF_MI2_DISPLAY_ITEMS:
@ -1418,12 +1421,32 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
}
private MiBand2Support setActivateDisplayOnLiftWrist(TransactionBuilder builder) {
boolean enable = HuamiCoordinator.getActivateDisplayOnLiftWrist();
LOG.info("Setting activate display on lift wrist to " + enable);
if (enable) {
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST);
} else {
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST);
ActivateDisplayOnLift displayOnLift = HuamiCoordinator.getActivateDisplayOnLiftWrist(getContext());
LOG.info("Setting activate display on lift wrist to " + displayOnLift);
switch (displayOnLift) {
case ON:
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST);
break;
case OFF:
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST);
break;
case SCHEDULED:
byte[] cmd = MiBand2Service.COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST.clone();
Calendar calendar = GregorianCalendar.getInstance();
Date start = HuamiCoordinator.getDisplayOnLiftStart();
calendar.setTime(start);
cmd[4] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
cmd[5] = (byte) calendar.get(Calendar.MINUTE);
Date end = HuamiCoordinator.getDisplayOnLiftEnd();
calendar.setTime(end);
cmd[6] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
cmd[7] = (byte) calendar.get(Calendar.MINUTE);
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), cmd);
}
return this;
}

View File

@ -150,6 +150,17 @@
<item>@string/p_scheduled</item>
</string-array>
<string-array name="activate_display_on_lift">
<item>@string/off</item>
<item>@string/on</item>
<item>@string/mi2_dnd_scheduled</item>
</string-array>
<string-array name="activate_display_on_lift_values">
<item>@string/p_off</item>
<item>@string/p_automatic</item>
<item>@string/p_scheduled</item>
</string-array>
<string-array name="pref_mi2_display_items">
<item>@string/chart_steps</item>
<item>@string/distance</item>

View File

@ -488,6 +488,7 @@
<string name="mi2_fw_installhandler_fw53_hint">You need to install version %1$s before installing this firmware!</string>
<string name="mi2_enable_text_notifications">Text notifications</string>
<string name="mi2_enable_text_notifications_summary"><![CDATA[Needs firmware >= 1.0.1.28 and Mili_pro.ft* installed.]]></string>
<string name="on">On</string>
<string name="off">Off</string>
<string name="mi2_dnd_off">Off</string>
<string name="mi2_dnd_automatic">Automatic (sleep detection)</string>

View File

@ -20,6 +20,7 @@
<item name="p_battery" type="string">battery</item>
<item name="p_off" type="string">off</item>
<item name="p_on" type="string">on</item>
<item name="p_automatic" type="string">automatic</item>
<item name="p_scheduled" type="string">scheduled</item>

View File

@ -122,14 +122,37 @@
android:summary="@string/mi2_prefs_display_items_summary"
android:title="@string/mi2_prefs_display_items"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="mi2_activate_display_on_lift_wrist"
android:title="@string/mi2_prefs_activate_display_on_lift" />
<PreferenceScreen
android:persistent="false"
android:title="@string/mi2_prefs_activate_display_on_lift">
<!-- workaround for missing toolbar -->
<PreferenceCategory android:title="@string/mi2_prefs_activate_display_on_lift" />
<ListPreference
android:defaultValue="@string/p_off"
android:entries="@array/activate_display_on_lift"
android:entryValues="@array/activate_display_on_lift_values"
android:key="activate_display_on_lift_wrist"
android:summary="%s"
android:title="@string/mi2_prefs_activate_display_on_lift" />
<nodomain.freeyourgadget.gadgetbridge.util.TimePreference
android:defaultValue="00:00"
android:dependency="activate_display_on_lift_wrist"
android:key="display_on_lift_start"
android:title="@string/mi2_prefs_do_not_disturb_start" />
<nodomain.freeyourgadget.gadgetbridge.util.TimePreference
android:defaultValue="00:00"
android:dependency="activate_display_on_lift_wrist"
android:key="display_on_lift_end"
android:title="@string/mi2_prefs_do_not_disturb_end" />
</PreferenceScreen>
<CheckBoxPreference
android:defaultValue="false"
android:dependency="mi2_activate_display_on_lift_wrist"
android:dependency="activate_display_on_lift_wrist"
android:key="mi2_rotate_wrist_to_switch_info"
android:title="@string/mi2_prefs_rotate_wrist_to_switch_info" />