2016-01-10 20:12:52 +01:00
|
|
|
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;
|
2016-12-31 19:27:21 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
2016-01-10 20:12:52 +01:00
|
|
|
|
2016-12-31 13:33:50 +01:00
|
|
|
class AppMessageHandlerMarioTime extends AppMessageHandler {
|
2016-01-10 20:12:52 +01:00
|
|
|
|
2016-12-31 13:33:50 +01:00
|
|
|
private static final int KEY_WEATHER_ICON_ID = 10;
|
|
|
|
private static final int KEY_WEATHER_TEMPERATURE = 11;
|
2016-01-10 20:12:52 +01:00
|
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerMarioTime.class);
|
|
|
|
|
2016-12-31 13:33:50 +01:00
|
|
|
AppMessageHandlerMarioTime(UUID uuid, PebbleProtocol pebbleProtocol) {
|
2016-01-10 20:12:52 +01:00
|
|
|
super(uuid, pebbleProtocol);
|
|
|
|
}
|
|
|
|
|
2016-12-31 19:27:21 +01:00
|
|
|
private byte[] encodeMarioWeatherMessage(WeatherSpec weatherSpec) {
|
2016-01-10 20:12:52 +01:00
|
|
|
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(2);
|
2016-12-31 19:27:21 +01:00
|
|
|
pairs.add(new Pair<>(KEY_WEATHER_ICON_ID, (Object) (byte) 1));
|
|
|
|
pairs.add(new Pair<>(KEY_WEATHER_TEMPERATURE, (Object) (byte) (weatherSpec.currentTemp - 273)));
|
2016-01-10 20:12:52 +01:00
|
|
|
byte[] weatherMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
|
|
|
|
|
|
|
|
ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length);
|
|
|
|
|
|
|
|
buf.put(weatherMessage);
|
|
|
|
|
|
|
|
return buf.array();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
2016-12-31 19:27:21 +01:00
|
|
|
// Just ACK
|
|
|
|
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
|
|
|
|
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
|
|
|
|
return new GBDeviceEvent[]{sendBytesAck};
|
2016-12-31 13:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-31 19:04:05 +01:00
|
|
|
public GBDeviceEvent[] onAppStart() {
|
2016-12-31 19:27:21 +01:00
|
|
|
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
|
2016-01-10 20:12:52 +01:00
|
|
|
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
2016-12-31 19:27:21 +01:00
|
|
|
sendBytes.encodedBytes = encodeMarioWeatherMessage(weatherSpec);
|
|
|
|
return new GBDeviceEvent[]{sendBytes};
|
|
|
|
}
|
2016-12-31 13:33:50 +01:00
|
|
|
|
2016-12-31 19:27:21 +01:00
|
|
|
@Override
|
|
|
|
public byte[] encodeUpdateWeather(WeatherSpec weatherSpec) {
|
|
|
|
return encodeMarioWeatherMessage(weatherSpec);
|
2016-01-10 20:12:52 +01:00
|
|
|
}
|
|
|
|
}
|