Skip to content

Commit

Permalink
Merge pull request #7 from okdar/feature/sun
Browse files Browse the repository at this point in the history
Added civil twilights
  • Loading branch information
okdar authored Jan 29, 2022
2 parents 548e66e + 871fb34 commit 4b86846
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.3.0 (Jan 29, 2022)
* added sunrise, sunset and civil twilights (powered by https://github.com/haraldh/SunCalc library)

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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Arc indicators around the screen display:
* do not disturb status
* number of alarms. First alarm is displayed as five minutes arc, each other as one minute arc.
* heart rate (on watches supporting partial update)
* sunrise, sunset and civil twilights
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.
3 changes: 2 additions & 1 deletion 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="SmartArcsTripApp" id="547fb49c0626476280e1121801561e5c" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.2.2">
<iq:application entry="SmartArcsTripApp" id="547fb49c0626476280e1121801561e5c" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.3.0">
<iq:products>
<iq:product id="d2air"/>
<iq:product id="d2charlie"/>
Expand Down Expand Up @@ -49,6 +49,7 @@
<iq:product id="vivolife"/>
</iq:products>
<iq:permissions>
<iq:uses-permission id="Positioning"/>
<iq:uses-permission id="SensorHistory"/>
</iq:permissions>
<iq:languages>
Expand Down
3 changes: 2 additions & 1 deletion 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="SmartArcsTripApp" id="5b7bdde686cc4867be63faf4c6ca83fb" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.2.0">
<iq:application entry="SmartArcsTripApp" id="5b7bdde686cc4867be63faf4c6ca83fb" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.3.0">
<iq:products>
<iq:product id="d2air"/>
<iq:product id="d2charlie"/>
Expand Down Expand Up @@ -46,6 +46,7 @@
<iq:product id="vivolife"/>
</iq:products>
<iq:permissions>
<iq:uses-permission id="Positioning"/>
<iq:uses-permission id="SensorHistory"/>
</iq:permissions>
<iq:languages>
Expand Down
3 changes: 2 additions & 1 deletion 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="SmartArcsTripApp" id="547fb49c0626476280e1121801561e5c" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.2.2">
<iq:application entry="SmartArcsTripApp" id="547fb49c0626476280e1121801561e5c" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.3.0">
<iq:products>
<iq:product id="d2air"/>
<iq:product id="d2charlie"/>
Expand Down Expand Up @@ -49,6 +49,7 @@
<iq:product id="vivolife"/>
</iq:products>
<iq:permissions>
<iq:uses-permission id="Positioning"/>
<iq:uses-permission id="SensorHistory"/>
</iq:permissions>
<iq:languages>
Expand Down
46 changes: 46 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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="dateFormat" type="number">1</property>
<property id="dateColor" type="number">0xAAAAAA</property>
Expand Down Expand Up @@ -96,6 +99,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="dateColor">Date color (off or color)</string>
<string id="dateFormat">Date format</string>
Expand Down Expand Up @@ -418,6 +424,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.dateColor" title="@Strings.dateColor">
<settingConfig type="list">
Expand Down
83 changes: 77 additions & 6 deletions source/SmartArcsTripView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Toybox.Application;
using Toybox.Graphics;
using Toybox.Lang;
using Toybox.Position;
using Toybox.SensorHistory;
using Toybox.System;
using Toybox.Time;
Expand Down Expand Up @@ -60,6 +61,10 @@ class SmartArcsTripView extends WatchUi.WatchFace {
var startPowerSaverMin;
var endPowerSaverMin;
var powerSaverIconRatio;
var sunriseStartAngle = 0;
var sunriseEndAngle = 0;
var sunsetStartAngle = 0;
var sunsetEndAngle = 0;

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

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

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

//we always want to refresh the full screen when we get a regular onUpdate call.
fullScreenRefresh = true;

Expand Down Expand Up @@ -199,6 +211,8 @@ class SmartArcsTripView extends WatchUi.WatchFace {
drawAlarms(targetDc, deviceSettings.alarmCount);
}

drawSun(targetDc);

if (showTicks) {
drawTicks(targetDc);
}
Expand Down Expand Up @@ -393,11 +407,15 @@ class SmartArcsTripView extends WatchUi.WatchFace {
bluetoothColor = app.getProperty("bluetoothColor");
dndColor = app.getProperty("dndColor");
alarmColor = app.getProperty("alarmColor");
sunriseColor = app.getProperty("sunriseColor");
sunsetColor = app.getProperty("sunsetColor");
} else {
notificationColor = oneColor;
bluetoothColor = oneColor;
dndColor = oneColor;
alarmColor = oneColor;
sunriseColor = oneColor;
sunsetColor = oneColor;
}
bgColor = app.getProperty("bgColor");
ticksColor = app.getProperty("ticksColor");
Expand Down Expand Up @@ -503,6 +521,8 @@ class SmartArcsTripView extends WatchUi.WatchFace {
hrTextDimension = dc.getTextDimensions("888", Graphics.FONT_TINY); //to compute correct clip boundaries
halfHRTextWidth = hrTextDimension[0] / 2;

computeSunConstants();

//constants pre-computed, doesn't need to be computed again
precompute = false;
}
Expand All @@ -524,10 +544,10 @@ class SmartArcsTripView 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++) {
for (var i = 0; i < 16; i++) {
angle = i * twoPI / 60.0;
if ((i % 15) == 0) { //quarter tick
if (ticks15MinWidth > 0) {
Expand Down Expand Up @@ -634,16 +654,30 @@ class SmartArcsTripView 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 @@ -954,4 +988,41 @@ class SmartArcsTripView 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 4b86846

Please sign in to comment.