Implement part of the macro engine
This commit is contained in:
@@ -1,4 +1,294 @@
|
|||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
#include "config_parser/parse_macro.h"
|
||||||
|
#include "config_parser/config_globals.h"
|
||||||
|
|
||||||
macro_reference_t AllMacros[MAX_MACRO_NUM];
|
macro_reference_t AllMacros[MAX_MACRO_NUM];
|
||||||
uint8_t AllMacrosCount;
|
uint8_t AllMacrosCount;
|
||||||
|
bool MacroPlaying = false;
|
||||||
|
usb_mouse_report_t MacroMouseReport = { 0 };
|
||||||
|
usb_basic_keyboard_report_t MacroBasicKeyboardReport = { 0 };
|
||||||
|
usb_media_keyboard_report_t MacroMediaKeyboardReport = { { 0 } };
|
||||||
|
usb_system_keyboard_report_t MacroSystemKeyboardReport = { { 0 } };
|
||||||
|
|
||||||
|
static uint8_t currentMacroIndex;
|
||||||
|
static uint16_t currentMacroActionIndex;
|
||||||
|
static macro_action_t currentMacroAction;
|
||||||
|
|
||||||
|
uint8_t characterToScancode(char character)
|
||||||
|
{
|
||||||
|
switch (character) {
|
||||||
|
case 'A' ... 'Z':
|
||||||
|
return 0;
|
||||||
|
case 'a' ... 'z':
|
||||||
|
return 0;
|
||||||
|
case '1' ... '9':
|
||||||
|
return 0;
|
||||||
|
case ')':
|
||||||
|
case '0':
|
||||||
|
return 0;
|
||||||
|
case '!':
|
||||||
|
return 0;
|
||||||
|
case '@':
|
||||||
|
return 0;
|
||||||
|
case '#':
|
||||||
|
return 0;
|
||||||
|
case '$':
|
||||||
|
return 0;
|
||||||
|
case '%':
|
||||||
|
return 0;
|
||||||
|
case '^':
|
||||||
|
return 0;
|
||||||
|
case '&':
|
||||||
|
return 0;
|
||||||
|
case '*':
|
||||||
|
return 0;
|
||||||
|
case '(':
|
||||||
|
return 0;
|
||||||
|
case '`':
|
||||||
|
case '~':
|
||||||
|
return 0;
|
||||||
|
case '[':
|
||||||
|
case '{':
|
||||||
|
return 0;
|
||||||
|
case ']':
|
||||||
|
case '}':
|
||||||
|
return 0;
|
||||||
|
case ';':
|
||||||
|
case ':':
|
||||||
|
return 0;
|
||||||
|
case '\'':
|
||||||
|
case '\"':
|
||||||
|
return 0;
|
||||||
|
case '+':
|
||||||
|
case '=':
|
||||||
|
return 0;
|
||||||
|
case '\\':
|
||||||
|
case '|':
|
||||||
|
return 0;
|
||||||
|
case '.':
|
||||||
|
case '>':
|
||||||
|
return 0;
|
||||||
|
case ',':
|
||||||
|
case '<':
|
||||||
|
return 0;
|
||||||
|
case '/':
|
||||||
|
case '\?':
|
||||||
|
return 0;
|
||||||
|
case '-':
|
||||||
|
case '_':
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addBasicScancode(uint8_t scancode)
|
||||||
|
{
|
||||||
|
if (scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_BASIC_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (MacroBasicKeyboardReport.scancodes[i] == scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_BASIC_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (!MacroBasicKeyboardReport.scancodes[i]) {
|
||||||
|
MacroBasicKeyboardReport.scancodes[i] = scancode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteBasicScancode(uint8_t scancode)
|
||||||
|
{
|
||||||
|
if (scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_BASIC_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (MacroBasicKeyboardReport.scancodes[i] == scancode) {
|
||||||
|
MacroBasicKeyboardReport.scancodes[i] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addModifiers(uint8_t modifiers)
|
||||||
|
{
|
||||||
|
MacroBasicKeyboardReport.modifiers |= modifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteModifiers(uint8_t modifiers)
|
||||||
|
{
|
||||||
|
MacroBasicKeyboardReport.modifiers &= ~modifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addMediaScancode(uint16_t scancode)
|
||||||
|
{
|
||||||
|
if (scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_MEDIA_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (MacroMediaKeyboardReport.scancodes[i] == scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_MEDIA_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (!MacroMediaKeyboardReport.scancodes[i]) {
|
||||||
|
MacroMediaKeyboardReport.scancodes[i] = scancode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteMediaScancode(uint16_t scancode)
|
||||||
|
{
|
||||||
|
if (scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_MEDIA_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (MacroMediaKeyboardReport.scancodes[i] == scancode) {
|
||||||
|
MacroMediaKeyboardReport.scancodes[i] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addSystemScancode(uint8_t scancode)
|
||||||
|
{
|
||||||
|
if (scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_SYSTEM_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (MacroSystemKeyboardReport.scancodes[i] == scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_SYSTEM_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (!MacroSystemKeyboardReport.scancodes[i]) {
|
||||||
|
MacroSystemKeyboardReport.scancodes[i] = scancode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteSystemScancode(uint8_t scancode)
|
||||||
|
{
|
||||||
|
if (scancode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < USB_SYSTEM_KEYBOARD_MAX_KEYS; i++) {
|
||||||
|
if (MacroSystemKeyboardReport.scancodes[i] == scancode) {
|
||||||
|
MacroSystemKeyboardReport.scancodes[i] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool processKeyMacroAction(void)
|
||||||
|
{
|
||||||
|
static bool pressStarted;
|
||||||
|
|
||||||
|
switch (currentMacroAction.key.action) {
|
||||||
|
case MacroSubAction_Press:
|
||||||
|
if (!pressStarted) {
|
||||||
|
pressStarted = true;
|
||||||
|
addModifiers(currentMacroAction.key.modifierMask);
|
||||||
|
switch (currentMacroAction.key.type) {
|
||||||
|
case KeystrokeType_Basic:
|
||||||
|
addBasicScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
case KeystrokeType_Media:
|
||||||
|
// addMediaScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
case KeystrokeType_System:
|
||||||
|
addSystemScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
pressStarted = false;
|
||||||
|
deleteModifiers(currentMacroAction.key.modifierMask);
|
||||||
|
switch (currentMacroAction.key.type) {
|
||||||
|
case KeystrokeType_Basic:
|
||||||
|
deleteBasicScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
case KeystrokeType_Media:
|
||||||
|
// deleteMediaScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
case KeystrokeType_System:
|
||||||
|
deleteSystemScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MacroSubAction_Release:
|
||||||
|
deleteModifiers(currentMacroAction.key.modifierMask);
|
||||||
|
switch (currentMacroAction.key.type) {
|
||||||
|
case KeystrokeType_Basic:
|
||||||
|
deleteBasicScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
case KeystrokeType_Media:
|
||||||
|
// deleteMediaScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
case KeystrokeType_System:
|
||||||
|
deleteSystemScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MacroSubAction_Hold:
|
||||||
|
addModifiers(currentMacroAction.key.modifierMask);
|
||||||
|
switch (currentMacroAction.key.type) {
|
||||||
|
case KeystrokeType_Basic:
|
||||||
|
addBasicScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
case KeystrokeType_Media:
|
||||||
|
// addMediaScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
case KeystrokeType_System:
|
||||||
|
addSystemScancode(currentMacroAction.key.scancode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool processCurrentMacroAction(void)
|
||||||
|
{
|
||||||
|
switch (currentMacroAction.type) {
|
||||||
|
case MacroActionType_Delay:
|
||||||
|
return false;
|
||||||
|
case MacroActionType_Key:
|
||||||
|
return processKeyMacroAction();
|
||||||
|
case MacroActionType_MouseButton:
|
||||||
|
return false;
|
||||||
|
case MacroActionType_MoveMouse:
|
||||||
|
return false;
|
||||||
|
case MacroActionType_ScrollMouse:
|
||||||
|
return false;
|
||||||
|
case MacroActionType_Text:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Macros_StartMacro(uint8_t index)
|
||||||
|
{
|
||||||
|
MacroPlaying = true;
|
||||||
|
currentMacroIndex = index;
|
||||||
|
currentMacroActionIndex = 0;
|
||||||
|
UserConfigBuffer.offset = AllMacros[index].firstMacroActionOffset;
|
||||||
|
ParseMacroAction(&UserConfigBuffer, ¤tMacroAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Macros_ContinueMacro(void)
|
||||||
|
{
|
||||||
|
if (processCurrentMacroAction()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (++currentMacroActionIndex == AllMacros[currentMacroIndex].macroActionsCount) {
|
||||||
|
MacroPlaying = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ParseMacroAction(&UserConfigBuffer, ¤tMacroAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
// Includes:
|
// Includes:
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "key_action.h"
|
#include "key_action.h"
|
||||||
|
#include "usb_device_config.h"
|
||||||
|
|
||||||
// Macros:
|
// Macros:
|
||||||
|
|
||||||
@@ -67,5 +69,15 @@
|
|||||||
|
|
||||||
extern macro_reference_t AllMacros[MAX_MACRO_NUM];
|
extern macro_reference_t AllMacros[MAX_MACRO_NUM];
|
||||||
extern uint8_t AllMacrosCount;
|
extern uint8_t AllMacrosCount;
|
||||||
|
extern bool MacroPlaying;
|
||||||
|
extern usb_mouse_report_t MacroMouseReport;
|
||||||
|
extern usb_basic_keyboard_report_t MacroBasicKeyboardReport;
|
||||||
|
extern usb_media_keyboard_report_t MacroMediaKeyboardReport;
|
||||||
|
extern usb_system_keyboard_report_t MacroSystemKeyboardReport;
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
void Macros_StartMacro(uint8_t index);
|
||||||
|
void Macros_ContinueMacro(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "slave_drivers/is31fl3731_driver.h"
|
#include "slave_drivers/is31fl3731_driver.h"
|
||||||
#include "slave_drivers/uhk_module_driver.h"
|
#include "slave_drivers/uhk_module_driver.h"
|
||||||
#include "led_pwm.h"
|
#include "led_pwm.h"
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
static uint8_t mouseWheelDivisorCounter = 0;
|
static uint8_t mouseWheelDivisorCounter = 0;
|
||||||
static uint8_t mouseSpeedAccelDivisorCounter = 0;
|
static uint8_t mouseSpeedAccelDivisorCounter = 0;
|
||||||
@@ -132,8 +133,17 @@ void UpdateActiveUsbReports()
|
|||||||
uint8_t systemScancodeIndex = 0;
|
uint8_t systemScancodeIndex = 0;
|
||||||
static uint8_t previousLayer = LAYER_ID_BASE;
|
static uint8_t previousLayer = LAYER_ID_BASE;
|
||||||
static uint8_t previousModifiers = 0;
|
static uint8_t previousModifiers = 0;
|
||||||
uint8_t activeLayer = getActiveLayer();
|
uint8_t activeLayer;
|
||||||
|
|
||||||
|
if (MacroPlaying) {
|
||||||
|
Macros_ContinueMacro();
|
||||||
|
memcpy(&UsbMouseReport, &MacroMouseReport, sizeof MacroMouseReport);
|
||||||
|
memcpy(&ActiveUsbBasicKeyboardReport, &MacroBasicKeyboardReport, sizeof MacroBasicKeyboardReport);
|
||||||
|
memcpy(&ActiveUsbMediaKeyboardReport, &MacroMediaKeyboardReport, sizeof MacroMediaKeyboardReport);
|
||||||
|
memcpy(&ActiveUsbSystemKeyboardReport, &MacroSystemKeyboardReport, sizeof MacroSystemKeyboardReport);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
activeLayer = getActiveLayer();
|
||||||
LedDisplay_SetLayer(activeLayer);
|
LedDisplay_SetLayer(activeLayer);
|
||||||
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
|
||||||
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user