move READ_PIN_COUNT parameter in constructors
This commit is contained in:
parent
a5d6fb8d9e
commit
e860d059cf
@ -98,40 +98,40 @@ Code_LEDLock o_capsLock(KEY_CAPS_LOCK, LED1);
|
|||||||
|
|
||||||
// ================= LEFT ROWS =================
|
// ================= LEFT ROWS =================
|
||||||
Key* ptrsKeys_L0[] = { &o_capsLock, &s_a };
|
Key* ptrsKeys_L0[] = { &o_capsLock, &s_a };
|
||||||
Row_uC row_L0(0, readPins, ptrsKeys_L0, READ_PIN_COUNT);
|
Row_uC row_L0(0, readPins, READ_PIN_COUNT, ptrsKeys_L0);
|
||||||
|
|
||||||
Key* ptrsKeys_L1[] = { &s_b, &s_c };
|
Key* ptrsKeys_L1[] = { &s_b, &s_c };
|
||||||
Row_uC row_L1(1, readPins, ptrsKeys_L1, READ_PIN_COUNT);
|
Row_uC row_L1(1, readPins, READ_PIN_COUNT, ptrsKeys_L1);
|
||||||
|
|
||||||
// ================= RIGHT ROWS ================
|
// ================= RIGHT ROWS ================
|
||||||
//typedef should be large in /home/wolfv/Documents/Arduino/keybrd_proj/keybrd/src/config_keybrd.h
|
//typedef should be large in /home/wolfv/Documents/Arduino/keybrd_proj/keybrd/src/config_keybrd.h
|
||||||
//Row_ShiftRegisters(STROBE_PIN, ptrsKeys[], READ_PIN_COUNT)
|
//Row_ShiftRegisters(STROBE_PIN, READ_PIN_COUNT, ptrsKeys[])
|
||||||
//the s_z are place holders and should not print
|
//the s_z are place holders and should not print
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//prints 0 1
|
//prints 0 1
|
||||||
Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z };
|
Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z };
|
||||||
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
||||||
Row_ShiftRegisters row_R0(8, ptrsKeys_R0, READ_PIN_COUNT_R0);
|
Row_ShiftRegisters row_R0(8, READ_PIN_COUNT_R0, ptrsKeys_R0);
|
||||||
|
|
||||||
//prints a b
|
//prints a b
|
||||||
Key* ptrsKeys_R1[] = { &s_a, &s_z, &s_z, &s_z, &s_b, &s_z, &s_z, &s_z };
|
Key* ptrsKeys_R1[] = { &s_a, &s_z, &s_z, &s_z, &s_b, &s_z, &s_z, &s_z };
|
||||||
const uint8_t READ_PIN_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
|
const uint8_t READ_PIN_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
|
||||||
Row_ShiftRegisters row_R1(9, ptrsKeys_R1, READ_PIN_COUNT_R1);
|
Row_ShiftRegisters row_R1(9, READ_PIN_COUNT_R1, ptrsKeys_R1);
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
//prints 0 1 2
|
//prints 0 1 2
|
||||||
Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
|
Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
|
||||||
&s_2, &s_z, &s_z, &s_z };
|
&s_2, &s_z, &s_z, &s_z };
|
||||||
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
||||||
Row_ShiftRegisters row_R0(8, ptrsKeys_R0, READ_PIN_COUNT_R0);
|
Row_ShiftRegisters row_R0(8, READ_PIN_COUNT_R0, ptrsKeys_R0);
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
//prints 0 1 2 3
|
//prints 0 1 2 3
|
||||||
Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
|
Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
|
||||||
&s_2, &s_z, &s_z, &s_z, &s_3, &s_z, &s_z, &s_z };
|
&s_2, &s_z, &s_z, &s_z, &s_3, &s_z, &s_z, &s_z };
|
||||||
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
||||||
Row_ShiftRegisters row_R0(8, ptrsKeys_R0, READ_PIN_COUNT_R0);
|
Row_ShiftRegisters row_R0(8, READ_PIN_COUNT_R0, ptrsKeys_R0);
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
//prints 0 1 2 3 4 5
|
//prints 0 1 2 3 4 5
|
||||||
@ -139,7 +139,7 @@ Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
|
|||||||
&s_2, &s_z, &s_z, &s_z, &s_3, &s_z, &s_z, &s_z,
|
&s_2, &s_z, &s_z, &s_z, &s_3, &s_z, &s_z, &s_z,
|
||||||
&s_4, &s_z, &s_z, &s_z, &s_5, &s_z, &s_z, &s_z };
|
&s_4, &s_z, &s_z, &s_z, &s_5, &s_z, &s_z, &s_z };
|
||||||
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
||||||
Row_ShiftRegisters row_R0(8, ptrsKeys_R0, READ_PIN_COUNT_R0);
|
Row_ShiftRegisters row_R0(8, READ_PIN_COUNT_R0, ptrsKeys_R0);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//prints 0 1 2 3 3 4 5 6, microseconds_per_scan=87 with SAMPLE_COUNT 4
|
//prints 0 1 2 3 3 4 5 6, microseconds_per_scan=87 with SAMPLE_COUNT 4
|
||||||
@ -148,7 +148,7 @@ Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
|
|||||||
&s_4, &s_z, &s_z, &s_z, &s_5, &s_z, &s_z, &s_z,
|
&s_4, &s_z, &s_z, &s_z, &s_5, &s_z, &s_z, &s_z,
|
||||||
&s_6, &s_z, &s_z, &s_z, &s_3, &s_4, &s_5, &s_6 };
|
&s_6, &s_z, &s_z, &s_z, &s_3, &s_4, &s_5, &s_6 };
|
||||||
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
const uint8_t READ_PIN_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
||||||
Row_ShiftRegisters row_R0(0, ptrsKeys_R0, READ_PIN_COUNT_R0);
|
Row_ShiftRegisters row_R0(0, READ_PIN_COUNT_R0, ptrsKeys_R0);
|
||||||
|
|
||||||
//prints a b c d u v w x
|
//prints a b c d u v w x
|
||||||
Key* ptrsKeys_R1[] = { &s_a, &s_z, &s_z, &s_z, &s_b, &s_z, &s_z, &s_z,
|
Key* ptrsKeys_R1[] = { &s_a, &s_z, &s_z, &s_z, &s_b, &s_z, &s_z, &s_z,
|
||||||
@ -156,7 +156,7 @@ Key* ptrsKeys_R1[] = { &s_a, &s_z, &s_z, &s_z, &s_b, &s_z, &s_z, &s_z,
|
|||||||
&s_e, &s_z, &s_z, &s_z, &s_f, &s_z, &s_z, &s_z,
|
&s_e, &s_z, &s_z, &s_z, &s_f, &s_z, &s_z, &s_z,
|
||||||
&s_g, &s_z, &s_z, &s_z, &s_u, &s_v, &s_w, &s_x };
|
&s_g, &s_z, &s_z, &s_z, &s_u, &s_v, &s_w, &s_x };
|
||||||
const uint8_t READ_PIN_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
|
const uint8_t READ_PIN_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
|
||||||
Row_ShiftRegisters row_R1(1, ptrsKeys_R1, READ_PIN_COUNT_R1);
|
Row_ShiftRegisters row_R1(1, READ_PIN_COUNT_R1, ptrsKeys_R1);
|
||||||
|
|
||||||
// ################### MAIN ####################
|
// ################### MAIN ####################
|
||||||
void setup()
|
void setup()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
pressRelease() calls key's press() or release() function if it was pressed or released.
|
pressRelease() calls key's press() or release() function if it was pressed or released.
|
||||||
Both parameters are bitwise.
|
Both parameters are bitwise.
|
||||||
*/
|
*/
|
||||||
void Row::pressRelease(const uint8_t READ_PIN_COUNT, const read_pins_t debouncedChanged)
|
void Row::pressRelease(const uint8_t readPinCount, const read_pins_t debouncedChanged)
|
||||||
{
|
{
|
||||||
read_pins_t isFallingEdge; //bitwise, 1 means falling edge
|
read_pins_t isFallingEdge; //bitwise, 1 means falling edge
|
||||||
read_pins_t isRisingEdge; //bitwise, 1 means rising edge
|
read_pins_t isRisingEdge; //bitwise, 1 means rising edge
|
||||||
@ -16,7 +16,7 @@ void Row::pressRelease(const uint8_t READ_PIN_COUNT, const read_pins_t debounced
|
|||||||
//bit=1 if last debounced changed from 0 to 1, else bit=0
|
//bit=1 if last debounced changed from 0 to 1, else bit=0
|
||||||
isRisingEdge = debouncedChanged & debounced;
|
isRisingEdge = debouncedChanged & debounced;
|
||||||
|
|
||||||
for (readMask=1, i=0; i < READ_PIN_COUNT; readMask<<=1, i++) //for each key in row
|
for (readMask=1, i=0; i < readPinCount; readMask<<=1, i++) //for each key in row
|
||||||
{
|
{
|
||||||
//release before press avoids impossible key sequence
|
//release before press avoids impossible key sequence
|
||||||
if (readMask & isFallingEdge) //if key was released
|
if (readMask & isFallingEdge) //if key was released
|
||||||
|
@ -14,7 +14,7 @@ class Row
|
|||||||
virtual void keyWasPressed();
|
virtual void keyWasPressed();
|
||||||
protected:
|
protected:
|
||||||
read_pins_t debounced; //bitwise, 1 means pressed, 0 means released
|
read_pins_t debounced; //bitwise, 1 means pressed, 0 means released
|
||||||
void pressRelease(const uint8_t READ_PIN_COUNT, const read_pins_t debouncedChanged);
|
void pressRelease(const uint8_t readPinCount, const read_pins_t debouncedChanged);
|
||||||
public:
|
public:
|
||||||
Row(Key *const ptrsKeys[]) : ptrsKeys(ptrsKeys), debounced(0) { }
|
Row(Key *const ptrsKeys[]) : ptrsKeys(ptrsKeys), debounced(0) { }
|
||||||
virtual void process()=0;
|
virtual void process()=0;
|
||||||
|
@ -31,7 +31,7 @@ class Row_ShiftRegisters : public Row
|
|||||||
Debouncer_4Samples debouncer;
|
Debouncer_4Samples debouncer;
|
||||||
//Debouncer_Not debouncer; //passed test
|
//Debouncer_Not debouncer; //passed test
|
||||||
public:
|
public:
|
||||||
Row_ShiftRegisters(const uint8_t STROBE_PIN, Key *const ptrsKeys[], uint8_t READ_PIN_COUNT)
|
Row_ShiftRegisters(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT, Key *const ptrsKeys[])
|
||||||
: Row(ptrsKeys), scanner(STROBE_PIN, READ_PIN_COUNT) { }
|
: Row(ptrsKeys), scanner(STROBE_PIN, READ_PIN_COUNT) { }
|
||||||
void begin();
|
void begin();
|
||||||
void process();
|
void process();
|
||||||
|
@ -32,8 +32,8 @@ class Row_uC : public Row
|
|||||||
Scanner_uC scanner;
|
Scanner_uC scanner;
|
||||||
Debouncer_4Samples debouncer;
|
Debouncer_4Samples debouncer;
|
||||||
public:
|
public:
|
||||||
Row_uC(const uint8_t strobePin, const uint8_t READ_PINS[],
|
Row_uC(const uint8_t strobePin, const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT,
|
||||||
Key *const ptrsKeys[], const uint8_t READ_PIN_COUNT)
|
Key *const ptrsKeys[])
|
||||||
: Row(ptrsKeys), scanner(strobePin, READ_PINS, READ_PIN_COUNT) { }
|
: Row(ptrsKeys), scanner(strobePin, READ_PINS, READ_PIN_COUNT) { }
|
||||||
void process();
|
void process();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user