1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Try to support MarioTime.

Does not work :/
This commit is contained in:
Andreas Shimokawa 2016-01-10 20:12:52 +01:00
parent 4bb78722b5
commit 7ba156da62
2 changed files with 71 additions and 1 deletions

View File

@ -0,0 +1,69 @@
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;
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;
public class AppMessageHandlerMarioTime extends AppMessageHandler {
public static final int KEY_WEATHER_ICON_ID = 10;
public static final int KEY_WEATHER_TEMPERATURE = 11;
public static final int KEY_WEATHER_REQUEST = 12;
private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerMarioTime.class);
public AppMessageHandlerMarioTime(UUID uuid, PebbleProtocol pebbleProtocol) {
super(uuid, pebbleProtocol);
}
private byte[] encodeWeatherMessage(int temperature, int condition) {
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));
byte[] weatherMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length);
// encode ack and put in front of push message (hack for acknowledging the last message)
buf.put(weatherMessage);
return buf.array();
}
@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};
}
ParcelableWeather2 weather = Weather.getInstance().getWeather2();
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeWeatherMessage(weather.currentConditionCode, weather.currentTemp - 273);
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
return new GBDeviceEvent[]{sendBytesAck, sendBytes};
}
}

View File

@ -351,6 +351,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
private static final UUID UUID_PEBBLE_HEALTH = UUID.fromString("36d8c6ed-4c83-4fa1-a9e2-8f12dc941f8c");
private static final UUID UUID_PEBBLE_TIMESTYLE = UUID.fromString("4368ffa4-f0fb-4823-90be-f754b076bdaa");
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 Map<UUID, AppMessageHandler> mAppMessageHandlers = new HashMap<>();
@ -361,7 +362,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
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_MARIOTIME, new AppMessageHandlerMarioTime(UUID_MARIOTIME, PebbleProtocol.this));
}
private static byte[] encodeSimpleMessage(short endpoint, byte command) {