Make the parser parse mouse properties, LED brightness values, and double tap switch layer timeout. Rename pointer config properties.
This commit is contained in:
@@ -8,7 +8,6 @@ uint8_t ReadUInt8(config_buffer_t *buffer)
|
||||
uint16_t ReadUInt16(config_buffer_t *buffer)
|
||||
{
|
||||
uint16_t uInt16 = ReadUInt8(buffer);
|
||||
|
||||
uInt16 |= ReadUInt8(buffer) << 8;
|
||||
return uInt16;
|
||||
}
|
||||
@@ -26,14 +25,12 @@ bool ReadBool(config_buffer_t *buffer)
|
||||
uint16_t ReadCompactLength(config_buffer_t *buffer)
|
||||
{
|
||||
uint16_t compactLength = ReadUInt8(buffer);
|
||||
|
||||
return compactLength == 0xFF ? ReadUInt16(buffer) : compactLength;
|
||||
}
|
||||
|
||||
const char *ReadString(config_buffer_t *buffer, uint16_t *len)
|
||||
{
|
||||
const char *string;
|
||||
|
||||
*len = ReadCompactLength(buffer);
|
||||
string = (const char *)(buffer->buffer + buffer->offset);
|
||||
buffer->offset += *len;
|
||||
|
||||
@@ -4,35 +4,84 @@
|
||||
#include "keymap.h"
|
||||
#include "config_globals.h"
|
||||
#include "macros.h"
|
||||
#include "usb_report_updater.h"
|
||||
|
||||
static parser_error_t parseModuleConfiguration(config_buffer_t *buffer)
|
||||
{
|
||||
uint8_t id = ReadUInt8(buffer);
|
||||
uint8_t initialPointerSpeed = ReadUInt8(buffer);
|
||||
uint8_t pointerAcceleration = ReadUInt8(buffer);
|
||||
uint8_t maxPointerSpeed = ReadUInt8(buffer);
|
||||
uint8_t deceleratedPointerSpeedMultiplier = ReadUInt8(buffer);
|
||||
uint8_t basePointerSpeedMultiplier = ReadUInt8(buffer);
|
||||
uint8_t acceleratedPointerSpeed = ReadUInt8(buffer);
|
||||
|
||||
(void)id;
|
||||
(void)initialPointerSpeed;
|
||||
(void)pointerAcceleration;
|
||||
(void)maxPointerSpeed;
|
||||
(void)deceleratedPointerSpeedMultiplier;
|
||||
(void)basePointerSpeedMultiplier;
|
||||
(void)acceleratedPointerSpeed;
|
||||
return ParserError_Success;
|
||||
}
|
||||
|
||||
parser_error_t ParseConfig(config_buffer_t *buffer)
|
||||
{
|
||||
// Miscellaneous properties
|
||||
|
||||
uint16_t len;
|
||||
uint16_t macroCount;
|
||||
uint16_t keymapCount;
|
||||
parser_error_t errorCode;
|
||||
|
||||
uint16_t dataModelVersion = ReadUInt16(buffer);
|
||||
uint16_t dataModelMajorVersion = ReadUInt16(buffer);
|
||||
uint16_t dataModelMinorVersion = ReadUInt16(buffer);
|
||||
uint16_t dataModelPatchVersion = ReadUInt16(buffer);
|
||||
uint16_t userConfigLength = ReadUInt16(buffer);
|
||||
(void)userConfigLength;
|
||||
ReadString(buffer, &len); // Ignore device name
|
||||
uint16_t moduleConfigurationCount = ReadCompactLength(buffer);
|
||||
const char *deviceName = ReadString(buffer, &len);
|
||||
uint16_t doubleTapSwitchLayerTimeout = ReadUInt16(buffer);
|
||||
|
||||
(void)dataModelVersion;
|
||||
(void)userConfigLength;
|
||||
(void)dataModelMajorVersion;
|
||||
(void)dataModelMinorVersion;
|
||||
(void)dataModelPatchVersion;
|
||||
(void)deviceName;
|
||||
|
||||
// LED brightness
|
||||
|
||||
uint8_t iconsAndLayerTextsBrightness = ReadUInt8(buffer);
|
||||
uint8_t alphanumericSegmentsBrightness = ReadUInt8(buffer);
|
||||
uint8_t keyBacklightBrightness = ReadUInt8(buffer);
|
||||
|
||||
(void)iconsAndLayerTextsBrightness;
|
||||
(void)alphanumericSegmentsBrightness;
|
||||
(void)keyBacklightBrightness;
|
||||
|
||||
// Mouse kinetic properties
|
||||
|
||||
uint8_t mouseMoveInitialSpeed = ReadUInt8(buffer);
|
||||
uint8_t mouseMoveAcceleration = ReadUInt8(buffer);
|
||||
uint8_t mouseMoveDeceleratedSpeed = ReadUInt8(buffer);
|
||||
uint8_t mouseMoveBaseSpeed = ReadUInt8(buffer);
|
||||
uint8_t mouseMoveAcceleratedSpeed = ReadUInt8(buffer);
|
||||
uint8_t mouseScrollInitialSpeed = ReadUInt8(buffer);
|
||||
uint8_t mouseScrollAcceleration = ReadUInt8(buffer);
|
||||
uint8_t mouseScrollDeceleratedSpeed = ReadUInt8(buffer);
|
||||
uint8_t mouseScrollBaseSpeed = ReadUInt8(buffer);
|
||||
uint8_t mouseScrollAcceleratedSpeed = ReadUInt8(buffer);
|
||||
|
||||
if (mouseMoveInitialSpeed == 0 ||
|
||||
mouseMoveAcceleration == 0 ||
|
||||
mouseMoveDeceleratedSpeed == 0 ||
|
||||
mouseMoveBaseSpeed == 0 ||
|
||||
mouseMoveAcceleratedSpeed == 0 ||
|
||||
mouseScrollInitialSpeed == 0 ||
|
||||
mouseScrollAcceleration == 0 ||
|
||||
mouseScrollDeceleratedSpeed == 0 ||
|
||||
mouseScrollBaseSpeed == 0 ||
|
||||
mouseScrollAcceleratedSpeed == 0)
|
||||
{
|
||||
return ParserError_InvalidMouseKineticProperty;
|
||||
}
|
||||
|
||||
// Module configurations
|
||||
|
||||
uint16_t moduleConfigurationCount = ReadCompactLength(buffer);
|
||||
|
||||
if (moduleConfigurationCount > 255) {
|
||||
return ParserError_InvalidModuleConfigurationCount;
|
||||
@@ -45,6 +94,8 @@ parser_error_t ParseConfig(config_buffer_t *buffer)
|
||||
}
|
||||
}
|
||||
|
||||
// Macros
|
||||
|
||||
macroCount = ReadCompactLength(buffer);
|
||||
if (macroCount > MAX_MACRO_NUM) {
|
||||
return ParserError_InvalidMacroCount;
|
||||
@@ -57,6 +108,8 @@ parser_error_t ParseConfig(config_buffer_t *buffer)
|
||||
}
|
||||
}
|
||||
|
||||
// Keymaps
|
||||
|
||||
keymapCount = ReadCompactLength(buffer);
|
||||
if (keymapCount == 0 || keymapCount > MAX_KEYMAP_NUM) {
|
||||
return ParserError_InvalidKeymapCount;
|
||||
@@ -69,7 +122,23 @@ parser_error_t ParseConfig(config_buffer_t *buffer)
|
||||
}
|
||||
}
|
||||
|
||||
// If parsing succeeded then apply the parsed values.
|
||||
|
||||
if (!ParserRunDry) {
|
||||
DoubleTapSwitchLayerTimeout = doubleTapSwitchLayerTimeout;
|
||||
|
||||
MouseMoveState.initialSpeed = mouseMoveInitialSpeed;
|
||||
MouseMoveState.acceleration = mouseMoveAcceleration;
|
||||
MouseMoveState.deceleratedSpeed = mouseMoveDeceleratedSpeed;
|
||||
MouseMoveState.baseSpeed = mouseMoveBaseSpeed;
|
||||
MouseMoveState.acceleratedSpeed = mouseMoveAcceleratedSpeed;
|
||||
|
||||
MouseScrollState.initialSpeed = mouseScrollInitialSpeed;
|
||||
MouseScrollState.acceleration = mouseScrollAcceleration;
|
||||
MouseScrollState.deceleratedSpeed = mouseScrollDeceleratedSpeed;
|
||||
MouseScrollState.baseSpeed = mouseScrollBaseSpeed;
|
||||
MouseScrollState.acceleratedSpeed = mouseScrollAcceleratedSpeed;
|
||||
|
||||
AllKeymapsCount = keymapCount;
|
||||
AllMacrosCount = macroCount;
|
||||
}
|
||||
|
||||
@@ -8,20 +8,21 @@
|
||||
// Typedefs:
|
||||
|
||||
typedef enum {
|
||||
ParserError_Success,
|
||||
ParserError_InvalidSerializedKeystrokeType,
|
||||
ParserError_InvalidSerializedMouseAction,
|
||||
ParserError_InvalidSerializedKeyActionType,
|
||||
ParserError_InvalidLayerCount,
|
||||
ParserError_InvalidModuleCount,
|
||||
ParserError_InvalidActionCount,
|
||||
ParserError_InvalidSerializedMacroActionType,
|
||||
ParserError_InvalidSerializedSwitchKeymapAction,
|
||||
ParserError_InvalidModuleConfigurationCount,
|
||||
ParserError_InvalidKeymapCount,
|
||||
ParserError_InvalidAbbreviationLen,
|
||||
ParserError_InvalidMacroCount,
|
||||
ParserError_InvalidSerializedPlayMacroAction,
|
||||
ParserError_Success = 0,
|
||||
ParserError_InvalidSerializedKeystrokeType = 1,
|
||||
ParserError_InvalidSerializedMouseAction = 2,
|
||||
ParserError_InvalidSerializedKeyActionType = 3,
|
||||
ParserError_InvalidLayerCount = 4,
|
||||
ParserError_InvalidModuleCount = 5,
|
||||
ParserError_InvalidActionCount = 6,
|
||||
ParserError_InvalidSerializedMacroActionType = 7,
|
||||
ParserError_InvalidSerializedSwitchKeymapAction = 8,
|
||||
ParserError_InvalidModuleConfigurationCount = 9,
|
||||
ParserError_InvalidKeymapCount = 10,
|
||||
ParserError_InvalidAbbreviationLen = 11,
|
||||
ParserError_InvalidMacroCount = 12,
|
||||
ParserError_InvalidSerializedPlayMacroAction = 13,
|
||||
ParserError_InvalidMouseKineticProperty = 14,
|
||||
} parser_error_t;
|
||||
|
||||
// Functions:
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
uint32_t UsbReportUpdateTime = 0;
|
||||
static uint32_t elapsedTime;
|
||||
|
||||
static uint16_t doubleTapSwitchLayerTimeout = 300;
|
||||
uint16_t DoubleTapSwitchLayerTimeout = 250;
|
||||
|
||||
static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
|
||||
|
||||
static mouse_kinetic_state_t mouseMoveState = {
|
||||
mouse_kinetic_state_t MouseMoveState = {
|
||||
.upState = SerializedMouseAction_MoveUp,
|
||||
.downState = SerializedMouseAction_MoveDown,
|
||||
.leftState = SerializedMouseAction_MoveLeft,
|
||||
@@ -37,7 +37,7 @@ static mouse_kinetic_state_t mouseMoveState = {
|
||||
.acceleratedSpeed = 80,
|
||||
};
|
||||
|
||||
static mouse_kinetic_state_t mouseScrollState = {
|
||||
mouse_kinetic_state_t MouseScrollState = {
|
||||
.upState = SerializedMouseAction_ScrollDown,
|
||||
.downState = SerializedMouseAction_ScrollUp,
|
||||
.leftState = SerializedMouseAction_ScrollLeft,
|
||||
@@ -47,7 +47,7 @@ static mouse_kinetic_state_t mouseScrollState = {
|
||||
.acceleration = 20,
|
||||
.deceleratedSpeed = 10,
|
||||
.baseSpeed = 20,
|
||||
.acceleratedSpeed = 40,
|
||||
.acceleratedSpeed = 50,
|
||||
};
|
||||
|
||||
void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
||||
@@ -128,17 +128,17 @@ void processMouseKineticState(mouse_kinetic_state_t *kineticState)
|
||||
|
||||
void processMouseActions()
|
||||
{
|
||||
processMouseKineticState(&mouseMoveState);
|
||||
ActiveUsbMouseReport->x = mouseMoveState.xOut;
|
||||
ActiveUsbMouseReport->y = mouseMoveState.yOut;
|
||||
mouseMoveState.xOut = 0;
|
||||
mouseMoveState.yOut = 0;
|
||||
processMouseKineticState(&MouseMoveState);
|
||||
ActiveUsbMouseReport->x = MouseMoveState.xOut;
|
||||
ActiveUsbMouseReport->y = MouseMoveState.yOut;
|
||||
MouseMoveState.xOut = 0;
|
||||
MouseMoveState.yOut = 0;
|
||||
|
||||
processMouseKineticState(&mouseScrollState);
|
||||
ActiveUsbMouseReport->wheelX = mouseScrollState.xOut;
|
||||
ActiveUsbMouseReport->wheelY = mouseScrollState.yOut;
|
||||
mouseScrollState.xOut = 0;
|
||||
mouseScrollState.yOut = 0;
|
||||
processMouseKineticState(&MouseScrollState);
|
||||
ActiveUsbMouseReport->wheelX = MouseScrollState.xOut;
|
||||
ActiveUsbMouseReport->wheelY = MouseScrollState.yOut;
|
||||
MouseScrollState.xOut = 0;
|
||||
MouseScrollState.yOut = 0;
|
||||
|
||||
// The following line makes the firmware crash for some reason:
|
||||
// SetDebugBufferFloat(60, mouseScrollState.currentSpeed);
|
||||
@@ -207,7 +207,7 @@ void applyKeyAction(key_state_t *keyState, key_action_t *action)
|
||||
case KeyActionType_SwitchLayer:
|
||||
if (!keyState->previous && previousLayer == LayerId_Base && action->switchLayer.mode == SwitchLayerMode_HoldAndDoubleTapToggle) {
|
||||
if (doubleTapSwitchLayerKey) {
|
||||
if (Timer_GetElapsedTime(&doubleTapSwitchLayerStartTime) < doubleTapSwitchLayerTimeout) {
|
||||
if (Timer_GetElapsedTime(&doubleTapSwitchLayerStartTime) < DoubleTapSwitchLayerTimeout) {
|
||||
ToggledLayer = action->switchLayer.layer;
|
||||
}
|
||||
doubleTapSwitchLayerKey = NULL;
|
||||
|
||||
@@ -63,6 +63,12 @@
|
||||
int16_t yOut;
|
||||
} mouse_kinetic_state_t;
|
||||
|
||||
// Variables:
|
||||
|
||||
extern uint16_t DoubleTapSwitchLayerTimeout;
|
||||
extern mouse_kinetic_state_t MouseMoveState;
|
||||
extern mouse_kinetic_state_t MouseScrollState;
|
||||
|
||||
// Functions:
|
||||
|
||||
void UpdateUsbReports(void);
|
||||
|
||||
Reference in New Issue
Block a user