Use constants to better illustrate bitfield usage

Binary notation and constants make it clearer how the bitfields are used to set the
correct bit in the `*HandMask` structures.
pull/365/head
Michael Richters 7 years ago
parent 0cb4ac7970
commit 83a5518bed

@ -212,14 +212,20 @@ void Model01::rebootBootloader() {
// shift a bit starting from the left (B10000000, or 128) by that many places to get // shift a bit starting from the left (B10000000, or 128) by that many places to get
// there. This is all nice and convenient because the keyboard has 64 keys, in symmetric // there. This is all nice and convenient because the keyboard has 64 keys, in symmetric
// halves, with eight keys per logical row. // halves, with eight keys per logical row.
constexpr byte HIGH_BIT = B10000000;
constexpr byte HAND_BIT = B00001000;
constexpr byte ROW_BITS = B00110000;
constexpr byte COL_BITS = B00000111;
void Model01::maskKey(byte row, byte col) { void Model01::maskKey(byte row, byte col) {
if (row >= ROWS || col >= COLS) if (row >= ROWS || col >= COLS)
return; return;
if (col & 8) { if (col & HAND_BIT) {
rightHandMask.rows[row] |= (128 >> (col & 7)); rightHandMask.rows[row] |= (HIGH_BIT >> (col & COL_BITS));
} else { } else {
leftHandMask.rows[row] |= (128 >> (col & 7)); leftHandMask.rows[row] |= (HIGH_BIT >> (col & COL_BITS));
} }
} }
@ -227,10 +233,10 @@ void Model01::unMaskKey(byte row, byte col) {
if (row >= ROWS || col >= COLS) if (row >= ROWS || col >= COLS)
return; return;
if (col & 8) { if (col & HAND_BIT) {
rightHandMask.rows[row] &= ~(128 >> (col & 7)); rightHandMask.rows[row] &= ~(HIGH_BIT >> (col & COL_BITS));
} else { } else {
leftHandMask.rows[row] &= ~(128 >> (col & 7)); leftHandMask.rows[row] &= ~(HIGH_BIT >> (col & COL_BITS));
} }
} }
@ -238,10 +244,10 @@ bool Model01::isKeyMasked(byte row, byte col) {
if (row >= ROWS || col >= COLS) if (row >= ROWS || col >= COLS)
return false; return false;
if (col & 8) { if (col & HAND_BIT) {
return rightHandMask.rows[row] & (128 >> (col & 7)); return rightHandMask.rows[row] & (HIGH_BIT >> (col & COL_BITS));
} else { } else {
return leftHandMask.rows[row] & (128 >> (col & 7)); return leftHandMask.rows[row] & (HIGH_BIT >> (col & COL_BITS));
} }
} }

Loading…
Cancel
Save