mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-24 09:35:50 +01:00
Marstek B2500: support battery pass-though, cleanups
This commit is contained in:
parent
3ef6f092b3
commit
899f283a1b
@ -598,4 +598,5 @@ public class DeviceSettingsPreferenceConst {
|
||||
public static final String PREF_BATTERY_DISCHARGE_INTERVALS_SET = "battery_discharge_intervals_set";
|
||||
public static final String PREF_BATTERY_DISCHARGE_MANAUAL = "battery_discharge_manual";
|
||||
public static final String PREF_BATTERY_MINIMUM_CHARGE = "battery_minimum_charge";
|
||||
public static final String PREF_BATTERY_ALLOW_PASS_THOUGH = "battery_allow_pass_though";
|
||||
}
|
||||
|
@ -884,6 +884,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
addPreferenceHandlerFor("lock");
|
||||
|
||||
addPreferenceHandlerFor(PREF_BATTERY_MINIMUM_CHARGE);
|
||||
addPreferenceHandlerFor(PREF_BATTERY_ALLOW_PASS_THOUGH);
|
||||
|
||||
final Preference dischargeIntervalsSet = findPreference(PREF_BATTERY_DISCHARGE_INTERVALS_SET);
|
||||
if (dischargeIntervalsSet != null) {
|
||||
|
@ -61,6 +61,7 @@ public class MarstekB2500DeviceCoordinator extends AbstractDeviceCoordinator {
|
||||
@Override
|
||||
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
||||
return new int[]{
|
||||
R.xml.devicesettings_battery_allow_pass_though,
|
||||
R.xml.devicesettings_battery_minimum_charge,
|
||||
R.xml.devicesettings_battery_discharge_5
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.marstek;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BATTERY_ALLOW_PASS_THOUGH;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BATTERY_DISCHARGE_INTERVALS_SET;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BATTERY_DISCHARGE_MANAUAL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BATTERY_MINIMUM_CHARGE;
|
||||
@ -45,6 +46,9 @@ public class MarstekB2500DeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
private static final byte[] COMMAND_REBOOT = new byte[]{COMMAND_PREFIX, 0x06, COMMAND, OPCODE_REBOOT, 0x01, 0x72};
|
||||
private static final byte[] COMMAND_SET_AUTO_DISCHARGE = new byte[]{COMMAND_PREFIX, 0x06, COMMAND, 0x11, 0x00, 0x47};
|
||||
private static final byte[] COMMAND_SET_POWERMETER_CHANNEL1 = new byte[]{COMMAND_PREFIX, 0x06, COMMAND, 0x2a, 0x00, 0x7c};
|
||||
private static final byte[] COMMAND_SET_BATTERY_ALLOW_PASS_THOUGH = new byte[]{COMMAND_PREFIX, 0x06, COMMAND, 0x0d, 0x00, 0x5b};
|
||||
private static final byte[] COMMAND_SET_BATTERY_DISALLOW_PASS_THOUGH = new byte[]{COMMAND_PREFIX, 0x06, COMMAND, 0x0d, 0x01, 0x5a};
|
||||
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MarstekB2500DeviceSupport.class);
|
||||
private int firmwareVersion;
|
||||
@ -97,7 +101,7 @@ public class MarstekB2500DeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
getDevice().setFirmwareVersion2("N/A");
|
||||
builder.requestMtu(512);
|
||||
builder.notify(getCharacteristic(UUID_CHARACTERISTIC_MAIN), true);
|
||||
builder.wait(3000);
|
||||
builder.wait(3500);
|
||||
builder.write(getCharacteristic(UUID_CHARACTERISTIC_MAIN), COMMAND_GET_INFOS1);
|
||||
builder.wait(750);
|
||||
builder.write(getCharacteristic(UUID_CHARACTERISTIC_MAIN), COMMAND_GET_INFOS2);
|
||||
@ -130,18 +134,26 @@ public class MarstekB2500DeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onSendConfiguration(final String config) {
|
||||
if (config.equals(PREF_BATTERY_DISCHARGE_INTERVALS_SET)) {
|
||||
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
|
||||
if (devicePrefs.getBoolean(PREF_BATTERY_DISCHARGE_MANAUAL, true)) {
|
||||
sendCommand("set discharge intervals", encodeDischargeIntervalsFromPreferences());
|
||||
} else {
|
||||
sendCommand("set dynamic discharge", COMMAND_SET_AUTO_DISCHARGE);
|
||||
sendCommand("set channel auto", COMMAND_SET_POWERMETER_CHANNEL1);
|
||||
}
|
||||
return;
|
||||
} else if (config.equals(PREF_BATTERY_MINIMUM_CHARGE)) {
|
||||
sendCommand("set minimum charge", encodeMinimumChargeFromPreferences());
|
||||
return;
|
||||
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
|
||||
switch (config) {
|
||||
case PREF_BATTERY_DISCHARGE_INTERVALS_SET:
|
||||
if (devicePrefs.getBoolean(PREF_BATTERY_DISCHARGE_MANAUAL, true)) {
|
||||
sendCommand("set discharge intervals", encodeDischargeIntervalsFromPreferences());
|
||||
} else {
|
||||
sendCommand("set dynamic discharge", COMMAND_SET_AUTO_DISCHARGE);
|
||||
sendCommand("set channel auto", COMMAND_SET_POWERMETER_CHANNEL1);
|
||||
}
|
||||
return;
|
||||
case PREF_BATTERY_MINIMUM_CHARGE:
|
||||
sendCommand("set minimum charge", encodeMinimumChargeFromPreferences());
|
||||
return;
|
||||
case PREF_BATTERY_ALLOW_PASS_THOUGH:
|
||||
if (devicePrefs.getBoolean(PREF_BATTERY_ALLOW_PASS_THOUGH, true)) {
|
||||
sendCommand("set allow pass-though", COMMAND_SET_BATTERY_ALLOW_PASS_THOUGH);
|
||||
} else {
|
||||
sendCommand("set disallow pass-though", COMMAND_SET_BATTERY_DISALLOW_PASS_THOUGH);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
LOG.warn("Unknown config changed: {}", config);
|
||||
@ -154,7 +166,7 @@ public class MarstekB2500DeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
buf.position(12); // skip header and unknown
|
||||
firmwareVersion = buf.get();
|
||||
boolean charge_before_discharge = buf.get() == 0x01;
|
||||
boolean battery_allow_passthough = buf.get() != 0x01;
|
||||
boolean manual_discharge_intervals = buf.get() != 0x01;
|
||||
buf.position(buf.position() + 3); // skip unknown
|
||||
byte battery_max_use = buf.get();
|
||||
@ -169,7 +181,7 @@ public class MarstekB2500DeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
devicePrefsEdit.putString(PREF_BATTERY_MINIMUM_CHARGE, String.valueOf(battery_minimum_charge));
|
||||
devicePrefsEdit.putBoolean(PREF_BATTERY_DISCHARGE_MANAUAL, manual_discharge_intervals);
|
||||
|
||||
devicePrefsEdit.putBoolean(PREF_BATTERY_ALLOW_PASS_THOUGH, battery_allow_passthough);
|
||||
devicePrefsEdit.apply();
|
||||
devicePrefsEdit.commit();
|
||||
|
||||
|
@ -2646,8 +2646,8 @@
|
||||
<string name="redmi_buds_5_pro_combo_all">ANC / Transparency / Off</string>
|
||||
<string name="redmi_buds_5_pro_double_connection">Double Connection</string>
|
||||
<string name="redmi_buds_5_pro_double_connection_description">Allow the earbuds to connect to two devices at the same time</string>
|
||||
<!-- <string name="redmi_buds_5_pro_spatial_audio">Spatial Audio</string>-->
|
||||
<!-- <string name="redmi_buds_5_pro_spatial_audio_mode">Spatial Audio Mode</string>-->
|
||||
<!-- <string name="redmi_buds_5_pro_spatial_audio">Spatial Audio</string>-->
|
||||
<!-- <string name="redmi_buds_5_pro_spatial_audio_mode">Spatial Audio Mode</string>-->
|
||||
<string name="redmi_buds_5_pro_adaptive_sound">Adaptive Sound</string>
|
||||
<string name="redmi_buds_5_pro_adaptive_sound_description">Adjusts the sound according to the ear shape and the environment</string>
|
||||
<string name="redmi_buds_5_pro_equalizer_preset_standard">Standard</string>
|
||||
@ -2741,8 +2741,8 @@
|
||||
<string name="pref_adaptive_volume_control_title">Adaptive volume control</string>
|
||||
<string name="pref_adaptive_noise_cancelling_title">Adaptive ANC</string>
|
||||
<string name="pref_adaptive_noise_cancelling_summary">Set the strength of the ANC automatically depending on the ambient sound level</string>
|
||||
<!-- <string name="pref_personalized_noise_cancelling_title">Personalized ANC</string>-->
|
||||
<!-- <string name="pref_personalized_noise_cancelling_summary">Set whether to use personalized active noise cancelling</string>-->
|
||||
<!-- <string name="pref_personalized_noise_cancelling_title">Personalized ANC</string>-->
|
||||
<!-- <string name="pref_personalized_noise_cancelling_summary">Set whether to use personalized active noise cancelling</string>-->
|
||||
<string name="sony_speak_to_chat">Speak-to-chat</string>
|
||||
<string name="sony_speak_to_chat_summary">Turn off noise cancelling automatically when you start talking.</string>
|
||||
<string name="sony_speak_to_chat_sensitivity">Voice Detection Sensitivity</string>
|
||||
@ -3559,14 +3559,16 @@
|
||||
<string name="about_build_details_copied_to_clipboard">Build details copied to clipboard</string>
|
||||
<string name="devicetype_marstek_b2500">Marstek B2500</string>
|
||||
<string name="battery_discharge_intervals">Battery Discharge Intervals</string>
|
||||
<string name="discharge_interval_1">Discharge Interval 1</string>
|
||||
<string name="discharge_interval_2">Discharge Interval 2</string>
|
||||
<string name="discharge_interval_3">Discharge Interval 3</string>
|
||||
<string name="discharge_interval_4">Discharge Interval 4</string>
|
||||
<string name="discharge_interval_5">Discharge Interval 5</string>
|
||||
<string name="discharge_interval_1">Discharge interval 1</string>
|
||||
<string name="discharge_interval_2">Discharge interval 2</string>
|
||||
<string name="discharge_interval_3">Discharge interval 3</string>
|
||||
<string name="discharge_interval_4">Discharge interval 4</string>
|
||||
<string name="discharge_interval_5">Discharge interval 5</string>
|
||||
<string name="power_w">Power in W</string>
|
||||
<string name="manual_discharge_summary">when disabled, this assumes intelligent discharge controlled by an external power meter (not supported by Gadgetbridge)</string>
|
||||
<string name="manual_discharge">Manual Discharge Intervals</string>
|
||||
<string name="manual_discharge">Manual discharge intervals</string>
|
||||
<string name="summary_battery_discharge_intervals_set">Send configuration below to device</string>
|
||||
<string name="battery_minimum_charge">Minimum allowed charge in %</string>
|
||||
<string name="battery_minimum_charge">Minimum battery charge in %</string>
|
||||
<string name="battery_allow_pass_though_summary">When enabled, the battery can be charged while discharging</string>
|
||||
<string name="battery_allow_pass_through">Allow battery pass-though</string>
|
||||
</resources>
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="battery_charge_before_discharge"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:summary="@string/battery_allow_pass_though_summary"
|
||||
android:title="@string/battery_allow_pass_through" />
|
||||
</androidx.preference.PreferenceScreen>
|
@ -2,7 +2,7 @@
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceScreen
|
||||
android:icon="@drawable/ic_battery"
|
||||
android:icon="@drawable/ic_access_time"
|
||||
android:key="screen_battery_discharge settings"
|
||||
android:persistent="false"
|
||||
android:title="@string/battery_discharge_intervals">
|
||||
|
@ -2,7 +2,6 @@
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<EditTextPreference
|
||||
android:icon="@drawable/ic_battery"
|
||||
android:defaultValue="10"
|
||||
android:inputType="number"
|
||||
android:key="battery_minimum_charge"
|
||||
|
Loading…
Reference in New Issue
Block a user