support for mapping keyboard keys to buttons

fixed unneeded display redraw to speed up responsiveness
master
Sascha Nitsch 2022-03-20 20:58:15 +01:00
parent 3503e354e8
commit 988dd9b99b
5 changed files with 58 additions and 20 deletions

View File

@ -404,27 +404,29 @@ void CimditProfile::rotaryAction(uint8_t num, int8_t delta) {
} }
void CimditProfile::showActiveProfile() { void CimditProfile::showActiveProfile() {
if (m_displayState != DISPLAY_PROFILE) {
#ifdef HAVE_DISPLAY #ifdef HAVE_DISPLAY
if (m_customImage) { if (m_customImage) {
m_eepromPosition = m_customImage; m_eepromPosition = m_customImage;
for (uint8_t y = 0; y < SCREEN_HEIGHT; ++y) { for (uint8_t y = 0; y < SCREEN_HEIGHT; ++y) {
for (uint8_t x = 0; x < SCREEN_WIDTH; x += 8) { for (uint8_t x = 0; x < SCREEN_WIDTH; x += 8) {
uint8_t img = nextUInt8(); uint8_t img = nextUInt8();
for (uint8_t t = 0; t < 8; ++t) { for (uint8_t t = 0; t < 8; ++t) {
display.drawPixel(x + t, y, (img >> (7-t)) & 1); display.drawPixel(x + t, y, (img >> (7-t)) & 1);
}
} }
} }
} else {
printTextCentered(m_profiles[m_activeProfile]);
} }
} else {
printTextCentered(m_profiles[m_activeProfile]);
}
#else #else
Serial.println(m_profiles[m_activeProfile]); Serial.println(m_profiles[m_activeProfile]);
#endif #endif
m_displayState = DISPLAY_PROFILE; m_displayState = DISPLAY_PROFILE;
display.display();
}
m_stateTimeout = hal.m_millis + PROFILE_TIME; m_stateTimeout = hal.m_millis + PROFILE_TIME;
m_stateStarted = hal.m_millis; m_stateStarted = hal.m_millis;
display.display();
} }
void CimditProfile::showActivate() { void CimditProfile::showActivate() {
@ -593,7 +595,15 @@ void CimditProfile::buttonAction(uint8_t num, bool state) {
if (!state) if (!state)
scanOrExecuteMacro(m_mappedButtons[i].m_value, true); scanOrExecuteMacro(m_mappedButtons[i].m_value, true);
break; break;
default: case KEYBOARD_BUTTON:
if (state) {
Keyboard.press((KeyboardKeycode)m_mappedButtons[i].m_value);
} else {
Keyboard.release((KeyboardKeycode)m_mappedButtons[i].m_value);
}
break;
case MAPPING_NONE:
case JOYSTICK_AXIS:
break; break;
} }
} }

View File

@ -91,7 +91,9 @@ class CimditProfile {
/// macro key pressed /// macro key pressed
MACRO_PRESS, MACRO_PRESS,
/// macro key released /// macro key released
MACRO_RELEASE MACRO_RELEASE,
/// mapping as keyboard button
KEYBOARD_BUTTON,
}; };
/// enums for use in macros /// enums for use in macros

View File

