mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 17:41:57 +01:00
Add ability to receive intents to com.banglejs.uart.tx (from apps like tasker) and send them to Bangle.js
This commit is contained in:
parent
96654a01fb
commit
031898f538
@ -105,7 +105,6 @@ import javax.xml.xpath.XPathFactory;
|
||||
|
||||
public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BangleJSDeviceSupport.class);
|
||||
private final BroadcastReceiver commandReceiver;
|
||||
|
||||
private BluetoothGattCharacteristic rxCharacteristic = null;
|
||||
private BluetoothGattCharacteristic txCharacteristic = null;
|
||||
@ -117,16 +116,24 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
private boolean realtimeStep = false;
|
||||
private int realtimeHRMInterval = 30*60;
|
||||
|
||||
// Local Intents - for app manager communication
|
||||
public static final String BANGLEJS_COMMAND_TX = "banglejs_command_tx";
|
||||
public static final String BANGLEJS_COMMAND_RX = "banglejs_command_rx";
|
||||
// Global Intents
|
||||
private static final String BANGLE_ACTION_UART_TX = "com.banglejs.uart.tx";
|
||||
|
||||
public BangleJSDeviceSupport() {
|
||||
super(LOG);
|
||||
addSupportedService(BangleJSConstants.UUID_SERVICE_NORDIC_UART);
|
||||
|
||||
registerLocalIntents();
|
||||
registerGlobalIntents();
|
||||
}
|
||||
|
||||
private void registerLocalIntents() {
|
||||
IntentFilter commandFilter = new IntentFilter();
|
||||
commandFilter.addAction(BANGLEJS_COMMAND_TX);
|
||||
commandReceiver = new BroadcastReceiver() {
|
||||
BroadcastReceiver commandReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
@ -147,6 +154,45 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
LocalBroadcastManager.getInstance(GBApplication.getContext()).registerReceiver(commandReceiver, commandFilter);
|
||||
}
|
||||
|
||||
private void registerGlobalIntents() {
|
||||
IntentFilter commandFilter = new IntentFilter();
|
||||
commandFilter.addAction(BANGLE_ACTION_UART_TX);
|
||||
BroadcastReceiver commandReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case BANGLE_ACTION_UART_TX: {
|
||||
/* In Tasker:
|
||||
Action: com.banglejs.uart.tx
|
||||
Cat: None
|
||||
Extra: line:Terminal.println(%avariable)
|
||||
Target: Broadcast Receiver
|
||||
|
||||
Variable: Number, Configure on Import, NOT structured, Value set, Nothing Exported, NOT Same as value
|
||||
*/
|
||||
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
|
||||
if (!devicePrefs.getBoolean(PREF_DEVICE_INTENTS, false)) return;
|
||||
String data = intent.getStringExtra("line");
|
||||
if (data==null) {
|
||||
GB.toast(getContext(), "UART TX Intent, but no 'line' supplied", Toast.LENGTH_LONG, GB.ERROR);
|
||||
return;
|
||||
}
|
||||
if (!data.endsWith("\n")) data += "\n";
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("TX");
|
||||
uartTx(builder, data);
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
GB.toast(getContext(), "Error in TX: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
GBApplication.getContext().registerReceiver(commandReceiver, commandFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||
LOG.info("Initializing");
|
||||
|
@ -269,7 +269,7 @@
|
||||
<string name="pref_title_device_internet_access">Allow Internet Access</string>
|
||||
<string name="pref_summary_device_internet_access">Allow apps on this device to access the internet</string>
|
||||
<string name="pref_title_device_intents">Allow Intents</string>
|
||||
<string name="pref_summary_device_intents">Allow apps on this device to send Android Intents</string>
|
||||
<string name="pref_summary_device_intents">Allow Bangle.js watch apps to send Android Intents, and allow other apps on Android (like Tasker) to send data to Bangle.js with the com.banglejs.uart.tx Intent.</string>
|
||||
<string name="pref_summary_sync_calendar">Enables calendar alerts, even when disconnected</string>
|
||||
<string name="pref_title_sync_caldendar">Sync calendar events</string>
|
||||
<string name="pref_summary_relax_firmware_checks">Relax firmware checks</string>
|
||||
|
Loading…
Reference in New Issue
Block a user