mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 19:36:50 +01:00
Add weather icon
This commit is contained in:
parent
be47541a5e
commit
4ff17153b6
@ -1125,16 +1125,47 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
public void onSendWeather(WeatherSpec weatherSpec) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("setWeather");
|
||||
|
||||
int currentTemp = 0;
|
||||
int todayMinTemp = 0;
|
||||
int todayMaxTemp = 0;
|
||||
byte[] command = WatchXPlusConstants.CMD_WEATHER_SET;
|
||||
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
|
||||
weatherInfo[0] = 0x00;
|
||||
weatherInfo[1] = 0x00;
|
||||
weatherInfo[2] = (byte) weatherSpec.todayMinTemp;
|
||||
weatherInfo[3] = (byte) weatherSpec.todayMaxTemp;
|
||||
weatherInfo[4] = (byte) weatherSpec.currentTemp;
|
||||
weatherInfo[0] = (byte )(currentConditionCode >> 8);
|
||||
weatherInfo[1] = (byte )currentConditionCode;
|
||||
weatherInfo[2] = (byte) todayMinTemp;
|
||||
weatherInfo[3] = (byte) todayMaxTemp;
|
||||
weatherInfo[4] = (byte) currentTemp;
|
||||
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
|
||||
buildCommand(command,
|
||||
WatchXPlusConstants.KEEP_ALIVE,
|
||||
|
@ -634,22 +634,21 @@
|
||||
android:entryValues="@array/wxp_language_values"
|
||||
android:key="wxp_language_pref"
|
||||
android:summary="%s" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_category_watchxplus_longsit_settings"
|
||||
android:title="@string/pref_header_wxp_longsit">
|
||||
<CheckBoxPreference
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:defaultValue="false"
|
||||
android:key="watchxplus_longsit_switch"
|
||||
android:summary="@string/pref_wxp_longsit_switch_summary"
|
||||
android:title="@string/prefs_wxp_longsit_switch" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="60"
|
||||
android:key="watchxplus_longsit_period"
|
||||
android:summary="@string/pref_wxp_longsit_period_summary"
|
||||
android:title="@string/pref_wxp_title_longsit"/>
|
||||
<PreferenceScreen
|
||||
android:key="pref_category_watchxplus_longsit_settings"
|
||||
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
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:defaultValue="false"
|
||||
android:key="watchxplus_longsit_switch"
|
||||
android:summary="@string/pref_wxp_longsit_switch_summary"
|
||||
android:title="@string/prefs_wxp_longsit_switch" />
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="pref_category_watchxplus_calibration"
|
||||
@ -675,13 +674,13 @@
|
||||
android:defaultValue="130"
|
||||
android:title="@string/pref_wxp_bp_calibration_high"
|
||||
android:summary="@string/pref_rtl_max_line_length_summary"/>
|
||||
<ListPreference
|
||||
android:defaultValue="1"
|
||||
android:title="@string/prefs_wxp_button_bp_calibration"
|
||||
android:entries="@array/wxp_bp_cal"
|
||||
android:entryValues="@array/wxp_bp_cal_values"
|
||||
android:key="wxp_button_BP_calibration_list"
|
||||
android:summary="@string/prefs_wxp_button_bp_calibration_sum" />
|
||||
<ListPreference
|
||||
android:defaultValue="1"
|
||||
android:title="@string/prefs_wxp_button_bp_calibration"
|
||||
android:entries="@array/wxp_bp_cal"
|
||||
android:entryValues="@array/wxp_bp_cal_values"
|
||||
android:key="wxp_button_BP_calibration_list"
|
||||
android:summary="@string/prefs_wxp_button_bp_calibration_sum" />
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
<!--
|
||||
|
Loading…
Reference in New Issue
Block a user