mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Pebble: dynamic key support for Square handler
This commit is contained in:
parent
712ce1aa8b
commit
a451b5367b
@ -9,7 +9,6 @@ import org.json.JSONObject;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||||
@ -25,7 +24,6 @@ class AppMessageHandlerHealthify extends AppMessageHandler {
|
|||||||
AppMessageHandlerHealthify(UUID uuid, PebbleProtocol pebbleProtocol) {
|
AppMessageHandlerHealthify(UUID uuid, PebbleProtocol pebbleProtocol) {
|
||||||
super(uuid, pebbleProtocol);
|
super(uuid, pebbleProtocol);
|
||||||
|
|
||||||
messageKeys = new HashMap<>();
|
|
||||||
try {
|
try {
|
||||||
JSONObject appKeys = getAppKeys();
|
JSONObject appKeys = getAppKeys();
|
||||||
KEY_TEMPERATURE = appKeys.getInt("TEMPERATURE");
|
KEY_TEMPERATURE = appKeys.getInt("TEMPERATURE");
|
||||||
|
@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.SimpleTimeZone;
|
import java.util.SimpleTimeZone;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
@ -59,7 +58,6 @@ class AppMessageHandlerMorpheuz extends AppMessageHandler {
|
|||||||
public AppMessageHandlerMorpheuz(UUID uuid, PebbleProtocol pebbleProtocol) {
|
public AppMessageHandlerMorpheuz(UUID uuid, PebbleProtocol pebbleProtocol) {
|
||||||
super(uuid, pebbleProtocol);
|
super(uuid, pebbleProtocol);
|
||||||
|
|
||||||
messageKeys = new HashMap<>();
|
|
||||||
try {
|
try {
|
||||||
JSONObject appKeys = getAppKeys();
|
JSONObject appKeys = getAppKeys();
|
||||||
keyPoint = appKeys.getInt("keyPoint");
|
keyPoint = appKeys.getInt("keyPoint");
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
|
||||||
|
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -10,26 +15,28 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
class AppMessageHandlerSquare extends AppMessageHandler {
|
class AppMessageHandlerSquare extends AppMessageHandler {
|
||||||
// "CfgKeyCelsiusTemperature":10001,
|
private int CfgKeyCelsiusTemperature;
|
||||||
// CfgKeyConditions":10002,
|
private int CfgKeyConditions;
|
||||||
//"CfgKeyWeatherError":10003,
|
private int CfgKeyWeatherMode;
|
||||||
// "CfgKeyWeatherMode":10004,
|
private int CfgKeyUseCelsius;
|
||||||
// "CfgKeyUseCelsius":10005,"
|
private int CfgKeyWeatherLocation;
|
||||||
// CfgKeyWeatherLocation":10006,"
|
|
||||||
// "CfgKeyTemperature":10000,
|
|
||||||
//
|
|
||||||
//
|
|
||||||
private static final int KEY_TEMP = 10001; //celsius
|
|
||||||
private static final int KEY_WEATHER = 10002;
|
|
||||||
private static final int KEY_WEATHER_MODE = 10004;
|
|
||||||
private static final int KEY_USE_CELSIUS = 10005; //celsius
|
|
||||||
private static final int KEY_LOCATION = 10006;
|
|
||||||
private static final int KEY_TEMP_F = 10000; //fahrenheit
|
|
||||||
|
|
||||||
AppMessageHandlerSquare(UUID uuid, PebbleProtocol pebbleProtocol) {
|
AppMessageHandlerSquare(UUID uuid, PebbleProtocol pebbleProtocol) {
|
||||||
super(uuid, pebbleProtocol);
|
super(uuid, pebbleProtocol);
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONObject appKeys = getAppKeys();
|
||||||
|
CfgKeyCelsiusTemperature = appKeys.getInt("CfgKeyCelsiusTemperature");
|
||||||
|
CfgKeyConditions = appKeys.getInt("CfgKeyConditions");
|
||||||
|
CfgKeyWeatherMode = appKeys.getInt("CfgKeyWeatherMode");
|
||||||
|
CfgKeyUseCelsius = appKeys.getInt("CfgKeyUseCelsius");
|
||||||
|
CfgKeyWeatherLocation = appKeys.getInt("CfgKeyWeatherLocation");
|
||||||
|
} catch (IOException | JSONException e) {
|
||||||
|
GB.toast("There was an error accessing the watchface configuration.", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] encodeSquareWeatherMessage(WeatherSpec weatherSpec) {
|
private byte[] encodeSquareWeatherMessage(WeatherSpec weatherSpec) {
|
||||||
@ -38,11 +45,11 @@ class AppMessageHandlerSquare extends AppMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(2);
|
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(2);
|
||||||
pairs.add(new Pair<>(KEY_WEATHER_MODE, (Object) 1));
|
pairs.add(new Pair<>(CfgKeyWeatherMode, (Object) 1));
|
||||||
pairs.add(new Pair<>(KEY_WEATHER, (Object) weatherSpec.currentCondition));
|
pairs.add(new Pair<>(CfgKeyConditions, (Object) weatherSpec.currentCondition));
|
||||||
pairs.add(new Pair<>(KEY_USE_CELSIUS, (Object) 1));
|
pairs.add(new Pair<>(CfgKeyUseCelsius, (Object) 1));
|
||||||
pairs.add(new Pair<>(KEY_TEMP, (Object) (weatherSpec.currentTemp - 273)));
|
pairs.add(new Pair<>(CfgKeyCelsiusTemperature, (Object) (weatherSpec.currentTemp - 273)));
|
||||||
pairs.add(new Pair<>(KEY_LOCATION, (Object) (weatherSpec.location)));
|
pairs.add(new Pair<>(CfgKeyWeatherLocation, (Object) (weatherSpec.location)));
|
||||||
byte[] weatherMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
|
byte[] weatherMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
|
||||||
|
|
||||||
ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length);
|
ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length);
|
||||||
|
@ -8,7 +8,6 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||||
@ -28,7 +27,6 @@ class AppMessageHandlerTrekVolle extends AppMessageHandler {
|
|||||||
AppMessageHandlerTrekVolle(UUID uuid, PebbleProtocol pebbleProtocol) {
|
AppMessageHandlerTrekVolle(UUID uuid, PebbleProtocol pebbleProtocol) {
|
||||||
super(uuid, pebbleProtocol);
|
super(uuid, pebbleProtocol);
|
||||||
|
|
||||||
messageKeys = new HashMap<>();
|
|
||||||
try {
|
try {
|
||||||
JSONObject appKeys = getAppKeys();
|
JSONObject appKeys = getAppKeys();
|
||||||
MESSAGE_KEY_WEATHER_TEMPERATURE = appKeys.getInt("WEATHER_TEMPERATURE");
|
MESSAGE_KEY_WEATHER_TEMPERATURE = appKeys.getInt("WEATHER_TEMPERATURE");
|
||||||
|
Loading…
Reference in New Issue
Block a user