1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-22 14:52:25 +02:00

Pebble: send temperatures according to the configured measurement system

Fixes #858
<Without further comments but feel free to insert a long rant about the beauty of the metric system>
This commit is contained in:
Daniele Gobbetti 2017-11-01 17:58:58 +01:00
parent e7839f1c39
commit 72f76b60d3
3 changed files with 22 additions and 5 deletions

View File

@ -2,6 +2,7 @@
#### Version NEXT
* Charts: added preference to disable swiping charts left/right and some UI changes
* Pebble: Use the configured unit system also for system weather app
#### Version 0.22.1
* Mi Band 2: Fix being detected as Amazfit Bip which lead to various problems especially on newly paired devices

View File

@ -39,6 +39,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagement;
@ -1222,6 +1223,20 @@ public class PebbleProtocol extends GBDeviceProtocol {
}
private byte[] encodeWeatherForecast(WeatherSpec weatherSpec) {
short currentTemp = (short) (weatherSpec.currentTemp - 273);
short todayMax = (short) (weatherSpec.todayMaxTemp - 273);
short todayMin = (short) (weatherSpec.todayMinTemp - 273);
short tomorrowMax = (short) (weatherSpec.tomorrowMaxTemp - 273);
short tomorrowMin = (short) (weatherSpec.tomorrowMinTemp - 273);
String units = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric));
if (units.equals(GBApplication.getContext().getString(R.string.p_unit_imperial))) {
currentTemp = (short) (currentTemp * 1.8f + 32);
todayMax = (short) (todayMax * 1.8f + 32);
todayMin = (short) (todayMin * 1.8f + 32);
tomorrowMax = (short) (tomorrowMax * 1.8f + 32);
tomorrowMin = (short) (tomorrowMin * 1.8f + 32);
}
final short WEATHER_FORECAST_LENGTH = 20;
String[] parts = {weatherSpec.location, weatherSpec.currentCondition};
@ -1242,13 +1257,13 @@ public class PebbleProtocol extends GBDeviceProtocol {
ByteBuffer buf = ByteBuffer.allocate(pin_length);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 3); // unknown, always 3?
buf.putShort((short) (weatherSpec.currentTemp - 273));
buf.putShort(currentTemp);
buf.put(Weather.mapToPebbleCondition(weatherSpec.currentConditionCode));
buf.putShort((short) (weatherSpec.todayMaxTemp - 273));
buf.putShort((short) (weatherSpec.todayMinTemp - 273));
buf.putShort(todayMax);
buf.putShort(todayMin);
buf.put(Weather.mapToPebbleCondition(weatherSpec.tomorrowConditionCode));
buf.putShort((short) (weatherSpec.tomorrowMaxTemp - 273));
buf.putShort((short) (weatherSpec.tomorrowMinTemp - 273));
buf.putShort(tomorrowMax);
buf.putShort(tomorrowMin);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) 0); // automatic location 0=manual 1=auto
buf.putShort(attributes_length);

View File

@ -3,6 +3,7 @@
<release version="next">
<change>Charts: added preference to disable swiping charts left/right and some UI changes
</change>
<change>Pebble: Use the configured unit system also for system weather app</change>
</release>
<release version="0.22.1" versioncode="109">
<change>Mi Band 2: Fix being detected as Amazfit Bip which lead to various problems especially on newly paired devices</change>