mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Pebble: allow weather to be send to watchfaces on fw < 4.x
This commit is contained in:
parent
1722a6dc47
commit
8b55110679
@ -532,8 +532,6 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
//return encodeWeatherPin(ts, "Weather", "1°/-1°", "Gadgetbridge is Sunny", "Berlin", 37);
|
//return encodeWeatherPin(ts, "Weather", "1°/-1°", "Gadgetbridge is Sunny", "Berlin", 37);
|
||||||
//return encodeWeatherForecast(ts, "Berlin", 0, 5, -5, 1, "Sexy", 7, 2, 1);
|
|
||||||
return encodeWeatherForecast(ts);
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
@ -1118,40 +1116,36 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] encodeSendWeather(WeatherSpec weatherSpec) {
|
public byte[] encodeSendWeather(WeatherSpec weatherSpec) {
|
||||||
if (mFwMajor < 4) {
|
byte[] forecastProtocol = null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
byte[] watchfaceProtocol = null;
|
byte[] watchfaceProtocol = null;
|
||||||
byte[] forecastProtocol = encodeWeatherForecast(weatherSpec.timestamp,
|
int length = 0;
|
||||||
weatherSpec.location,
|
if (mFwMajor >= 4) {
|
||||||
weatherSpec.currentTemp - 273,
|
forecastProtocol = encodeWeatherForecast(weatherSpec);
|
||||||
weatherSpec.todayMaxTemp - 273,
|
length += forecastProtocol.length;
|
||||||
weatherSpec.todayMinTemp - 273,
|
}
|
||||||
Weather.mapToPebbleCondition(weatherSpec.currentConditionCode),
|
|
||||||
weatherSpec.currentCondition,
|
|
||||||
weatherSpec.tomorrowMaxTemp - 273,
|
|
||||||
weatherSpec.tomorrowMinTemp - 273,
|
|
||||||
Weather.mapToPebbleCondition(weatherSpec.tomorrowConditionCode)
|
|
||||||
);
|
|
||||||
AppMessageHandler handler = mAppMessageHandlers.get(currentRunningApp);
|
AppMessageHandler handler = mAppMessageHandlers.get(currentRunningApp);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
watchfaceProtocol = handler.encodeUpdateWeather(weatherSpec);
|
watchfaceProtocol = handler.encodeUpdateWeather(weatherSpec);
|
||||||
|
if (watchfaceProtocol != null) {
|
||||||
|
length += watchfaceProtocol.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(length);
|
||||||
|
|
||||||
|
if (forecastProtocol != null) {
|
||||||
|
buf.put(forecastProtocol);
|
||||||
|
}
|
||||||
|
if (watchfaceProtocol != null) {
|
||||||
|
buf.put(watchfaceProtocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (watchfaceProtocol != null) {
|
|
||||||
ByteBuffer buf = ByteBuffer.allocate(forecastProtocol.length + watchfaceProtocol.length);
|
|
||||||
buf.put(forecastProtocol);
|
|
||||||
buf.put(watchfaceProtocol);
|
|
||||||
return buf.array();
|
return buf.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return forecastProtocol;
|
private byte[] encodeWeatherForecast(WeatherSpec weatherSpec) {
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] encodeWeatherForecast(int timestamp, String location, int tempNow, int tempHighToday, int tempLowToday, int conditionCodeToday, String conditionToday, int tempHighTomorrow, int tempLowTomorrow, int conditionCodeTomorrow) {
|
|
||||||
final short WEATHER_FORECAST_LENGTH = 20;
|
final short WEATHER_FORECAST_LENGTH = 20;
|
||||||
|
|
||||||
String[] parts = {location, conditionToday};
|
String[] parts = {weatherSpec.location, weatherSpec.currentCondition};
|
||||||
|
|
||||||
// Calculate length first
|
// Calculate length first
|
||||||
short attributes_length = 0;
|
short attributes_length = 0;
|
||||||
@ -1169,15 +1163,15 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
ByteBuffer buf = ByteBuffer.allocate(pin_length);
|
ByteBuffer buf = ByteBuffer.allocate(pin_length);
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
buf.put((byte) 3); // unknown, always 3?
|
buf.put((byte) 3); // unknown, always 3?
|
||||||
buf.putShort((short) tempNow);
|
buf.putShort((short) (weatherSpec.currentTemp - 273));
|
||||||
buf.put((byte) conditionCodeToday);
|
buf.put((byte) Weather.mapToPebbleCondition(weatherSpec.currentConditionCode));
|
||||||
buf.putShort((short) tempHighToday);
|
buf.putShort((short) (weatherSpec.todayMaxTemp - 273));
|
||||||
buf.putShort((short) tempLowToday);
|
buf.putShort((short) (weatherSpec.todayMinTemp - 273));
|
||||||
buf.put((byte) conditionCodeTomorrow);
|
buf.put((byte) Weather.mapToPebbleCondition(weatherSpec.tomorrowConditionCode));
|
||||||
buf.putShort((short) tempHighTomorrow);
|
buf.putShort((short) (weatherSpec.tomorrowMaxTemp - 273));
|
||||||
buf.putShort((short) tempLowTomorrow);
|
buf.putShort((short) (weatherSpec.tomorrowMinTemp - 273));
|
||||||
buf.putInt(timestamp);
|
buf.putInt(weatherSpec.timestamp);
|
||||||
buf.put((byte) 0); // automatic location
|
buf.put((byte) 0); // automatic location 0=manual 1=auto
|
||||||
buf.putShort(attributes_length);
|
buf.putShort(attributes_length);
|
||||||
|
|
||||||
// Encode Pascal-Style Strings
|
// Encode Pascal-Style Strings
|
||||||
|
Loading…
Reference in New Issue
Block a user