ATC_TLSR_Paper: support enabling/disabling oepl protocol, fix setting BLE advertising interval

This commit is contained in:
Andreas Shimokawa
2025-07-03 20:49:57 +02:00
parent 8916555044
commit 7e7f554045
5 changed files with 36 additions and 10 deletions
@@ -651,5 +651,6 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_DEVICE_STRESS_TEST_DISPOSE = "pref_device_stress_test_dispose";
public static final String PREF_ATC_TLSR_PAPER_MODEL = "pref_atc_tlsr_paper_model";
public static final String PREF_ATC_TLSR_PAPER_BLE_ADV_INTERVAL = "pref_atc_tlsr_ble_adv_interval";
public static final String PREF_ATC_TLSR_PAPER_BLE_ADV_INTERVAL = "pref_atc_tlsr_paper_ble_adv_interval";
public static final String PREF_ATC_TLSR_PAPER_OEPL_PROTOCOL_ENABLE = "pref_atc_tlsr_paper_oepl_protocol_enable";
}
@@ -969,6 +969,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
addPreferenceHandlerFor(PREF_ATC_TLSR_PAPER_MODEL);
addPreferenceHandlerFor(PREF_ATC_TLSR_PAPER_BLE_ADV_INTERVAL);
addPreferenceHandlerFor(PREF_ATC_TLSR_PAPER_OEPL_PROTOCOL_ENABLE);
final Preference dischargeIntervalsSet = findPreference(PREF_BATTERY_DISCHARGE_INTERVALS_SET);
if (dischargeIntervalsSet != null) {
@@ -59,8 +59,10 @@ public class ATCTLSRPaperDeviceSupport extends AbstractBTLESingleDeviceSupport {
public static final UUID UUID_CHARACTERISTIC_MAIN = UUID.fromString("00001337-0000-1000-8000-00805f9b34fb");
private static final Logger LOG = LoggerFactory.getLogger(ATCTLSRPaperDeviceSupport.class);
private static final byte[] COMMAND_GET_CONFIGURATION = new byte[]{0x00, 0x05};
private static final byte[] COMMAND_ENABLE_OEPL = new byte[]{0x00, 0x06};
private static final byte[] COMMAND_DISABLE_OEPL = new byte[]{0x00, 0x07};
private static final byte[] COMMAND_CONFIGURE_HS_154_BWRY_JD = new byte[]{0x00, 0x10, 0x26, 0x00, 0x6C, 0x00, 0x05, 0x00, 0x01, 0x01, 0x00, (byte) 0xC8, 0x00, (byte) 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x02, 0x01, 0x10, 0x03, (byte) 0x80, 0x01, 0x02, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, (byte) 0x80, 0x03, 0x40, 0x01, 0x20, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02, 0x01, 0x10, 0x01, 0x08, 0x03, (byte) 0x80, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x40, 0x02, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
private int epaper_width = 0;
private int epaper_height = 0;
private int epaper_colors = 0;
@@ -240,6 +242,9 @@ public class ATCTLSRPaperDeviceSupport extends AbstractBTLESingleDeviceSupport {
buf.position(32);
epaper_colors = buf.get();
buf.position(35);
boolean oepl_enabled = buf.get() == 0x01;
buf.position(41);
int ble_adv_interval = buf.getShort() & 0xffff;
@@ -247,11 +252,12 @@ public class ATCTLSRPaperDeviceSupport extends AbstractBTLESingleDeviceSupport {
model = 10000; //HACK for unsupported HS 154 BWRY JD
}
LOG.info("decoded data: version={}, width={}, height={}, nr_colors={}, w/h swapped={}, model={} ble_adv_interval={}", version, epaper_width, epaper_height, epaper_colors, is_wh_swapped, model, ble_adv_interval);
LOG.info("decoded data: version={}, width={}, height={}, nr_colors={}, w/h swapped={}, model={} ble_adv_interval={}, oepl_enabled={}", version, epaper_width, epaper_height, epaper_colors, is_wh_swapped, model, ble_adv_interval, oepl_enabled);
SharedPreferences.Editor editor = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).edit();
editor.putString(DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_MODEL, String.valueOf(model));
editor.putString(DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_BLE_ADV_INTERVAL, String.valueOf(ble_adv_interval));
editor.putBoolean(DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_OEPL_PROTOCOL_ENABLE, oepl_enabled);
editor.apply();
final TransactionBuilder builder = new TransactionBuilder("set initialized");
@@ -263,6 +269,7 @@ public class ATCTLSRPaperDeviceSupport extends AbstractBTLESingleDeviceSupport {
public void onSendConfiguration(String config) {
if (DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_MODEL.equals(config)
|| DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_BLE_ADV_INTERVAL.equals(config)
|| DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_OEPL_PROTOCOL_ENABLE.equals(config)
) {
TransactionBuilder builder;
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
@@ -280,8 +287,17 @@ public class ATCTLSRPaperDeviceSupport extends AbstractBTLESingleDeviceSupport {
if (DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_BLE_ADV_INTERVAL.equals(config)) {
String bt_adv_interval = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_BLE_ADV_INTERVAL, "1000");
int interval = Integer.parseInt(bt_adv_interval);
builder.write(getCharacteristic(UUID_CHARACTERISTIC_MAIN), new byte[]{0x00, 0x08, (byte) (interval & 0xff), (byte) ((interval >> 8) & 0xff)});
builder.write(getCharacteristic(UUID_CHARACTERISTIC_MAIN), new byte[]{0x00, 0x08, (byte) ((interval >> 8) & 0xff), (byte) (interval & 0xff)});
}
if (DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_OEPL_PROTOCOL_ENABLE.equals(config)) {
boolean enable_oepl_protocol = sharedPrefs.getBoolean(DeviceSettingsPreferenceConst.PREF_ATC_TLSR_PAPER_OEPL_PROTOCOL_ENABLE, true);
if (enable_oepl_protocol) {
builder.write(getCharacteristic(UUID_CHARACTERISTIC_MAIN), COMMAND_ENABLE_OEPL);
} else {
builder.write(getCharacteristic(UUID_CHARACTERISTIC_MAIN), COMMAND_DISABLE_OEPL);
}
}
builder.queue(getQueue());
} catch (IOException e) {
GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e);
+4 -2
View File
@@ -4085,6 +4085,8 @@
<string name="pref_calendar_target_app_title">Target app on watch for calendar events</string>
<string name="same_image_already_on_device">same image already on device</string>
<string name="sending_image">sending image</string>
<string name="pref_atc_tlsr_model_title">Display Model</string>
<string name="pref_atc_tlsr_ble_adv_interval_title">BLE Advertising Interval</string>
<string name="pref_atc_tlsr_paper_model_title">Display Model</string>
<string name="pref_atc_tlsr_paper_ble_adv_interval_title">BLE Advertising Interval</string>
<string name="pref_atc_tlsr_paper_oepl_protocol_enable_title">Enable OEPL protocol</string>
<string name="pref_atc_tlsr_paper_oepl_protocol_enable_summary">Disable this if only using BLE to save power</string>
</resources>
@@ -6,12 +6,18 @@
android:entryValues="@array/atc_tlsr_paper_models_values"
android:key="pref_atc_tlsr_paper_model"
android:summary="%s"
android:title="@string/pref_atc_tlsr_model_title" />
android:title="@string/pref_atc_tlsr_paper_model_title" />
<ListPreference
android:defaultValue="1"
android:defaultValue="3200"
android:entries="@array/atc_tlsr_paper_ble_adv_interval"
android:entryValues="@array/atc_tlsr_paper_ble_adv_interval_values"
android:key="pref_atc_tlsr_ble_adv_interval"
android:key="pref_atc_tlsr_paper_ble_adv_interval"
android:summary="%s"
android:title="@string/pref_atc_tlsr_ble_adv_interval_title" />
android:title="@string/pref_atc_tlsr_paper_ble_adv_interval_title" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_atc_tlsr_paper_oepl_protocol_enable"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_atc_tlsr_paper_oepl_protocol_enable_summary"
android:title="@string/pref_atc_tlsr_paper_oepl_protocol_enable_title" />
</androidx.preference.PreferenceScreen>