support for mapping keyboard keys to buttons
fixed unneeded display redraw to speed up responsiveness
This commit is contained in:
parent
3503e354e8
commit
988dd9b99b
5 changed files with 58 additions and 20 deletions
|
@ -404,27 +404,29 @@ void CimditProfile::rotaryAction(uint8_t num, int8_t delta) {
|
|||
}
|
||||
|
||||
void CimditProfile::showActiveProfile() {
|
||||
if (m_displayState != DISPLAY_PROFILE) {
|
||||
#ifdef HAVE_DISPLAY
|
||||
if (m_customImage) {
|
||||
m_eepromPosition = m_customImage;
|
||||
for (uint8_t y = 0; y < SCREEN_HEIGHT; ++y) {
|
||||
for (uint8_t x = 0; x < SCREEN_WIDTH; x += 8) {
|
||||
uint8_t img = nextUInt8();
|
||||
for (uint8_t t = 0; t < 8; ++t) {
|
||||
display.drawPixel(x + t, y, (img >> (7-t)) & 1);
|
||||
if (m_customImage) {
|
||||
m_eepromPosition = m_customImage;
|
||||
for (uint8_t y = 0; y < SCREEN_HEIGHT; ++y) {
|
||||
for (uint8_t x = 0; x < SCREEN_WIDTH; x += 8) {
|
||||
uint8_t img = nextUInt8();
|
||||
for (uint8_t t = 0; t < 8; ++t) {
|
||||
display.drawPixel(x + t, y, (img >> (7-t)) & 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printTextCentered(m_profiles[m_activeProfile]);
|
||||
}
|
||||
} else {
|
||||
printTextCentered(m_profiles[m_activeProfile]);
|
||||
}
|
||||
#else
|
||||
Serial.println(m_profiles[m_activeProfile]);
|
||||
Serial.println(m_profiles[m_activeProfile]);
|
||||
#endif
|
||||
m_displayState = DISPLAY_PROFILE;
|
||||
m_displayState = DISPLAY_PROFILE;
|
||||
display.display();
|
||||
}
|
||||
m_stateTimeout = hal.m_millis + PROFILE_TIME;
|
||||
m_stateStarted = hal.m_millis;
|
||||
display.display();
|
||||
}
|
||||
|
||||
void CimditProfile::showActivate() {
|
||||
|
@ -593,7 +595,15 @@ void CimditProfile::buttonAction(uint8_t num, bool state) {
|
|||
if (!state)
|
||||
scanOrExecuteMacro(m_mappedButtons[i].m_value, true);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,9 @@ class CimditProfile {
|
|||
/// macro key pressed
|
||||
MACRO_PRESS,
|
||||
/// macro key released
|
||||
MACRO_RELEASE
|
||||
MACRO_RELEASE,
|
||||
/// mapping as keyboard button
|
||||
KEYBOARD_BUTTON,
|
||||
};
|
||||
|
||||
/// enums for use in macros
|
||||
|
|
|
@ -55,6 +55,11 @@
|
|||
"source": 58,
|
||||
"type": "MACRO_RELEASE",
|
||||
"macro": 5
|
||||
},
|
||||
{
|
||||
"source": 50,
|
||||
"type": "KEYBOARD_BUTTON",
|
||||
"target": "KEY_0"
|
||||
}
|
||||
],
|
||||
"mappedaxis": [
|
||||
|
|
|
@ -10,7 +10,7 @@ type ProfileJson = {
|
|||
type EntityJson = {
|
||||
source: number;
|
||||
type: string;
|
||||
target?: number;
|
||||
target?: number|string;
|
||||
axis?: number;
|
||||
value?: number;
|
||||
macro?: number;
|
||||
|
@ -46,7 +46,8 @@ class ProfileGenerator {
|
|||
"PREV_PROFILE",
|
||||
"SWITCH_PROFILE",
|
||||
"MACRO_PRESS",
|
||||
"MACRO_RELEASE"
|
||||
"MACRO_RELEASE",
|
||||
"KEYBOARD_BUTTON",
|
||||
];
|
||||
private macroEnum: Array<string> = [
|
||||
"MACRO_NULL",
|
||||
|
@ -430,7 +431,11 @@ class ProfileGenerator {
|
|||
var tmp = this.hexString(entity.source);
|
||||
tmp += this.hexString(this.profileEnum.indexOf(entity.type));
|
||||
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) {
|
||||
tmp += this.hexString(entity.axis);
|
||||
} 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())]};
|
||||
if (entity.type === 'JOYSTICK_BUTTON' || entity.type === 'MOUSE_BUTTON') {
|
||||
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') {
|
||||
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') {
|
||||
|
|
|
@ -55,6 +55,11 @@ textarea{width:100%}#string{height:5vh}.codeEditor,.lineCounter{font-family:cour
|
|||
"source": 58,
|
||||
"type": "MACRO_RELEASE",
|
||||
"macro": 5
|
||||
},
|
||||
{
|
||||
"source": 50,
|
||||
"type": "KEYBOARD_BUTTON",
|
||||
"target": "KEY_0"
|
||||
}
|
||||
],
|
||||
"mappedaxis": [
|
||||
|
@ -220,7 +225,8 @@ var ProfileGenerator = (function () {
|
|||
"PREV_PROFILE",
|
||||
"SWITCH_PROFILE",
|
||||
"MACRO_PRESS",
|
||||
"MACRO_RELEASE"
|
||||
"MACRO_RELEASE",
|
||||
"KEYBOARD_BUTTON",
|
||||
];
|
||||
this.macroEnum = [
|
||||
"MACRO_NULL",
|
||||
|
@ -598,7 +604,12 @@ var ProfileGenerator = (function () {
|
|||
var tmp = this.hexString(entity.source);
|
||||
tmp += this.hexString(this.profileEnum.indexOf(entity.type));
|
||||
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) {
|
||||
tmp += this.hexString(entity.axis);
|
||||
|
@ -787,6 +798,9 @@ var ProfileGenerator = (function () {
|
|||
if (entity.type === 'JOYSTICK_BUTTON' || entity.type === 'MOUSE_BUTTON') {
|
||||
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') {
|
||||
entity.axis = this.fromHexU(tokens.shift());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue