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

Implement Hourly chime which was added in firmware 1.1.2.46

This commit is contained in:
NekoBox 2022-08-09 15:30:21 +03:00 committed by Gitea
parent b3714ca05b
commit ad38a32cc8
9 changed files with 100 additions and 1 deletions

View File

@ -226,4 +226,8 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_AUTH_KEY = "authkey";
public static final String PREF_USER_FITNESS_GOAL = "fitness_goal";
public static final String PREF_USER_FITNESS_GOAL_NOTIFICATION = "fitness_goal_notification";
public static final String PREF_HOURLY_CHIME_ENABLE = "hourly_chime_enable";
public static final String PREF_HOURLY_CHIME_START = "hourly_chime_start";
public static final String PREF_HOURLY_CHIME_END = "hourly_chime_end";
}

View File

@ -552,6 +552,9 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
addPreferenceHandlerFor(PREF_UM25_SHOW_THRESHOLD_NOTIFICATION);
addPreferenceHandlerFor(PREF_UM25_SHOW_THRESHOLD);
addPreferenceHandlerFor(PREF_HOURLY_CHIME_ENABLE);
addPreferenceHandlerFor(PREF_HOURLY_CHIME_START);
addPreferenceHandlerFor(PREF_HOURLY_CHIME_END);
String sleepTimeState = prefs.getString(PREF_SLEEP_TIME, PREF_DO_NOT_DISTURB_OFF);
boolean sleepTimeScheduled = sleepTimeState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);

View File

@ -423,4 +423,17 @@ public abstract class HuamiCoordinator extends AbstractBLEDeviceCoordinator {
public DeviceSpecificSettingsCustomizer getDeviceSpecificSettingsCustomizer(final GBDevice device) {
return new HuamiSettingsCustomizer(device);
}
public static boolean getHourlyChime(String deviceAddress) {
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
return prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_HOURLY_CHIME_ENABLE, false);
}
public static Date getHourlyChimeStart(String deviceAddress) {
return getTimePreference(DeviceSettingsPreferenceConst.PREF_HOURLY_CHIME_START, "09:00", deviceAddress);
}
public static Date getHourlyChimeEnd(String deviceAddress) {
return getTimePreference(DeviceSettingsPreferenceConst.PREF_HOURLY_CHIME_END, "22:00", deviceAddress);
}
}

View File

