Pebble: First shot at TrekVolle support

Also some cleanups
here
Andreas Shimokawa 2017-01-01 16:24:46 +01:00
parent 8b55110679
commit f25605f5a1
10 changed files with 144 additions and 64 deletions

View File

@ -10,7 +10,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
public class AppMessageHandler {
class AppMessageHandler {
final PebbleProtocol mPebbleProtocol;
final UUID mUUID;

View File

@ -2,12 +2,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import android.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Objects;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
@ -19,8 +15,6 @@ class AppMessageHandlerHealthify extends AppMessageHandler {
private static final int KEY_TEMPERATURE = 10021;
private static final int KEY_CONDITIONS = 10022;
private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerHealthify.class);
AppMessageHandlerHealthify(UUID uuid, PebbleProtocol pebbleProtocol) {
super(uuid, pebbleProtocol);
}
@ -53,6 +47,9 @@ class AppMessageHandlerHealthify extends AppMessageHandler {
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[]{null};
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeMarioWeatherMessage(weatherSpec);
return new GBDeviceEvent[]{sendBytes};

View File

@ -2,9 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import android.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.UUID;
@ -19,8 +16,6 @@ class AppMessageHandlerMarioTime extends AppMessageHandler {
private static final int KEY_WEATHER_ICON_ID = 10;
private static final int KEY_WEATHER_TEMPERATURE = 11;
private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerMarioTime.class);
AppMessageHandlerMarioTime(UUID uuid, PebbleProtocol pebbleProtocol) {
super(uuid, pebbleProtocol);
}
@ -53,6 +48,9 @@ class AppMessageHandlerMarioTime extends AppMessageHandler {
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[]{null};
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeMarioWeatherMessage(weatherSpec);
return new GBDeviceEvent[]{sendBytes};

View File

@ -22,21 +22,21 @@ import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMisfitSample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class AppMessageHandlerMisfit extends AppMessageHandler {
class AppMessageHandlerMisfit extends AppMessageHandler {
public static final int KEY_SLEEPGOAL = 1;
public static final int KEY_STEP_ROGRESS = 2;
public static final int KEY_SLEEP_PROGRESS = 3;
public static final int KEY_VERSION = 4;
public static final int KEY_SYNC = 5;
public static final int KEY_INCOMING_DATA_BEGIN = 6;
public static final int KEY_INCOMING_DATA = 7;
public static final int KEY_INCOMING_DATA_END = 8;
public static final int KEY_SYNC_RESULT = 9;
private static final int KEY_SLEEPGOAL = 1;
private static final int KEY_STEP_ROGRESS = 2;
private static final int KEY_SLEEP_PROGRESS = 3;
private static final int KEY_VERSION = 4;
private static final int KEY_SYNC = 5;
private static final int KEY_INCOMING_DATA_BEGIN = 6;
private static final int KEY_INCOMING_DATA = 7;
private static final int KEY_INCOMING_DATA_END = 8;
private static final int KEY_SYNC_RESULT = 9;
private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerMisfit.class);
public AppMessageHandlerMisfit(UUID uuid, PebbleProtocol pebbleProtocol) {
AppMessageHandlerMisfit(UUID uuid, PebbleProtocol pebbleProtocol) {
super(uuid, pebbleProtocol);
}

View File

@ -20,37 +20,37 @@ import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleMorpheuzSampleP
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMorpheuzSample;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class AppMessageHandlerMorpheuz extends AppMessageHandler {
class AppMessageHandlerMorpheuz extends AppMessageHandler {
public static final int KEY_POINT = 1;
public static final int KEY_POINT_46 = 10000;
public static final int KEY_CTRL = 2;
public static final int KEY_CTRL_46 = 10001;
public static final int KEY_FROM = 3;
public static final int KEY_FROM_46 = 10002;
public static final int KEY_TO = 4;
public static final int KEY_TO_46 = 10003;
public static final int KEY_BASE = 5;
public static final int KEY_BASE_46 = 10004;
public static final int KEY_VERSION = 6;
public static final int KEY_VERSION_46 = 10005;
public static final int KEY_GONEOFF = 7;
public static final int KEY_GONEOFF_46 = 10006;
public static final int KEY_TRANSMIT = 8;
public static final int KEY_TRANSMIT_46 = 10007;
public static final int KEY_AUTO_RESET = 9;
public static final int KEY_AUTO_RESET_46 = 10008;
public static final int KEY_SNOOZES = 10;
public static final int KEY_SNOOZES_46 = 10009;
public static final int KEY_FAULT_46 = 10010;
private static final int KEY_POINT = 1;
private static final int KEY_POINT_46 = 10000;
private static final int KEY_CTRL = 2;
private static final int KEY_CTRL_46 = 10001;
private static final int KEY_FROM = 3;
private static final int KEY_FROM_46 = 10002;
private static final int KEY_TO = 4;
private static final int KEY_TO_46 = 10003;
private static final int KEY_BASE = 5;
private static final int KEY_BASE_46 = 10004;
private static final int KEY_VERSION = 6;
private static final int KEY_VERSION_46 = 10005;
private static final int KEY_GONEOFF = 7;
private static final int KEY_GONEOFF_46 = 10006;
private static final int KEY_TRANSMIT = 8;
private static final int KEY_TRANSMIT_46 = 10007;
private static final int KEY_AUTO_RESET = 9;
private static final int KEY_AUTO_RESET_46 = 10008;
private static final int KEY_SNOOZES = 10;
private static final int KEY_SNOOZES_46 = 10009;
private static final int KEY_FAULT_46 = 10010;
public static final int CTRL_TRANSMIT_DONE = 1;
public static final int CTRL_VERSION_DONE = 2;
public static final int CTRL_GONEOFF_DONE = 4;
public static final int CTRL_DO_NEXT = 8;
public static final int CTRL_SET_LAST_SENT = 16;
public static final int CTRL_LAZARUS = 32;
public static final int CTRL_SNOOZES_DONE = 64;
private static final int CTRL_TRANSMIT_DONE = 1;
private static final int CTRL_VERSION_DONE = 2;
private static final int CTRL_GONEOFF_DONE = 4;
private static final int CTRL_DO_NEXT = 8;
private static final int CTRL_SET_LAST_SENT = 16;
private static final int CTRL_LAZARUS = 32;
private static final int CTRL_SNOOZES_DONE = 64;
// data received from Morpheuz in native format
private int version = 0;

View File

@ -14,7 +14,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleColor;
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
import ru.gelin.android.weather.notification.ParcelableWeather2;
public class AppMessageHandlerPebStyle extends AppMessageHandler {
class AppMessageHandlerPebStyle extends AppMessageHandler {
public static final int KEY_AMPM_TEXT = 21;
public static final int KEY_BLUETOOTH_ALERT = 2;
public static final int KEY_BLUETOOTH_ICON = 20;

View File

@ -2,9 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import android.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.UUID;
@ -13,7 +10,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
public class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
private static final int MESSAGE_KEY_WeatherCondition = 10000;
private static final int MESSAGE_KEY_WeatherForecastCondition = 10002;
private static final int MESSAGE_KEY_WeatherForecastHighTemp = 10003;
@ -35,9 +32,7 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
private static final int ICON_THUNDERSTORM = 10;
private static final int ICON_WEATHER_GENERIC = 11;
private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerTimeStylePebble.class);
public AppMessageHandlerTimeStylePebble(UUID uuid, PebbleProtocol pebbleProtocol) {
AppMessageHandlerTimeStylePebble(UUID uuid, PebbleProtocol pebbleProtocol) {
super(uuid, pebbleProtocol);
}
@ -125,6 +120,9 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[]{null};
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeTimeStylePebbleWeather(weatherSpec);
return new GBDeviceEvent[]{sendBytes};

View File

@ -0,0 +1,85 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import android.util.Pair;
import java.util.ArrayList;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
class AppMessageHandlerTrekVolle extends AppMessageHandler {
private static final int MESSAGE_KEY_WEATHER_TEMPERATURE = 10000;
private static final int MESSAGE_KEY_WEATHER_CONDITIONS = 10001;
private static final int MESSAGE_KEY_WEATHER_ICON = 10002;
private static final int MESSAGE_KEY_WEATHER_TEMPERATURE_MIN = 10024;
private static final int MESSAGE_KEY_WEATHER_TEMPERATURE_MAX = 10025;
private static final int MESSAGE_KEY_WEATHER_LOCATION = 10030;
AppMessageHandlerTrekVolle(UUID uuid, PebbleProtocol pebbleProtocol) {
super(uuid, pebbleProtocol);
}
private int getIconForConditionCode(int conditionCode, boolean isNight) {
/*
case 1: return RESOURCE_ID_IMAGE_WEATHER_CLEARNIGHT;
case 2: return RESOURCE_ID_IMAGE_WEATHER_CLEAR;
case 3: return RESOURCE_ID_IMAGE_WEATHER_CLOUDYNIGHT;
case 4: return RESOURCE_ID_IMAGE_WEATHER_CLOUDY;
case 5: return RESOURCE_ID_IMAGE_WEATHER_CLOUDS;
case 6: return RESOURCE_ID_IMAGE_WEATHER_THICKCLOUDS;
case 7: return RESOURCE_ID_IMAGE_WEATHER_RAIN;
case 8: return RESOURCE_ID_IMAGE_WEATHER_RAINYNIGHT;
case 9: return RESOURCE_ID_IMAGE_WEATHER_RAINY;
case 10: return RESOURCE_ID_IMAGE_WEATHER_LIGHTNING;
case 11: return RESOURCE_ID_IMAGE_WEATHER_SNOW;
case 12: return RESOURCE_ID_IMAGE_WEATHER_MIST;
*/
return 2;
}
private byte[] encodeTrekVolleWeather(WeatherSpec weatherSpec) {
if (weatherSpec == null) {
return null;
}
boolean isNight = false; // FIXME
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
pairs.add(new Pair<>(MESSAGE_KEY_WEATHER_TEMPERATURE, (Object) (weatherSpec.currentTemp - 273)));
pairs.add(new Pair<>(MESSAGE_KEY_WEATHER_CONDITIONS, (Object) (weatherSpec.currentCondition)));
pairs.add(new Pair<>(MESSAGE_KEY_WEATHER_ICON, (Object) (getIconForConditionCode(weatherSpec.currentConditionCode, isNight))));
pairs.add(new Pair<>(MESSAGE_KEY_WEATHER_TEMPERATURE_MAX, (Object) (weatherSpec.todayMaxTemp - 273)));
pairs.add(new Pair<>(MESSAGE_KEY_WEATHER_TEMPERATURE_MIN, (Object) (weatherSpec.todayMinTemp - 273)));
pairs.add(new Pair<>(MESSAGE_KEY_WEATHER_LOCATION, (Object) weatherSpec.location));
return mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
}
@Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
// Just ACK
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
return new GBDeviceEvent[]{sendBytesAck};
}
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[]{null};
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeTrekVolleWeather(weatherSpec);
return new GBDeviceEvent[]{sendBytes};
}
@Override
public byte[] encodeUpdateWeather(WeatherSpec weatherSpec) {
return encodeTrekVolleWeather(weatherSpec);
}
}

View File

@ -16,7 +16,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionHealthSteps.class);

View File

@ -361,6 +361,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
private static final UUID UUID_PEBSTYLE = UUID.fromString("da05e84d-e2a2-4020-a2dc-9cdcf265fcdd");
private static final UUID UUID_MARIOTIME = UUID.fromString("43caa750-2896-4f46-94dc-1adbd4bc1ff3");
private static final UUID UUID_HELTHIFY = UUID.fromString("7ee97b2c-95e8-4720-b94e-70fccd905d98");
private static final UUID UUID_TREKVOLLE = UUID.fromString("2da02267-7a19-4e49-9ed1-439d25db14e4");
private static final UUID UUID_ZERO = new UUID(0, 0);
@ -375,9 +376,10 @@ public class PebbleProtocol extends GBDeviceProtocol {
mAppMessageHandlers.put(UUID_MORPHEUZ, new AppMessageHandlerMorpheuz(UUID_MORPHEUZ, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_MISFIT, new AppMessageHandlerMisfit(UUID_MISFIT, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_PEBBLE_TIMESTYLE, new AppMessageHandlerTimeStylePebble(UUID_PEBBLE_TIMESTYLE, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_PEBSTYLE, new AppMessageHandlerPebStyle(UUID_PEBSTYLE, PebbleProtocol.this));
//mAppMessageHandlers.put(UUID_PEBSTYLE, new AppMessageHandlerPebStyle(UUID_PEBSTYLE, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_MARIOTIME, new AppMessageHandlerMarioTime(UUID_MARIOTIME, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_HELTHIFY, new AppMessageHandlerHealthify(UUID_HELTHIFY, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_TREKVOLLE, new AppMessageHandlerTrekVolle(UUID_TREKVOLLE, PebbleProtocol.this));
}
private final HashMap<Byte, DatalogSession> mDatalogSessions = new HashMap<>();
@ -1164,10 +1166,10 @@ public class PebbleProtocol extends GBDeviceProtocol {
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 3); // unknown, always 3?
buf.putShort((short) (weatherSpec.currentTemp - 273));
buf.put((byte) Weather.mapToPebbleCondition(weatherSpec.currentConditionCode));
buf.put(Weather.mapToPebbleCondition(weatherSpec.currentConditionCode));
buf.putShort((short) (weatherSpec.todayMaxTemp - 273));
buf.putShort((short) (weatherSpec.todayMinTemp - 273));
buf.put((byte) Weather.mapToPebbleCondition(weatherSpec.tomorrowConditionCode));
buf.put(Weather.mapToPebbleCondition(weatherSpec.tomorrowConditionCode));
buf.putShort((short) (weatherSpec.tomorrowMaxTemp - 273));
buf.putShort((short) (weatherSpec.tomorrowMinTemp - 273));
buf.putInt(weatherSpec.timestamp);