@ -55,6 +55,11 @@
"source": 58, "source": 58,
"type": "MACRO_RELEASE", "type": "MACRO_RELEASE",
"macro": 5 "macro": 5
},
{
"source": 50,
"type": "KEYBOARD_BUTTON",
"target": "KEY_0"
} }
], ],
"mappedaxis": [ "mappedaxis": [

View File

@ -10,7 +10,7 @@ type ProfileJson = {
type EntityJson = { type EntityJson = {
source: number; source: number;
type: string; type: string;
target?: number; target?: number|string;
axis?: number; axis?: number;
value?: number; value?: number;
macro?: number; macro?: number;
@ -46,7 +46,8 @@ class ProfileGenerator {
"PREV_PROFILE", "PREV_PROFILE",
"SWITCH_PROFILE", "SWITCH_PROFILE",
"MACRO_PRESS", "MACRO_PRESS",
"MACRO_RELEASE" "MACRO_RELEASE",
"KEYBOARD_BUTTON",
]; ];
private macroEnum: Array<string> = [ private macroEnum: Array<string> = [
"MACRO_NULL", "MACRO_NULL",
@ -430,7 +431,11 @@ class ProfileGenerator {
var tmp = this.hexString(entity.source); var tmp = this.hexString(entity.source);
tmp += this.hexString(this.profileEnum.indexOf(entity.type)); tmp += this.hexString(this.profileEnum.indexOf(entity.type));
if (entity.target !== undefined) { if (entity.target !== undefined) {
tmp += this.hexString(entity.target); if (typeof(entity.target) === "number") {
tmp += this.hexString(<number>entity.target);
} else {
tmp += this.hexString(this.keyLookup[<string>entity.target]);
}
} else if (entity.axis !== undefined) { } else if (entity.axis !== undefined) {
tmp += this.hexString(entity.axis); tmp += this.hexString(entity.axis);
} else if (entity.value !== undefined) { } else if (entity.value !== undefined) {
@ -610,6 +615,8 @@ class ProfileGenerator {
var entity: EntityJson = {source: this.fromHexU(tokens.shift()), type: this.profileEnum[this.fromHexU(tokens.shift())]}; var entity: EntityJson = {source: this.fromHexU(tokens.shift()), type: this.profileEnum[this.fromHexU(tokens.shift())]};
if (entity.type === 'JOYSTICK_BUTTON' || entity.type === 'MOUSE_BUTTON') { if (entity.type === 'JOYSTICK_BUTTON' || entity.type === 'MOUSE_BUTTON') {
entity.target = this.fromHexU(tokens.shift()); entity.target = this.fromHexU(tokens.shift());
} else if (entity.type === 'KEYBOARD_BUTTON') {
entity.target = this.getKey(this.fromHexU(tokens.shift()));
} else if (entity.type === 'JOYSTICK_AXIS') { } else if (entity.type === 'JOYSTICK_AXIS') {
entity.axis = this.fromHexU(tokens.shift()); entity.axis = this.fromHexU(tokens.shift());
} else if (entity.type === 'MOUSE_REL_X_AXIS' || entity.type === 'MOUSE_REL_Y_AXIS' || entity.type === 'MOUSE_REL_WHEEL') { } else if (entity.type === 'MOUSE_REL_X_AXIS' || entity.type === 'MOUSE_REL_Y_AXIS' || entity.type === 'MOUSE_REL_WHEEL') {

View File

@ -55,6 +55,11 @@ textarea{width:100%}#string{height:5vh}.codeEditor,.lineCounter{font-family:cour
"source": 58, "source": 58,
"type": "MACRO_RELEASE", "type": "MACRO_RELEASE",
"macro": 5 "macro": 5
},
{
"source": 50,
"type": "KEYBOARD_BUTTON",
"target": "KEY_0"
} }
], ],
"mappedaxis": [ "mappedaxis": [
@ -220,7 +225,8 @@ var ProfileGenerator = (function () {
"PREV_PROFILE", "PREV_PROFILE",
"SWITCH_PROFILE", "SWITCH_PROFILE",
"MACRO_PRESS", "MACRO_PRESS",
"MACRO_RELEASE" "MACRO_RELEASE",
"KEYBOARD_BUTTON",
]; ];
this.macroEnum = [ this.macroEnum = [
"MACRO_NULL", "MACRO_NULL",
@ -598,7 +604,12 @@ var ProfileGenerator = (function () {
var tmp = this.hexString(entity.source); var tmp = this.hexString(entity.source);
tmp += this.hexString(this.profileEnum.indexOf(entity.type)); tmp += this.hexString(this.profileEnum.indexOf(entity.type));
if (entity.target !== undefined) { if (entity.target !== undefined) {
tmp += this.hexString(entity.target); if (typeof (entity.target) === "number") {
tmp += this.hexString(entity.target);
}
else {
tmp += this.hexString(this.keyLookup[entity.target]);
}
} }
else if (entity.axis !== undefined) { else if (entity.axis !== undefined) {
tmp += this.hexString(entity.axis); tmp += this.hexString(entity.axis);
@ -787,6 +798,9 @@ var ProfileGenerator = (function () {
if (entity.type === 'JOYSTICK_BUTTON' || entity.type === 'MOUSE_BUTTON') { if (entity.type === 'JOYSTICK_BUTTON' || entity.type === 'MOUSE_BUTTON') {
entity.target = this.fromHexU(tokens.shift()); entity.target = this.fromHexU(tokens.shift());
} }
else if (entity.type === 'KEYBOARD_BUTTON') {
entity.target = this.getKey(this.fromHexU(tokens.shift()));
}
else if (entity.type === 'JOYSTICK_AXIS') { else if (entity.type === 'JOYSTICK_AXIS') {
entity.axis = this.fromHexU(tokens.shift()); entity.axis = this.fromHexU(tokens.shift());
} }