settings.js: wrap time

Posted on
  • I was a bit annoyed that when setting the time the hours did not wrap.
    So when going up it would stuck at 23 instead of wrapping to 0 and when going down it would be stuck at 0.

    I tried to change this by modifying the Hour section of showSetTimeMenu in settings.js to this:

    'Hour': {
          value: d.getHours(),
          min: -1,
          max: 24,
          step: 1,
          onchange: v => {
            d = new Date();
            d.setHours((v+24)%24);
            setTime(d.getTime() / 1000);
          }
        },
    

    I thought that would to the trick but to no avail.
    I did overwrite settings.js on the bangle; that did not work, then I rebooted but still no luck.
    I've read back settings.js to verify that it is actually the modified version and it is.
    What am I doing wrong ???

  • Looks like there is no two-way-binding between both. I guess the wrapping needs to be done in E.showMenu(). But you do know that you can easily set the time from gps or from the "About"-Tab in the app loader?

  • I think that code will just get stuck at -1 and 24. This should work a bit better (untested):

    min: -24, 
    max: 23,
    step: 1,
    format: v => (v+24)%24,
    onchange: v => { /* same as above */ }
    

    As for why you aren't seeing your changes - a bit of a long shot, but you could be running into this issue. If that's the case, upgrading to a newer firmware version should help.

    Also, I assume you're using the espruino IDE to upload your changes to the watch? You might find it more convenient to clone the repository locally and test your changes using either apploader.js or a local server, as discussed in this thread.

  • @Humpelstilzchen I expect the configuration only to be done using min and max, as the code to set the minutes uses the same mechanism.

    Wrt gps time: that is nice, but does not work that well when you are inside and need a forced reboot.
    Wrt the app loader: great suggestion, I was unaware of that, thank you.

    @NebbishHacker I tried my changed settings on the phone by updating settings.js but that did not change things, not even after a reboot. It did not get stuck .
    I'm at the latest FW version (actually what was latest last Friday somewhere during the day).
    I'm indeed using the IDE, I was unaware of how to do that with apploader.js, thanks for the reference (and I did not really consider a local server but that is also definitely a possible path to pursue.

  • Wrt gps time: that is nice, but does not work that well when you are inside and need a forced reboot.

    It does - the GPS remembers the time regardless of whether it has signal or not. You just need to have got a GPS lock once, then you can reboot as many times as you want regardless of where you are and it'll update fine.

    I'm at the latest FW version

    Did you do 'install default apps' or 'remove all apps' after updating the firmware? If you were using the old firmware and the storage got corrupt then you'd still see the same issue until you cleared the storage and fixed it - it just won't happen again with the new firmware.

  • Btw is there a way to automatically set the time as soon as the watch gets a gps fix?

  • @Humpelstilzchen I think gps time does this?

    @Gordon I can confirm that after a reboot I got the gps time again. Maybe it was due to the firmware upgrade that it lost the time.

    I did not install default apps or so after the firmware update. Will do so later today and report back.
    Meanwhile, I'm still curious whether my original suggestion is sound (and whether you want a pull request for it).

  • I mean automatically, without any manual intervention. e.g. when using the gps recorder the clock does set the time without me having to press any additional buttons.

  • Btw is there a way to automatically set the time as soon as the watch gets a gps fix?

    There's the 'GPS Time' app that makes it easy - or you could just hold BTN1+BTN3 to reboot and it'll pull it in then...

    @FransM yes, wrapping time sounds like a great idea. Personally, I'd forget about min/max and do:

    'Hour': {
          value: d.getHours(),
          onchange: function(v) {
            this.value = (v+24)%24;
            d = new Date();
            d.setHours(this.value);
            setTime(d.getTime() / 1000);
          }
        },
    

    The (v+X)%X pattern is really neat - I'll have to use that in future.

    Having said all that, the current 'set time' menu looks very broken to me (time keeps moving the background but the menu doesn't!).

    For example if you set 12:59 and then wait a minute, then change the minutes again, the menu will show 12:59 but the time will be 13:59.

    I'll push a change in a few minutes with this fixed - and the wrapping added

  • @Gordon Thanks for the patch to add wrapping.
    Unfortunately there is one issue with it. You cannot select 31 as a date.
    Here's a pull request to fix that: https://github.com/espruino/BangleApps/pĀ­ull/490

    Actually it is possible to create invalid dates like Feb 30 or Jun 31 but I feel it is not really worth the effort to "fix" that. Introducing the number of days per month is easy but then come leap years, someone with a date like Jan 30, moving Jan to Feb (and 30 becomes invalid).
    My suggestion is not to bother about that.

    Edit: LOL you're quick, my pull request was already merged before I finished typing this message :-)

  • Thanks! Actually I think if you put an invalid date in, Espruino will just magically convert it to the next valid day, so it's no big deal.

  • There's the 'GPS Time' app that makes it easy - or you could just hold BTN1+BTN3 to reboot and it'll pull it in then...

    I will just code a widget then. It will update the Bangle time from GPS every time it has a valid fix.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

settings.js: wrap time

Posted by Avatar for FransM @FransM

Actions