Skip to content

Commit

Permalink
Merge pull request #23 from okdar/feature/sun
Browse files Browse the repository at this point in the history
Feature/sun
  • Loading branch information
okdar authored Jan 11, 2022
2 parents 1607fc2 + 1d30e64 commit 3908542
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.6.0 (Jan 11, 2022)
* added sunrise, sunset and civil twilights (powered by https://github.com/haraldh/SunCalc library)

# 1.5.4 (Jun 21, 2021)
* watch face available for Descent™ Mk2 S, Forerunner® 55, Forerunner® 945 LTE

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Arc indicators around the screen display:
* Bluetooth status
* do not disturb status
* number of alarms. First alarm is displayed as five minutes arc, each other as one minute arc.
* 'always on' second hand
* sunrise, sunset and civil twilights

Text infos on the screen display:
* heart rate
Expand All @@ -17,3 +17,7 @@ Text infos on the screen display:
* date

SmartArcs watch face was inspired by Activity Classic Watch Face (https://apps.garmin.com/en-US/apps/8432711c-837b-41bc-a9b1-370037d60ef1) and ManniAT Face (https://apps.garmin.com/en-US/apps/b9f63114-cebb-4da0-b7ae-dd021ed00016).

'Always on' second hand

Power saver
Binary file removed connect_iq_store/black.png
Binary file not shown.
Binary file added connect_iq_store/power_saver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added connect_iq_store/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed connect_iq_store/white.png
Binary file not shown.
Binary file removed docs/pover_saver_big.png
Binary file not shown.
6 changes: 4 additions & 2 deletions manifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="SmartArcsApp" id="f9b0f982693411e9a9231681be663d3e" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.5.4">
<iq:application entry="SmartArcsApp" id="f9b0f982693411e9a9231681be663d3e" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.6.0">
<iq:products>
<iq:product id="approachs62"/>
<iq:product id="d2air"/>
Expand Down Expand Up @@ -55,7 +55,9 @@
<iq:product id="vivoactive4s"/>
<iq:product id="vivolife"/>
</iq:products>
<iq:permissions/>
<iq:permissions>
<iq:uses-permission id="Positioning"/>
</iq:permissions>
<iq:languages>
<iq:language>eng</iq:language>
</iq:languages>
Expand Down
6 changes: 4 additions & 2 deletions manifest.xml.beta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="SmartArcsApp" id="2eafd80f81794ced90db35ccfcb29945" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.5.23">
<iq:application entry="SmartArcsApp" id="2eafd80f81794ced90db35ccfcb29945" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.6.0">
<iq:products>
<iq:product id="approachs62"/>
<iq:product id="d2charlie"/>
Expand Down Expand Up @@ -47,7 +47,9 @@
<iq:product id="vivoactive4s"/>
<iq:product id="vivolife"/>
</iq:products>
<iq:permissions/>
<iq:permissions>
<iq:uses-permission id="Positioning"/>
</iq:permissions>
<iq:languages>
<iq:language>eng</iq:language>
</iq:languages>
Expand Down
6 changes: 4 additions & 2 deletions manifest.xml.prod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="SmartArcsApp" id="f9b0f982693411e9a9231681be663d3e" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.5.4">
<iq:application entry="SmartArcsApp" id="f9b0f982693411e9a9231681be663d3e" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.6.0">
<iq:products>
<iq:product id="approachs62"/>
<iq:product id="d2air"/>
Expand Down Expand Up @@ -55,7 +55,9 @@
<iq:product id="vivoactive4s"/>
<iq:product id="vivolife"/>
</iq:products>
<iq:permissions/>
<iq:permissions>
<iq:uses-permission id="Positioning"/>
</iq:permissions>
<iq:languages>
<iq:language>eng</iq:language>
</iq:languages>
Expand Down
Binary file removed pover_saver_big.png
Binary file not shown.
Binary file removed power_saver_small.png
Binary file not shown.
46 changes: 46 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<property id="dndColor" type="number">0xAA00FF</property>
<property id="alarmColor" type="number">0xFFAA00</property>

<property id="sunriseColor" type="number">0xAA0000</property>
<property id="sunsetColor" type="number">0x0000FF</property>

<property id="eventName" type="string"></property>
<property id="eventDate" type="number">1573331777</property>
<property id="eventColor" type="number">-999</property>
Expand Down Expand Up @@ -109,6 +112,9 @@

<string id="alarmColor">Alarm indicator color (off or color)</string>

<string id="sunriseColor">Sunrise indicator color (off or color)</string>
<string id="sunsetColor">Sunset indicator color (off or color)</string>

<string id="eventName">Event name</string>
<string id="eventDate">Event date</string>
<string id="eventColor">Event color (off or color)</string>
Expand Down Expand Up @@ -471,6 +477,46 @@
</settingConfig>
</setting>

<setting propertyKey="@Properties.sunriseColor" title="@Strings.sunriseColor">
<settingConfig type="list">
<listEntry value="-999">@Strings.off</listEntry>
<listEntry value="0xFFFFFF">@Strings.white</listEntry>
<listEntry value="0xAAAAAA">@Strings.ltGray</listEntry>
<listEntry value="0x555555">@Strings.dkGray</listEntry>
<listEntry value="0x000000">@Strings.black</listEntry>
<listEntry value="0xFF0000">@Strings.red</listEntry>
<listEntry value="0xAA0000">@Strings.dkRed</listEntry>
<listEntry value="0xFF5500">@Strings.orange</listEntry>
<listEntry value="0xFFAA00">@Strings.yellow</listEntry>
<listEntry value="0x00FF00">@Strings.green</listEntry>
<listEntry value="0x00AA00">@Strings.dkGreen</listEntry>
<listEntry value="0x00AAFF">@Strings.blue</listEntry>
<listEntry value="0x0000FF">@Strings.dkBlue</listEntry>
<listEntry value="0xAA00FF">@Strings.purple</listEntry>
<listEntry value="0xFF00FF">@Strings.pink</listEntry>
</settingConfig>
</setting>

<setting propertyKey="@Properties.sunsetColor" title="@Strings.sunsetColor">
<settingConfig type="list">
<listEntry value="-999">@Strings.off</listEntry>
<listEntry value="0xFFFFFF">@Strings.white</listEntry>
<listEntry value="0xAAAAAA">@Strings.ltGray</listEntry>
<listEntry value="0x555555">@Strings.dkGray</listEntry>
<listEntry value="0x000000">@Strings.black</listEntry>
<listEntry value="0xFF0000">@Strings.red</listEntry>
<listEntry value="0xAA0000">@Strings.dkRed</listEntry>
<listEntry value="0xFF5500">@Strings.orange</listEntry>
<listEntry value="0xFFAA00">@Strings.yellow</listEntry>
<listEntry value="0x00FF00">@Strings.green</listEntry>
<listEntry value="0x00AA00">@Strings.dkGreen</listEntry>
<listEntry value="0x00AAFF">@Strings.blue</listEntry>
<listEntry value="0x0000FF">@Strings.dkBlue</listEntry>
<listEntry value="0xAA00FF">@Strings.purple</listEntry>
<listEntry value="0xFF00FF">@Strings.pink</listEntry>
</settingConfig>
</setting>

<setting propertyKey="@Properties.eventColor" title="@Strings.eventColor">
<settingConfig type="list">
<listEntry value="-999">@Strings.off</listEntry>
Expand Down
86 changes: 79 additions & 7 deletions source/SmartArcsView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using Toybox.Activity;
using Toybox.Application;
using Toybox.Graphics;
using Toybox.Lang;
using Toybox.Position;
using Toybox.System;
using Toybox.Time;
using Toybox.Time.Gregorian;
Expand All @@ -46,6 +47,7 @@ class SmartArcsView extends WatchUi.WatchFace {
var screenWidth;
var screenRadius;
var arcRadius;
var twoPI = Math.PI * 2;
var dualTimeLocationY;
var dualTimeTimeY;
var dualTimeAmPmY;
Expand All @@ -65,6 +67,10 @@ class SmartArcsView extends WatchUi.WatchFace {
var endPowerSaverMin;
var screenResolutionRatio;
var powerSaverIconRatio;
var sunriseStartAngle = 0;
var sunriseEndAngle = 0;
var sunsetStartAngle = 0;
var sunsetEndAngle = 0;

//user settings
var bgColor;
Expand Down Expand Up @@ -107,6 +113,8 @@ class SmartArcsView extends WatchUi.WatchFace {
var powerSaver;
var powerSaverRefreshInterval;
var powerSaverIconColor;
var sunriseColor;
var sunsetColor;

function initialize() {
loadUserSettings();
Expand Down Expand Up @@ -158,6 +166,11 @@ class SmartArcsView extends WatchUi.WatchFace {
computeConstants(dc);
}

//recompute sunrise/sunset constants every hour - to address new location when traveling
if (clockTime.min == 0) {
computeSunConstants();
}

var today = Time.today();

//we always want to refresh the full screen when we get a regular onUpdate call.
Expand Down Expand Up @@ -194,6 +207,8 @@ class SmartArcsView extends WatchUi.WatchFace {
drawAlarms(targetDc, deviceSettings.alarmCount);
}

drawSun(targetDc);

if (ticks != null) {
drawTicks(targetDc);
}
Expand Down Expand Up @@ -276,12 +291,16 @@ class SmartArcsView extends WatchUi.WatchFace {
dndColor = app.getProperty("dndColor");
alarmColor = app.getProperty("alarmColor");
secondHandColor = app.getProperty("secondHandColor");
sunriseColor = app.getProperty("sunriseColor");
sunsetColor = app.getProperty("sunsetColor");
} else {
notificationColor = oneColor;
bluetoothColor = oneColor;
dndColor = oneColor;
alarmColor = oneColor;
secondHandColor = oneColor;
sunriseColor = oneColor;
sunsetColor = oneColor;
}
bgColor = app.getProperty("bgColor");
ticksColor = app.getProperty("ticksColor");
Expand Down Expand Up @@ -442,6 +461,8 @@ class SmartArcsView extends WatchUi.WatchFace {
}
arcRadius = screenRadius - (arcPenWidth / 2);

computeSunConstants();

//constants pre-computed, doesn't need to be computed again
needComputeConstants = false;
}
Expand All @@ -463,11 +484,11 @@ class SmartArcsView extends WatchUi.WatchFace {

function computeTicks() {
var angle;
ticks = new [31];
//to save the memory compute only half of the ticks, second half will be mirrored.
ticks = new [16];
//to save the memory compute only a quarter of the ticks, the rest will be mirrored.
//I believe it will still save some CPU utilization
for (var i = 0; i < 31; i++) {
angle = (i * Math.PI * 2) / 60.0;
for (var i = 0; i < 16; i++) {
angle = i * twoPI / 60.0;
if ((i % 15) == 0) { //quarter tick
if (ticks15MinWidth > 0) {
ticks[i] = computeTickRectangle(angle, 20, ticks15MinWidth);
Expand Down Expand Up @@ -572,16 +593,30 @@ class SmartArcsView extends WatchUi.WatchFace {
function drawTicks(dc) {
var coord = new [4];
dc.setColor(ticksColor, Graphics.COLOR_TRANSPARENT);
for (var i = 0; i < 31; i++) {
for (var i = 0; i < 16; i++) {
//30-45 ticks
if (ticks[i] != null) {
dc.fillPolygon(ticks[i]);
}

//mirror pre-computed ticks from the left side to the right side
if (i > 0 && i <30 && ticks[i] != null) {
//mirror pre-computed ticks
if (i >= 0 && i <= 15 && ticks[i] != null) {
//15-30 ticks
for (var j = 0; j < 4; j++) {
coord[j] = [screenWidth - ticks[i][j][0], ticks[i][j][1]];
}
dc.fillPolygon(coord);

//45-60 ticks
for (var j = 0; j < 4; j++) {
coord[j] = [ticks[i][j][0], screenWidth - ticks[i][j][1]];
}
dc.fillPolygon(coord);

//0-15 ticks
for (var j = 0; j < 4; j++) {
coord[j] = [screenWidth - ticks[i][j][0], screenWidth - ticks[i][j][1]];
}
dc.fillPolygon(coord);
}
}
Expand Down Expand Up @@ -974,4 +1009,41 @@ class SmartArcsView extends WatchUi.WatchFace {

powerSaverDrawn = true;
}

function computeSunConstants() {
var posInfo = Toybox.Position.getInfo();
if (posInfo != null && posInfo.position != null) {
var sc = new SunCalc();
var time_now = Time.now();
var loc = posInfo.position.toRadians();
sunriseStartAngle = computeSunAngle(sc.calculate(time_now, loc, SunCalc.DAWN));
sunriseEndAngle = computeSunAngle(sc.calculate(time_now, loc, SunCalc.SUNRISE));
sunsetStartAngle = computeSunAngle(sc.calculate(time_now, loc, SunCalc.SUNSET));
sunsetEndAngle = computeSunAngle(sc.calculate(time_now, loc, SunCalc.DUSK));
}
}

function computeSunAngle(time) {
var timeInfo = Time.Gregorian.info(time, Time.FORMAT_SHORT);
var angle = ((timeInfo.hour % 12) * 60.0) + timeInfo.min;
angle = angle / (12 * 60.0) * twoPI;
return -(angle - Math.PI/2) * 180 / Math.PI;
}

function drawSun(dc) {
dc.setPenWidth(7);

//draw sunrise
if (sunriseColor != offSettingFlag) {
dc.setColor(sunriseColor, Graphics.COLOR_TRANSPARENT);
dc.drawArc(screenRadius, screenRadius, screenRadius - 17, Graphics.ARC_CLOCKWISE, sunriseStartAngle, sunriseEndAngle);
}

//draw sunset
if (sunsetColor != offSettingFlag) {
dc.setColor(sunsetColor, Graphics.COLOR_TRANSPARENT);
dc.drawArc(screenRadius, screenRadius, screenRadius - 13, Graphics.ARC_CLOCKWISE, sunsetStartAngle, sunsetEndAngle);
}
}

}
Loading

0 comments on commit 3908542

Please sign in to comment.