You are reading a single comment by @storm64 and its replies. Click here to read the full conversation.
  • 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

About

Avatar for storm64 @storm64 started