Pebble: Adapt MarioTime logic

This commit is contained in:
Andreas Shimokawa 2016-12-31 19:27:21 +01:00
parent 984e639e97
commit b811247704
1 changed files with 15 additions and 31 deletions

View File

@ -12,13 +12,12 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; 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 ru.gelin.android.weather.notification.ParcelableWeather2; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
class AppMessageHandlerMarioTime extends AppMessageHandler { class AppMessageHandlerMarioTime extends AppMessageHandler {
private static final int KEY_WEATHER_ICON_ID = 10; private static final int KEY_WEATHER_ICON_ID = 10;
private static final int KEY_WEATHER_TEMPERATURE = 11; 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); private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerMarioTime.class);
@ -26,10 +25,10 @@ class AppMessageHandlerMarioTime extends AppMessageHandler {
super(uuid, pebbleProtocol); super(uuid, pebbleProtocol);
} }
private byte[] encodeWeatherMessage(int temperature, int condition) { private byte[] encodeMarioWeatherMessage(WeatherSpec weatherSpec) {
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(2); 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_ICON_ID, (Object) (byte) 1));
pairs.add(new Pair<>(KEY_WEATHER_TEMPERATURE, (Object) (byte) temperature)); pairs.add(new Pair<>(KEY_WEATHER_TEMPERATURE, (Object) (byte) (weatherSpec.currentTemp - 273)));
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);
@ -41,37 +40,22 @@ class AppMessageHandlerMarioTime extends AppMessageHandler {
@Override @Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) { public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
boolean weatherRequested = false; // Just ACK
for (Pair<Integer, Object> pair : pairs) { GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
switch (pair.first) { sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
case KEY_WEATHER_REQUEST: return new GBDeviceEvent[]{sendBytesAck};
LOG.info("got weather request");
weatherRequested = true;
break;
default:
LOG.info("unknown key " + pair.first);
}
}
if (!weatherRequested) {
return new GBDeviceEvent[]{null};
}
return onAppStart();
} }
@Override @Override
public GBDeviceEvent[] onAppStart() { public GBDeviceEvent[] onAppStart() {
ParcelableWeather2 weather = Weather.getInstance().getWeather2(); WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weather == null) {
return new GBDeviceEvent[]{null};
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes(); GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeWeatherMessage(weather.currentTemp - 273, 1); // FIXME: condition code sendBytes.encodedBytes = encodeMarioWeatherMessage(weatherSpec);
return new GBDeviceEvent[]{sendBytes};
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes(); }
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
return new GBDeviceEvent[]{sendBytesAck, sendBytes};
@Override
public byte[] encodeUpdateWeather(WeatherSpec weatherSpec) {
return encodeMarioWeatherMessage(weatherSpec);
} }
} }