Need advice for adding seconds on watch face.

Need advice for adding seconds on watch face.

Good day to all.
One of users of my wf asked to add seconds. I’ve used options, where you can select to show seconds or dots between Hrs. and Min. I’ve used vertical position of seconds in digits.

Main question, that seconds coming with delay. When you just look on device (so it’s going out from sleep) for few seconds in shows good, but periodically lost seconds: 1-2-5-6-8 etc. Here below my code. Will be appreciated for advices, how to optimize it, to remove delays.

//Seconds or dots
//Seconds
if(App.getApp().getProperty("ShowSeconds")){
var secondsFirstDig = (System.getClockTime().sec)/10;
var secondsSecondDig = (System.getClockTime().sec) - secondsFirstDig * 10;
//Darw seconds
var showFirstDig= new Ui.Text({
:text=>secondsFirstDig.toString(),
:color=>Gfx.COLOR_LT_GRAY,
:font=>Ui.loadResource(Rez.Fonts.Day),
:locX =>120,
:locY=>95,
:justification=>Gfx.TEXT_JUSTIFY_CENTER
});
showFirstDig.draw(dc);
var showSecondDig= new Ui.Text({
:text=>secondsSecondDig.toString(),
:color=>Gfx.COLOR_LT_GRAY,
:font=>Ui.loadResource(Rez.Fonts.Day),
:locX =>120,
:locY=>115,
:justification=>Gfx.TEXT_JUSTIFY_CENTER
});
showSecondDig.draw(dc);
}
else{
//Draw Dots or Do not Disturb if on
dc.setPenWidth(1);
if(Sys.getDeviceSettings().doNotDisturb){
dc.setColor(Gfx.COLOR_RED, Gfx.COLOR_TRANSPARENT);
dc.drawCircle(120, 112, 5);
dc.drawLine(123, 115, 116, 108);
dc.drawCircle(120, 132, 5);
dc.drawLine(123, 135, 116, 128);
}
else{
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
dc.drawCircle(120, 112, 5);
dc.drawCircle(120, 132, 5);
}
}
  • You're not using onPartialUpdate(), correct? (no "seconds all the time").
    So, you want to only display seconds after a call to onExitSleep() and before a call to onEnterSleep()

    I do two things in onEnterSleep() and onExitSleep() - I set a boolean so that onUpdate() knows which mode it's in, and do a Ui.RequestUpdate() if things have changed to insure the screen shows correctly.
  • Yes, this is correct, I’m not using onPartialUpdate(). I use check: if in options selected to show seconds, it’s show it, if not – show dots (just graphic).
    Main problem is that the seconds time to time jumping through one. And it’s really seems like the reason, that watch goes to sleep mode for some moments. Need to make check.
    However, I thinks, it’s will be really better to use onPartialUpdate().
    Will, try will see.

    Thanks for, as usual good and useful, advices, Jim.
  • Get it to work right without onPartialUpdate() first, as 1hz adds a new level of complexity with dealing with clip regions, the power budget and handling what happens in the delegate for exceeding the power budget.

    The basic flow you'll want to get working is:

    in onUpdate()

    if in lowPower, don't show seconds
    if not in lowPower, show seconds

    and with onEnterSleep set lowPower to true and call Ui.requestUpdate(), and in onExitSleep, set lowPower to be false.

    In the sim, under settings, you can check/uncheck "Low Power Mode" to test things there.
  • Yes, usage of onPartialUpdate() will make code really heavily without reason…

    I made by your advice, and all smooth with it (thanks).
    Remain point, that seconds, sometimes, are jumping over one (not +1, but sometimes +2), it goes, for example: 1, 2, 4, 5, 7, 8 ect. At simulator all fine…
    To show seconds vertically, I’ve separate first and second digit, maybe error somewhere there…

    Here is code:
    var secondsFirstDig = (System.getClockTime().sec)/10;
    var secondsSecondDig = (System.getClockTime().sec) - secondsFirstDig * 10;
  • try
    var sec=Sys.getClockTime.sec;
    var dig1=sec/10;
    var dig2=sec%10;

    and make sure to use Ui.requestUpdate when things change.

    Do you have a complex WF where it might be taking a long time to draw and could miss a onUpdate() when they are coming every second? Maybe comment out some code, and see if things start working on the real watch.
  • O! Thanks for nice idea to improve code.

    I add one more Ui.requestUpdate with same result.
    But after abt 5 min after reinstallation of wf, all become in order by itself.

    Finally, it looks like reason in a watch face. It’s complex and really possible, that it's cannot reach update in a second...

    Thanks for your help and advices