diff --git a/cimditprofile.cpp b/cimditprofile.cpp index d5a8b3d..d675dd3 100644 --- a/cimditprofile.cpp +++ b/cimditprofile.cpp @@ -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; } } diff --git a/cimditprofile.h b/cimditprofile.h index a5d093c..da0a96d 100644 --- a/cimditprofile.h +++ b/cimditprofile.h @@ -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 diff --git a/profilegenerator/html/index.html b/profilegenerator/html/index.html index 6f799ab..80a773f 100644 --- a/profilegenerator/html/index.html +++ b/profilegenerator/html/index.html @@ -55,6 +55,11 @@ "source": 58, "type": "MACRO_RELEASE", "macro": 5 + }, + { + "source": 50, + "type": "KEYBOARD_BUTTON", + "target": "KEY_0" } ], "mappedaxis": [ diff --git a/profilegenerator/ts/ProfileGenerator.ts b/profilegenerator/ts/ProfileGenerator.ts index 6938019..5430773 100644 --- a/profilegenerator/ts/ProfileGenerator.ts +++ b/profilegenerator/ts/ProfileGenerator.ts @@ -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 = [ "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(entity.target); + } else { + tmp += this.hexString(this.keyLookup[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') { diff --git a/profilegenerator/webroot/index.html b/profilegenerator/webroot/index.html index 45a0aab..8476ca6 100644 --- a/profilegenerator/webroot/index.html +++ b/profilegenerator/webroot/index.html @@ -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()); }