Detect charging or on wrist

Posted on
  • Is it possible to detect whether a bangle.js2 is either on charge or (preferably) not on a wrist? If so I want to look in to possibly creating an app to silence the vibration/notification in those circumstances. I've tried a search using the obvious terms and cannot find anything that already exists.

  • For charging there is Bangle.isCharging.
    "Not on a wrist" is tricky, but I guess you could use the accelerometer and check if there is no movement for a certain period. Maybe even check for x and y being zero if you always place it face up/down.

  • Checking heart rate could work?

  • Thanks. I like the "face down" tip. That looks like it may be what I'm looking for.

  • I installed the SleepLog app yesterday, that says it uses the internal temperature sensor to help identify if it's on a wrist, there might be something in that app you could reuse rather than start from scratch.

  • Ta. That could work for removal, but I was also hoping to pause heartrate monitoring when removed as well as silencing. Perhaps a hybrid approach might work, with movement/orientation switching is back to "being worn" mode. All good food for thought...

  • Great - I'll take a look. I also saw an app that scheduled silent times, so I was going to look at the code for that as well to see what I could "borrow".

  • You could use movement from http://www.espruino.com/Reference#l_Bang­le_getHealthStatus to detect if the Bangle is moving around at all, and also the HRM-raw event that comes from the HRM on Bangle.js 2 has a field for whether it thinks the Bangle is being worn (eg if something is close to the HRM) - but if the Bangle is on a table then it could still be fooled.

  • Ta - I'll look into the HRM event as well. Lots of options to research!

  • Maybe I have something that suits your needs:
    I wrote a little helper function to get only the isWearing value from HRM-raw.

    Here a little example:

        checkIsWearing(
          (isWearingStatus, messages) => { print(messages[isWearingStatus ? 1 : 0]); },
          [
            "You are not wearing the watch.",
            "Yor watch is on your wrist or on a surface that appears similar."
          ]
        );
    

    The return function is called with the isWearing-status as first and the passed data as second argument: returnFn(isWearing, data);

    Here the code of this function:

        // define function to check if the bangle is worn by using the hrm
        function checkIsWearing(returnFn, data) {
          // create a temporary object to store data and functions
          global.tmpWearingCheck = {
            // define temporary hrm listener function to read the wearing status
            hrmListener: hrm => tmpWearingCheck.isWearing = hrm.isWearing,
            // set default wearing status
            isWearing: false,
          };
     
          // enable HRM
          Bangle.setHRMPower(true, "wearingCheck");
          // wait until HRM is initialised
          setTimeout((returnFn, data) => {
            // add HRM listener
            Bangle.on('HRM-raw', tmpWearingCheck.hrmListener);
            // wait for two cycles (HRM working on 60Hz)
            setTimeout((returnFn, data) => {
              // remove listener and disable HRM
              Bangle.removeListener('HRM-raw', tmpWearingCheck.hrmListener);
              Bangle.setHRMPower(false, "wearingCheck");
              // cache wearing status
              var isWearing = tmpWearingCheck.isWearing;
              // clear temporary object
              delete global.tmpWearingCheck;
              // call return function with status
              returnFn(isWearing, data);
            }, 34, returnFn, data);
          }, 2500, returnFn, data);
        }
    

    I am using this in the 0.10+ version of sleeplog:
    https://github.com/storm64/BangleApps/bl­ob/sleeplog_beta/apps/sleeplog/boot.js

  • If you want another example of the thermometer-solution, it's implemented in the app 'Activity Reminder'.

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

Detect charging or on wrist

Posted by Avatar for user143355 @user143355

Actions