Avatar for Michaelnik

Michaelnik

Member since Mar 2020 • Last active Aug 2020
  • 6 conversations
  • 15 comments

Most recent activity

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Michaelnik

    That linked-above DSP310 would require smaller breakout board to fit...

    Ar there any sensor benchmarking sites? All those folks eval chips individually...

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Michaelnik

    I have idea of a project: I would like to measure elevation change in air... with good precision <=.5m.

    Espruino supports MS5803 which seems ok sensor compared but I understand it has only.2 mbar so ~1.5m air max precision. Is that right? Bosh's sensors BMP3xx seem to be doing better.... .5m (the newest 2020 chip is even more precise but I see no breakouts available). Should I hack C for this and add Js API code for BMP3xx?

    The another problem is need to proof the puck for wet env (not underwater but strong splash). Silicon on top is great but how to seal the whole? I could ziplock (plastic bag it) but that is a bit lame. Any ideas?

    Which form factor? Does the orange breakout off ebay like this https://github.com/sparkfun/SparkFun_MS5­803-14BA_Breakout_Arduino_Library fit?

    What precision could I expect? could I do 5-10Hz? Are there any problems with float calcs? https://lukemiller.org/index.php/2014/04­/arduino-code-for-ms5803-pressure-sensor­s/

  • in JavaScript
    Avatar for Michaelnik

    I want to display consistent:

    • current time in currently configured TZ and
    • current time UTC (or any other TZ)
      on current vertical clock (instead Steps which is not working anyway).

    The below works in emu (to show current tz and UTC) but only for the short time using E approach (but what if to new Date() calls span the minute...i.e one is in prev minute, other is in the next?).

    For the second approach the added value would be 0 for UTC but it does not work....

    require("Font8x12").add(Graphics);
    let HRMstate = false;
    let currentHRM = "CALC";
    
    
    function drawTimeDate() {
      var d = new Date();
      var h = d.getHours(), m = d.getMinutes(), day = d.getDate(), month = d.getMonth(), weekDay = d.getDay();
    
      var daysOfWeek = ["SUN", "MON", "TUE","WED","THU","FRI","SAT"];
      var hours = (" "+h).substr(-2);
      var mins= ("0"+m).substr(-2);
      var date = `${daysOfWeek[weekDay]}|${day}|${("0"+(m­onth+1)).substr(-2)}`;
    
    
      // Reset the state of the graphics library
      g.reset();
      // Set color
      g.setColor('#2ecc71');
      // draw the current time (4x size 7 segment)
      g.setFont("8x12",9);
      g.setFontAlign(-1,0); // align right bottom
      g.drawString(hours, 25, 65, true /*clear background*/);
      g.drawString(mins, 25, 155, true /*clear background*/);
    
      // draw the date (2x size 7 segment)
      g.setFont("6x8",2);
      g.setFontAlign(-1,0); // align right bottom
      g.drawString(date, 20, 215, true /*clear background*/);
      
      drawOtherTimezone(d, 0);
    }
    
    
    //We will create custom "Widgets" for our face.
    
    function drawOtherTimezone(d, tzOffset) {
      //Reset to defaults.
      g.reset();
      
      // calculate the other tz date
      var currentTz = d.getTimezoneOffset(); // -6 for me now in emu
      E.setTimeZone(tzOffset);
      var d2 = new Date();
      E.setTimeZone(currentTz); // return to default
      
      /*
      var d2 = new Date(d2+tzOffset*3600000);
      */
    
      var h = d2.getHours(), m = d2.getMinutes(), day = d2.getDate(), month = d2.getMonth(), weekDay = d2.getDay();
      var hoursMins = (" "+h).substr(-2)+":"+("0"+m).substr(-2);
    
      // draw the other tz date
      g.setColor('#7f8c8d');
      g.setFont("8x12",2);
      g.setFontAlign(-1,0); // align right bottom
      g.drawString("UTC+"+tzOffset, 145, 40, true /*clear background*/);
      g.setColor('#bdc3c7');
      g.drawString(hoursMins, 145, 65, true /*clear background*/);
    }
    
    function drawBPM(on) {
      //Reset to defaults.
      g.reset();
      g.setColor('#7f8c8d');
      g.setFont("8x12",2);
      g.setFontAlign(-1,0);
      var heartRate = 0;
    
      if(on){
        g.drawString("BPM", 145, 105, true);
        g.setColor('#e74c3c');
        g.drawString("*", 190, 105, false);
        g.setColor('#bdc3c7');
        //Showing current heartrate reading.
        heartRate = currentHRM.toString() + "    ";
        return g.drawString(heartRate, 145, 130, true /*clear background*/);
      } else {
        g.drawString("BPM  ", 145, 105, true /*clear background*/);
        g.setColor('#bdc3c7');
        return g.drawString("-    ", 145, 130, true); //Padding
      }
    }
    
    function drawBattery() {
      let charge = E.getBattery();
      //Reset to defaults.
      g.reset();
      // draw the date (2x size 7 segment)
      g.setColor('#7f8c8d');
      g.setFont("8x12",2);
      g.setFontAlign(-1,0); // align right bottom
      g.drawString("CHARGE", 145, 170, true /*clear background*/);
      g.setColor('#bdc3c7');
      g.drawString(`${charge}%`, 145, 195, true /*clear background*/);
    }
    
    
    // Clear the screen once, at startup
    g.clear();
    
    // draw immediately at first
    drawTimeDate();
    drawBPM();
    drawBattery();
    
    var secondInterval = setInterval(()=>{
      drawTimeDate();
    }, 15000);
    
    // Stop updates when LCD is off, restart when on
    Bangle.on('lcdPower',on=>{
      if (on) {
        secondInterval = setInterval(()=>{
          drawTimeDate();
        }, 15000);
        //Screen on
        drawBPM(HRMstate);
        drawTimeDate();
        drawBattery();
      } else {
        //Screen off
        clearInterval(secondInterval);
      }
    });
    
    // Show launcher when middle button pressed
    setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
    
    Bangle.on('touch', function(button) {
      if(button == 1 || button == 2){
        Bangle.showLauncher();
      }
    });
    
    //HRM Controller.
    setWatch(function(){
      if(!HRMstate){
        console.log("Toggled HRM");
        //Turn on.
        Bangle.buzz();
        Bangle.setHRMPower(1);
        currentHRM = "CALC";
        HRMstate = true;
      } else if(HRMstate){
        console.log("Toggled HRM");
        //Turn off.
        Bangle.buzz();
        Bangle.setHRMPower(0);
        HRMstate = false;
        currentHRM = [];
      }
      drawBPM(HRMstate);
    }, BTN1, { repeat: true, edge: "falling" });
    
    Bangle.on('HRM', function(hrm) {
      if(hrm.confidence > 90){
        /*Do more research to determine effect algorithm for heartrate average.*/
        console.log(hrm.bpm);
        currentHRM = hrm.bpm;
        drawBPM(HRMstate);
      }
    });
    
    
    //Bangle.on('step', function(up) {
    //  console.log("Step");
    //});
    
    
  • in JavaScript
    Avatar for Michaelnik

    Hmm, in emulator I get

    >Uncaught Error: Function "getTimezoneOffset" not found!
     at line 41 col 21
          var tz = Date.getTimezoneOffset();
                        ^
    

    Another problem I run into changing timezone in E and resetting is to pull another Date is I have to pull Date 2 times and the minutes could be off (59 in one, 00 in other)....

  • in JavaScript
    Avatar for Michaelnik

    This lib looks quite sane https://momentjs.com/timezone/ (MIT license). Is there a way to include something like that?

    // hypothetical conversion for display of current time in different timezone
    var now = moment(Date().toISOString())
    now.tz('America/Los_Angeles').format('ha­ z');  // 5am PDT
    

    For me js is still mystery so no idea where .format() in the above comes from...

  • in JavaScript
    Avatar for Michaelnik

    I wanted to add clock in a different tz (on bangle.js). I looked at Date() and it has no API to obtain Date in custom tz, is that right?

    Timezones could also be useful for setting clock offset which is now an unfriendly number.

    M

  • in Bangle.js
    Avatar for Michaelnik

    Hello!
    TLDR: Is Flag Raiser app supposed to work with the Puck v2?

    I got Web BT working with my Puck.js v2 (i.e send LED on/off code when clicking on buttons in Chromium).

    I would like to do the same from Bangle.js so I picked Flag Raiser app to modify it (it was doing nothing to the puck).

    I looked at Web BT puck.js library and it seems to have different service GUIDS
    var NORDIC_SERVICE = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
    var NORDIC_TX = "6e400002-b5a3-f393-e0a9-e50e24dcca9e";
    var NORDIC_RX = "6e400003-b5a3-f393-e0a9-e50e24dcca9e";
    but when I change Flag Raiser code and use the new address then

    Uncaught Error: Function "" not found!
     at line 17 col 611
    ...Done!");busy=false;redraw();}).catch(­function(e){console.log("ERROR",e);bus..­.
                                                 ^
    in function called from system
    Uncaught Error: Unhandled promise rejection: No device found matching filters
    >
    

    What does that mean? Tips? Suggestions?
    M

Actions