Avatar for BrianB

BrianB

Member since Feb 2017 • Last active Mar 2017
  • 1 conversations
  • 2 comments

Most recent activity

  • in Puck.js
    Avatar for BrianB

    Here's the code:

    var controls = require("ble_hid_controls");
    NRF.setServices(undefined, { hid : controls.report });
    
    NRF.on('connect',()=>{
      digitalPulse(LED2,1,1000);
    });
    NRF.on('disconnect',()=>{
      digitalPulse(LED1,1,1000);
      NRF.connect();
      return;
    });
    
    var tempTimer = 0;
    var timerID = null;
    console.log("Battery : "+Puck.getBatteryPercentage()+"%");
    var init_mag = Puck.mag();
    var cur_mag,last_mag,IntervalID,offset_ang,v­olumeChanged;
    function cal_ang(xyz){
      xyz.x -= init_mag.x;
      xyz.y -= init_mag.y;
      xyz.z -= init_mag.z;
      return (Math.atan2(xyz.y, xyz.x) * 180) / Math.PI;
    }
    var cur_ang = cal_ang(Puck.mag());
    var last_ang = cur_ang;
    setWatch(function() {
       digitalWrite(LED3,1);
      start_mag();
    }, BTN, {edge:"rising", debounce:10, repeat:true});
    setWatch(function() {
      stop_mag();
      if(volumeChanged === null){
        onBtnTap();
      }
      all_lights_off();
    }, BTN, {edge:"falling", debounce:10, repeat:true});
    function start_mag(){
      volumeChanged = null;
      IntervalID = setInterval(function () {
        cur_ang = cal_ang(Puck.mag());
        offset_ang = cur_ang - last_ang;
        if(Math.abs(offset_ang) > 3 && Math.abs(offset_ang) <45){
          if(offset_ang < 0){
            console.log(" - :" + offset_ang);
            controls.volumeDown();
          }else{
            console.log(" + :" + offset_ang);
            controls.volumeUp();
          }
          last_ang = cur_ang;
          volumeChanged = 5;
          all_lights_off();
          digitalWrite(LED2,1);
        }else if(Math.abs(offset_ang) > 45){
          last_ang = cur_ang;
        }
      }, 500);
    }
    function stop_mag(){
      clearInterval(IntervalID);
    }
    function onBtnTap(){
      if(timerID !== null){
        clearTimeout(timerID);
      }
      tempTimer+=1;
      timerID = setTimeout(function () {  
        if(tempTimer == 1){
          controls.playpause();
        }else if(tempTimer == 2){
          controls.next();
          console.log("next");
        }else if(tempTimer >= 3){
          controls.prev();
          console.log("prev");
        }
        tempTimer = 0;
        timerID = null;
                              
      }, 500);
    }
    function all_lights_off(){
       digitalWrite(LED1,0);
       digitalWrite(LED2,0);
       digitalWrite(LED3,0);
    }
    
    //process.on('uncaughtException', function() {
    //  digitalWrite(LED1,1);
    //  load();
    //});
    

    After looking at lots of examples, I thought it should be put at the top. But perhaps that's the wrong place.

    Here's the full error I'm getting now:

    >BLE Connected, queueing BLE restart for later
    Battery : 100%
    =undefined
    Uncaught Error: BLE HID not enabled
     at line 1 col 55
    NRF.sendHIDReport(a,function(){NRF.sendH­IDReport(0,b)})
                                                          ^
    in function "b" called from line 1 col 6
    b(8,a)
         ^
    in function "playpause" called from line 72 col 26
          controls.playpause();
                             ^
    in function called from system
    > 
    
  • in Puck.js
    Avatar for BrianB

    I've been playing around with this for several weeks now, and I'm loving it!

    I'm just having one main problem: when I take the puck and walk out of range of the central device (my laptop), it auto-reconnects to the laptop's bluetooth when I get back into range but doesn't execute any of the commands I have written on button press. When I look at the console, it says

    Uncaught Error: BLE HID not enabled
    

    It's registering that it's connected, but doesn't allow me to do anything. I have to click "remove" on my computer's bluetooth menu, turn bluetooth off, then back on, then pair again through the Web IDE to get it to not get caught in the error.

    Any help understanding the error or fixing it would be great. (I've done extensive Googling to no avail.)

    Thanks!

Actions