1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-26 03:46:49 +01:00

Add weather icon

This commit is contained in:
mamutcho 2019-11-17 17:02:51 +02:00
parent be47541a5e
commit 4ff17153b6
2 changed files with 60 additions and 30 deletions

View File

@ -1125,16 +1125,47 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
public void onSendWeather(WeatherSpec weatherSpec) { public void onSendWeather(WeatherSpec weatherSpec) {
try { try {
TransactionBuilder builder = performInitialized("setWeather"); TransactionBuilder builder = performInitialized("setWeather");
int currentTemp = 0;
int todayMinTemp = 0;
int todayMaxTemp = 0;
byte[] command = WatchXPlusConstants.CMD_WEATHER_SET; byte[] command = WatchXPlusConstants.CMD_WEATHER_SET;
byte[] weatherInfo = new byte[5]; byte[] weatherInfo = new byte[5];
String currentCondition = weatherSpec.currentCondition;
// set weather icon
int currentConditionCode = 0; // 0 is sunny
switch (currentCondition) {
case "Overcast clouds":
currentConditionCode = 1;
case "Broken clouds":
currentConditionCode = 2;
break;
}
if ((currentCondition.contains("Fog")) || (currentCondition.contains("fog"))) { currentConditionCode = 3; }
if ((currentCondition.contains("Rain")) || (currentCondition.contains("rain"))) { currentConditionCode = 257; }
if ((currentCondition.contains("Snow")) || (currentCondition.contains("snow"))) { currentConditionCode = 514; }
if ((currentCondition.contains("Sand")) || (currentCondition.contains("sand"))) { currentConditionCode = 769; }
if ((currentCondition.contains("Dust")) || (currentCondition.contains("dust"))) { currentConditionCode = 769; }
if ((currentCondition.contains("Sleet")) || (currentCondition.contains("sleet"))) { currentConditionCode = 1026; }
// calculate for temps under 0
currentTemp = (Math.abs(weatherSpec.currentTemp)) - 273;
if (currentTemp < 0) {
currentTemp = (Math.abs(currentTemp) ^ 255) + 1;
}
todayMinTemp = (Math.abs(weatherSpec.todayMinTemp)) - 273;
if (todayMinTemp < 0) {
todayMinTemp = (Math.abs(todayMinTemp) ^ 255) + 1;
}
todayMaxTemp = (Math.abs(weatherSpec.todayMaxTemp)) - 273;
if (todayMaxTemp < 0) {
todayMaxTemp = (Math.abs(todayMaxTemp) ^ 255) + 1;
}
LOG.warn(" Set weather min: " + todayMinTemp + " max: " + todayMaxTemp + " current: " + currentTemp + " icon: " + currentCondition);
// First two bytes are controlling the icon // First two bytes are controlling the icon
weatherInfo[0] = 0x00; weatherInfo[0] = (byte )(currentConditionCode >> 8);
weatherInfo[1] = 0x00; weatherInfo[1] = (byte )currentConditionCode;
weatherInfo[2] = (byte) weatherSpec.todayMinTemp; weatherInfo[2] = (byte) todayMinTemp;
weatherInfo[3] = (byte) weatherSpec.todayMaxTemp; weatherInfo[3] = (byte) todayMaxTemp;
weatherInfo[4] = (byte) weatherSpec.currentTemp; weatherInfo[4] = (byte) currentTemp;
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(command, buildCommand(command,
WatchXPlusConstants.KEEP_ALIVE, WatchXPlusConstants.KEEP_ALIVE,

View File

@ -634,22 +634,21 @@
android:entryValues="@array/wxp_language_values" android:entryValues="@array/wxp_language_values"
android:key="wxp_language_pref" android:key="wxp_language_pref"
android:summary="%s" /> android:summary="%s" />
</PreferenceCategory> <PreferenceScreen
<PreferenceCategory
android:key="pref_category_watchxplus_longsit_settings" android:key="pref_category_watchxplus_longsit_settings"
android:title="@string/pref_header_wxp_longsit"> android:title="@string/pref_header_wxp_longsit">
<EditTextPreference
android:defaultValue="60"
android:key="watchxplus_longsit_period"
android:summary="@string/pref_wxp_longsit_period_summary"
android:title="@string/pref_wxp_title_longsit"/>
<CheckBoxPreference <CheckBoxPreference
android:layout="@layout/preference_checkbox" android:layout="@layout/preference_checkbox"
android:defaultValue="false" android:defaultValue="false"
android:key="watchxplus_longsit_switch" android:key="watchxplus_longsit_switch"
android:summary="@string/pref_wxp_longsit_switch_summary" android:summary="@string/pref_wxp_longsit_switch_summary"
android:title="@string/prefs_wxp_longsit_switch" /> android:title="@string/prefs_wxp_longsit_switch" />
<EditTextPreference </PreferenceScreen>
android:defaultValue="60"
android:key="watchxplus_longsit_period"
android:summary="@string/pref_wxp_longsit_period_summary"
android:title="@string/pref_wxp_title_longsit"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="pref_category_watchxplus_calibration" android:key="pref_category_watchxplus_calibration"