mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 13:26: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) {
|
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,
|
||||||
|
@ -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
|
||||||
|
android:key="pref_category_watchxplus_longsit_settings"
|
||||||
<PreferenceCategory
|
android:title="@string/pref_header_wxp_longsit">
|
||||||
android:key="pref_category_watchxplus_longsit_settings"
|
<EditTextPreference
|
||||||
android:title="@string/pref_header_wxp_longsit">
|
android:defaultValue="60"
|
||||||
<CheckBoxPreference
|
android:key="watchxplus_longsit_period"
|
||||||
android:layout="@layout/preference_checkbox"
|
android:summary="@string/pref_wxp_longsit_period_summary"
|
||||||
android:defaultValue="false"
|
android:title="@string/pref_wxp_title_longsit"/>
|
||||||
android:key="watchxplus_longsit_switch"
|
<CheckBoxPreference
|
||||||
android:summary="@string/pref_wxp_longsit_switch_summary"
|
android:layout="@layout/preference_checkbox"
|
||||||
android:title="@string/prefs_wxp_longsit_switch" />
|
android:defaultValue="false"
|
||||||
<EditTextPreference
|
android:key="watchxplus_longsit_switch"
|
||||||
android:defaultValue="60"
|
android:summary="@string/pref_wxp_longsit_switch_summary"
|
||||||
android:key="watchxplus_longsit_period"
|
android:title="@string/prefs_wxp_longsit_switch" />
|
||||||
android:summary="@string/pref_wxp_longsit_period_summary"
|
</PreferenceScreen>
|
||||||
android:title="@string/pref_wxp_title_longsit"/>
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_category_watchxplus_calibration"
|
android:key="pref_category_watchxplus_calibration"
|
||||||
@ -675,13 +674,13 @@
|
|||||||
android:defaultValue="130"
|
android:defaultValue="130"
|
||||||
android:title="@string/pref_wxp_bp_calibration_high"
|
android:title="@string/pref_wxp_bp_calibration_high"
|
||||||
android:summary="@string/pref_rtl_max_line_length_summary"/>
|
android:summary="@string/pref_rtl_max_line_length_summary"/>
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:defaultValue="1"
|
android:defaultValue="1"
|
||||||
android:title="@string/prefs_wxp_button_bp_calibration"
|
android:title="@string/prefs_wxp_button_bp_calibration"
|
||||||
android:entries="@array/wxp_bp_cal"
|
android:entries="@array/wxp_bp_cal"
|
||||||
android:entryValues="@array/wxp_bp_cal_values"
|
android:entryValues="@array/wxp_bp_cal_values"
|
||||||
android:key="wxp_button_BP_calibration_list"
|
android:key="wxp_button_BP_calibration_list"
|
||||||
android:summary="@string/prefs_wxp_button_bp_calibration_sum" />
|
android:summary="@string/prefs_wxp_button_bp_calibration_sum" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<!--
|
<!--
|
||||||
|
Loading…
Reference in New Issue
Block a user