Extract the applyConfig USB command into usb_command_apply_config.[ch]
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "keymap.h"
|
||||
#include "microseconds/microseconds_pit.c"
|
||||
#include "i2c_watchdog.h"
|
||||
#include "usb_commands/usb_command_apply_config.h"
|
||||
|
||||
uint8_t UsbDebugInfo[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
|
||||
|
||||
@@ -93,57 +94,6 @@ void readMergeSensor(void)
|
||||
SetResponseByte(MERGE_SENSOR_IS_MERGED);
|
||||
}
|
||||
|
||||
void ApplyConfig(void)
|
||||
{
|
||||
// Validate the staging configuration.
|
||||
|
||||
ParserRunDry = true;
|
||||
StagingUserConfigBuffer.offset = 0;
|
||||
GenericHidOutBuffer[0] = ParseConfig(&StagingUserConfigBuffer);
|
||||
*(uint16_t*)(GenericHidOutBuffer+1) = StagingUserConfigBuffer.offset;
|
||||
GenericHidOutBuffer[3] = 0;
|
||||
|
||||
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make the staging configuration the current one.
|
||||
|
||||
char oldKeymapAbbreviation[KEYMAP_ABBREVIATION_LENGTH];
|
||||
uint8_t oldKeymapAbbreviationLen;
|
||||
memcpy(oldKeymapAbbreviation, AllKeymaps[CurrentKeymapIndex].abbreviation, KEYMAP_ABBREVIATION_LENGTH);
|
||||
oldKeymapAbbreviationLen = AllKeymaps[CurrentKeymapIndex].abbreviationLen;
|
||||
|
||||
uint8_t *temp = ValidatedUserConfigBuffer.buffer;
|
||||
ValidatedUserConfigBuffer.buffer = StagingUserConfigBuffer.buffer;
|
||||
StagingUserConfigBuffer.buffer = temp;
|
||||
|
||||
ParserRunDry = false;
|
||||
ValidatedUserConfigBuffer.offset = 0;
|
||||
GenericHidOutBuffer[0] = ParseConfig(&ValidatedUserConfigBuffer);
|
||||
*(uint16_t*)(GenericHidOutBuffer+1) = ValidatedUserConfigBuffer.offset;
|
||||
GenericHidOutBuffer[3] = 1;
|
||||
|
||||
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch to the keymap of the updated configuration of the same name or the default keymap.
|
||||
|
||||
for (uint8_t keymapId = 0; keymapId < AllKeymapsCount; keymapId++) {
|
||||
if (AllKeymaps[keymapId].abbreviationLen != oldKeymapAbbreviationLen) {
|
||||
continue;
|
||||
}
|
||||
if (memcmp(oldKeymapAbbreviation, AllKeymaps[keymapId].abbreviation, oldKeymapAbbreviationLen)) {
|
||||
continue;
|
||||
}
|
||||
SwitchKeymap(keymapId);
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchKeymap(DefaultKeymapIndex);
|
||||
}
|
||||
|
||||
void setLedPwm(void)
|
||||
{
|
||||
uint8_t brightnessPercent = GenericHidInBuffer[1];
|
||||
@@ -285,8 +235,8 @@ void UsbProtocolHandler(void)
|
||||
case UsbCommand_WriteUserConfiguration:
|
||||
writeConfiguration(false);
|
||||
break;
|
||||
case UsbCommand_ApplyConfig:
|
||||
ApplyConfig();
|
||||
case UsbCommandId_ApplyConfig:
|
||||
UsbCommand_ApplyConfig();
|
||||
break;
|
||||
case UsbCommand_SetLedPwm:
|
||||
setLedPwm();
|
||||
|
||||
Reference in New Issue
Block a user