Skip to content

Commit

Permalink
closes $47 settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tumb1er committed Feb 15, 2019
1 parent 2aa0390 commit f93b91a
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 16 deletions.
10 changes: 10 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<properties>
<property id="appVersion" type="string">0.7.0</property>
<property id="backgroundColor" type="number">85</property>
<property id="twoHertzMode" type="boolean">true</property>
<property id="powersafeViaDND" type="boolean">true</property>
<property id="powersafeViaMove" type="boolean">true</property>
<property id="powersafeViaHR" type="boolean">true</property>
<property id="heartRateMultiplier" type="float">1.2</property>
<property id="powersafeModeDelay" type="number">60</property>
</properties>
40 changes: 40 additions & 0 deletions resources/settings/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<settings>

<setting propertyKey="@Properties.appVersion" title="@Strings.AppVersionTitle">
<settingConfig type="alphaNumeric" readonly="true" />
</setting>

<setting propertyKey="@Properties.backgroundColor" title="@Strings.BackgroundColorTitle"
prompt="@Strings.BackgroundColorPrompt">
<settingConfig type="list">
<listEntry value="0">@Strings.Black</listEntry>
<listEntry value="85">@Strings.Blue</listEntry>
<listEntry value="21760">@Strings.Green</listEntry>
<listEntry value="5570560">@Strings.Red</listEntry>
</settingConfig>
</setting>

<setting propertyKey="@Properties.twoHertzMode" title="@Strings.TwoHertzMode">
<settingConfig type="boolean" />
</setting>

<setting propertyKey="@Properties.powersafeViaDND" title="@Strings.PowersafeViaDND">
<settingConfig type="boolean" />
</setting>

<setting propertyKey="@Properties.powersafeViaMove" title="@Strings.PowersafeViaMove">
<settingConfig type="boolean" />
</setting>

<setting propertyKey="@Properties.powersafeViaHR" title="@Strings.PowersafeViaHR">
<settingConfig type="boolean" />
</setting>
<setting propertyKey="@Properties.heartRateMultiplier" title="@Strings.HeartRateMultiplier">
<settingConfig type="numeric" />
</setting>
<setting propertyKey="@Properties.powersafeModeDelay" title="@Strings.PowersafeModeDelay">
<settingConfig type="numeric" />
</setting>


</settings>
13 changes: 13 additions & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,17 @@
<string id="Months">JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC</string>
<string id="Icons">ZABSN</string>

<string id="AppVersionTitle">Application Version</string>
<string id="BackgroundColorTitle">Background color</string>
<string id="BackgroundColorPrompt">Select background color</string>
<string id="Black">black</string>
<string id="Blue">dark blue</string>
<string id="Green">dark green</string>
<string id="Red">dark red</string>
<string id="TwoHertzMode">2Hz second hand</string>
<string id="PowersafeViaDND">Enter power safe mode in dnd</string>
<string id="PowersafeViaMove">Enter power safe mode if move bar is full</string>
<string id="PowersafeViaHR">Enter power safe mode in resting HR</string>
<string id="HeartRateMultiplier">Resting heart rate multiplier for power safe mode detection</string>
<string id="PowersafeModeDelay">Delay before entering powersafe mode in seconds</string>
</strings>
13 changes: 12 additions & 1 deletion source/ElPrimeroApp.mc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using Toybox.Application;

