Avatar for sp

sp

Member since Apr 2021 • Last active Jan 2023
  • 2 conversations
  • 21 comments

new programmer, interested in embedded systems and IOT

Most recent activity

    • 17 comments
    • 1,258 views
  • in Bangle.js
    Avatar for sp

    Tried BTN1, BTN both didn't work.
    How can I get a tiny text just next to the button that says RESET.

  • in Bangle.js
    Avatar for sp

    on Bangle.JS2 how can I add a button with label RESET to reset the maxZ value? I tried this code from the counter app but it doesn't work. I've added it after line 80.

    setWatch(() => {
       maxZ = 0;
       updateScreen();
     }, BTN2, {repeat:true});
    
  • in Bangle.js
    Avatar for sp

    Thanks guys. I noted on the AccelLog app there is a factor of 8192 used and here you have initialised maxZ = 10000.

  • in Bangle.js
    Avatar for sp

    many thanks @ganblejs

  • in Bangle.js
    Avatar for sp

    Right, well I get the dial but no hand and no value, here's my code below;

    var center = {
      x: g.getWidth()/2,
      y: g.getHeight()/2,
    };
    
    var MIN = 0;
    var MAX = 12;
    var NUMBER_OF_VALUES = MAX - MIN;
    var SCALE_TICK_STEP = 4;
    var SCALE_VALUES_STEP = 2;
    var NUMBER_OF_LABELS = NUMBER_OF_VALUES / SCALE_VALUES_STEP;
    var NUMBER_OF_TICKS = NUMBER_OF_VALUES / SCALE_TICK_STEP;
    var ZERO_OFFSET = (Math.PI / 4) * 3;
    var SCALE_SPAN = (Math.PI / 2) * 3;
    var TICK_LENGTH = 10;
    var HAND_LENGTH = 45;
    var HAND_WIDTH = 5;
    var maxZ = 0;
    
    function generatePoly(radius, width, angle){
      var x = center.x + Math.cos(angle) * radius;
      var y = center.y + Math.sin(angle) * radius;
      var d = {
        x: width/2 * Math.cos(angle + Math.PI/2),
        y: width/2 * Math.sin(angle + Math.PI/2),
      };
      
      var poly = [center.x - d.x, center.y - d.y, center.x + d.x, center.y + d.y, x + d.x, y + d.y, x - d.x, y - d.y];
      
      return poly;
    }
    
    function drawHand(value){
      g.setColor(g.theme.fg2);
      
      g.setFontAlign(0,0);
      g.setFont("Vector",24);
      g.drawString(value, center.x, center.y * 2 - 65, true);
    
      var angle = SCALE_SPAN / NUMBER_OF_VALUES * (value - MIN) + ZERO_OFFSET;
      g.fillPoly(generatePoly(HAND_LENGTH, HAND_WIDTH, angle), true);
      g.fillCircle(center.x ,center.y, 4);
    }
    
    
    function drawTicks(){
      g.setColor(g.theme.fg);
      for(let i= 0; i <= NUMBER_OF_TICKS; i++){
        var angle = (i * (SCALE_SPAN/NUMBER_OF_TICKS)) + ZERO_OFFSET;
    
        var tickWidth = i%5==0 ? 5 : 2;
        g.fillPoly(generatePoly(center.x, tickWidth, angle), true);
      }
      
      g.setColor(g.theme.bg);
      g.fillCircle(center.x,center.y,center.x - TICK_LENGTH);
    }
    
    
    function drawScaleLabels(){
      g.setColor(g.theme.fg);
      g.setFont("Vector",17);
    
      let label = MIN;
      for (let i=0;i <= NUMBER_OF_LABELS; i++){
        var angle = (i * (SCALE_SPAN/NUMBER_OF_LABELS)) + ZERO_OFFSET;
        var labelDimensions = g.stringMetrics(label);
    
        var LABEL_PADDING = 5;
        var radius = center.x - TICK_LENGTH - LABEL_PADDING;
        var x = center.x + Math.cos(angle) * radius;
        var y = center.y + Math.sin(angle) * radius;
    
        var visualX = x > center.x ? x - labelDimensions.width : x + labelDimensions.width > center.x ? x - (labelDimensions.width / 2) : x;
        var visualY = y >= center.y - labelDimensions.height / 2 ? y - labelDimensions.height / 2 : y;
    
        g.drawString(label, visualX, visualY);
    
        label += SCALE_VALUES_STEP;
      }
    }
    
    g.setBgColor(g.theme.bg);
    g.clear();
    
    drawTicks();
    drawScaleLabels();
    drawIcons();
    
    
    try {
     function accelHandler() {
      if (accel.z > maxZ) {
          maxZ = accel.z;
        }
        
        drawHand(Math.round(maxZ));
        layout.maxZ.label = maxZ;
       
      // layout.render();
      }
       Bangle.setPollInterval(80);
      Bangle.on('accel', accelHandler);
    
    
    } catch(e) {
      print(e.message);
       print("value exceeds limits");
      drawHand(MIN);
    }
    
  • in Bangle.js
    Avatar for sp

    Still no hand.

  • in Bangle.js
    Avatar for sp

    Still not getting it.

  • in Bangle.js
    Avatar for sp

    I've set the Min and Max values but still I'm not getting the value to display.
    Below is my modified code, what's wrong with this, there is no hand on display;

    try {
     function accelHandler(accel) {
      if (accel.z > maxZ) {
          maxZ = accel.z.toFixed(2);
        }
        
     
        drawHand(Math.round(accel.maxZ));
       layout.render();
      }
       Bangle.setPollInterval(80);
      Bangle.on('accel', accelHandler);
    
    
    } catch(e) {
      print(e.message);
       print("value exceeds limits");
        drawHand(MIN);
    }
    
  • in Bangle.js
    Avatar for sp

    Hey Gordan,
    If there is a Bangle3 in the works I would like to see more health sensors on board. Like the HR cum SpO2 sensor from Maxim + Body temperature sensor + any hydration solutions if possible.
    Spotify integration ??
    Any payments app??
    Messaging app integrations??
    Wireless charging??
    bigger screen smaller bezels,
    more smoother and nicer fonts,
    simpler way to place fonts on the screen and size them as per need,
    The Bangle2 is already a remarkable watch! Hats off. Anything more is definitely a bonus.
    Cheers!

Actions