This commit is contained in:
Jonas Zeunert
2020-04-09 21:44:32 +02:00
15 changed files with 226 additions and 34 deletions

View File

@@ -120,7 +120,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${Threads_LIBRARIES})
if(ENABLE_TESTING) if(ENABLE_TESTING)
add_subdirectory(tests) #add_subdirectory(tests)
message(WARNING "Tests not built!")
endif(ENABLE_TESTING) endif(ENABLE_TESTING)
if(BUILD_NETWORKING) if(BUILD_NETWORKING)

View File

@@ -3,6 +3,7 @@
"input_matrix" : "input_matrix" :
[ [
{ {
<<<<<<< HEAD
"name" : "Tilt 2", "name" : "Tilt 2",
"address" : 2, "address" : 2,
"priority" : 2 "priority" : 2
@@ -34,187 +35,347 @@
}, },
{ {
"name" : "Outhole", "name" : "Outhole",
=======
"name" : "Outhole",
"name_datasheeet" : "Out hole",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 16, "address" : 16,
"priority" : 99, "priority" : 99,
"bounce_time" : 10 "bounce_time" : 10
}, },
{ {
"name" : "Left Outlane", "name" : "Left Outlane",
<<<<<<< HEAD
=======
"name_datasheeet" : "Left outer exit canal",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 17, "address" : 17,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Left Inlane", "name" : "Left Inlane",
<<<<<<< HEAD
=======
"name_datasheeet" : "Inner left canal",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 18, "address" : 18,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Left Slingshot", "name" : "Left Slingshot",
<<<<<<< HEAD
=======
"name_datasheeet" : "Left flap contacts",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 19, "address" : 19,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Right Slingshot", "name" : "Right Slingshot",
<<<<<<< HEAD
=======
"name_datasheeet" : "Right flap contacts",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 20, "address" : 20,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Right Inlane", "name" : "Right Inlane",
<<<<<<< HEAD
=======
"name_datasheeet" : "Right inner canal",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 21, "address" : 21,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Right Outlane", "name" : "Right Outlane",
<<<<<<< HEAD
=======
"name_datasheeet" : "Right central exit canal",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 22, "address" : 22,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Right Outlane Kicker", "name" : "Right Outlane Kicker",
<<<<<<< HEAD
=======
"name_datasheeet" : "Right kicker contact",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 23, "address" : 23,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Rebound Contact", "name" : "Rebound Contact",
=======
"name" : " Rebound Contact",
"name_datasheeet" : "Contacts",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 24, "address" : 24,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Left Bank Left", "name" : "Left Bank Left",
<<<<<<< HEAD
=======
"name_datasheeet" : "1st moving target bottom left bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 25, "address" : 25,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Left Bank Middle Left", "name" : "Left Bank Middle Left",
<<<<<<< HEAD
=======
"name_datasheeet" : "2nd moving target bottom left bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 26, "address" : 26,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Left Bank Middle Right", "name" : "Left Bank Middle Right",
<<<<<<< HEAD
=======
"name_datasheeet" : "3rd moving target bottom left bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 27, "address" : 27,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Left Bank Right", "name" : "Left Bank Right",
<<<<<<< HEAD
=======
"name_datasheeet" : "4th moving target bottom left bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 28, "address" : 28,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Special Red", "name" : "Special Red",
=======
"name" : "Special red",
"name_datasheeet" : "Fixed special red target",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 29, "address" : 29,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Special Orange", "name" : "Special Orange",
<<<<<<< HEAD
=======
"name_datasheeet" : "Fixed special orange target",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 30, "address" : 30,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Right Bank Left", "name" : "Right Bank Left",
<<<<<<< HEAD
=======
"name_datasheeet" : "1st moving target bottom right bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 31, "address" : 31,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Right Bank Middle", "name" : "Right Bank Middle",
<<<<<<< HEAD
=======
"name_datasheeet" : "2nd moving target bottom right bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 32, "address" : 32,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Right Bank Right", "name" : "Right Bank Right",
<<<<<<< HEAD
=======
"name_datasheeet" : "3rd moving target bottom right bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 33, "address" : 33,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Spinner", "name" : "Spinner",
<<<<<<< HEAD
=======
"name_datasheeet" : "Spinning target",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 34, "address" : 34,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Canal Button Top", "name" : "Canal Button Top",
=======
"name" : "Canal Button Bottom",
"name_datasheeet" : "1st Button",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 35, "address" : 35,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Canal Button Middle Top", "name" : "Canal Button Middle Top",
=======
"name" : "Canal Button Middle Bottom",
"name_datasheeet" : "2nd button",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 36, "address" : 36,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Canal Button Middle", "name" : "Canal Button Middle",
<<<<<<< HEAD
=======
"name_datasheeet" : "3rd button",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 37, "address" : 37,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Canal Button Middle Bottom", "name" : "Canal Button Middle Bottom",
=======
"name" : "Canal Button Middle Top",
"name_datasheeet" : "4th button",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 38, "address" : 38,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Canal Button Bottom", "name" : "Canal Button Bottom",
=======
"name" : "Canal Button Top",
"name_datasheeet" : "5th button",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 39, "address" : 39,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Top Bank Left", "name" : "Top Bank Left",
<<<<<<< HEAD
=======
"name_datasheeet" : "1st moving target top central bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 40, "address" : 40,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Top Bank Middle Left", "name" : "Top Bank Middle Left",
<<<<<<< HEAD
=======
"name_datasheeet" : "2nd moving target top central bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 41, "address" : 41,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Top Bank Middle", "name" : "Top Bank Middle",
<<<<<<< HEAD
=======
"name_datasheeet" : "3rd moving target top central bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 42, "address" : 42,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Top Bank Middle Right", "name" : "Top Bank Middle Right",
<<<<<<< HEAD
=======
"name_datasheeet" : "4th moving target top central bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 43, "address" : 43,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Top Bank Right", "name" : "Top Bank Right",
<<<<<<< HEAD
=======
"name_datasheeet" : "5th moving target top central bank",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 44, "address" : 44,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Fixed Target 1", "name" : "Fixed Target 1",
=======
"name" : "Fixed target 1",
"name_datasheeet" : "1st fixed target",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 45, "address" : 45,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Fixed Target 2", "name" : "Fixed Target 2",
=======
"name" : "Fixed target 2",
"name_datasheeet" : "2nd fixed target",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 46, "address" : 46,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Left Pop", "name" : "Left Pop",
<<<<<<< HEAD
=======
"name_datasheeet" : "Top left pop contact",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 47, "address" : 47,
"priority" : 2 "priority" : 2
}, },
{ {
"name" : "Right Pop", "name" : "Right Pop",
<<<<<<< HEAD
=======
"name_datasheeet" : "Bottom right pop contact",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 48, "address" : 48,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Fixed Target 5", "name" : "Fixed Target 5",
=======
"name" : "Fixed target 5",
"name_datasheeet" : "5th fixed target",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 49, "address" : 49,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Fixed Target 4", "name" : "Fixed Target 4",
=======
"name" : "Fixed target 4",
"name_datasheeet" : "4th fixed target",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 50, "address" : 50,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Fixed Target 3", "name" : "Fixed Target 3",
=======
"name" : "Fixed target 3",
"name_datasheeet" : "3rd fixed target",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 51, "address" : 51,
"priority" : 2 "priority" : 2
}, },
{ {
<<<<<<< HEAD
"name" : "Rising ball", "name" : "Rising ball",
=======
"name" : "Rising Ball",
"name_datasheeet" : "Rising ball contact",
>>>>>>> 362bbd9d368f163913e3f942e6b6006e50881b8f
"address" : 52, "address" : 52,
"priority" : 2 "priority" : 2
} }

View File

@@ -1,4 +1,4 @@
{ {
"update_frequency": 1000, "update_frequency": 1000,
"display_board" : "display_board" :
{ {
@@ -15,7 +15,8 @@
"C": 6, "C": 6,
"D": 5 "D": 5
}, },
"run" : 12 "run" : 21,
"lt" : 26
}, },
"displays" : "displays" :
[ [

View File

@@ -39,6 +39,7 @@ public:
void activate_displays() const; void activate_displays() const;
void deactivate_displays() const; void deactivate_displays() const;
void rotate_displays() const;
void activate_all_lamps() const; void activate_all_lamps() const;
void deactivate_all_lamps() const; void deactivate_all_lamps() const;

View File

@@ -230,6 +230,12 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseDisplay(const std
return response; return response;
} }
if (display_name == "test")
{
this->output_driver->rotate_displays();
return response;
}
auto opt_display = this->output_driver->get_display(display_name); auto opt_display = this->output_driver->get_display(display_name);
if(!opt_display) if(!opt_display)

View File

@@ -16,12 +16,10 @@ namespace detail
{ {
DisplayBoardPinController::DisplayBoardPinController(std::map<std::string, uint8_t> & pins_display) : DisplayBoardPinController::DisplayBoardPinController(std::map<std::string, uint8_t> & pins_display) :
pins_display_board{std::move(pins_display)} pins_display_board{}
{ {
this->set_pin_map(pins_display);
initialize_pins_output(); initialize_pins_output();
clear();
CLOG(DEBUG, OUTPUT_LOGGER) << "Created DisplayBoardPinController"; CLOG(DEBUG, OUTPUT_LOGGER) << "Created DisplayBoardPinController";
} }
@@ -31,26 +29,20 @@ DisplayBoardPinController::DisplayBoardPinController() :
CLOG(DEBUG, OUTPUT_LOGGER) << "Created DisplayBoardPinController without pin map"; 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 void DisplayBoardPinController::initDisplay(const items::OutputDisplay &display) const
{ {
initialize_output_pin(display.get_address()); initialize_output_pin(display.get_address());
write_pin(display.get_address(), DISPLAY_LOW);
write_pin(display.get_address(), 0);
} }
void DisplayBoardPinController::activate_displays() const 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 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 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 void DisplayBoardPinController::write_display_digit(uint8_t display_address, uint8_t content, uint8_t position) const
{ {
select_display_segment(position); select_display_segment(position);
select_display_digit(content); select_display_digit(content);
run_display(display_address); run_display(display_address);
std::this_thread::sleep_for(std::chrono::milliseconds(DISPLAY_SLEEP_TIME_MILLI)); 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 void DisplayBoardPinController::run_display(uint8_t address) const
{ {
write_pin(address, 1); write_pin(address, DISPLAY_HIGH);
write_pin(address, 0); write_pin(address, DISPLAY_LOW);
} }
void DisplayBoardPinController::set_pin_map(std::map<std::string, uint8_t> & pins_display) void DisplayBoardPinController::set_pin_map(std::map<std::string, uint8_t> & pins_display)
{ {
this->pins_display_board.insert(pins_display.begin(), pins_display.end()); this->pins_display_board.insert(pins_display.begin(), pins_display.end());
this->initialize_pins_output(); this->initialize_pins_output();
this->init_pin_states();
clear();
} }
void DisplayBoardPinController::initialize_pins_output() void DisplayBoardPinController::initialize_pins_output()
{ {
for(auto& pin : this->pins_display_board) { for(auto& pin : this->pins_display_board)
{
initialize_output_pin(pin.second); 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);
}
} }
} }
} }

View File

@@ -34,11 +34,11 @@ public:
private: private:
void initialize_pins_output(); void initialize_pins_output();
void clear();
void write_display_digit(uint8_t display_address, uint8_t content, uint8_t position) const; 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_segment(uint8_t digit) const;
void select_display_digit(uint8_t content) const; void select_display_digit(uint8_t content) const;
void run_display(uint8_t address) const; void run_display(uint8_t address) const;
void init_pin_states();
private: private:
std::map<std::string, uint8_t> pins_display_board; std::map<std::string, uint8_t> pins_display_board;

View File

@@ -161,6 +161,23 @@ void OutputDriver::shut_down_driver() const
CLOG(INFO, OUTPUT_LOGGER) << "Deactivated all output items."; 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 */ } /* namespace output */

View File

@@ -45,6 +45,7 @@ void DisplayFactory::create_pin_map()
{ {
nlohmann::json board_config = this->object.at(config_path::display_board); 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["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); nlohmann::json segment_select = board_config.at(config_path::display_segement_select);
this->pin_map["segment_select_A"] = segment_select.at("A"); this->pin_map["segment_select_A"] = segment_select.at("A");

View File

@@ -48,6 +48,7 @@ namespace config_path
const char display_digit_select[] = "digit_select"; const char display_digit_select[] = "digit_select";
const char display_digits[] = "digits"; const char display_digits[] = "digits";
const char display_list[] = "displays"; const char display_list[] = "displays";
const char display_lt_pin[] = "lt";
} }
class ItemFactory class ItemFactory

View File

@@ -45,8 +45,8 @@ std::string Display::fit_score_string(std::string & score_string, const unsigned
if (score_length > length) if (score_length > length)
{ {
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display"; CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
std::string full_display; std::string filled_display;
return full_display.insert(0, length, '9'); return filled_display.insert(0, length, '9');
} }
score_string.insert(0, length - score_length, '\0'); score_string.insert(0, length - score_length, '\0');

View File

@@ -16,6 +16,9 @@
#define INPUT_SLEEP_DURATION_NANO 800 #define INPUT_SLEEP_DURATION_NANO 800
#define INPUT_HANDLER_TIMEOUT_MILLI 2000 #define INPUT_HANDLER_TIMEOUT_MILLI 2000
#define DISPLAY_HIGH 0
#define DISPLAY_LOW 1
#define PULLDOWN false #define PULLDOWN false
#define DISPLAY_SLEEP_TIME_MILLI 1 #define DISPLAY_SLEEP_TIME_MILLI 1

View File

@@ -2,8 +2,8 @@
// Created by johannes on 17.07.19. // Created by johannes on 17.07.19.
// //
#ifndef FLIPPR_DRIVER_WIRINGPITESTING_H #ifndef FLIPPR_DRIVER_TEST_WIRINGPITESTING_H
#define FLIPPR_DRIVER_WIRINGPITESTING_H #define FLIPPR_DRIVER_TEST_WIRINGPITESTING_H
#include <iostream> #include <iostream>
#include <random> #include <random>
@@ -17,24 +17,24 @@ static int wiringPiSetup()
return 0; 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; //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 //std::cout << "Reading pin " << pin << std::endl
return rand()%2 == 0 ? 1 : 0; 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; //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; //std::cout << "mcp23017Setup called with pinBase " << pinBase << " and i2cAddress " << i2cAddress << std::endl;

View File

@@ -27,6 +27,9 @@ class Networking:
def getDisplays(self): def getDisplays(self):
return self.get("/displays").json() return self.get("/displays").json()
def testDisplays(self):
return self.get("/displays/test")
def triggerSolenoid(self, solenoid): def triggerSolenoid(self, solenoid):
self.get("/solenoids/" + solenoid + "/trigger") self.get("/solenoids/" + solenoid + "/trigger")

0
cli/main.py Normal file → Executable file
View File