Fix SwitchKeymapByAbbreviation() and use it in place of a for block of equivalent functionality within UsbCommand_ApplyConfig()

This commit is contained in:
László Monda
2018-04-10 21:27:56 +02:00
parent 1e61a39210
commit 7002e7de52
2 changed files with 4 additions and 10 deletions

View File

@@ -28,9 +28,9 @@ void SwitchKeymapById(uint8_t index)
bool SwitchKeymapByAbbreviation(uint8_t length, char *abbrev) bool SwitchKeymapByAbbreviation(uint8_t length, char *abbrev)
{ {
for (uint8_t i=0; i<MAX_KEYMAP_NUM; i++) { for (uint8_t i=0; i<AllKeymapsCount; i++) {
keymap_reference_t *keymap = AllKeymaps + i; keymap_reference_t *keymap = AllKeymaps + i;
if (keymap->abbreviationLen == length && strcmp(keymap->abbreviation, abbrev) == 0) { if (keymap->abbreviationLen == length && memcmp(keymap->abbreviation, abbrev, length) == 0) {
SwitchKeymapById(i); SwitchKeymapById(i);
return true; return true;
} }

View File

@@ -45,14 +45,8 @@ void UsbCommand_ApplyConfig(void)
} }
// Switch to the keymap of the updated configuration of the same name or the default keymap. // Switch to the keymap of the updated configuration of the same name or the default keymap.
if (SwitchKeymapByAbbreviation(oldKeymapAbbreviationLen, oldKeymapAbbreviation)) {
for (uint8_t keymapId = 0; keymapId < AllKeymapsCount; keymapId++) { return;
if (AllKeymaps[keymapId].abbreviationLen == oldKeymapAbbreviationLen &&
!memcmp(oldKeymapAbbreviation, AllKeymaps[keymapId].abbreviation, oldKeymapAbbreviationLen))
{
SwitchKeymapById(keymapId);
return;
}
} }
SwitchKeymapById(DefaultKeymapIndex); SwitchKeymapById(DefaultKeymapIndex);