Skip to content

Commit e18ceea

Browse files
committed
Check for duplicate pins in rows and columns
1 parent 88a0088 commit e18ceea

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,10 @@ msgstr ""
19981998
msgid "Row entry must be digitalio.DigitalInOut"
19991999
msgstr ""
20002000

2001+
#: shared-bindings/keypad/KeyMatrix.c
2002+
msgid "Row or Column pin duplicated"
2003+
msgstr ""
2004+
20012005
#: main.c
20022006
msgid "Running in safe mode! Not running saved code.\n"
20032007
msgstr ""

shared-bindings/keypad/KeyMatrix.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ STATIC mp_obj_t keypad_keymatrix_make_new(const mp_obj_type_t *type, size_t n_ar
102102
column_pins_array[column] = pin;
103103
}
104104

105+
for (size_t row = 0; row < num_row_pins; row++) {
106+
for (size_t row2 = row + 1; row2 < num_row_pins; row2++) {
107+
if (row_pins_array[row] == row_pins_array[row2]) {
108+
mp_raise_ValueError(translate("Row or Column pin duplicated"));
109+
}
110+
}
111+
112+
for (size_t column = 0; column < num_column_pins; column++) {
113+
if (row_pins_array[row] == column_pins_array[column]) {
114+
mp_raise_ValueError(translate("Row or Column pin duplicated"));
115+
}
116+
}
117+
}
118+
119+
for (size_t column = 0; column < num_column_pins; column++) {
120+
for (size_t column2 = column + 1; column2 < num_column_pins; column2++) {
121+
if (column_pins_array[column] == column_pins_array[column2]) {
122+
mp_raise_ValueError(translate("Row or Column pin duplicated"));
123+
}
124+
}
125+
}
126+
105127
common_hal_keypad_keymatrix_construct(self, num_row_pins, row_pins_array, num_column_pins, column_pins_array, args[ARG_columns_to_anodes].u_bool, interval, max_events);
106128
return MP_OBJ_FROM_PTR(self);
107129
}

0 commit comments

Comments
 (0)