Skip to content

Commit

Permalink
added keycodes supported by BlueMicri firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
jpconstantineau committed Jan 21, 2023
1 parent cc16174 commit dc129b1
Show file tree
Hide file tree
Showing 5 changed files with 700 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=bluemicro_hid
version=0.0.7
version=0.0.9
author=Pierre Constantineau <[email protected]>
maintainer=Pierre Constantineau <[email protected]>
sentence=Creates a unified facade to both TinyUSB and nRF52 BlueFruit HID interfaces.
Expand Down
62 changes: 62 additions & 0 deletions src/bluemicro_hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,65 @@
;
#endif
#endif

static std::vector<uint8_t> reportvector;

/**************************************************************************************************************************/
trigger_keycodes_t sendKeys(trigger_keycodes_t activeKeycodes)
{
// Serial.println("S");
static bool has_key = false; // must be static to remember previous state
if ( activeKeycodes.empty() )
{
// send empty key report if previously has key pressed
if (has_key)
{
bluemicro_hid.keyboardRelease();
has_key = false;
}
}
else
{
has_key = true;
uint8_t currentMod = 0;
for (auto keycode : activeKeycodes)
{
auto hidKeycode = static_cast<uint8_t>(keycode & 0x00FF);
auto extraModifiers = static_cast<uint8_t>((keycode & 0xFF00) >> 8);

if (hidKeycode >= KC_A && hidKeycode <= KC_EXSEL)
{
// add hidKeycode to report vector
reportvector.push_back(hidKeycode);
}
//check if the hid keycode contains a modifier. // also check for macros.
switch (hidKeycode) {
case KC_LCTRL: currentMod |= 1; currentMod |= extraModifiers; break;
case KC_LSHIFT: currentMod |= 2; currentMod |= extraModifiers; break;
case KC_LALT: currentMod |= 4; currentMod |= extraModifiers; break;
case KC_LGUI: currentMod |= 8; currentMod |= extraModifiers; break;
case KC_RCTRL: currentMod |= 16; currentMod |= extraModifiers; break;
case KC_RSHIFT: currentMod |= 32; currentMod |= extraModifiers; break;
case KC_RALT: currentMod |= 64; currentMod |= extraModifiers; break;
case KC_RGUI: currentMod |= 128; currentMod |= extraModifiers; break;
}
//add all of the extra modifiers into the curren modifier
currentMod |= extraModifiers;
}

uint8_t keycode[6] = { 0 };
uint8_t keycodeposition = 0;
for (auto thiskeycode : reportvector)
{
if (keycodeposition<6)
{
keycode[keycodeposition] = thiskeycode;
}
keycodeposition++;
}
bluemicro_hid.keyboardReport(currentMod, keycode);
activeKeycodes.clear();
reportvector.clear();
}
return activeKeycodes;
}
5 changes: 5 additions & 0 deletions src/bluemicro_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include "bluetooth.h"
#include "usb.h"
#include "hid_queues.h"
#include "hid_keycodes.h"
extern HID_Queues bluemicro_hid;

typedef std::vector <uint16_t> trigger_keycodes_t;
typedef std::vector <uint8_t> trigger_keys_t;
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes);
trigger_keycodes_t sendKeys(trigger_keycodes_t activeKeycodes);
#endif
Loading

0 comments on commit dc129b1

Please sign in to comment.