• Sorry for this newbie question, first day playing with this.
    Everything is latest. Have EspruinoHub started in systemctl.
    I can connect to the raspberrypi EspruinoHub ide, connect to Puck and upload code.
    Puck firmware 2v00
    Found some code in tutorials and hacked it together. All I want to achieve is to have a button press result in a keyboard type the letter p

    After sending the code I disconnect and reconnect
    Click on the puck and console says

    Uncaught Error: Got BLE error 0x8 (INVALID_STATE)
     at line 1 col 104
    ...0,0,0],function(){a&&a()})})
                                  ^
    in function "tap" called from line 6 col 36
        kb.tap(kb.KEY.P, 0,function(){});
    
    in function called from system
    >
    

    If I click the puck again I get

    Click 2
    

    Here is the full code:

    
    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    var clickcount = 0;
    var clickevent = null;
    
    
    setWatch((e) => {
      clickcount++;
      if (clickevent !== null) clearTimeout(clickevent);
    
      if (clickcount === 1) {
        setLEDS(false, true, false);
        kb.tap(kb.KEY.P, 0,function(){});
      } else if (clickcount === 2) {
        setLEDS(true, false, false);
        //kb.tap(kb.KEY.Z, 0);
      } else if (clickcount === 3) {
        setLEDS(false, false, true);
        //kb.tap(kb.KEY.S, 0);
      } else {
        setLEDS(true, true, true);
      }
    
      clickevent = setTimeout(() => {
        if (clickcount === 1) {
          console.log("Click 1");
        } else if (clickcount === 2) {
          console.log("Click 2");
    
        } else if (clickcount === 3) {
          console.log("Click 3");
    
        }
    
        clickcount = 0;
      }, 350);
    }, BTN, {
      edge: "rising",
      debounce: 50,
      repeat: true
    });
    
    setWatch((e) => {
      setLEDS(false, false, false);
      setTimeout(() => {
        clickevent = null;
      }, 400);
    }, BTN, {
      edge: "falling",
      debounce: 50,
      repeat: true
    });
    
    const setLEDS = (LED1on, LED2on, LED3on) => {
      LED1.reset();
      LED2.reset();
      LED3.reset();
    
      if (LED1on) LED1.set();
      if (LED2on) LED2.set();
      if (LED3on) LED3.set();
    };
    
    

    Thank you for helping me. I'm totally confused.

About

Avatar for user95552 @user95552 started