1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

performConnected() -> builder.qeueue(getQueue())

This commit is contained in:
cpfeiffer 2019-01-03 00:44:34 +01:00
parent c69be1f94b
commit fb85326939
6 changed files with 39 additions and 29 deletions

View File

@ -110,9 +110,14 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
/** /**
* Send commands like this to the device: * Send commands like this to the device:
* <p> * <p>
* <code>perform("sms notification").write(someCharacteristic, someByteArray).queue(getQueue());</code> * <code>performInitialized("sms notification").write(someCharacteristic, someByteArray).queue(getQueue());</code>
* </p> * </p>
* TODO: support orchestration of multiple reads and writes depending on returned values * This will asynchronously
* <ul>
* <li>connect to the device (if necessary)</li>
* <li>initialize the device (if necessary)</li>
* <li>execute the commands collected with the returned transaction builder</li>
* </ul>
* *
* @see #performConnected(Transaction) * @see #performConnected(Transaction)
* @see #initializeDevice(TransactionBuilder) * @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 * @param transaction
* @throws IOException * @throws IOException
* @see {@link #performInitialized(String)} * @see {@link #performInitialized(String)}

View File

@ -415,7 +415,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
setCurrentDate(builder); setCurrentDate(builder);
setCurrentTime(builder); setCurrentTime(builder);
performConnected(builder.getTransaction()); builder.queue(getQueue());
}catch(IOException e){ }catch(IOException e){
} }
@ -446,7 +446,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
} }
setAlarm(builder, null); 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); GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
}catch(Exception e){} }catch(Exception e){}
@ -532,7 +532,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
TransactionBuilder builder = performInitialized("Shutdown"); TransactionBuilder builder = performInitialized("Shutdown");
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SHUTDOWN, HPlusConstants.ARG_SHUTDOWN_EN}); builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SHUTDOWN, HPlusConstants.ARG_SHUTDOWN_EN});
performConnected(builder.getTransaction()); builder.queue(getQueue());
}catch(Exception e){ }catch(Exception e){
} }
@ -545,7 +545,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
TransactionBuilder builder = performInitialized("HeartRateTest"); TransactionBuilder builder = performInitialized("HeartRateTest");
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_HEARTRATE_STATE, HPlusConstants.ARG_HEARTRATE_MEASURE_ON}); //Set Real Time... ? 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){ }catch(Exception e){
} }
@ -563,7 +563,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
state = HPlusConstants.ARG_HEARTRATE_ALLDAY_OFF; state = HPlusConstants.ARG_HEARTRATE_ALLDAY_OFF;
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_ALLDAY_HRM, state}); builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_ALLDAY_HRM, state});
performConnected(builder.getTransaction()); builder.queue(getQueue());
}catch(Exception e){ }catch(Exception e){
} }
@ -575,7 +575,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
TransactionBuilder builder = performInitialized("findMe"); TransactionBuilder builder = performInitialized("findMe");
setFindMe(builder, start); setFindMe(builder, start);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error toggling Find Me: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); 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; msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER;
for (int i = 0; i < msg.length - 1; i++) 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); builder.write(ctrlCharacteristic, msg);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error setting Vibration: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); 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); builder.write(ctrlCharacteristic, msg);
} }
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error showing incoming call: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); 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; msg[2] = (byte) remaining;
builder.write(ctrlCharacteristic, msg); builder.write(ctrlCharacteristic, msg);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error showing device Notification: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error showing device Notification: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);

View File

@ -101,7 +101,7 @@ public class ID115Support extends AbstractBTLEDeviceSupport {
try { try {
TransactionBuilder builder = performInitialized("time"); TransactionBuilder builder = performInitialized("time");
setTime(builder); setTime(builder);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch(IOException e) { } catch(IOException e) {
LOG.warn("Unable to send current time", e); LOG.warn("Unable to send current time", e);
} }
@ -193,7 +193,7 @@ public class ID115Support extends AbstractBTLEDeviceSupport {
builder.write(normalWriteCharacteristic, new byte[] { builder.write(normalWriteCharacteristic, new byte[] {
ID115Constants.CMD_ID_DEVICE_RESTART, ID115Constants.CMD_KEY_REBOOT ID115Constants.CMD_ID_DEVICE_RESTART, ID115Constants.CMD_KEY_REBOOT
}); });
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch(Exception e) { } catch(Exception e) {
} }
} }
@ -350,7 +350,7 @@ public class ID115Support extends AbstractBTLEDeviceSupport {
ID115Constants.CMD_KEY_NOTIFY_STOP, ID115Constants.CMD_KEY_NOTIFY_STOP,
1 1
}); });
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch(IOException e) { } catch(IOException e) {
LOG.warn("Unable to stop call notification", e); LOG.warn("Unable to stop call notification", e);
} }

View File

@ -215,7 +215,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport {
} }
builder.write(ctrlCharacteristic, currentPacket); builder.write(ctrlCharacteristic, currentPacket);
} }
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());
} }
@ -284,7 +284,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport {
alarms.get(i).isEnabled() ? cal.get(Calendar.MINUTE) : -1 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); 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) { } catch(IOException e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());
@ -296,7 +296,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport {
try { try {
TransactionBuilder builder = performInitialized("SetTime"); TransactionBuilder builder = performInitialized("SetTime");
syncDateAndTime(builder); syncDateAndTime(builder);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch(IOException e) { } catch(IOException e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());
} }
@ -373,7 +373,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport {
builder.write(ctrlCharacteristic, commandWithChecksum( builder.write(ctrlCharacteristic, commandWithChecksum(
JYouConstants.CMD_ACTION_REBOOT_DEVICE, 0, 0 JYouConstants.CMD_ACTION_REBOOT_DEVICE, 0, 0
)); ));
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch(Exception e) { } catch(Exception e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());
} }
@ -386,7 +386,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport {
builder.write(ctrlCharacteristic, commandWithChecksum( builder.write(ctrlCharacteristic, commandWithChecksum(
JYouConstants.CMD_ACTION_HEARTRATE_SWITCH, 0, 1 JYouConstants.CMD_ACTION_HEARTRATE_SWITCH, 0, 1
)); ));
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch(Exception e) { } catch(Exception e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());
} }
@ -400,7 +400,7 @@ public class TeclastH30Support extends AbstractBTLEDeviceSupport {
builder.write(ctrlCharacteristic, commandWithChecksum( builder.write(ctrlCharacteristic, commandWithChecksum(
JYouConstants.CMD_SET_HEARTRATE_AUTO, 0, enable ? 1 : 0 JYouConstants.CMD_SET_HEARTRATE_AUTO, 0, enable ? 1 : 0
)); ));
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch(Exception e) { } catch(Exception e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());
} }

View File

@ -176,7 +176,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
try { try {
TransactionBuilder builder = performInitialized("setTime"); TransactionBuilder builder = performInitialized("setTime");
setTime(builder); setTime(builder);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error setting time: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error setting time: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
} }
@ -308,7 +308,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
(byte) 0x11 (byte) 0x11
}; };
builder.write(ctrlCharacteristic, msg); builder.write(ctrlCharacteristic, msg);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error starting heart rate measurement: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); 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 1
}; };
builder.write(ctrlCharacteristic, msg); builder.write(ctrlCharacteristic, msg);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set vibration", e); LOG.warn("Unable to set vibration", e);
} }
@ -514,7 +514,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
(byte) iconId (byte) iconId
}; };
builder.write(ctrlCharacteristic, msg); builder.write(ctrlCharacteristic, msg);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error showing icon: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); 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); System.arraycopy(bytes, 0, msg, 2, length);
builder.write(ctrlCharacteristic, msg); builder.write(ctrlCharacteristic, msg);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error showing notificaton: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); 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 No1F1Constants.NOTIFICATION_STOP
}; };
builder.write(ctrlCharacteristic, msg); builder.write(ctrlCharacteristic, msg);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to stop notification", e); LOG.warn("Unable to stop notification", e);
} }
@ -578,7 +578,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
(byte) 0xfa (byte) 0xfa
}; };
builder.write(ctrlCharacteristic, msg); builder.write(ctrlCharacteristic, msg);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error fetching activity data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error fetching activity data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
} }

View File

@ -455,7 +455,7 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport {
try { try {
builder = performInitialized("fetchActivityData"); builder = performInitialized("fetchActivityData");
requestDetailedData(builder); requestDetailedData(builder);
performConnected(builder.getTransaction()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
GB.toast(getContext(), "Error fetching activity data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR); GB.toast(getContext(), "Error fetching activity data: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
} }