diff --git a/package.json b/package.json
index 3e0276c..a6444a3 100644
--- a/package.json
+++ b/package.json
@@ -31,6 +31,7 @@
"PKJS_READY",
"PKJS_TEMP_BAR_COUNT",
"CLAY_SHOW_TIME_MG",
+ "CLAY_TEMP_BAR_0",
"CLAY_LOW_FUEL_BARS",
"CLAY_LED_COLOR",
"CLAY_BG_COLOR",
diff --git a/src/c/main.c b/src/c/main.c
index f246943..62c443b 100644
--- a/src/c/main.c
+++ b/src/c/main.c
@@ -53,7 +53,7 @@ static const uint8_t s_bar_spacing = s_bar_height + 1;
static void batt_callback(BatteryChargeState state) {
s_batt_level = state.charge_percent / 5;
layer_mark_dirty(s_fuel_layer);
- if (!s_low_fuel_indicator && s_batt_level <= settings.LowFuelBars) {
+ if (!s_low_fuel_indicator && s_batt_level <= settings.LowFuelBars && settings.LowFuelBars != 21) {
replace_gbitmap_color(s_applied_fg, settings.ColorLowFuel, s_e_icon, s_e_layer);
s_low_fuel_indicator = true;
} else if (s_low_fuel_indicator && s_batt_level > settings.LowFuelBars) {
@@ -62,7 +62,6 @@ static void batt_callback(BatteryChargeState state) {
}
}
-// TODO use temperature (for now it updates with battery usage)
static void temp_update_proc(Layer *layer, GContext *ctx) {
graphics_context_set_fill_color(ctx, GColorWhite);
const uint8_t bar_count = s_temp_level;
@@ -112,6 +111,21 @@ static void fuel_mg_update_proc(Layer *layer, GContext *ctx) {
temp_fuel_mg_update_proc_helper(layer, ctx, true);
}
+static void update_temperature() {
+ DictionaryIterator *out;
+ AppMessageResult result = app_message_outbox_begin(&out);
+ if (result != APP_MSG_OK) {
+ s_temp_level = 0; // error; set to 0 bars to indicate TODO invert color and set to 20?
+ return;
+ }
+ dict_write_int8(out, MESSAGE_KEY_PKJS_TEMP_BAR_COUNT, 1);
+ result = app_message_outbox_send();
+ if (result != APP_MSG_OK) {
+ s_temp_level = 0; // error; set to 0 bars to indicate TODO invert color and set to 20?
+ return;
+ }
+}
+
static void apply_settings(bool first_run) {
// LED&BG
light_set_color(settings.ColorLED); // no-op on unsupported platforms
@@ -183,6 +197,9 @@ static void apply_settings(bool first_run) {
s_applied_fg = settings.ColorFG;
}
+ // changes to temperature range
+ update_temperature();
+
// changes to low fuel threshold
batt_callback(battery_state_service_peek());
}
@@ -262,21 +279,6 @@ static void update_minute_1() {
}
}
-static void update_temperature() {
- DictionaryIterator *out;
- AppMessageResult result = app_message_outbox_begin(&out);
- if (result != APP_MSG_OK) {
- s_temp_level = 0; // error; set to 0 bars to indicate TODO invert color and set to 20?
- return;
- }
- dict_write_int8(out, MESSAGE_KEY_PKJS_TEMP_BAR_COUNT, 1);
- result = app_message_outbox_send();
- if (result != APP_MSG_OK) {
- s_temp_level = 0; // error; set to 0 bars to indicate TODO invert color and set to 20?
- return;
- }
-}
-
static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
update_minute_1();
if (s_pkjs_ready && tick_time->tm_min % 30 == 0) {
@@ -350,7 +352,7 @@ static void init() {
persist_read_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
} else {
settings.ShowTimeMG = false;
- settings.LowFuelBars = 2;
+ settings.LowFuelBars = 21;
settings.ColorLED = GColorWhite;
settings.ColorBG = GColorBlue;
settings.ColorMGBars = GColorDarkGray;
diff --git a/src/pkjs/config.js b/src/pkjs/config.js
index 5ebe269..d692437 100644
--- a/src/pkjs/config.js
+++ b/src/pkjs/config.js
@@ -16,13 +16,24 @@ module.exports = [
"type": "toggle",
"messageKey": "CLAY_SHOW_TIME_MG",
"defaultValue": false,
- "label": "Show time segments midground"
+ "label": "Show time segments midground",
+ "description": "Show or hide the unlit segments behind the time."
+ },
+ {
+ "type": "slider",
+ "messageKey": "CLAY_TEMP_BAR_0",
+ defaultValue: -32,
+ min: -50,
+ max: 0,
+ "label": "Minimum of temperature range",
+ "description": "Default: -32°C
Measured in Celsius, this value sets the temperature that is considered the minimum on the watchface. When it is this temperature, 0 temperature bars will be displayed. The maximum is this value +80, making the default maximum 48°C."
},
{
"type": "select",
"messageKey": "CLAY_LOW_FUEL_BARS",
- "defaultValue": 10,
- "label": "Low fuel percentage",
+ "defaultValue": 2,
+ "label": "Low fuel indicator percentage",
+ "description": "The low fuel indicator will appear at this battery percentage.",
"options": [
{
"label": "disabled",
diff --git a/src/pkjs/customClay.js b/src/pkjs/customClay.js
index d5f936e..9e5cccd 100644
--- a/src/pkjs/customClay.js
+++ b/src/pkjs/customClay.js
@@ -29,7 +29,6 @@ module.exports = function (minified) {
}
}
- // TODO show/hide LED color selector (only on emery)
function toggleCustomColors() {
if (this.get()) {
clayConfig.getItemById('color_preset_selector').hide();
diff --git a/src/pkjs/weather.js b/src/pkjs/weather.js
index 4c07037..f20884f 100644
--- a/src/pkjs/weather.js
+++ b/src/pkjs/weather.js
@@ -15,14 +15,21 @@ function locationSuccess(pos) {
xhrRequest(url, 'GET',
function (responseText) {
- var json = JSON.parse(responseText);
+ const current_temp = JSON.parse(responseText).current.temperature_2m;
+ const min_temp = JSON.parse(localStorage.getItem('clay-settings')).CLAY_TEMP_BAR_0;
+ const max_temp = min_temp + 80;
- // clamp into a range of 80 (technically 81)C (-32,48), -32C=-25.6F, 48C=118.4F
- var temperature = Math.min(Math.max(json.current.temperature_2m, -32), 48);
- // set set range minimum to 0 (add 32) and convert to bars (0-20)
- temperature = Math.round((temperature + 32) / 4);
+ const clamped_temp = Math.min(Math.max(current_temp, min_temp), max_temp);
+ const normalized_temp = clamped_temp - min_temp;
+ const temp_bars = Math.round(normalized_temp / 4);
- Pebble.sendAppMessage({ PKJS_TEMP_BAR_COUNT: temperature });
+ console.log("Current temp: " + current_temp);
+ console.log("Min temp: " + min_temp);
+ console.log("Max temp: " + max_temp);
+ console.log("Clamped temp: " + clamped_temp);
+ console.log("Bars " + temp_bars);
+
+ Pebble.sendAppMessage({ PKJS_TEMP_BAR_COUNT: temp_bars });
}
);
}