Hi John,
I have taken the ble_shining_kb example sketch from the Examples -> Mbed BLE HID and cut it back to a very simple example. It will send a 'B' then '.' then a LEFT_ARROW. The result should end up producing BBBBB..... but the result I get is 'B.M' repeating, so 'B.MB.MB.MB.M' and so on. So my interpretation is that LEFT_ARROW is being interpreted as 'M'.
Note: I am using IDE 2.0.0 and I had to reduce the version of Arduino Mbed OS Nano Boards by Arduino (using the Boards Manager) from the current v3.4.1 to v3.0.1 in order to get it to pair properly. I don't know why, but with the newer board profile it will not pair properly to my iOS or MacOS devices.
Also, I find the LEFT_ARROW declared in HIDKeyboardService.h and I don't exactly understand the declaration. I will include my code and the LEFT_ARROW code below.
First, my small example as mentioned above:
#include "Nano33BleHID.h"
#include "signal_utils.h"
unsigned long beginOfDelay = 0;
Nano33BleKeyboard bleKb("Shining Keyboard");
void setup()
{
// General setup.
// Initialize both BLE and the HID.
bleKb.initialize();
// Launch the event queue that will manage both BLE events and the loop.
// After this call the main thread will be halted.
MbedBleHID_RunEventThread();
}
void loop()
{
if (!bleKb.connected()) {
return;
}
if (millis()>beginOfDelay+1000) {
// Retrieve the HIDService to update.
auto *kb = bleKb.hid();
kb->sendCharacter('B');
kb->sendCharacter('.');
kb->sendCharacter(LEFT_ARROW);
beginOfDelay = millis();
}
}
Second, the declaration of LEFT_ARROW. I included all of the code from the HIDKeyboardService.h in case you see something that will help.
#ifndef BLE_HID_KEYBOARD_SERVICE_H__
#define BLE_HID_KEYBOARD_SERVICE_H__
#if BLE_FEATURE_GATT_SERVER
#include "services/HIDService.h"
/* -------------------------------------------------------------------------- */
/* Ascii index of special function char. */
enum FunctionKeyChar_t {
KEY_F1 = 128, /* F1 key */
KEY_F2, /* F2 key */
KEY_F3, /* F3 key */
KEY_F4, /* F4 key */
KEY_F5, /* F5 key */
KEY_F6, /* F6 key */
KEY_F7, /* F7 key */
KEY_F8, /* F8 key */
KEY_F9, /* F9 key */
KEY_F10, /* F10 key */
KEY_F11, /* F11 key */
KEY_F12, /* F12 key */
KEY_PRINT_SCREEN, /* Print Screen key */
KEY_SCROLL_LOCK, /* Scroll lock */
KEY_CAPS_LOCK, /* caps lock */
KEY_NUM_LOCK, /* num lock */
KEY_INSERT, /* Insert key */
KEY_HOME, /* Home key */
KEY_PAGE_UP, /* Page Up key */
KEY_PAGE_DOWN, /* Page Down key */
RIGHT_ARROW, /* Right arrow */
LEFT_ARROW, /* Left arrow */
DOWN_ARROW, /* Down arrow */
UP_ARROW, /* Up arrow */
};
typedef uint16_t KeyCode_t;
/* Represent a key that could be sent by the HID. */
struct KeySym_t {
enum Modifier {
KEY_NONE = 0,
KEY_CTRL = 1 << 0,
KEY_SHIFT = 1 << 1,
KEY_ALT = 1 << 2,
};
/* Construct a Keysym directly by raw values. */
KeySym_t(uint8_t _usage, uint8_t _modifiers)
: usage(_usage)
, modifiers(_modifiers)
{}
/* Construct a Keysym from a specific keycode. */
explicit KeySym_t(KeyCode_t _keycode);
uint8_t usage;
uint8_t modifiers;
};
/**
* BLE HID Keyboard Service
*
* @par usage
*
* When this class is instantiated, it adds a keyboard HID service in
* the GattServer.
*
* @attention Multiple instances of this hid service are not supported.
* @see HIDService
*/
class HIDKeyboardService : public HIDService {
public:
HIDKeyboardService(BLE &_ble);
ble::adv_data_appearance_t appearance() const override {
return ble::adv_data_appearance_t::KEYBOARD;
}
/* Return the KeySym for a specific character. */
KeySym_t charToKeySym(unsigned char c) const;
/* Send a press & release report for a single character. */
void sendCharacter(unsigned char c);
/* Register a down report for the specific keysym. */
void keydown(KeySym_t keysym);
/* Register a release report. */
void keyup();
};
/* -------------------------------------------------------------------------- */
#endif // BLE_FEATURE_GATT_SERVER
#endif // BLE_HID_KEYBOARD_SERVICE_H__
Thanks again.
Regards,
Bob