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)
add_subdirectory(tests)
#add_subdirectory(tests)
message(WARNING "Tests not built!")
endif(ENABLE_TESTING)
if(BUILD_NETWORKING)

View File

@@ -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
}

View File

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

View File

@@ -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;

View File

@@ -230,6 +230,12 @@ boost::optional<Poco::JSON::Object> 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)

View File

@@ -16,12 +16,10 @@ namespace detail
{
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();
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<std::string, uint8_t> & 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);
}
}
}
}

View File

@@ -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<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.";
}
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 */

View File

@@ -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");

View File

@@ -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

View File

@@ -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');

View File

@@ -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

View File

@@ -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 <iostream>
#include <random>
@@ -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;