Pebble: Adapt MarioTime logic
This commit is contained in:
parent
984e639e97
commit
b811247704
|
@ -12,13 +12,12 @@ import java.util.UUID;
|
|||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
||||
import ru.gelin.android.weather.notification.ParcelableWeather2;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
|
||||
class AppMessageHandlerMarioTime extends AppMessageHandler {
|
||||
|
||||
private static final int KEY_WEATHER_ICON_ID = 10;
|
||||
private static final int KEY_WEATHER_TEMPERATURE = 11;
|
||||
private static final int KEY_WEATHER_REQUEST = 12;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerMarioTime.class);
|
||||
|
||||
|
@ -26,10 +25,10 @@ class AppMessageHandlerMarioTime extends AppMessageHandler {
|
|||
super(uuid, pebbleProtocol);
|
||||
}
|
||||
|
||||
private byte[] encodeWeatherMessage(int temperature, int condition) {
|
||||
private byte[] encodeMarioWeatherMessage(WeatherSpec weatherSpec) {
|
||||
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(2);
|
||||
pairs.add(new Pair<>(KEY_WEATHER_ICON_ID, (Object) (byte) condition));
|
||||
pairs.add(new Pair<>(KEY_WEATHER_TEMPERATURE, (Object) (byte) temperature));
|
||||
pairs.add(new Pair<>(KEY_WEATHER_ICON_ID, (Object) (byte) 1));
|
||||
pairs.add(new Pair<>(KEY_WEATHER_TEMPERATURE, (Object) (byte) (weatherSpec.currentTemp - 273)));
|
||||
byte[] weatherMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length);
|
||||
|
@ -41,37 +40,22 @@ class AppMessageHandlerMarioTime extends AppMessageHandler {
|
|||
|
||||
@Override
|
||||
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
||||
boolean weatherRequested = false;
|
||||
for (Pair<Integer, Object> pair : pairs) {
|
||||
switch (pair.first) {
|
||||
case KEY_WEATHER_REQUEST:
|
||||
LOG.info("got weather request");
|
||||
weatherRequested = true;
|
||||
break;
|
||||
default:
|
||||
LOG.info("unknown key " + pair.first);
|
||||
}
|
||||
}
|
||||
if (!weatherRequested) {
|
||||
return new GBDeviceEvent[]{null};
|
||||
}
|
||||
return onAppStart();
|
||||
// Just ACK
|
||||
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
|
||||
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
|
||||
return new GBDeviceEvent[]{sendBytesAck};
|
||||
}
|
||||
|
||||
@Override
|
||||
public GBDeviceEvent[] onAppStart() {
|
||||
ParcelableWeather2 weather = Weather.getInstance().getWeather2();
|
||||
|
||||
if (weather == null) {
|
||||
return new GBDeviceEvent[]{null};
|
||||
}
|
||||
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
|
||||
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
||||
sendBytes.encodedBytes = encodeWeatherMessage(weather.currentTemp - 273, 1); // FIXME: condition code
|
||||
|
||||
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
|
||||
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
|
||||
|
||||
return new GBDeviceEvent[]{sendBytesAck, sendBytes};
|
||||
sendBytes.encodedBytes = encodeMarioWeatherMessage(weatherSpec);
|
||||
return new GBDeviceEvent[]{sendBytes};
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeUpdateWeather(WeatherSpec weatherSpec) {
|
||||
return encodeMarioWeatherMessage(weatherSpec);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue