Skip to content

Commit 197d19a

Browse files
committed
Corrected KLM log messages
* Moved SwapOnly opcode message to cover "unused" case * Adjusted Size switch statement to account for non standard sizes * Fixed InsertRow opcode insertion index * Corrected RemoveRow opcode to ensure removal didn't skip keys * Small formatting and style fixes
1 parent 4d73e02 commit 197d19a

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

KeyboardLayoutManager/KeyboardLayoutManager.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,17 @@ KeyboardLayoutManager::KeyboardLayoutManager(KEYBOARD_LAYOUT layout, KEYBOARD_SI
417417
name = KEYBOARD_NAME_TKL;
418418
break;
419419

420-
default:
420+
case KEYBOARD_SIZE::KEYBOARD_SIZE_FULL:
421421
name = KEYBOARD_NAME_FULL;
422+
break;
423+
424+
default:
425+
/*-------------------------------------------------------------*\
426+
| If the keyboard size is not a standard size output |
427+
| the combined number as a string |
428+
\*-------------------------------------------------------------*/
429+
name = "Size (";
430+
name.append(std::to_string(size) + ") ");
422431
}
423432

424433
/*---------------------------------------------------------------------*\
@@ -618,6 +627,9 @@ void KeyboardLayoutManager::SwapKey(keyboard_led swp_key)
618627
\*---------------------------------------------------------------------*/
619628
if((swp_row == keymap[key_idx].row) && (swp_col == keymap[key_idx].col))
620629
{
630+
std::string tmp_name = (strlen(swp_name) == 0) ? LOG_MSG_UNUSED_KEY : swp_name;
631+
LOG_DEBUG("[%s] Swapping in %s and %s out @ %02d, %02d", KLM_CLASS_NAME, tmp_name.c_str(), keymap[key_idx].name, swp_row, swp_col);
632+
621633
/*---------------------------------------------------------------------*\
622634
| If the key to be swapped in is an unused key, we want to remove the |
623635
| entry from the keymap rather than perform a swap |
@@ -632,8 +644,6 @@ void KeyboardLayoutManager::SwapKey(keyboard_led swp_key)
632644
\*---------------------------------------------------------------------*/
633645
else
634646
{
635-
std::string swap_name = (strlen(swp_name) == 0) ? LOG_MSG_UNUSED_KEY : swp_name;
636-
LOG_DEBUG("[%s] Swapping in %s and %s out @ %02d, %02d", KLM_CLASS_NAME, swap_name.c_str(), keymap[key_idx].name, swp_row, swp_col);
637647
keymap[key_idx].name = swp_name;
638648
keymap[key_idx].value = swp_value;
639649
}
@@ -758,7 +768,7 @@ bool KeyboardLayoutManager::InsertRow(uint8_t ins_row)
758768

759769
for(/*key_idx*/; key_idx < keymap.size(); key_idx++)
760770
{
761-
if(ins_row > keymap[key_idx].row)
771+
if(ins_row <= keymap[key_idx].row)
762772
{
763773
break;
764774
}
@@ -797,13 +807,17 @@ void KeyboardLayoutManager::RemoveRow(uint8_t rmv_row)
797807
\*---------------------------------------------------------------------*/
798808
unsigned int key_idx = 0;
799809

800-
for(/*key_idx*/; key_idx < keymap.size() && rmv_row > keymap[key_idx].row; key_idx++)
810+
while(key_idx < keymap.size() && rmv_row >= keymap[key_idx].row)
801811
{
802812
if(rmv_row == keymap[key_idx].row)
803813
{
804814
LOG_DEBUG("[%s] Removing %s @ %02d, %02d from row %d", KLM_CLASS_NAME, keymap[key_idx].name, keymap[key_idx].row, keymap[key_idx].col, rmv_row);
805815
keymap.erase(keymap.begin() + key_idx);
806816
}
817+
else
818+
{
819+
key_idx++;
820+
}
807821
}
808822

809823
/*---------------------------------------------------------------------*\

0 commit comments

Comments
 (0)