diff --git a/FlippR-Driver/CMakeLists.txt b/FlippR-Driver/CMakeLists.txt index a998016..18855c0 100644 --- a/FlippR-Driver/CMakeLists.txt +++ b/FlippR-Driver/CMakeLists.txt @@ -120,7 +120,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${Threads_LIBRARIES}) if(ENABLE_TESTING) - add_subdirectory(tests) + #add_subdirectory(tests) + message(WARNING "Tests not built!") endif(ENABLE_TESTING) if(BUILD_NETWORKING) diff --git a/FlippR-Driver/contrib/json_example/input/Input_Matrix_Config.json b/FlippR-Driver/contrib/json_example/input/Input_Matrix_Config.json index 00ed848..afb858c 100644 --- a/FlippR-Driver/contrib/json_example/input/Input_Matrix_Config.json +++ b/FlippR-Driver/contrib/json_example/input/Input_Matrix_Config.json @@ -3,6 +3,7 @@ "input_matrix" : [ { +<<<<<<< HEAD "name" : "Tilt 2", "address" : 2, "priority" : 2 @@ -34,187 +35,347 @@ }, { "name" : "Outhole", +======= + "name" : "Outhole", + "name_datasheeet" : "Out hole", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 16, "priority" : 99, "bounce_time" : 10 }, { "name" : "Left Outlane", +<<<<<<< HEAD +======= + "name_datasheeet" : "Left outer exit canal", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 17, "priority" : 2 }, { "name" : "Left Inlane", +<<<<<<< HEAD +======= + "name_datasheeet" : "Inner left canal", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 18, "priority" : 2 }, { "name" : "Left Slingshot", +<<<<<<< HEAD +======= + "name_datasheeet" : "Left flap contacts", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 19, "priority" : 2 }, { "name" : "Right Slingshot", +<<<<<<< HEAD +======= + "name_datasheeet" : "Right flap contacts", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 20, "priority" : 2 }, { "name" : "Right Inlane", +<<<<<<< HEAD +======= + "name_datasheeet" : "Right inner canal", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 21, "priority" : 2 }, { "name" : "Right Outlane", +<<<<<<< HEAD +======= + "name_datasheeet" : "Right central exit canal", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 22, "priority" : 2 }, { "name" : "Right Outlane Kicker", +<<<<<<< HEAD +======= + "name_datasheeet" : "Right kicker contact", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 23, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Rebound Contact", +======= + "name" : " Rebound Contact", + "name_datasheeet" : "Contacts", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 24, "priority" : 2 }, { "name" : "Left Bank Left", +<<<<<<< HEAD +======= + "name_datasheeet" : "1st moving target bottom left bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 25, "priority" : 2 }, { "name" : "Left Bank Middle Left", +<<<<<<< HEAD +======= + "name_datasheeet" : "2nd moving target bottom left bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 26, "priority" : 2 }, { "name" : "Left Bank Middle Right", +<<<<<<< HEAD +======= + "name_datasheeet" : "3rd moving target bottom left bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 27, "priority" : 2 }, { "name" : "Left Bank Right", +<<<<<<< HEAD +======= + "name_datasheeet" : "4th moving target bottom left bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 28, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Special Red", +======= + "name" : "Special red", + "name_datasheeet" : "Fixed special red target", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 29, "priority" : 2 }, { "name" : "Special Orange", +<<<<<<< HEAD +======= + "name_datasheeet" : "Fixed special orange target", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 30, "priority" : 2 }, { "name" : "Right Bank Left", +<<<<<<< HEAD +======= + "name_datasheeet" : "1st moving target bottom right bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 31, "priority" : 2 }, { "name" : "Right Bank Middle", +<<<<<<< HEAD +======= + "name_datasheeet" : "2nd moving target bottom right bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 32, "priority" : 2 }, { "name" : "Right Bank Right", +<<<<<<< HEAD +======= + "name_datasheeet" : "3rd moving target bottom right bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 33, "priority" : 2 }, { "name" : "Spinner", +<<<<<<< HEAD +======= + "name_datasheeet" : "Spinning target", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 34, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Canal Button Top", +======= + "name" : "Canal Button Bottom", + "name_datasheeet" : "1st Button", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 35, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Canal Button Middle Top", +======= + "name" : "Canal Button Middle Bottom", + "name_datasheeet" : "2nd button", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 36, "priority" : 2 }, { "name" : "Canal Button Middle", +<<<<<<< HEAD +======= + "name_datasheeet" : "3rd button", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 37, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Canal Button Middle Bottom", +======= + "name" : "Canal Button Middle Top", + "name_datasheeet" : "4th button", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 38, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Canal Button Bottom", +======= + "name" : "Canal Button Top", + "name_datasheeet" : "5th button", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 39, "priority" : 2 }, { "name" : "Top Bank Left", +<<<<<<< HEAD +======= + "name_datasheeet" : "1st moving target top central bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 40, "priority" : 2 }, { "name" : "Top Bank Middle Left", +<<<<<<< HEAD +======= + "name_datasheeet" : "2nd moving target top central bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 41, "priority" : 2 }, { "name" : "Top Bank Middle", +<<<<<<< HEAD +======= + "name_datasheeet" : "3rd moving target top central bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 42, "priority" : 2 }, { "name" : "Top Bank Middle Right", +<<<<<<< HEAD +======= + "name_datasheeet" : "4th moving target top central bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 43, "priority" : 2 }, { "name" : "Top Bank Right", +<<<<<<< HEAD +======= + "name_datasheeet" : "5th moving target top central bank", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 44, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Fixed Target 1", +======= + "name" : "Fixed target 1", + "name_datasheeet" : "1st fixed target", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 45, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Fixed Target 2", +======= + "name" : "Fixed target 2", + "name_datasheeet" : "2nd fixed target", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 46, "priority" : 2 }, { "name" : "Left Pop", +<<<<<<< HEAD +======= + "name_datasheeet" : "Top left pop contact", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 47, "priority" : 2 }, { "name" : "Right Pop", +<<<<<<< HEAD +======= + "name_datasheeet" : "Bottom right pop contact", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 48, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Fixed Target 5", +======= + "name" : "Fixed target 5", + "name_datasheeet" : "5th fixed target", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 49, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Fixed Target 4", +======= + "name" : "Fixed target 4", + "name_datasheeet" : "4th fixed target", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 50, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Fixed Target 3", +======= + "name" : "Fixed target 3", + "name_datasheeet" : "3rd fixed target", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 51, "priority" : 2 }, { +<<<<<<< HEAD "name" : "Rising ball", +======= + "name" : "Rising Ball", + "name_datasheeet" : "Rising ball contact", +>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f "address" : 52, "priority" : 2 } diff --git a/FlippR-Driver/contrib/json_example/output/Display_Config.json b/FlippR-Driver/contrib/json_example/output/Display_Config.json index 2998018..397d6c7 100644 --- a/FlippR-Driver/contrib/json_example/output/Display_Config.json +++ b/FlippR-Driver/contrib/json_example/output/Display_Config.json @@ -1,4 +1,4 @@ -{ + { "update_frequency": 1000, "display_board" : { @@ -15,7 +15,8 @@ "C": 6, "D": 5 }, - "run" : 12 + "run" : 21, + "lt" : 26 }, "displays" : [ diff --git a/FlippR-Driver/include/output/OutputDriver.h b/FlippR-Driver/include/output/OutputDriver.h index 3a76137..466af89 100644 --- a/FlippR-Driver/include/output/OutputDriver.h +++ b/FlippR-Driver/include/output/OutputDriver.h @@ -39,6 +39,7 @@ public: void activate_displays() const; void deactivate_displays() const; + void rotate_displays() const; void activate_all_lamps() const; void deactivate_all_lamps() const; diff --git a/FlippR-Driver/networking/output/OutputRequestHandler.cpp b/FlippR-Driver/networking/output/OutputRequestHandler.cpp index 537210d..eb17bc3 100644 --- a/FlippR-Driver/networking/output/OutputRequestHandler.cpp +++ b/FlippR-Driver/networking/output/OutputRequestHandler.cpp @@ -230,6 +230,12 @@ boost::optional OutputRequestHandler::parseDisplay(const std return response; } + if (display_name == "test") + { + this->output_driver->rotate_displays(); + return response; + } + auto opt_display = this->output_driver->get_display(display_name); if(!opt_display) diff --git a/FlippR-Driver/src/output/detail/DisplayBoardPinController.cpp b/FlippR-Driver/src/output/detail/DisplayBoardPinController.cpp index 9a6c9c9..434844c 100644 --- a/FlippR-Driver/src/output/detail/DisplayBoardPinController.cpp +++ b/FlippR-Driver/src/output/detail/DisplayBoardPinController.cpp @@ -16,12 +16,10 @@ namespace detail { DisplayBoardPinController::DisplayBoardPinController(std::map & pins_display) : - pins_display_board{std::move(pins_display)} + pins_display_board{} { + this->set_pin_map(pins_display); initialize_pins_output(); - - clear(); - CLOG(DEBUG, OUTPUT_LOGGER) << "Created DisplayBoardPinController"; } @@ -31,26 +29,20 @@ DisplayBoardPinController::DisplayBoardPinController() : CLOG(DEBUG, OUTPUT_LOGGER) << "Created DisplayBoardPinController without pin map"; } -void DisplayBoardPinController::clear() -{ - std::for_each(this->pins_display_board.begin(), this->pins_display_board.end(), [](auto& pin) { write_pin(pin.second, 0); }); -} - void DisplayBoardPinController::initDisplay(const items::OutputDisplay &display) const { initialize_output_pin(display.get_address()); - - write_pin(display.get_address(), 0); + write_pin(display.get_address(), DISPLAY_LOW); } void DisplayBoardPinController::activate_displays() const { - write_pin(pins_display_board.at("run"), 1); + write_pin(pins_display_board.at("run"), DISPLAY_LOW); } void DisplayBoardPinController::deactivate_displays() const { - write_pin(pins_display_board.at("run"), 0); + write_pin(pins_display_board.at("run"), DISPLAY_HIGH); } void DisplayBoardPinController::write_display(const items::OutputDisplay &display) const @@ -66,11 +58,8 @@ void DisplayBoardPinController::write_display(const items::OutputDisplay &displa void DisplayBoardPinController::write_display_digit(uint8_t display_address, uint8_t content, uint8_t position) const { select_display_segment(position); - select_display_digit(content); - run_display(display_address); - std::this_thread::sleep_for(std::chrono::milliseconds(DISPLAY_SLEEP_TIME_MILLI)); } @@ -91,25 +80,33 @@ void DisplayBoardPinController::select_display_digit(uint8_t content) const void DisplayBoardPinController::run_display(uint8_t address) const { - write_pin(address, 1); - write_pin(address, 0); + write_pin(address, DISPLAY_HIGH); + write_pin(address, DISPLAY_LOW); } void DisplayBoardPinController::set_pin_map(std::map & pins_display) { this->pins_display_board.insert(pins_display.begin(), pins_display.end()); - this->initialize_pins_output(); - - clear(); + this->init_pin_states(); } void DisplayBoardPinController::initialize_pins_output() { - for(auto& pin : this->pins_display_board) { + for(auto& pin : this->pins_display_board) + { initialize_output_pin(pin.second); } } +void DisplayBoardPinController::init_pin_states() +{ + for(auto& pin : this->pins_display_board) + { + write_pin(pin.second, DISPLAY_LOW); + } + write_pin(this->pins_display_board["run"], DISPLAY_HIGH); +} + } } } \ No newline at end of file diff --git a/FlippR-Driver/src/output/detail/DisplayBoardPinController.h b/FlippR-Driver/src/output/detail/DisplayBoardPinController.h index 7dcaf84..9fe3bc0 100644 --- a/FlippR-Driver/src/output/detail/DisplayBoardPinController.h +++ b/FlippR-Driver/src/output/detail/DisplayBoardPinController.h @@ -34,11 +34,11 @@ public: private: void initialize_pins_output(); - void clear(); void write_display_digit(uint8_t display_address, uint8_t content, uint8_t position) const; void select_display_segment(uint8_t digit) const; void select_display_digit(uint8_t content) const; void run_display(uint8_t address) const; + void init_pin_states(); private: std::map pins_display_board; diff --git a/FlippR-Driver/src/output/detail/OutputDriver.cpp b/FlippR-Driver/src/output/detail/OutputDriver.cpp index 37444fc..4842be1 100644 --- a/FlippR-Driver/src/output/detail/OutputDriver.cpp +++ b/FlippR-Driver/src/output/detail/OutputDriver.cpp @@ -161,6 +161,23 @@ void OutputDriver::shut_down_driver() const CLOG(INFO, OUTPUT_LOGGER) << "Deactivated all output items."; } +void OutputDriver::rotate_displays() const +{ + CLOG(INFO, OUTPUT_LOGGER) << "Running display test!"; + for (auto display : this->get_displays()) + { + CLOG(INFO, OUTPUT_LOGGER) << "Testing display " << display->get_name(); + for (int i = 8; i < 100000000; i = i*10) + { + CLOG(INFO, OUTPUT_LOGGER) << "Score " << i; + display->write_score(i); + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + } + display->write_score(0); + } + CLOG(INFO, OUTPUT_LOGGER) << "Display test finished!"; +} + } } /* namespace output */ diff --git a/FlippR-Driver/src/output/factories/DisplayFactory.cpp b/FlippR-Driver/src/output/factories/DisplayFactory.cpp index 49613b4..8910e42 100644 --- a/FlippR-Driver/src/output/factories/DisplayFactory.cpp +++ b/FlippR-Driver/src/output/factories/DisplayFactory.cpp @@ -45,6 +45,7 @@ void DisplayFactory::create_pin_map() { nlohmann::json board_config = this->object.at(config_path::display_board); this->pin_map["run"] = board_config.at(config_path::run_pin); + this->pin_map["lt"] = board_config.at(config_path::display_lt_pin); nlohmann::json segment_select = board_config.at(config_path::display_segement_select); this->pin_map["segment_select_A"] = segment_select.at("A"); diff --git a/FlippR-Driver/src/output/factories/ItemFactory.h b/FlippR-Driver/src/output/factories/ItemFactory.h index 216bb2b..1aa4182 100644 --- a/FlippR-Driver/src/output/factories/ItemFactory.h +++ b/FlippR-Driver/src/output/factories/ItemFactory.h @@ -48,6 +48,7 @@ namespace config_path const char display_digit_select[] = "digit_select"; const char display_digits[] = "digits"; const char display_list[] = "displays"; + const char display_lt_pin[] = "lt"; } class ItemFactory diff --git a/FlippR-Driver/src/output/items/detail/Display.cpp b/FlippR-Driver/src/output/items/detail/Display.cpp index dd8d037..14bb4a9 100644 --- a/FlippR-Driver/src/output/items/detail/Display.cpp +++ b/FlippR-Driver/src/output/items/detail/Display.cpp @@ -45,8 +45,8 @@ std::string Display::fit_score_string(std::string & score_string, const unsigned if (score_length > length) { CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display"; - std::string full_display; - return full_display.insert(0, length, '9'); + std::string filled_display; + return filled_display.insert(0, length, '9'); } score_string.insert(0, length - score_length, '\0'); diff --git a/FlippR-Driver/src/utility/config.h b/FlippR-Driver/src/utility/config.h index 7e5245d..051a1bd 100644 --- a/FlippR-Driver/src/utility/config.h +++ b/FlippR-Driver/src/utility/config.h @@ -16,6 +16,9 @@ #define INPUT_SLEEP_DURATION_NANO 800 #define INPUT_HANDLER_TIMEOUT_MILLI 2000 +#define DISPLAY_HIGH 0 +#define DISPLAY_LOW 1 + #define PULLDOWN false #define DISPLAY_SLEEP_TIME_MILLI 1 diff --git a/FlippR-Driver/src/utility/wiringPiTesting.hpp b/FlippR-Driver/src/utility/wiringPiTesting.hpp index b952d71..9edcb00 100644 --- a/FlippR-Driver/src/utility/wiringPiTesting.hpp +++ b/FlippR-Driver/src/utility/wiringPiTesting.hpp @@ -2,8 +2,8 @@ // Created by johannes on 17.07.19. // -#ifndef FLIPPR_DRIVER_WIRINGPITESTING_H -#define FLIPPR_DRIVER_WIRINGPITESTING_H +#ifndef FLIPPR_DRIVER_TEST_WIRINGPITESTING_H +#define FLIPPR_DRIVER_TEST_WIRINGPITESTING_H #include #include @@ -17,24 +17,24 @@ static int wiringPiSetup() return 0; } -void pinMode(int pin, int mode) +static void pinMode(int pin, int mode) { //std::cout << "Set pin " << pin << " into mode " << mode << std::endl; } -int digitalRead(int pin) +static int digitalRead(int pin) { //std::cout << "Reading pin " << pin << std::endl return rand()%2 == 0 ? 1 : 0; } -void digitalWrite(int pin, int value) +static void digitalWrite(int pin, int value) { //std::cout << "Writing pin " << pin << " with value " << value << std::endl; } -int mcp23017Setup(const int pinBase, const int i2cAddress) +static int mcp23017Setup(const int pinBase, const int i2cAddress) { //std::cout << "mcp23017Setup called with pinBase " << pinBase << " and i2cAddress " << i2cAddress << std::endl; diff --git a/cli/FlippR_Networking.py b/cli/FlippR_Networking.py index e3de1f1..aabea77 100644 --- a/cli/FlippR_Networking.py +++ b/cli/FlippR_Networking.py @@ -27,6 +27,9 @@ class Networking: def getDisplays(self): return self.get("/displays").json() + def testDisplays(self): + return self.get("/displays/test") + def triggerSolenoid(self, solenoid): self.get("/solenoids/" + solenoid + "/trigger") diff --git a/cli/main.py b/cli/main.py old mode 100644 new mode 100755