Commit d5341eea authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

add latch files and add latch pin name.

Renamed keypad row column pin macros as well
parent 349c3c84
#ifndef DOOR_CONTROLLER_MAIN_INCLUDE_APP_LATCH_H_
#define DOOR_CONTROLLER_MAIN_INCLUDE_APP_LATCH_H_
#endif //DOOR_CONTROLLER_MAIN_INCLUDE_APP_LATCH_H_
......@@ -32,14 +32,16 @@
//#define UPDATE_SKIP_VERSION_CHECK
#define ROW0_PIN 14
#define ROW1_PIN 12
#define ROW2_PIN 13
#define ROW3_PIN 15
#define COL0_PIN 4
#define COL1_PIN 5
#define COL2_PIN 18
#define DOOR_LATCH_PIN 19
#define KEYPAD_ROW0_PIN 14
#define KEYPAD_ROW1_PIN 12
#define KEYPAD_ROW2_PIN 13
#define KEYPAD_ROW3_PIN 15
#define KEYPAD_COL0_PIN 4
#define KEYPAD_COL1_PIN 5
#define KEYPAD_COL2_PIN 18
#define DOOR_LOCK_PIN 12
#define DOOR_OPEN_LENGTH_MS (2.5 * 1000)
......
......@@ -11,14 +11,14 @@
// 1 minute
#define KEYPAD_EVENT_HOOK_WAIT_TIME 1000 * 60
#define KEYPAD_ROW_PIN_MASK (PIN_MASK(ROW0_PIN) \
| PIN_MASK(ROW1_PIN) \
| PIN_MASK(ROW2_PIN) \
| PIN_MASK(ROW3_PIN))
#define KEYPAD_ROW_PIN_MASK (PIN_MASK(KEYPAD_ROW0_PIN) \
| PIN_MASK(KEYPAD_ROW1_PIN) \
| PIN_MASK(KEYPAD_ROW2_PIN) \
| PIN_MASK(KEYPAD_ROW3_PIN))
#define KEYPAD_COL_PIN_MASK (PIN_MASK(COL0_PIN) \
| PIN_MASK(COL1_PIN) \
| PIN_MASK(COL2_PIN))
#define KEYPAD_COL_PIN_MASK (PIN_MASK(KEYPAD_COL0_PIN) \
| PIN_MASK(KEYPAD_COL1_PIN) \
| PIN_MASK(KEYPAD_COL2_PIN))
// These macros are defined for critical sections dealing with a mutex so it is harder to forget
// to unlock the mutex when done, and also so one does not lock improperly. Just wrap anything dealing with
......@@ -35,16 +35,16 @@
door_list_node_t key_handle_list_head;
static const int key_row_pins[ROWS] = {
ROW0_PIN,
ROW1_PIN,
ROW2_PIN,
ROW3_PIN,
KEYPAD_ROW0_PIN,
KEYPAD_ROW1_PIN,
KEYPAD_ROW2_PIN,
KEYPAD_ROW3_PIN,
};
static const int key_column_pins[COLUMNS] = {
COL0_PIN,
COL1_PIN,
COL2_PIN,
KEYPAD_COL0_PIN,
KEYPAD_COL1_PIN,
KEYPAD_COL2_PIN,
};
static const unsigned char keypad_map[ROWS][COLUMNS] = {
......
......@@ -66,26 +66,26 @@ TEST_CASE("keypad module scans the keypad")
SECTION("module handles a press")
{
set_key_level(ROW0_PIN, COL0_PIN, true);
set_key_level(KEYPAD_ROW0_PIN, KEYPAD_COL0_PIN, true);
run_test();
REQUIRE(pressed_keys['1']);
}
SECTION("module handles a release")
{
set_key_level(ROW0_PIN, COL0_PIN, true);
set_key_level(KEYPAD_ROW0_PIN, KEYPAD_COL0_PIN, true);
run_test();
set_key_level(ROW0_PIN, COL0_PIN, false);
set_key_level(KEYPAD_ROW0_PIN, KEYPAD_COL0_PIN, false);
run_test();
REQUIRE(released_keys['1']);
}
SECTION("module handles multiple key presses")
{
set_key_level(ROW0_PIN, COL0_PIN, true);
set_key_level(ROW1_PIN, COL1_PIN, true);
set_key_level(ROW2_PIN, COL2_PIN, true);
set_key_level(ROW3_PIN, COL0_PIN, true);
set_key_level(KEYPAD_ROW0_PIN, KEYPAD_COL0_PIN, true);
set_key_level(KEYPAD_ROW1_PIN, KEYPAD_COL1_PIN, true);
set_key_level(KEYPAD_ROW2_PIN, KEYPAD_COL2_PIN, true);
set_key_level(KEYPAD_ROW3_PIN, KEYPAD_COL0_PIN, true);
run_test();
......@@ -97,19 +97,19 @@ TEST_CASE("keypad module scans the keypad")
SECTION("module handles multiple key releases while some keys are still pressed")
{
set_key_level(ROW0_PIN, COL0_PIN, true);
set_key_level(ROW1_PIN, COL1_PIN, true);
set_key_level(ROW2_PIN, COL2_PIN, true);
set_key_level(ROW3_PIN, COL0_PIN, true);
set_key_level(KEYPAD_ROW0_PIN, KEYPAD_COL0_PIN, true);
set_key_level(KEYPAD_ROW1_PIN, KEYPAD_COL1_PIN, true);
set_key_level(KEYPAD_ROW2_PIN, KEYPAD_COL2_PIN, true);
set_key_level(KEYPAD_ROW3_PIN, KEYPAD_COL0_PIN, true);
run_test();
REQUIRE(pressed_keys['1']);
REQUIRE(pressed_keys['5']);
REQUIRE(pressed_keys['9']);
REQUIRE(pressed_keys['*']);
set_key_level(ROW0_PIN, COL0_PIN, false);
set_key_level(ROW1_PIN, COL1_PIN, false);
set_key_level(ROW2_PIN, COL2_PIN, false);
set_key_level(KEYPAD_ROW0_PIN, KEYPAD_COL0_PIN, false);
set_key_level(KEYPAD_ROW1_PIN, KEYPAD_COL1_PIN, false);
set_key_level(KEYPAD_ROW2_PIN, KEYPAD_COL2_PIN, false);
run_test();
REQUIRE(released_keys['1']);
REQUIRE(released_keys['5']);
......@@ -126,9 +126,9 @@ TEST_CASE("keypad module scans the keypad")
door_configured_input_pins = mask;
};
run_test();
REQUIRE(door_configured_input_pins == (PIN_MASK(COL0_PIN) |
PIN_MASK(COL1_PIN) |
PIN_MASK(COL2_PIN)));
REQUIRE(door_configured_input_pins == (PIN_MASK(KEYPAD_COL0_PIN) |
PIN_MASK(KEYPAD_COL1_PIN) |
PIN_MASK(KEYPAD_COL2_PIN)));
}
SECTION("module sets up output pins")
......@@ -139,15 +139,15 @@ TEST_CASE("keypad module scans the keypad")
door_configured_output_pins = mask;
};
run_test();
REQUIRE(door_configured_output_pins == (PIN_MASK(ROW0_PIN) |
PIN_MASK(ROW1_PIN) |
PIN_MASK(ROW2_PIN) |
PIN_MASK(ROW3_PIN)));
REQUIRE(door_configured_output_pins == (PIN_MASK(KEYPAD_ROW0_PIN) |
PIN_MASK(KEYPAD_ROW1_PIN) |
PIN_MASK(KEYPAD_ROW2_PIN) |
PIN_MASK(KEYPAD_ROW3_PIN)));
}
SECTION("module unregisters callbacks")
{
set_key_level(ROW0_PIN, COL0_PIN, true);
set_key_level(KEYPAD_ROW0_PIN, KEYPAD_COL0_PIN, true);
door_keypad_callback_t a = {
.on_press = press,
.on_release = release,
......@@ -158,7 +158,7 @@ TEST_CASE("keypad module scans the keypad")
door_keypad_stop();
door_keypad_scan_task(nullptr);
set_key_level(ROW0_PIN, COL0_PIN, false);
set_key_level(KEYPAD_ROW0_PIN, KEYPAD_COL0_PIN, false);
door_keypad_initialize();
door_keypad_unregister_callback(cb);
door_keypad_stop();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment