-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added functions for handling matrices and layers
- Loading branch information
1 parent
ef4dfab
commit 94d0144
Showing
5 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=bluemicro_hid | ||
version=0.0.10 | ||
version=0.0.11 | ||
author=Pierre Constantineau <[email protected]> | ||
maintainer=Pierre Constantineau <[email protected]> | ||
sentence=Creates a unified facade to both TinyUSB and nRF52 BlueFruit HID interfaces. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-FileCopyrightText: 2022-2023 BlueMicro_HID_Arduino_Library contributors (https://github.com/jpconstantineau/BlueMicro_HID_Arduino_Library/graphs/contributors) | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include "hid_functions.h" | ||
|
||
/**************************************************************************************************************************/ | ||
// Standard Layer mapping Function | ||
// conforms to addlayer_cb_t | ||
/**************************************************************************************************************************/ | ||
uint8_t AddLayers(uint8_t layer, uint16_t keycode) { | ||
uint8_t keyValue = static_cast<uint8_t>(keycode & 0x00FF); | ||
if (keyValue >= LAYER_0 && keyValue <= LAYER_F) | ||
{ | ||
//layer = layer | (1 << (keyValue - 0xF0)) ; // this is a mask | ||
layer = layer + (keyValue - LAYER_0) ; // this is a number | ||
} | ||
return layer; | ||
} | ||
|
||
/**************************************************************************************************************************/ | ||
// Standard Matrix mapping Function | ||
// conforms to getkeycode_cb_t | ||
/**************************************************************************************************************************/ | ||
uint16_t getKeycode(uint16_t pressedkey, uint8_t layer) | ||
{ | ||
return ((pressedkey + layer * matrixsize)<keymapsize) ? keymap[pressedkey + layer * matrixsize] : 0; | ||
} | ||
|
||
/**************************************************************************************************************************/ | ||
// Process Keys with Layers entered - custom matrix mapping | ||
/**************************************************************************************************************************/ | ||
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes, getkeycode_cb_t getKeycodefn, uint8_t layer) | ||
{ | ||
//std::transform Needs #include <algorithm> | ||
std::transform(activeKeys.cbegin(), activeKeys.cend(), std::back_inserter(activeKeycodes), | ||
[layer, getKeycodefn](uint16_t pressedkey) {return getKeycodefn(pressedkey, layer);} ); | ||
return activeKeycodes; | ||
} | ||
/**************************************************************************************************************************/ | ||
// Process Keys with No Layers entered - custom matrix mapping | ||
/**************************************************************************************************************************/ | ||
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes, getkeycode_cb_t getKeycodefn) | ||
{ | ||
uint8_t layer = 0; | ||
return processKeys(activeKeys, activeKeycodes, getKeycodefn, layer); | ||
} | ||
/**************************************************************************************************************************/ | ||
// Process Keys with default matrix mapping - Layer entered | ||
/**************************************************************************************************************************/ | ||
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes, uint8_t layer) | ||
{ | ||
return processKeys(activeKeys, activeKeycodes, getKeycode, layer); | ||
} | ||
/**************************************************************************************************************************/ | ||
// Process Keys with No Layers entered - default matrix mapping | ||
/**************************************************************************************************************************/ | ||
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes) | ||
{ | ||
uint8_t layer = 0; | ||
return processKeys(activeKeys, activeKeycodes, getKeycode, layer); | ||
} | ||
|
||
/**************************************************************************************************************************/ | ||
// get Layer from pressed keys - custom matrix mapping - Custom Layer mapping | ||
/**************************************************************************************************************************/ | ||
uint8_t getLayer(trigger_keys_t activeKeys, addlayer_cb_t AddLayersFn, getkeycode_cb_t getKeycodefn) | ||
{ | ||
trigger_keycodes_t triggerKeys; | ||
triggerKeys = processKeys(activeKeys,triggerKeys,getKeycodefn); // get keycodes for layer 0 | ||
// std::accumulate needs #include <numeric> | ||
return std::accumulate(triggerKeys.begin(), triggerKeys.end(), 0, AddLayersFn); | ||
} | ||
|
||
/**************************************************************************************************************************/ | ||
// get Layer from pressed keys - Standard matrix mapping - Custom Layer mapping | ||
/**************************************************************************************************************************/ | ||
uint8_t getLayer(trigger_keys_t activeKeys, addlayer_cb_t AddLayersFn) | ||
{ | ||
return getLayer(activeKeys, AddLayersFn, getKeycode); | ||
} | ||
|
||
/**************************************************************************************************************************/ | ||
// get Layer from pressed keys - custom matrix mapping - Standard Layer mapping | ||
/**************************************************************************************************************************/ | ||
uint8_t getLayer(trigger_keys_t activeKeys, getkeycode_cb_t getKeycodefn) | ||
{ | ||
return getLayer(activeKeys, AddLayers, getKeycodefn); | ||
} | ||
|
||
/**************************************************************************************************************************/ | ||
// get Layer from pressed keys - Standard matrix mapping - Standard Layer mapping | ||
/**************************************************************************************************************************/ | ||
uint8_t getLayer(trigger_keys_t activeKeys) | ||
{ | ||
return getLayer(activeKeys, AddLayers, getKeycode); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-FileCopyrightText: 2022-2023 BlueMicro_HID_Arduino_Library contributors (https://github.com/jpconstantineau/BlueMicro_HID_Arduino_Library/graphs/contributors) | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#ifndef HID_FUNCTIONS_H | ||
#define HID_FUNCTIONS_H | ||
#include <cstdint> | ||
#include <vector> | ||
#include <numeric> | ||
#include <algorithm> | ||
#include "hid_types.h" | ||
#include "hid_keycodes.h" | ||
#include "hid_utils.h" | ||
|
||
extern uint16_t keymap[] ; | ||
const extern uint16_t matrixsize; | ||
const extern uint16_t keymapsize; | ||
|
||
|
||
// Standard Mapping Functions | ||
uint8_t AddLayers(uint8_t layer, uint16_t keycode); | ||
uint16_t getKeycode(uint16_t pressedkey, uint8_t layer); | ||
|
||
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes, getkeycode_cb_t getKeycodefn, uint8_t layer); | ||
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes, getkeycode_cb_t getKeycodefn); | ||
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes, uint8_t layer); | ||
trigger_keycodes_t processKeys(trigger_keys_t activeKeys, trigger_keycodes_t activeKeycodes); | ||
|
||
uint8_t getLayer(trigger_keys_t activeKeys, addlayer_cb_t AddLayersFn, getkeycode_cb_t getKeycodefn); | ||
uint8_t getLayer(trigger_keys_t activeKeys, addlayer_cb_t AddLayersFn); | ||
uint8_t getLayer(trigger_keys_t activeKeys, getkeycode_cb_t getKeycodefn); | ||
uint8_t getLayer(trigger_keys_t activeKeys); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
// SPDX-FileCopyrightText: 2022-2023 BlueMicro_HID_Arduino_Library contributors (https://github.com/jpconstantineau/BlueMicro_HID_Arduino_Library/graphs/contributors) | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#ifndef HID_TYPES_H | ||
#define HID_TYPES_H | ||
|
||
typedef std::vector <uint16_t> trigger_keycodes_t; | ||
typedef std::vector <uint8_t> trigger_keys_t; | ||
|
||
// TypeDefs for mapping functions | ||
typedef uint8_t (*addlayer_cb_t)(uint8_t layer, uint16_t keycode); | ||
typedef uint16_t (*getkeycode_cb_t)(uint16_t pressedkey, uint8_t layer); | ||
|
||
#endif |