Added Sun settings and 12hrs in sunrise and set times

master
David Volovskiy 2025-02-25 04:32:11 -05:00
parent b34218aa5c
commit f7002a782f
4 changed files with 49 additions and 7 deletions

View File

@ -12,4 +12,4 @@
0.12: Added setting to change Battery estimate to hours
0.13: Fixed Battery estimate Default to percentage and improved setting string
0.14: Use `power_usage` module
0.15: Ring can now show hours, minute, or seconds hand, or battery; Allowed for 12hr time; Ring now goes up in 5% increments
0.15: Ring can now show hours, minute, or seconds hand, day/night left, or battery; Allowed for 12hr time; Ring now goes up in 5% increments

View File

@ -18,9 +18,16 @@ See [#1248](https://github.com/espruino/BangleApps/issues/1248)
* Uses mylocation.json from MyLocation app to calculate sunrise and sunset times for your location
* If your Sunrise, Sunset times look odd make sure you have setup your location using
[MyLocation](https://banglejs.com/apps/?id=mylocation)
* The screen is updated every minute to save battery power
* The screen is updated every minute to save battery power, unless the ring is set to display seconds, then it updates every 5 seconds.
* Uses the [BloggerSansLight](https://www.1001fonts.com/rounded-fonts.html?page=3) font, which if free for commercial use
* You need to run >2V22 to show the battery estimate in hours
* In the settings, the ring can be set to:
* Hours - Displays the ring as though it's the hour hand on an analog clock.
* Minutes - Displays the ring as though it's the minute hand on an analog clock.
* Seconds - Displays the ring as though it's the seconds hand on an analog clock.
* Steps - Displays the ring as the amount of steps taken that day out of 10,000.
* Battery - Displays the ring as the amount of battery percentage left.
* Sun - Displays the ring as the amount of time that has passed from sunrise to sunset in the day and the amount of time between sunset and sunrise at night.
## Future Development
* Use mini icons in the information line rather that text

View File

@ -99,21 +99,52 @@ function loadLocation() {
function extractTime(d){
var h = d.getHours(), m = d.getMinutes();
if (settings.hr_12) {
h = h % 12;
if (h == 0) h = 12;
}
return(("0"+h).substr(-2) + ":" + ("0"+m).substr(-2));
}
var sunRise = "00:00";
var sunSet = "00:00";
var drawCount = 0;
var sunStart;
var sunFull;
function updateSunRiseSunSet(now, lat, lon, line){
function updateSunRiseSunSet(now, lat, lon, sunLeftCalcs){
// get today's sunlight times for lat/lon
var times = SunCalc.getTimes(new Date(), lat, lon);
var times = SunCalc.getTimes(now, lat, lon);
// format sunrise time from the Date object
sunRise = extractTime(times.sunrise);
sunSet = extractTime(times.sunset);
if (!sunLeftCalcs) return;
let sunLeft = times.sunset - now;
if (sunLeft < 0) { // If it's already night
let tmrw = now;
tmrw.setDate(tmrw.getDate() + 1);
let timesTmrw = SunCalc.getTimes(tmrw, lat, lon);
sunStart = times.sunset;
sunFull = timesTmrw.sunrise - sunStart;
}
else {
sunLeft = now - times.sunrise;
if (sunLeft < 0) { // If it's not morning yet.
let yest = now;
yest.setDate(yest.getDate() - 1);
let timesYest = SunCalc.getTimes(yest, lat, lon);
sunStart = timesYest.sunset;
sunFull = times.sunrise - sunStart;
}
else { // We're in the middle of the day
sunStart = times.sunrise;
sunFull = times.sunset - sunStart;
}
}
}
function batteryString(){
let stringToInsert;
@ -242,6 +273,9 @@ function drawClock() {
case 'Battery':
ring_percent = E.getBattery();
break;
case 'Sun':
ring_percent = 100 * (date - sunStart) / sunFull;
break;
}
if (settings.hr_12) {
@ -269,7 +303,7 @@ function drawClock() {
// recalc sunrise / sunset every hour
if (drawCount % 60 == 0)
updateSunRiseSunSet(new Date(), location.lat, location.lon);
updateSunRiseSunSet(new Date(), location.lat, location.lon, settings.ring == 'Sun');
drawCount++;
}
@ -665,6 +699,7 @@ Bangle.setUI("clockupdown", btn=> {
loadSettings();
loadLocation();
updateSunRiseSunSet(new Date(), location.lat, location.lon, true);
g.clear();
Bangle.loadWidgets();

View File

@ -27,7 +27,7 @@
var color_options = ['Green','Orange','Cyan','Purple','Red','Blue'];
var fg_code = ['#0f0','#ff0','#0ff','#f0f','#f00','#00f'];
var gy_code = ['#020','#220','#022','#202','#200','#002'];
var ring_options = ['Hours', 'Minutes', 'Seconds', 'Steps', 'Battery'];
var ring_options = ['Hours', 'Minutes', 'Seconds', 'Steps', 'Battery', 'Sun'];
E.showMenu({
'': { 'title': 'Daisy Clock' },
@ -66,7 +66,7 @@
},
'Ring Display': {
value: 0 | ring_options.indexOf(s.ring),
min: 0, max: 4,
min: 0, max: 5,
format: v => ring_options[v],
onchange: v => {
s.ring = ring_options[v];