From fb85326939a6a2672f9ff62846c8f6815003311f Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Thu, 3 Jan 2019 00:44:34 +0100 Subject: [PATCH] performConnected() -> builder.qeueue(getQueue()) --- .../btle/AbstractBTLEDeviceSupport.java | 14 +++++++++++-- .../service/devices/hplus/HPlusSupport.java | 20 +++++++++---------- .../service/devices/id115/ID115Support.java | 6 +++--- .../devices/jyou/TeclastH30Support.java | 12 +++++------ .../service/devices/no1f1/No1F1Support.java | 14 ++++++------- .../service/devices/xwatch/XWatchSupport.java | 2 +- 6 files changed, 39 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java index c65153ba0..93caef3ff 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEDeviceSupport.java @@ -110,9 +110,14 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im /** * Send commands like this to the device: *

- * perform("sms notification").write(someCharacteristic, someByteArray).queue(getQueue()); + * performInitialized("sms notification").write(someCharacteristic, someByteArray).queue(getQueue()); *

- * TODO: support orchestration of multiple reads and writes depending on returned values + * This will asynchronously + * * * @see #performConnected(Transaction) * @see #initializeDevice(TransactionBuilder) @@ -133,6 +138,11 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im } /** + * Ensures that the device is connected and (only then) performs the actions of the given + * transaction builder. + * + * In contrast to {@link #performInitialized(String)}, no initialization sequence is performed + * with the device, only the actions of the given builder are executed. * @param transaction * @throws IOException * @see {@link #performInitialized(String)} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java index 92e8dd209..7460cbf9f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusSupport.java @@ -415,7 +415,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { setCurrentDate(builder); setCurrentTime(builder); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); }catch(IOException e){ } @@ -446,7 +446,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { } setAlarm(builder, null); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO); }catch(Exception e){} @@ -532,7 +532,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { TransactionBuilder builder = performInitialized("Shutdown"); builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SHUTDOWN, HPlusConstants.ARG_SHUTDOWN_EN}); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); }catch(Exception e){ } @@ -545,7 +545,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { TransactionBuilder builder = performInitialized("HeartRateTest"); builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_HEARTRATE_STATE, HPlusConstants.ARG_HEARTRATE_MEASURE_ON}); //Set Real Time... ? - performConnected(builder.getTransaction()); + builder.queue(getQueue()); }catch(Exception e){ } @@ -563,7 +563,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { state = HPlusConstants.ARG_HEARTRATE_ALLDAY_OFF; builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_ALLDAY_HRM, state}); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); }catch(Exception e){ } @@ -575,7 +575,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { TransactionBuilder builder = performInitialized("findMe"); setFindMe(builder, start); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error toggling Find Me: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); } @@ -591,10 +591,10 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER; for (int i = 0; i < msg.length - 1; i++) - msg[i + 1] = (byte) "GadgetBridge".charAt(i); + msg[i + 1] = (byte) "Gadgetbridge".charAt(i); builder.write(ctrlCharacteristic, msg); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error setting Vibration: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); } @@ -711,7 +711,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { builder.write(ctrlCharacteristic, msg); } - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error showing incoming call: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); @@ -774,7 +774,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport { msg[2] = (byte) remaining; builder.write(ctrlCharacteristic, msg); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error showing device Notification: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/id115/ID115Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/id115/ID115Support.java index 0d6975022..600816633 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/id115/ID115Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/id115/ID115Support.java @@ -101,7 +101,7 @@ public class ID115Support extends AbstractBTLEDeviceSupport { try { TransactionBuilder builder = performInitialized("time"); setTime(builder); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch(IOException e) { LOG.warn("Unable to send current time", e); } @@ -193,7 +193,7 @@ public class ID115Support extends AbstractBTLEDeviceSupport { builder.write(normalWriteCharacteristic, new byte[] { ID115Constants.CMD_ID_DEVICE_RESTART, ID115Constants.CMD_KEY_REBOOT }); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch(Exception e) { } } @@ -350,7 +350,7 @@ public class ID115Support extends AbstractBTLEDeviceSupport { ID115Constants.CMD_KEY_NOTIFY_STOP, 1 }); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch(IOException e) { LOG.warn("Unable to stop call notification", e); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/TeclastH30Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/TeclastH30Support.java index 2b367af8a..839d820a9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/TeclastH30Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/TeclastH30Support.java @@ -215,7 +215,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport { } builder.write(ctrlCharacteristic, currentPacket); } - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { LOG.warn(e.getMessage()); } @@ -284,7 +284,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport { alarms.get(i).isEnabled() ? cal.get(Calendar.MINUTE) : -1 )); } - performConnected(builder.getTransaction()); + builder.queue(getQueue()); GB.toast(getContext(), "Alarm settings applied - do note that the current device does not support day specification", Toast.LENGTH_LONG, GB.INFO); } catch(IOException e) { LOG.warn(e.getMessage()); @@ -296,7 +296,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport { try { TransactionBuilder builder = performInitialized("SetTime"); syncDateAndTime(builder); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch(IOException e) { LOG.warn(e.getMessage()); } @@ -373,7 +373,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport { builder.write(ctrlCharacteristic, commandWithChecksum( JYouConstants.CMD_ACTION_REBOOT_DEVICE, 0, 0 )); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch(Exception e) { LOG.warn(e.getMessage()); } @@ -386,7 +386,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport { builder.write(ctrlCharacteristic, commandWithChecksum( JYouConstants.CMD_ACTION_HEARTRATE_SWITCH, 0, 1 )); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch(Exception e) { LOG.warn(e.getMessage()); } @@ -400,7 +400,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport { builder.write(ctrlCharacteristic, commandWithChecksum( JYouConstants.CMD_SET_HEARTRATE_AUTO, 0, enable ? 1 : 0 )); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch(Exception e) { LOG.warn(e.getMessage()); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java index 3e9020d27..f339c949c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java @@ -176,7 +176,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { try { TransactionBuilder builder = performInitialized("setTime"); setTime(builder); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error setting time: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); } @@ -308,7 +308,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { (byte) 0x11 }; builder.write(ctrlCharacteristic, msg); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error starting heart rate measurement: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); } @@ -500,7 +500,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { 1 }; builder.write(ctrlCharacteristic, msg); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { LOG.warn("Unable to set vibration", e); } @@ -514,7 +514,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { (byte) iconId }; builder.write(ctrlCharacteristic, msg); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error showing icon: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); } @@ -546,7 +546,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { System.arraycopy(bytes, 0, msg, 2, length); builder.write(ctrlCharacteristic, msg); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error showing notificaton: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); } @@ -560,7 +560,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { No1F1Constants.NOTIFICATION_STOP }; builder.write(ctrlCharacteristic, msg); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { LOG.warn("Unable to stop notification", e); } @@ -578,7 +578,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { (byte) 0xfa }; builder.write(ctrlCharacteristic, msg); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error fetching activity data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java index 016be3a40..5cac3ed15 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java @@ -455,7 +455,7 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport { try { builder = performInitialized("fetchActivityData"); requestDetailedData(builder); - performConnected(builder.getTransaction()); + builder.queue(getQueue()); } catch (IOException e) { GB.toast(getContext(), "Error fetching activity data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); }