Ejemplo n.º 1
0
TEST(CodeCheckTests, test_if_key_input_is_valid_12c)
{

    CodeCheck checker;
    checker.keyPressed(1);
    checker.keyPressed(2);
    checker.keyPressed(0);
    EXPECT_EQ("", checker.getCodeEntered());
}
Ejemplo n.º 2
0
TEST(CodeCheckTests, test_if_key_input_is_valid_12e)//e should reset code if code incorrect
{

    CodeCheck checker;
    checker.keyPressed(1);
    checker.keyPressed(2);
    checker.keyPressed(2);
    EXPECT_EQ("", checker.getCodeEntered());
}
Ejemplo n.º 3
0
TEST(CodeCheckTests, test_if_key_input_is_valid_doorPin_true_1234e)
{
    bool unlockCalled = false;

    CodeCheck checker;

    checker.SetUnlockCallback([&unlockCalled]()
    {
        unlockCalled = true;
    });

    checker.keyPressed(9);
    checker.keyPressed(11);
    checker.keyPressed(8);
    checker.keyPressed(10);
    checker.keyPressed(2);
    EXPECT_TRUE(unlockCalled) << "unlock Callback wasn't called";
}
Ejemplo n.º 4
0
TEST(CodeCheckTests, test_if_key_input_is_invalid_doorPin_false_1233e)
{
    bool unlockCalled = false;

    CodeCheck checker;
    checker.SetUnlockCallback([&unlockCalled]()
    {
        unlockCalled = true;
    });
    checker.keyPressed(9);
    checker.keyPressed(11);
    checker.keyPressed(8);
    checker.keyPressed(6);
    checker.keyPressed(2);
    EXPECT_FALSE(unlockCalled) << "unlock Callback was called when it wasn't expected";
}
Ejemplo n.º 5
0
TEST(CodeCheckTests, test_if_no_code_has_been_entered)
{

    CodeCheck checker;
    EXPECT_EQ(false, checker.inputCheck(""));
}
Ejemplo n.º 6
0
TEST(CodeCheckTests, test_if_the_strings_match)
{
    CodeCheck checker;
    EXPECT_EQ(true, checker.inputCheck("1234"));
}
Ejemplo n.º 7
0
TEST(CodeCheckTests, test_if_incorrect_code_is_entered_returns_false)
{

    CodeCheck checker;
    EXPECT_EQ(false, checker.inputCheck("12364"));
}
Ejemplo n.º 8
0
int main()
{
    wiringPiSetup();

    std::string boxID = "1111R";
    std::string URL = "http://192.168.0.110/events/";

    LibCurlPostClient client = LibCurlPostClient();
    Postman pat(URL, &client);
    Cabinet cabinet(&pat, boxID);

    using namespace std::placeholders;

    auto doorEventCallback = std::bind(&Cabinet::DoorEventCallback, &cabinet, _1);

    WiringPiPin doorPin{2};
    Switch doorSwitch{&doorPin, doorEventCallback};

    /**** hanger switch ****/

    auto hangerEventCallback = std::bind(&Cabinet::HangerEventCallback, &cabinet, _1);

    WiringPiPin hangerPin{3};
    Switch hangerSwitch{&hangerPin, hangerEventCallback};


    /**** H-Bridge Lock ****/
    WiringPiPin lockOpen{0};
    WiringPiPin lockClose{7};

    // If the program has been run before then make
    // sure both of the pins are low before configuring
    // either of them as outputs
    lockOpen.State(false);
    lockClose.State(false);

    lockOpen.ConfigureAsOutput();
    lockOpen.State(false);
    // IMPORTANT - make sure the Open pin is low before
    // changing the Close pin to an output to avoid
    // shorting the power rails
    lockClose.ConfigureAsOutput();
    lockClose.State(false);

    HBridgeLock lock{&lockOpen, &lockClose};

    /**** Matrix Keypad ****/
    WiringPiPin column1{27};
    WiringPiPin column2{28};
    WiringPiPin column3{29};

    WiringPiPin row1{22};
    WiringPiPin row2{23};
    WiringPiPin row3{24};
    WiringPiPin row4{25};

    column1.ConfigureAsOutput();
    column2.ConfigureAsOutput();
    column3.ConfigureAsOutput();

    MatrixKeypadReader reader{&column1, &column2, &column3, &row1, &row2, &row3, &row4};
    MatrixKeypad keypad{&reader};

    CodeCheck codeChecker;

    using namespace std::placeholders;
    keypad.SetKeyPressedCallback(std::bind(&CodeCheck::keyPressed, &codeChecker, _1));
    codeChecker.SetUnlockCallback(std::bind(&HBridgeLock::Unlock, &lock));


    while(true)
    {
        keypad.Service();
        lock.Service();

        doorSwitch.Service();

        hangerSwitch.Service();

        /* Limit how fast ServiceIter is run, otherwise will deplete the
            battery quicker than it should. */

        std::this_thread::sleep_for(std::chrono::milliseconds(SERVICE_SLEEP_TIME_MILLISECONDS));

    }

    return 0;

}