Light temperature warning indicator for GPS timeout, API timeout, and API failure
This commit is contained in:
+16
-4
@@ -44,7 +44,7 @@ static bool s_pkjs_ready = false;
|
|||||||
static bool s_fuel_is_warning = false;
|
static bool s_fuel_is_warning = false;
|
||||||
static int s_batt_level;
|
static int s_batt_level;
|
||||||
static bool s_temp_is_warning = false;
|
static bool s_temp_is_warning = false;
|
||||||
static uint8_t s_temp_level;
|
static int8_t s_temp_level;
|
||||||
|
|
||||||
// bar statics
|
// bar statics
|
||||||
static const uint8_t s_bar_height = 8;
|
static const uint8_t s_bar_height = 8;
|
||||||
@@ -52,8 +52,11 @@ static const uint8_t s_bar_width = 17;
|
|||||||
static const uint8_t s_bar_spacing = s_bar_height + 1;
|
static const uint8_t s_bar_spacing = s_bar_height + 1;
|
||||||
|
|
||||||
static void toggle_fuel_warning_state(bool enable_warning, bool force) {
|
static void toggle_fuel_warning_state(bool enable_warning, bool force) {
|
||||||
|
if (!force && (enable_warning == s_fuel_is_warning)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
GColor dst = enable_warning ? settings.ColorWarning : settings.ColorFG;
|
GColor dst = enable_warning ? settings.ColorWarning : settings.ColorFG;
|
||||||
if ((!force && (enable_warning == s_fuel_is_warning)) || (s_first_settings_application && !enable_warning && dst.argb == s_applied_e.argb)) {
|
if (s_first_settings_application && !enable_warning && dst.argb == s_applied_e.argb) {
|
||||||
// at startup, s_applied_e.argb is GColorWhite
|
// at startup, s_applied_e.argb is GColorWhite
|
||||||
// for those using white fg, do not pointlessly replace white at startup if that is the destination anyway
|
// for those using white fg, do not pointlessly replace white at startup if that is the destination anyway
|
||||||
return;
|
return;
|
||||||
@@ -64,8 +67,11 @@ static void toggle_fuel_warning_state(bool enable_warning, bool force) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void toggle_temp_warning_state(bool enable_warning, bool force) {
|
static void toggle_temp_warning_state(bool enable_warning, bool force) {
|
||||||
|
if (!force && (enable_warning == s_temp_is_warning)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
GColor dst = enable_warning ? settings.ColorWarning : settings.ColorFG;
|
GColor dst = enable_warning ? settings.ColorWarning : settings.ColorFG;
|
||||||
if ((!force && (enable_warning == s_temp_is_warning)) || (s_first_settings_application && !enable_warning && dst.argb == s_applied_c_h.argb)) {
|
if (s_first_settings_application && !enable_warning && dst.argb == s_applied_c_h.argb) {
|
||||||
// at startup, s_applied_c_h.argb is GColorWhite
|
// at startup, s_applied_c_h.argb is GColorWhite
|
||||||
// for those using white fg, do not pointlessly replace white at startup if that is the destination anyway
|
// for those using white fg, do not pointlessly replace white at startup if that is the destination anyway
|
||||||
return;
|
return;
|
||||||
@@ -387,8 +393,14 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|||||||
// TEMPERATURE DATA
|
// TEMPERATURE DATA
|
||||||
Tuple *temp_bar_count = dict_find(iter, MESSAGE_KEY_PKJS_TEMP_BAR_COUNT);
|
Tuple *temp_bar_count = dict_find(iter, MESSAGE_KEY_PKJS_TEMP_BAR_COUNT);
|
||||||
if (temp_bar_count) {
|
if (temp_bar_count) {
|
||||||
s_temp_level = temp_bar_count->value->uint8;
|
int8_t new_temp_level = temp_bar_count->value->int8;
|
||||||
|
if (new_temp_level >= 0) {
|
||||||
|
s_temp_level = new_temp_level;
|
||||||
|
toggle_temp_warning_state(false, false);
|
||||||
layer_mark_dirty(s_temp_layer);
|
layer_mark_dirty(s_temp_layer);
|
||||||
|
} else {
|
||||||
|
toggle_temp_warning_state(true, false);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-2
@@ -1,7 +1,22 @@
|
|||||||
|
function weatherFailure() {
|
||||||
|
Pebble.sendAppMessage({ PKJS_TEMP_BAR_COUNT: -1 });
|
||||||
|
}
|
||||||
|
|
||||||
var xhrRequest = function (url, type, callback) {
|
var xhrRequest = function (url, type, callback) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.timeout = 7500;
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
|
if (xhr.status === 200) {
|
||||||
callback(this.responseText);
|
callback(this.responseText);
|
||||||
|
} else {
|
||||||
|
weatherFailure();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.onerror = function () {
|
||||||
|
weatherFailure();
|
||||||
|
};
|
||||||
|
xhr.ontimeout = function () {
|
||||||
|
weatherFailure();
|
||||||
};
|
};
|
||||||
xhr.open(type, url);
|
xhr.open(type, url);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
@@ -31,8 +46,8 @@ function locationSuccess(pos) {
|
|||||||
function getWeather() {
|
function getWeather() {
|
||||||
navigator.geolocation.getCurrentPosition(
|
navigator.geolocation.getCurrentPosition(
|
||||||
locationSuccess,
|
locationSuccess,
|
||||||
null,
|
weatherFailure,
|
||||||
{ timeout: 15000, maximumAge: 60000 }
|
{ timeout: 7500, maximumAge: 60000 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user