Hello everybody,
I added a function to my watchface which isn't working but I really don't have a clue why.
The goal is simply to sum up the min and hours moved on a day. To a certain extend that works but every once in a while he resets and I don't know why. I never reached vaules over 40 min before it got reset for no reason I understand.
Anybody aware of the fault I made?
The view.mc
using Toybox.Lang as Lang;
using Toybox.System as Sys;
import Toybox.WatchUi;
using Toybox.Time.Gregorian as Date;
using Toybox.Application as App;
using Toybox.ActivityMonitor as Mon;
class Last_MoveView extends WatchUi.WatchFace {
var stepsolds = 0;
var summoved = 0;
var hoursmoved=0;
var minmoved=0;
var minalt = 0;
function initialize() {
WatchFace.initialize();
}
// Load your resources here
function onLayout(dc) {
setLayout(Rez.Layouts.WatchFace(dc));
}
// Called when this View is brought to the foreground. Restore
// the state of this View and prepare it to be shown. This includes
// loading resources into memory.
function onShow() {
}
// Update the view
function onUpdate(dc) {
setsummoved();
View.onUpdate(dc);
}
// Called when this View is removed from the screen. Save the
// state of this View here. This includes freeing resources from
// memory.
function onHide() {
}
// The user has just looked at their watch. Timers and animations may be started here.
function onExitSleep() {
}
// Terminate any active timers and prepare for slow updates.
function onEnterSleep() {
}
the function:
function setsummoved() {
var zeit = Sys.getClockTime();
var stepnews = Mon.getInfo().steps;
//stepnews =50;
//summoved =100;
if (zeit.hour>5) { //datealt
if (stepnews>stepsolds+20){ //and (now.min>minalt)
if (zeit.min>minalt) {
summoved=summoved+1;
if (summoved>60){
hoursmoved=(summoved/60); //summoved % 60;
minmoved = summoved % 60;//summoved - (hoursmoved*60);
} else {
hoursmoved=0;
minmoved = summoved;
}
}
}
var timeStrings = Lang.format("$1$:$2$", [hoursmoved, minmoved.format("%02d")]);
var view = View.findDrawableById("summovedDisplay"); //Anzeige Mitte Z3 Uhrzeit der letzten Bewegung 55 85
view.setText(timeStrings);
minalt=zeit.min;
stepsolds=stepnews;
}else{
summoved=null;
hoursmoved=null;
minmoved=null;
}
}
The Layout:
<layout id="WatchFace">
<label id="summovedDisplay" x="55%" y="85%" font="Graphics.FONT_XTINY" justification="Graphics.TEXT_JUSTIFY_CENTER" />
</layout>