2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2019-2020 Andreas Shimokawa, Gordon Williams
|
2019-12-15 22:07:00 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2019-11-28 19:02:47 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.banglejs;
|
|
|
|
|
|
|
|
import android.bluetooth.BluetoothGatt;
|
|
|
|
import android.bluetooth.BluetoothGattCharacteristic;
|
2019-12-04 17:42:28 +01:00
|
|
|
import android.content.Context;
|
2019-11-28 19:02:47 +01:00
|
|
|
import android.net.Uri;
|
2019-11-29 18:01:57 +01:00
|
|
|
import android.widget.Toast;
|
2019-11-28 19:02:47 +01:00
|
|
|
|
2019-12-14 12:01:52 +01:00
|
|
|
import org.json.JSONArray;
|
2019-12-04 17:42:28 +01:00
|
|
|
import org.json.JSONException;
|
2019-11-29 18:01:57 +01:00
|
|
|
import org.json.JSONObject;
|
2019-12-14 12:01:52 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Calendar;
|
2020-04-01 12:33:05 +02:00
|
|
|
import java.util.SimpleTimeZone;
|
2019-12-14 12:01:52 +01:00
|
|
|
import java.util.UUID;
|
2019-11-28 19:02:47 +01:00
|
|
|
|
2020-04-01 12:33:05 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2019-12-04 17:42:28 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
2019-12-04 18:23:34 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl;
|
2019-11-28 19:02:47 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSConstants;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
2019-12-04 17:42:28 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
2019-11-28 19:02:47 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
2019-11-29 18:01:57 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2020-04-01 12:33:05 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2019-11-28 19:02:47 +01:00
|
|
|
|
|
|
|
public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(BangleJSDeviceSupport.class);
|
2019-12-14 12:01:52 +01:00
|
|
|
private BluetoothGattCharacteristic rxCharacteristic = null;
|
|
|
|
private BluetoothGattCharacteristic txCharacteristic = null;
|
2019-11-28 19:02:47 +01:00
|
|
|
|
2019-11-29 18:01:57 +01:00
|
|
|
private String receivedLine = "";
|
|
|
|
|
2019-11-28 19:02:47 +01:00
|
|
|
public BangleJSDeviceSupport() {
|
|
|
|
super(LOG);
|
|
|
|
addSupportedService(BangleJSConstants.UUID_SERVICE_NORDIC_UART);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
|
|
|
LOG.info("Initializing");
|
|
|
|
|
|
|
|
gbDevice.setState(GBDevice.State.INITIALIZING);
|
|
|
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
|
|
|
|
|
|
|
rxCharacteristic = getCharacteristic(BangleJSConstants.UUID_CHARACTERISTIC_NORDIC_UART_RX);
|
|
|
|
txCharacteristic = getCharacteristic(BangleJSConstants.UUID_CHARACTERISTIC_NORDIC_UART_TX);
|
|
|
|
builder.setGattCallback(this);
|
|
|
|
builder.notify(rxCharacteristic, true);
|
|
|
|
|
2019-11-29 18:07:11 +01:00
|
|
|
uartTx(builder, " \u0003"); // clear active line
|
2020-04-01 12:33:05 +02:00
|
|
|
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
if (prefs.getBoolean("datetime_synconconnect", true))
|
|
|
|
setTime(builder);
|
2019-11-28 19:02:47 +01:00
|
|
|
//sendSettings(builder);
|
|
|
|
|
|
|
|
// get version
|
|
|
|
|
|
|
|
gbDevice.setState(GBDevice.State.INITIALIZED);
|
|
|
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
|
|
|
|
|
|
|
LOG.info("Initialization Done");
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Write a string of data, and chunk it up
|
2019-12-14 12:01:52 +01:00
|
|
|
private void uartTx(TransactionBuilder builder, String str) {
|
|
|
|
LOG.info("UART TX: " + str);
|
|
|
|
byte[] bytes;
|
|
|
|
bytes = str.getBytes(StandardCharsets.UTF_8);
|
2019-11-28 19:02:47 +01:00
|
|
|
for (int i=0;i<bytes.length;i+=20) {
|
|
|
|
int l = bytes.length-i;
|
|
|
|
if (l>20) l=20;
|
2019-12-14 12:01:52 +01:00
|
|
|
byte[] packet = new byte[l];
|
|
|
|
System.arraycopy(bytes, i, packet, 0, l);
|
2019-11-28 19:02:47 +01:00
|
|
|
builder.write(txCharacteristic, packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-04 17:42:28 +01:00
|
|
|
/// Write a string of data, and chunk it up
|
2019-12-14 12:01:52 +01:00
|
|
|
private void uartTxJSON(String taskName, JSONObject json) {
|
2019-12-04 17:42:28 +01:00
|
|
|
try {
|
|
|
|
TransactionBuilder builder = performInitialized(taskName);
|
|
|
|
uartTx(builder, "\u0010GB("+json.toString()+")\n");
|
|
|
|
builder.queue(getQueue());
|
|
|
|
} catch (IOException e) {
|
|
|
|
GB.toast(getContext(), "Error in "+taskName+": " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-14 12:01:52 +01:00
|
|
|
private void handleUartRxLine(String line) {
|
2019-12-04 17:42:28 +01:00
|
|
|
LOG.info("UART RX LINE: " + line);
|
|
|
|
|
2019-12-14 12:01:52 +01:00
|
|
|
if (">Uncaught ReferenceError: \"gb\" is not defined".equals(line))
|
2019-12-04 17:42:28 +01:00
|
|
|
GB.toast(getContext(), "Gadgetbridge plugin not installed on Bangle.js", Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
else if (line.charAt(0)=='{') {
|
|
|
|
// JSON - we hope!
|
|
|
|
try {
|
|
|
|
JSONObject json = new JSONObject(line);
|
|
|
|
handleUartRxJSON(json);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
GB.toast(getContext(), "Malformed JSON from Bangle.js: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-14 12:01:52 +01:00
|
|
|
private void handleUartRxJSON(JSONObject json) throws JSONException {
|
2019-12-04 17:42:28 +01:00
|
|
|
switch (json.getString("t")) {
|
|
|
|
case "info":
|
|
|
|
GB.toast(getContext(), "Bangle.js: " + json.getString("msg"), Toast.LENGTH_LONG, GB.INFO);
|
|
|
|
break;
|
|
|
|
case "warn":
|
|
|
|
GB.toast(getContext(), "Bangle.js: " + json.getString("msg"), Toast.LENGTH_LONG, GB.WARN);
|
|
|
|
break;
|
|
|
|
case "error":
|
|
|
|
GB.toast(getContext(), "Bangle.js: " + json.getString("msg"), Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
break;
|
|
|
|
case "status": {
|
|
|
|
Context context = getContext();
|
|
|
|
if (json.has("bat")) {
|
|
|
|
int b = json.getInt("bat");
|
|
|
|
if (b<0) b=0;
|
|
|
|
if (b>100) b=100;
|
|
|
|
gbDevice.setBatteryLevel((short)b);
|
|
|
|
if (b < 30) {
|
|
|
|
gbDevice.setBatteryState(BatteryState.BATTERY_LOW);
|
|
|
|
GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), String.valueOf(b)), "", context);
|
|
|
|
} else {
|
|
|
|
gbDevice.setBatteryState(BatteryState.BATTERY_NORMAL);
|
|
|
|
GB.removeBatteryNotification(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (json.has("volt"))
|
|
|
|
gbDevice.setBatteryVoltage((float)json.getDouble("volt"));
|
|
|
|
gbDevice.sendDeviceUpdateIntent(context);
|
|
|
|
} break;
|
|
|
|
case "findPhone": {
|
|
|
|
boolean start = json.has("n") && json.getBoolean("n");
|
|
|
|
GBDeviceEventFindPhone deviceEventFindPhone = new GBDeviceEventFindPhone();
|
|
|
|
deviceEventFindPhone.event = start ? GBDeviceEventFindPhone.Event.START : GBDeviceEventFindPhone.Event.STOP;
|
|
|
|
evaluateGBDeviceEvent(deviceEventFindPhone);
|
|
|
|
} break;
|
|
|
|
case "music": {
|
|
|
|
GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl();
|
|
|
|
deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.valueOf(json.getString("n").toUpperCase());
|
|
|
|
evaluateGBDeviceEvent(deviceEventMusicControl);
|
|
|
|
} break;
|
|
|
|
case "call": {
|
|
|
|
GBDeviceEventCallControl deviceEventCallControl = new GBDeviceEventCallControl();
|
|
|
|
deviceEventCallControl.event = GBDeviceEventCallControl.Event.valueOf(json.getString("n").toUpperCase());
|
|
|
|
evaluateGBDeviceEvent(deviceEventCallControl);
|
|
|
|
} break;
|
2019-12-04 18:23:34 +01:00
|
|
|
case "notify" : {
|
|
|
|
GBDeviceEventNotificationControl deviceEvtNotificationControl = new GBDeviceEventNotificationControl();
|
|
|
|
// .title appears unused
|
|
|
|
deviceEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.valueOf(json.getString("n").toUpperCase());
|
|
|
|
if (json.has("id"))
|
|
|
|
deviceEvtNotificationControl.handle = json.getInt("id");
|
|
|
|
if (json.has("tel"))
|
|
|
|
deviceEvtNotificationControl.phoneNumber = json.getString("tel");
|
|
|
|
if (json.has("msg"))
|
|
|
|
deviceEvtNotificationControl.reply = json.getString("msg");
|
|
|
|
evaluateGBDeviceEvent(deviceEvtNotificationControl);
|
|
|
|
} break;
|
2019-12-04 17:42:28 +01:00
|
|
|
/*case "activity": {
|
|
|
|
BangleJSActivitySample sample = new BangleJSActivitySample();
|
|
|
|
sample.setTimestamp((int) (GregorianCalendar.getInstance().getTimeInMillis() / 1000L));
|
|
|
|
sample.setHeartRate(json.getInteger("hrm"));
|
|
|
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
|
|
|
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
|
|
|
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
|
|
|
|
BangleJSSampleProvider provider = new BangleJSSampleProvider(getDevice(), dbHandler.getDaoSession());
|
|
|
|
sample.setDeviceId(deviceId);
|
|
|
|
sample.setUserId(userId);
|
|
|
|
provider.addGBActivitySample(sample);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
LOG.warn("Error saving current heart rate: " + ex.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
} break;*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 19:02:47 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCharacteristicChanged(BluetoothGatt gatt,
|
|
|
|
BluetoothGattCharacteristic characteristic) {
|
|
|
|
if (super.onCharacteristicChanged(gatt, characteristic)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (BangleJSConstants.UUID_CHARACTERISTIC_NORDIC_UART_RX.equals(characteristic.getUuid())) {
|
2019-12-14 12:01:52 +01:00
|
|
|
byte[] chars = characteristic.getValue();
|
2019-11-29 18:01:57 +01:00
|
|
|
String packetStr = new String(chars);
|
|
|
|
LOG.info("RX: " + packetStr);
|
|
|
|
receivedLine += packetStr;
|
2019-12-14 12:01:52 +01:00
|
|
|
while (receivedLine.contains("\n")) {
|
2019-11-29 18:01:57 +01:00
|
|
|
int p = receivedLine.indexOf("\n");
|
|
|
|
String line = receivedLine.substring(0,p-1);
|
|
|
|
receivedLine = receivedLine.substring(p+1);
|
2019-12-04 17:42:28 +01:00
|
|
|
handleUartRxLine(line);
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setTime(TransactionBuilder builder) {
|
2020-04-01 12:33:05 +02:00
|
|
|
long ts = System.currentTimeMillis();
|
|
|
|
float tz = SimpleTimeZone.getDefault().getOffset(ts) / (1000 * 60 * 60.0f);
|
|
|
|
// set time
|
|
|
|
String cmd = "\u0010setTime("+(ts/1000)+");";
|
|
|
|
// set timezone
|
|
|
|
cmd += "E.setTimeZone("+tz+");";
|
|
|
|
// write timezone to settings
|
|
|
|
cmd += "(s=>{s&&(s.timezone="+tz+")&&require('Storage').write('setting.json',s);})(require('Storage').readJSON('setting.json',1))";
|
|
|
|
uartTx(builder, cmd+"\n");
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean useAutoConnect() {
|
2019-12-04 17:42:28 +01:00
|
|
|
return true;
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNotification(NotificationSpec notificationSpec) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "notify");
|
|
|
|
o.put("id", notificationSpec.getId());
|
|
|
|
o.put("src", notificationSpec.sourceName);
|
|
|
|
o.put("title", notificationSpec.title);
|
|
|
|
o.put("subject", notificationSpec.subject);
|
|
|
|
o.put("body", notificationSpec.body);
|
|
|
|
o.put("sender", notificationSpec.sender);
|
|
|
|
o.put("tel", notificationSpec.phoneNumber);
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onNotification", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDeleteNotification(int id) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "notify-");
|
|
|
|
o.put("id", id);
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onDeleteNotification", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetTime() {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
TransactionBuilder builder = performInitialized("setTime");
|
|
|
|
setTime(builder);
|
|
|
|
builder.queue(getQueue());
|
|
|
|
} catch (Exception e) {
|
|
|
|
GB.toast(getContext(), "Error setting time: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "alarm");
|
|
|
|
JSONArray jsonalarms = new JSONArray();
|
|
|
|
o.put("d", jsonalarms);
|
|
|
|
|
|
|
|
for (Alarm alarm : alarms) {
|
|
|
|
if (!alarm.getEnabled()) continue;
|
|
|
|
JSONObject jsonalarm = new JSONObject();
|
|
|
|
jsonalarms.put(jsonalarm);
|
|
|
|
|
|
|
|
Calendar calendar = AlarmUtils.toCalendar(alarm);
|
|
|
|
// TODO: getRepetition to ensure it only happens on correct day?
|
|
|
|
jsonalarm.put("h", alarm.getHour());
|
|
|
|
jsonalarm.put("m", alarm.getMinute());
|
|
|
|
}
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onSetAlarms", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetCallState(CallSpec callSpec) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "call");
|
2019-12-14 12:01:52 +01:00
|
|
|
String[] cmdString = {"", "undefined", "accept", "incoming", "outgoing", "reject", "start", "end"};
|
2019-11-29 18:01:57 +01:00
|
|
|
o.put("cmd", cmdString[callSpec.command]);
|
|
|
|
o.put("name", callSpec.name);
|
|
|
|
o.put("number", callSpec.number);
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onSetCallState", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-12-04 17:42:28 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetCannedMessages(CannedMessagesSpec cannedMessagesSpec) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetMusicState(MusicStateSpec stateSpec) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "musicstate");
|
2019-12-14 12:01:52 +01:00
|
|
|
String[] musicStates = {"play", "pause", "stop", ""};
|
2019-11-29 18:01:57 +01:00
|
|
|
o.put("state", musicStates[stateSpec.state]);
|
|
|
|
o.put("position", stateSpec.position);
|
|
|
|
o.put("shuffle", stateSpec.shuffle);
|
|
|
|
o.put("repeat", stateSpec.repeat);
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onSetMusicState", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetMusicInfo(MusicSpec musicSpec) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "musicinfo");
|
|
|
|
o.put("artist", musicSpec.artist);
|
|
|
|
o.put("album", musicSpec.album);
|
|
|
|
o.put("track", musicSpec.track);
|
|
|
|
o.put("dur", musicSpec.duration);
|
|
|
|
o.put("c", musicSpec.trackCount);
|
|
|
|
o.put("n", musicSpec.trackNr);
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onSetMusicInfo", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnableRealtimeSteps(boolean enable) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInstallApp(Uri uri) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAppInfoReq() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAppStart(UUID uuid, boolean start) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAppDelete(UUID uuid) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAppConfiguration(UUID appUuid, String config, Integer id) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAppReorder(UUID[] uuids) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFetchRecordedData(int dataTypes) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReset(int flags) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onHeartRateTest() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnableRealtimeHeartRateMeasurement(boolean enable) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFindDevice(boolean start) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "find");
|
|
|
|
o.put("n", start);
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onFindDevice", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetConstantVibration(int integer) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "vibrate");
|
|
|
|
o.put("n", integer);
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onSetConstantVibration", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScreenshotReq() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnableHeartRateSleepSupport(boolean enable) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSetHeartRateMeasurementInterval(int seconds) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAddCalendarEvent(CalendarEventSpec calendarEventSpec) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDeleteCalendarEvent(byte type, long id) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSendConfiguration(String config) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReadConfiguration(String config) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTestNewFunction() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSendWeather(WeatherSpec weatherSpec) {
|
2019-11-29 18:01:57 +01:00
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("t", "weather");
|
|
|
|
o.put("temp", weatherSpec.currentTemp);
|
|
|
|
o.put("hum", weatherSpec.currentHumidity);
|
|
|
|
o.put("txt", weatherSpec.currentCondition);
|
|
|
|
o.put("wind", weatherSpec.windSpeed);
|
|
|
|
o.put("loc", weatherSpec.location);
|
2019-12-04 17:42:28 +01:00
|
|
|
uartTxJSON("onSendWeather", o);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
LOG.info("JSONException: " + e.getLocalizedMessage());
|
2019-11-29 18:01:57 +01:00
|
|
|
}
|
2019-11-28 19:02:47 +01:00
|
|
|
}
|
|
|
|
}
|