mirror of
https://git.wetfence.xyz/RandyTheSilly/Civic-Segments.git
synced 2026-09-06 02:27:14 -04:00
Make temperature range configurable
This commit is contained in:
+13
-6
@@ -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 });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user