@ -245,6 +245,9 @@ public class HuamiService {
public static final short CHUNKED2021_ENDPOINT_COMPAT = 0x0090;
public static final short CHUNKED2021_ENDPOINT_SMSREPLY = 0x0013;
public static final byte[] COMMAND_ENABLE_HOURLY_CHIME = new byte[] { (byte) 0xfe, 0x0b, 0x00, 0x01, 0x0a, 0x00, 0x16, 0x00 };
public static final byte[] COMMAND_DISABLE_HOURLY_CHIME = new byte[] { (byte) 0xfe, 0x0b, 0x00, 0x00 };
static {
MIBAND_DEBUG = new HashMap<>();
MIBAND_DEBUG.put(UUID_SERVICE_MIBAND_SERVICE, "MiBand Service");

View File

@ -57,7 +57,6 @@ public class AmazfitNeoCoordinator extends HuamiCoordinator {
}
@Override
public InstallHandler findInstallHandler(Uri uri, Context context) {
AmazfitNeoFWInstallHandler handler = new AmazfitNeoFWInstallHandler(uri, context);
@ -89,6 +88,7 @@ public class AmazfitNeoCoordinator extends HuamiCoordinator {
R.xml.devicesettings_timeformat,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_inactivity_dnd,
R.xml.devicesettings_hourly_chime,
R.xml.devicesettings_disconnectnotification,
R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_bt_connected_advertisement,

View File

@ -179,6 +179,9 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_ENABLED;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_THRESHOLD;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HEARTRATE_STRESS_MONITORING;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HOURLY_CHIME_ENABLE;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HOURLY_CHIME_END;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_HOURLY_CHIME_START;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_START;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_END;
@ -2704,6 +2707,11 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport {
case PREF_INACTIVITY_DND_END:
setInactivityWarnings(builder);
break;
case PREF_HOURLY_CHIME_ENABLE:
case PREF_HOURLY_CHIME_START:
case PREF_HOURLY_CHIME_END:
setHourlyChime(builder);
break;
case SettingsActivity.PREF_MEASUREMENT_SYSTEM:
setDistanceUnit(builder);
break;
@ -3547,6 +3555,39 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport {
return this;
}
protected HuamiSupport setHourlyChime(TransactionBuilder builder) {
if (!supportsHourlyChime())
return this;
boolean enable = HuamiCoordinator.getHourlyChime(gbDevice.getAddress());
LOG.info("Setting hourly chime to " + enable);
if (enable) {
byte[] data = HuamiService.COMMAND_ENABLE_HOURLY_CHIME.clone();
Calendar calendar = GregorianCalendar.getInstance();
Date intervalStart = HuamiCoordinator.getHourlyChimeStart(gbDevice.getAddress());
Date intervalEnd = HuamiCoordinator.getHourlyChimeEnd(gbDevice.getAddress());
calendar.setTime(intervalStart);
data[HuamiService.INACTIVITY_WARNINGS_INTERVAL_1_START_HOURS] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
data[HuamiService.INACTIVITY_WARNINGS_INTERVAL_1_START_MINUTES] = (byte) calendar.get(Calendar.MINUTE);
calendar.setTime(intervalEnd);
data[HuamiService.INACTIVITY_WARNINGS_INTERVAL_1_END_HOURS] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
data[HuamiService.INACTIVITY_WARNINGS_INTERVAL_1_END_MINUTES] = (byte) calendar.get(Calendar.MINUTE);
writeToConfiguration(builder, data);
} else {
writeToConfiguration(builder, HuamiService.COMMAND_DISABLE_HOURLY_CHIME);
}
return this;
}
public boolean supportsHourlyChime() { return false; }
private HuamiSupport setDisconnectNotification(TransactionBuilder builder) {
DisconnectNotificationSetting disconnectNotificationSetting = HuamiCoordinator.getDisconnectNotificationSetting(getContext(), gbDevice.getAddress());
LOG.info("Setting disconnect notification to " + disconnectNotificationSetting);
@ -3920,6 +3961,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport {
setDisplayCaller(builder);
setGoalNotification(builder);
setInactivityWarnings(builder);
setHourlyChime(builder);
setHeartrateSleepSupport(builder);
setHeartrateActivityMonitoring(builder);
setHeartrateAlert(builder);

View File

@ -80,6 +80,9 @@ public class AmazfitNeoSupport extends MiBand5Support {
writeToChunked(builder, 2, bytes);
}
@Override
public boolean supportsHourlyChime() { return true; }
@Override
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
return new AmazfitNeoFWHelper(uri, context);

View File

@ -1753,6 +1753,8 @@
<string name="step_streak_days_hint">Number of consecutive days with steps goal being reached</string>
<string name="steps_streaks_total_steps_hint">Total number of steps in the whole streak</string>
<string name="steps_streaks_total_steps_average_hint">Total average %d steps per day</string>
<string name="prefs_hourly_chime">Hourly chime</string>
<string name="prefs_hourly_chime_summary">The watch will beep once an hour</string>
<string name="devicetype_binary_sensor">Binary sensor</string>
</resources>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
android:icon="@drawable/ic_action_find_lost_device"
android:key="screen_hourly_chime"
android:persistent="false"
android:summary="@string/prefs_hourly_chime_summary"
android:title="@string/prefs_hourly_chime">
<SwitchPreference
android:defaultValue="false"
android:key="hourly_chime_enable"
android:title="@string/prefs_hourly_chime"
android:summary="@string/prefs_hourly_chime_summary" />
<nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
android:defaultValue="09:00"
android:dependency="hourly_chime_enable"
android:key="hourly_chime_start"
android:title="@string/mi2_prefs_do_not_disturb_start" />
<nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
android:defaultValue="22:00"
android:dependency="hourly_chime_enable"
android:key="hourly_chime_end"
android:title="@string/mi2_prefs_do_not_disturb_end" />
</PreferenceScreen>
</androidx.preference.PreferenceScreen>