class ElPrimeroApp extends Application.AppBase {

var mView = null;

function initialize() {
AppBase.initialize();
}
Expand All @@ -16,7 +18,16 @@ class ElPrimeroApp extends Application.AppBase {

// Return the initial view of your application here
function getInitialView() {
return [ new ElPrimeroView() ];
mView = new ElPrimeroView();
return [ mView ];
}

function onSettingsChanged() {
if (mView == null || mView.mState == null) {
return;
}
mView.mState.readSettings();
WatchUi.requestUpdate();
}

}
12 changes: 6 additions & 6 deletions source/ElPrimeroView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ class ElPrimeroView extends WatchUi.WatchFace {
System.println("invalidateHands: hour");

// erasing hour hand at previous position
dc.setColor(0x000055, cTransparent);
dc.setColor(mState.mBackgroundColor, cTransparent);
mHourHand.drawVector(dc, mHourHand.mPos, cx - 120, cy + 1 - 120);
}

if (mMinuteHand.mPos != mState.mMinutePos) {
System.println("invalidateHands: min");

// erasing minute hand at previous position
dc.setColor(0x000055, cTransparent);
dc.setColor(mState.mBackgroundColor, cTransparent);
mMinuteHand.drawVector(dc, mMinuteHand.mPos, cx - 120, cy + 1 - 120);
}

Expand Down Expand Up @@ -393,9 +393,8 @@ class ElPrimeroView extends WatchUi.WatchFace {
if (flags == State.ALL) {
System.println("drawBackgrounds: all");

bc.setColor(0xFFFFFF, 0x000055);
bc.setColor(0xFFFFFF, mState.mBackgroundColor);
bc.clear();
bc.setColor(0xFFFFFF, 0x000055);
for (pos=0; pos < PosGlyphs; pos++) {
coords = getXY(pos, cCoords);
char = pos + 32;
Expand All @@ -404,7 +403,7 @@ class ElPrimeroView extends WatchUi.WatchFace {
} else if ((flags & State.MINUTE) && mMinuteHand.mPos != null) {
System.println("drawBackgrounds: minute/ticks");

bc.setColor(0xFFFFFF, 0x000055);
bc.setColor(0xFFFFFF, mState.mBackgroundColor);
char = 32 + mMinuteHand.mPos / 3;
coords = getXY(mMinuteHand.mPos / 3, cCoords);
bc.drawText(10 + coords[0], -1 + coords[1], mBackgroundFont, char.toChar(), Graphics.TEXT_JUSTIFY_LEFT);
Expand Down Expand Up @@ -570,7 +569,8 @@ class ElPrimeroView extends WatchUi.WatchFace {
// Drawing image to device context
if (flags == State.ALL) {
System.println("Clear DC");
dc.setColor(0xAAAAAA, 0x000055);
dc.setColor(0xAAAAAA, mState.mBackgroundColor);
dc.clearClip();
dc.clear();
}

Expand Down
51 changes: 42 additions & 9 deletions source/State.mc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Toybox.System;
using Toybox.UserProfile;
using Toybox.ActivityMonitor;
using Toybox.SensorHistory;
using Toybox.Application.Properties;

/**
State computes differences to be drawn on watch face and current values.
Expand All @@ -21,6 +22,16 @@ class State {
var mIsPowersafeMode = false;

var mBackgroundTime = null;
var mPowersafeModeDelay = 60;

var mBackgroundColor = 0x000000;

/**
1 - enter power safe mode via dnd
2 - enter power safe mode via movement
4 - enter power safe mode via heart rate
*/
var mPowersafeFlags = 7;

enum {
// icons states
Expand Down Expand Up @@ -56,6 +67,7 @@ class State {
var mFlags = 0;

function initialize() {
readSettings();
update();
}

Expand Down Expand Up @@ -348,19 +360,26 @@ class State {
return;
}

// via do not disturb;
var flag = (mIcons && DND) > 0;
// via full movement scale;
flag = flag || mMovementFraction == 5;
// via missing heartbeat
flag = flag || mHeartRateValue == null;
// via low heartrate
flag = flag || mHeartRateValue != null && mSleepHRThreshold != null && mHeartRateValue < mSleepHRThreshold;
var flag = 0;
if (mPowersafeFlags & 1) {
// via do not disturb;
flag = flag || (mIcons && DND) > 0;
}
if (mPowersafeFlags & 2) {
// via full movement scale;
flag = flag || mMovementFraction == 5;
}
if (mPowersafeFlags & 4) {
// via missing heartbeat
flag = flag || mHeartRateValue == null;
// via low heartrate
flag = flag || mHeartRateValue != null && mSleepHRThreshold != null && mHeartRateValue < mSleepHRThreshold;
}

// enter powersafe mode only from background mode
flag = flag && mIsBackgroundMode;
// enter powersafe mode 60 seconds later than background mode activated
flag = flag && mBackgroundTime != null && time.subtract(mBackgroundTime).value() >= 60;
flag = flag && mBackgroundTime != null && time.subtract(mBackgroundTime).value() >= mPowersafeModeDelay;

if (mIsPowersafeMode != flag) {
if (mIsPowersafeMode) {
Expand All @@ -384,4 +403,18 @@ class State {
mFlags = ALL;
// System.println(["reset", isInBackground, mFlags.format("%x")]);
}

/**
Reads settings values and resets view
*/
function readSettings() {
mBackgroundColor = Properties.getValue("backgroundColor");
mPowersafeFlags = 0;
mPowersafeFlags |= (Properties.getValue("powersafeViaDND"))? 1: 0;
mPowersafeFlags |= (Properties.getValue("powersafeViaMove"))? 2: 0;
mPowersafeFlags |= (Properties.getValue("powersafeViaHR"))? 4: 0;
mSleepHRMultiplier = Properties.getValue("heartRateMultiplier");
mPowersafeModeDelay = Properties.getValue("powersafeModeDelay");
mFlags = ALL;
}
}

0 comments on commit f93b91a

Please sign in to comment.