1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Pixoo: support "clap hands to turn off screen" and "sleep after silence" settings

Also fix crc calculation :P
This commit is contained in:
Andreas Shimokawa 2023-12-19 21:08:25 +01:00
parent 198800e087
commit 81c9aa5faf
5 changed files with 30 additions and 7 deletions

View File

@ -396,4 +396,6 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_DEVICE_ACTION_WOKE_UP_BROADCAST = "prefs_events_forwarding_wokeup_broadcast";
public static final String PREF_DEVICE_ACTION_START_NON_WEAR_SELECTIONS = "events_forwarding_startnonwear_action_selections";
public static final String PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST = "prefs_events_forwarding_startnonwear_broadcast";
public static final String PREF_CLAP_HANDS_TO_WAKEUP_DEVICE = "pref_key_clap_hands_to_wakeup_device";
public static final String PREF_POWER_SAVING = "pref_key_power_saving";
}

View File

@ -144,10 +144,10 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
ListPreference languageListPreference = findPreference("language");
CharSequence[] entries = languageListPreference.getEntries();
CharSequence[] values = languageListPreference.getEntryValues();
for (int i=entries.length-1;i>=0;i--) {
if (!ArrayUtils.contains(supportedLanguages,values[i])) {
entries = ArrayUtils.remove(entries,i);
values = ArrayUtils.remove(values,i);
for (int i = entries.length - 1; i >= 0; i--) {
if (!ArrayUtils.contains(supportedLanguages, values[i])) {
entries = ArrayUtils.remove(entries, i);
values = ArrayUtils.remove(values, i);
}
}
languageListPreference.setEntries(entries);
@ -324,7 +324,6 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
}
addPreferenceHandlerFor(PREF_SWIPE_UNLOCK);
addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
addPreferenceHandlerFor(PREF_DATEFORMAT);
@ -566,6 +565,9 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
addPreferenceHandlerFor(PREF_SLEEP_MODE_SCHEDULE_START);
addPreferenceHandlerFor(PREF_SLEEP_MODE_SCHEDULE_END);
addPreferenceHandlerFor(PREF_CLAP_HANDS_TO_WAKEUP_DEVICE);
addPreferenceHandlerFor(PREF_POWER_SAVING);
addPreferenceHandlerFor("lock");
String sleepTimeState = prefs.getString(PREF_SLEEP_TIME, PREF_DO_NOT_DISTURB_OFF);
@ -981,7 +983,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
}
final Preference notificationSettings = findPreference(PREFS_PER_APP_NOTIFICATION_SETTINGS);
if(notificationSettings != null) {
if (notificationSettings != null) {
notificationSettings.setOnPreferenceClickListener(preference -> {
final Intent intent = new Intent(getContext(), AppSpecificNotificationSettingsActivity.class);
intent.putExtra(GBDevice.EXTRA_DEVICE, getDevice());

View File

@ -79,6 +79,7 @@ public class PixooCoordinator extends AbstractBLEDeviceCoordinator {
@Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{
R.xml.devicesettings_pixoo,
R.xml.devicesettings_screen_brightness,
R.xml.devicesettings_timeformat,
};

View File

@ -174,6 +174,20 @@ public class PixooProtocol extends GBDeviceProtocol {
0x2d,
(byte) (is24hour ? 1 : 0),
});
case DeviceSettingsPreferenceConst.PREF_CLAP_HANDS_TO_WAKEUP_DEVICE:
boolean clap = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_CLAP_HANDS_TO_WAKEUP_DEVICE, false);
return encodeProtocol(new byte[]{
(byte) 0xa7,
(byte) (clap ? 1 : 0),
});
case DeviceSettingsPreferenceConst.PREF_POWER_SAVING:
boolean power_saving = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_POWER_SAVING, false);
return encodeProtocol(new byte[]{
(byte) 0xb2,
(byte) (power_saving ? 1 : 0),
});
}
@ -363,7 +377,7 @@ public class PixooProtocol extends GBDeviceProtocol {
msgBuf.put(payload);
short crc = (short) (((payload.length + 2) & 0xff) + ((payload.length + 2) >> 8));
for (byte b : payload) {
crc += b;
crc += (b & 0xff);
}
msgBuf.putShort(crc);
msgBuf.put((byte) 0x02);

View File

@ -493,6 +493,10 @@
<string name="zetime_signaling_beep_once">Beep once</string>
<string name="zetime_signaling_beep_twice">Beep twice</string>
<string name="zetime_signaling_vibrate_beep_once">Vibrate and beep once</string>
<!-- pixoo specific settings -->
<string name="clap_hands_to_wakeup_device">Clap hands to turn up screen</string>"
<string name="clap_hands_to_wakeup_device_summary">Clapping again will turn off the screen</string>"
<string name="pixoo_power_saving_summary">The screen will turn off after the microphone has detected silence for a while</string>
<!-- Device specific settings -->
<string name="title_activity_device_specific_settings">Device specific settings</string>
<string name="pref_title_authkey">Auth Key</string>