diff --git a/.idea/workspace.xml b/.idea/workspace.xml index eb6c324..5787d34 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -12,8 +12,14 @@ + + + + - + + + + + - + - - - - - - - - - - - + + - + - - + + + + + + + + + - + - - + + - + + + + + + + + + + - - + + @@ -76,19 +92,19 @@ - + - - + + - + - - + + @@ -96,8 +112,8 @@ - - + + @@ -105,16 +121,6 @@ - - - - - - - - - - @@ -132,8 +138,6 @@ @@ -229,6 +235,13 @@ + + + + + + + @@ -263,6 +276,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -323,6 +361,7 @@ + @@ -394,12 +433,15 @@ - + + + + - @@ -414,7 +456,7 @@ - + @@ -462,88 +504,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -575,13 +535,6 @@ - - - - - - - @@ -1158,13 +1111,6 @@ - - - - - - - @@ -1175,12 +1121,6 @@ - - - - - - @@ -1202,6 +1142,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -1209,6 +1173,12 @@ + + + + + + @@ -1220,52 +1190,113 @@ + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + - - - - - + + - + - - + + - - + + diff --git a/FlippR-Driver/include/output/OutputDriver.h b/FlippR-Driver/include/output/OutputDriver.h index bd5e60b..3b16cd7 100644 --- a/FlippR-Driver/include/output/OutputDriver.h +++ b/FlippR-Driver/include/output/OutputDriver.h @@ -32,6 +32,10 @@ public: virtual void activate_displays() const = 0; virtual void deactivate_displays() const = 0; + virtual void deactivate_all_lamps() const; + virtual void activate_all_lamps() const; + virtual void rotate_all_lamps() const; + virtual std::vector> get_lamps() const = 0; virtual std::vector> get_solenoids() const = 0; virtual std::vector> get_sounds() const = 0; diff --git a/FlippR-Driver/src/output/detail/OutputDriver.cpp b/FlippR-Driver/src/output/detail/OutputDriver.cpp index 73d8f71..5e3864c 100644 --- a/FlippR-Driver/src/output/detail/OutputDriver.cpp +++ b/FlippR-Driver/src/output/detail/OutputDriver.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "OutputDriver.h" @@ -37,6 +38,28 @@ void OutputDriver::deactivate_displays() const display_controller->deactivate_displays(); } + +void OutputDriver::deactivate_all_lamps() const +{ + std::for_each(lamps.begin(), lamps.end(), [](items::Lamp& lamp){lamp.deactivate();}); +} + +void OutputDriver::activate_all_lamps() const +{ + std::for_each(lamps.begin(), lamps.end(), [](items::Lamp& lamp){lamp.activate();}); +} + +void OutputDriver::rotate_all_lamps() const +{ + for(auto lamp = lamps.begin(); lamp != lamps.end(); lamp++) + { + lamp->second->activate(); + // ToDo sleep time + is this thread safe?? + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + lamp->second->deactivate(); + } +} + std::vector> OutputDriver::get_sounds() const { std::vector> sounds; @@ -93,6 +116,7 @@ boost::optional> OutputDriver::get_display(uint8 return this->displays.find(number)->second; } + } } /* namespace output */ } diff --git a/FlippR-Driver/src/output/detail/OutputDriver.h b/FlippR-Driver/src/output/detail/OutputDriver.h index ea130bb..e6c2a8e 100644 --- a/FlippR-Driver/src/output/detail/OutputDriver.h +++ b/FlippR-Driver/src/output/detail/OutputDriver.h @@ -23,13 +23,20 @@ namespace detail class OutputDriver : public output::OutputDriver { public: - OutputDriver(std::unique_ptr display_controller, std::map> solenoids, std::map> lamps, std::map> sounds, std::map> displays); + OutputDriver(std::unique_ptr display_controller, std::map> solenoids, + std::map> lamps, std::map> sounds, + std::map> displays); ~OutputDriver() override = default; void activate_displays() const override; void deactivate_displays() const override; + void deactivate_all_lamps() const override; + void activate_all_lamps() const override; + void rotate_all_lamps() const override; + + // todo driver board run for activate/deactivate? // todo what is flipper_relay ? std::vector> get_lamps() const override; std::vector> get_solenoids() const override; diff --git a/FlippR-Driver/src/utility/networking/output/OutputRequestHandler.cpp b/FlippR-Driver/src/utility/networking/output/OutputRequestHandler.cpp index c727318..a257114 100644 --- a/FlippR-Driver/src/utility/networking/output/OutputRequestHandler.cpp +++ b/FlippR-Driver/src/utility/networking/output/OutputRequestHandler.cpp @@ -28,7 +28,7 @@ OutputRequestHandler::OutputRequestHandler(std::shared_ptr * address/{item_type}/[item_name]/[action]/[score] * * Where - * {item_type} is either solenoids, lamps, sounds, displays + * {item_type} is either solenoids, lamps, sounds, displays, or one of the two special events: activate and deactivate * [item_name] is the string name of an item (optional if you want to get the list of all available items) * [action] is the particular action for the item: * Solenoids: trigger @@ -43,15 +43,29 @@ void OutputRequestHandler::handleRequest(HTTPServerRequest &request, HTTPServerResponse &response) { auto path_segments = getPathSegments(URI(request.getURI())); - // ToDo catch exception + + // fill up vector + for(int i = path_segments.size(); i < 4; i++) + { + path_segments.emplace_back(""); + } + std::string item_type = path_segments.at(0); std::string item_name = path_segments.at(1); std::string action = path_segments.at(2); - std::string score = ""; + std::string score = path_segments.at(3); - if(item_type == "displays") + if(item_type == "deactivate") { - score = path_segments.at(3); + this->output_driver->deactivate_displays(); + this->output_driver->deactivate_all_lamps(); + return; + } + + if(item_type == "activate") + { + this->output_driver->activate_displays(); + return; } response.setContentType("text/json"); @@ -105,7 +119,7 @@ boost::optional OutputRequestHandler::parseSolenoid(const st if(item_name == "") { Poco::JSON::Object response; - response.set("solenoids", output_driver->get_solenoids()); + response.set("solenoids", this->output_driver->get_solenoids()); return response; } @@ -135,7 +149,7 @@ boost::optional OutputRequestHandler::parseLamp(const std::s if(item_name == "") { Poco::JSON::Object response; - response.set("lamps", output_driver->get_lamps()); + response.set("lamps", this->output_driver->get_lamps()); return response; } @@ -169,7 +183,7 @@ boost::optional OutputRequestHandler::parseSound(const std:: if(item_name == "") { Poco::JSON::Object response; - response.set("sounds", output_driver->get_lamps()); + response.set("sounds", this->output_driver->get_lamps()); return response; } @@ -199,9 +213,10 @@ boost::optional OutputRequestHandler::parseDisplay(const std if(item_name == "") { Poco::JSON::Object response; - response.set("displays", output_driver->get_displays()); + response.set("displays", this->output_driver->get_displays()); return response; } + uint8_t display_number = std::stoi(item_name); auto opt_display = this->output_driver->get_display(display_number); @@ -240,7 +255,6 @@ std::vector OutputRequestHandler::getPathSegments(Poco::URI uri) return path_segments; } - } } diff --git a/FlippR-Driver/tests/input/TestEventHandler.cpp b/FlippR-Driver/tests/input/TestEventHandler.cpp index 1084860..f6c127d 100644 --- a/FlippR-Driver/tests/input/TestEventHandler.cpp +++ b/FlippR-Driver/tests/input/TestEventHandler.cpp @@ -37,7 +37,7 @@ SCENARIO("An EventHandler gets created", "[construction}") THEN("It should register itself at the input_driver") { - REQUIRE((bool)Verify(Method(input_driver_mock, register_event_handler).Using(&handler))); + REQUIRE((bool)Verify(Method(input_driver_mock, register_event_handler).Using(&handler))); } } } diff --git a/FlippR-Driver/tests/output/TestLamp.cpp b/FlippR-Driver/tests/output/TestLamp.cpp index 051bafc..cef9e99 100644 --- a/FlippR-Driver/tests/output/TestLamp.cpp +++ b/FlippR-Driver/tests/output/TestLamp.cpp @@ -10,16 +10,51 @@ #include "utility/LoggerFactory.h" - -// testing purposes -#define private public - #include "output/items/detail/Lamp.h" using namespace flippR_driver::output; using namespace fakeit; -SCENARIO("") +SCENARIO("A Lamp gets activated") { + GIVEN("A Lamp") + { + Mock pin_controller; + Fake(Dtor(pin_controller)); + When(Method(pin_controller, activate)).AlwaysReturn(); + items::detail::Lamp lamp(std::make_shared(pin_controller), 0, 0); + + WHEN("The lamp gets activated") + { + lamp.activate(); + + THEN("It should call the pin_controller with itself") + { + REQUIRE((bool) Verify(Method(pin_controller, activate).Using(&lamp))); + } + } + } +} + +SCENARIO("A Lamp gets deactivated") +{ + GIVEN("A Lamp") + { + Mock pin_controller; + Fake(Dtor(pin_controller)); + When(Method(pin_controller, deactivate)).AlwaysReturn(); + + items::detail::Lamp lamp(std::make_shared(pin_controller), 0, 0); + + WHEN("The lamp gets deactivated") + { + lamp.deactivate(); + + THEN("It should call the pin_controller with itself") + { + REQUIRE((bool) Verify(Method(pin_controller, deactivate).Using(&lamp))); + } + } + } } diff --git a/FlippR-Driver/tests/output/TestOutputDriver.cpp b/FlippR-Driver/tests/output/TestOutputDriver.cpp index e11add3..8ad2078 100644 --- a/FlippR-Driver/tests/output/TestOutputDriver.cpp +++ b/FlippR-Driver/tests/output/TestOutputDriver.cpp @@ -5,6 +5,7 @@ * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert */ +#include #include "catch.hpp" #include "fakeit.hpp" @@ -14,13 +15,24 @@ // testing purposes #define private public -#include "output/OutputDriver.h" +#include "output/detail/OutputDriver.h" -using namespace flippR_driver::output; +using namespace flippR_driver; using namespace fakeit; -SCENARIO("") +SCENARIO("The OutputDriver should activate the displays") { + GIVEN("An OutputDriver") + { + Mock display_controller; + When(Method(display_controller, activate_displays)).AlwaysReturn(); + output::detail::OutputDriver outputDriver(std::make_unique(display_controller), nullptr, nullptr, nullptr, nullptr); + output::detail::OutputDriver output_driver(std::make_unique(display_controller), NULL, nullptr, nullptr, nullptr); + WHEN("The displays get activated") + { + + } + } }