Did big refactoring and further adapted OutputDriverFactory as well as uptuput dricer to new board layouts.
This commit is contained in:
@@ -9,9 +9,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
OutputInterpreter::OutputInterpreter(std::string output_pin_config_file, std::string output_lamp_config_file,
|
||||
std::string output_solenoid_config_file, std::string output_sound_config_file,
|
||||
std::string output_display_config_file)
|
||||
OutputInterpreter::OutputInterpreter(std::string output_lamp_config_file, std::string output_solenoid_config_file,
|
||||
std::string output_sound_config_file, std::string output_display_config_file)
|
||||
{
|
||||
std::ifstream output_pin_config_stream;
|
||||
std::ifstream lamp_config_stream;
|
||||
@@ -21,7 +20,6 @@ OutputInterpreter::OutputInterpreter(std::string output_pin_config_file, std::st
|
||||
|
||||
try
|
||||
{
|
||||
output_pin_config_stream.open(output_pin_config_file);
|
||||
lamp_config_stream.open(output_lamp_config_file);
|
||||
solenoid_config_stream.open(output_solenoid_config_file);
|
||||
sound_config_stream.open(output_sound_config_file);
|
||||
@@ -32,9 +30,5 @@ OutputInterpreter::OutputInterpreter(std::string output_pin_config_file, std::st
|
||||
cerr << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
output_driver = flippR_driver::get_OutputDriver(output_pin_config_stream, lamp_config_stream,
|
||||
solenoid_config_stream,
|
||||
sound_config_stream,
|
||||
display_config_stream);
|
||||
|
||||
output_driver = flippR_driver::get_OutputDriver(lamp_config_stream, solenoid_config_stream, sound_config_stream, display_config_stream);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
class OutputInterpreter
|
||||
{
|
||||
public:
|
||||
OutputInterpreter(std::string output_pin_config_file, std::string output_lamp_config_file,
|
||||
std::string output_solenoid_config_file, std::string output_sound_config_file,
|
||||
std::string output_display_config_file);
|
||||
OutputInterpreter(std::string output_lamp_config_file, std::string output_solenoid_config_file,
|
||||
std::string output_sound_config_file, std::string output_display_config_file);
|
||||
|
||||
void startInterpreter();
|
||||
|
||||
|
||||
@@ -1,7 +1,31 @@
|
||||
{
|
||||
"display_board" :
|
||||
{
|
||||
"display_select" :
|
||||
{
|
||||
"1" : 0,
|
||||
"2" : 0,
|
||||
"3" : 0,
|
||||
"4" : 0,
|
||||
"5" : 0
|
||||
},
|
||||
"segment_select" :
|
||||
{
|
||||
"A" : 0,
|
||||
"B" : 0,
|
||||
"C" : 0
|
||||
},
|
||||
"digit_select" :
|
||||
{
|
||||
"A": 0,
|
||||
"B": 0,
|
||||
"C": 0,
|
||||
"D": 0
|
||||
},
|
||||
"run" : 0
|
||||
},
|
||||
"displays" :
|
||||
[
|
||||
// todo add name!
|
||||
{
|
||||
"digits" : 8,
|
||||
"id" : 1,
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
{
|
||||
"display_board" :
|
||||
{
|
||||
"display_select" :
|
||||
{
|
||||
"1" : 0,
|
||||
"2" : 0,
|
||||
"3" : 0,
|
||||
"4" : 0,
|
||||
"5" : 0
|
||||
},
|
||||
"segment_select" :
|
||||
{
|
||||
"A" : 0,
|
||||
"B" : 0,
|
||||
"C" : 0
|
||||
},
|
||||
"digit_select" :
|
||||
{
|
||||
"A": 0,
|
||||
"B": 0,
|
||||
"C": 0,
|
||||
"D": 0
|
||||
},
|
||||
"run" : 0
|
||||
},
|
||||
"driver_board" :
|
||||
{
|
||||
"i2c_address" : 32,
|
||||
"pin_base" : 65,
|
||||
"pin-select" :
|
||||
{
|
||||
"A" : 0,
|
||||
"B" : 1,
|
||||
"C" : 2
|
||||
},
|
||||
"data" : 3,
|
||||
"CL" : 4,
|
||||
"latch-select" :
|
||||
{
|
||||
"mux1" : 8,
|
||||
"mux2" : 9,
|
||||
"A" : 5,
|
||||
"B" : 6,
|
||||
"C" : 7
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,7 @@
|
||||
namespace flippR_driver
|
||||
{
|
||||
std::shared_ptr<input::InputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream);
|
||||
std::shared_ptr<output::OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& lamp_config,
|
||||
std::shared_ptr<output::OutputDriver> get_OutputDriver(std::istream& lamp_config,
|
||||
std::istream& solenoid_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config);
|
||||
|
||||
@@ -10,13 +10,17 @@
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
#include "output/items/Solenoid.h"
|
||||
#include "output/items/Lamp.h"
|
||||
#include "output/items/Sound.h"
|
||||
#include "output/items/Display.h"
|
||||
#include <output/items/Flipper.h>
|
||||
|
||||
|
||||
namespace flippR_driver
|
||||
@@ -27,24 +31,44 @@ namespace output
|
||||
class OutputDriver
|
||||
{
|
||||
public:
|
||||
virtual ~OutputDriver() = default;
|
||||
OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids,
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamps, std::map<std::string, std::shared_ptr<items::Sound>> sounds,
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flippers, std::map<uint8_t, std::shared_ptr<output::items::Display>> displays);
|
||||
|
||||
virtual void activate_displays() const = 0;
|
||||
virtual void deactivate_displays() const = 0;
|
||||
~OutputDriver() = default;
|
||||
|
||||
virtual void deactivate_all_lamps() const = 0;
|
||||
virtual void activate_all_lamps() const = 0;
|
||||
virtual void rotate_all_lamps() const = 0;
|
||||
void activate_displays() const;
|
||||
void deactivate_displays() const;
|
||||
|
||||
virtual std::vector<std::shared_ptr<items::Lamp>> get_lamps() const = 0;
|
||||
virtual std::vector<std::shared_ptr<items::Solenoid>> get_solenoids() const = 0;
|
||||
virtual std::vector<std::shared_ptr<items::Sound>> get_sounds() const = 0;
|
||||
virtual std::vector<std::shared_ptr<items::Display>> get_displays() const = 0;
|
||||
void activate_all_lamps() const;
|
||||
void deactivate_all_lamps() const;
|
||||
void rotate_all_lamps() const;
|
||||
|
||||
virtual boost::optional<std::shared_ptr<items::Lamp>> get_lamp(const std::string &name) const = 0;
|
||||
virtual boost::optional<std::shared_ptr<items::Solenoid>> get_solenoid(const std::string &name) const = 0;
|
||||
virtual boost::optional<std::shared_ptr<items::Sound>> get_sound(const std::string &name) const = 0;
|
||||
virtual boost::optional<std::shared_ptr<items::Display>> get_display(uint8_t number) const = 0;
|
||||
void activate_all_flipper_relays() const;
|
||||
void deactivate_all_flipper_relays() const;
|
||||
|
||||
// todo driver board run for activate/deactivate?
|
||||
// todo what is flipper_relay ?
|
||||
std::vector<std::shared_ptr<items::Lamp>> get_lamps() const;
|
||||
std::vector<std::shared_ptr<items::Solenoid>> get_solenoids() const;
|
||||
std::vector<std::shared_ptr<items::Sound>> get_sounds() const;
|
||||
std::vector<std::shared_ptr<items::Flipper>> get_flippers() const;
|
||||
std::vector<std::shared_ptr<items::Display>> get_displays() const;
|
||||
|
||||
boost::optional<std::shared_ptr<items::Lamp>> get_lamp(const std::string &name) const;
|
||||
boost::optional<std::shared_ptr<items::Solenoid>> get_solenoid(const std::string &name) const;
|
||||
boost::optional<std::shared_ptr<items::Sound>> get_sound(const std::string &name) const;
|
||||
boost::optional<std::shared_ptr<items::Flipper>> get_flipper(const std::string &name) const;
|
||||
boost::optional<std::shared_ptr<items::Display>> get_display(uint8_t number) const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<output::DisplayController> display_controller;
|
||||
|
||||
const std::map<std::string, std::shared_ptr<items::Lamp>> lamps;
|
||||
const std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids;
|
||||
const std::map<std::string, std::shared_ptr<items::Sound>> sounds;
|
||||
const std::map<std::string, std::shared_ptr<items::Flipper>> flippers;
|
||||
const std::map<uint8_t, std::shared_ptr<items::Display>> displays;
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
|
||||
@@ -40,7 +40,6 @@ FlippRServer::FlippRServer() :
|
||||
output_port(9981),
|
||||
input_config("Not set"),
|
||||
matrix_config("Not set"),
|
||||
output_pin_config("Not set"),
|
||||
lamp_config("Not set"),
|
||||
solenoid_config("Not set"),
|
||||
sound_config("Not set"),
|
||||
@@ -104,7 +103,6 @@ void FlippRServer::initialize(Application &self)
|
||||
|
||||
void FlippRServer::initialize_output_driver()
|
||||
{
|
||||
std::ifstream output_pin_config_stream;
|
||||
std::ifstream lamp_config_stream;
|
||||
std::ifstream solenoid_config_stream;
|
||||
std::ifstream sound_config_stream;
|
||||
@@ -112,7 +110,6 @@ void FlippRServer::initialize_output_driver()
|
||||
|
||||
try
|
||||
{
|
||||
output_pin_config_stream.open(this->output_pin_config);
|
||||
lamp_config_stream.open(this->lamp_config);
|
||||
solenoid_config_stream.open(this->solenoid_config);
|
||||
sound_config_stream.open(this->sound_config);
|
||||
@@ -124,8 +121,7 @@ void FlippRServer::initialize_output_driver()
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
this->output_driver = flippR_driver::get_OutputDriver(output_pin_config_stream,
|
||||
lamp_config_stream,
|
||||
this->output_driver = flippR_driver::get_OutputDriver(lamp_config_stream,
|
||||
solenoid_config_stream,
|
||||
sound_config_stream,
|
||||
display_config_stream);
|
||||
@@ -228,12 +224,6 @@ void FlippRServer::defineOptions(OptionSet& options)
|
||||
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
|
||||
.argument("matric-config", true));
|
||||
|
||||
options.addOption(Option("output-pin-config", "O", "Specify where the matrix-config file is located. Only needed when not in this folder.")
|
||||
.required(this->output_pin_config == "Not set")
|
||||
.repeatable(false)
|
||||
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
|
||||
.argument("output-pin-config", true));
|
||||
|
||||
options.addOption(Option("lamp-config", "L", "Specify where the lamp-config file is located. Only needed when not in this folder.")
|
||||
.required(this->lamp_config == "Not set")
|
||||
.repeatable(false)
|
||||
@@ -265,8 +255,6 @@ void FlippRServer::handle_config_file(const std::string &name, const std::string
|
||||
this->input_config = value;
|
||||
else if(name == "matrix-config")
|
||||
this->matrix_config = value;
|
||||
else if(name == "output-pin-config")
|
||||
this->output_pin_config = value;
|
||||
else if(name == "lamp-config")
|
||||
this->lamp_config = value;
|
||||
else if(name == "solenoid-config")
|
||||
|
||||
@@ -26,9 +26,6 @@ public:
|
||||
void initialize(Poco::Util::Application& self);
|
||||
|
||||
void defineOptions(Poco::Util::OptionSet& options);
|
||||
|
||||
void handle_set_input_port(const std::string &name, const std::string &port);
|
||||
void handle_set_output_port(const std::string &name, const std::string &port);
|
||||
void handle_help(const std::string &name, const std::string &port);
|
||||
void handle_config_file(const std::string &name, const std::string &value);
|
||||
|
||||
@@ -52,7 +49,6 @@ private:
|
||||
|
||||
std::string input_config;
|
||||
std::string matrix_config;
|
||||
std::string output_pin_config;
|
||||
std::string lamp_config;
|
||||
std::string solenoid_config;
|
||||
std::string sound_config;
|
||||
|
||||
@@ -60,12 +60,14 @@ void OutputRequestHandler::handleRequest(HTTPServerRequest &request,
|
||||
{
|
||||
this->output_driver->deactivate_displays();
|
||||
this->output_driver->deactivate_all_lamps();
|
||||
this->output_driver->deactivate_all_flipper_relays();
|
||||
return;
|
||||
}
|
||||
|
||||
if(item_type == "activate")
|
||||
{
|
||||
this->output_driver->activate_displays();
|
||||
this->output_driver->activate_all_flipper_relays();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,6 +111,10 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseRequest(const std
|
||||
{
|
||||
return parseDisplay(item_name, action, score);
|
||||
}
|
||||
else if(item_type == "flippers")
|
||||
{
|
||||
return parseFlipper(item_name, action);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Poco::NotFoundException("No item type called " + item_type);
|
||||
@@ -249,6 +255,40 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseDisplay(const std
|
||||
return {};
|
||||
}
|
||||
|
||||
boost::optional<Poco::JSON::Object> OutputRequestHandler::parseFlipper(const std::string& item_name, const std::string& action)
|
||||
{
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("flippers", this->output_driver->get_flippers());
|
||||
return response;
|
||||
}
|
||||
|
||||
auto opt_flipper = this->output_driver->get_flipper(item_name);
|
||||
|
||||
if(!opt_flipper)
|
||||
{
|
||||
throw new Poco::NotFoundException("No flipper with name \"" + item_name + "\"!");
|
||||
}
|
||||
|
||||
auto flipper = opt_flipper->get();
|
||||
|
||||
if(action == "activate")
|
||||
{
|
||||
flipper->activate();
|
||||
}
|
||||
else if(action == "deactivate")
|
||||
{
|
||||
flipper->deactivate();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Poco::NotFoundException("No action with name \"" + action + "\" on flippers!");
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::string> OutputRequestHandler::getPathSegments(Poco::URI uri)
|
||||
{
|
||||
std::vector<std::string> path_segments;
|
||||
|
||||
@@ -33,6 +33,7 @@ private:
|
||||
boost::optional<Poco::JSON::Object> parseLamp(const std::string& item_name, const std::string& action);
|
||||
boost::optional<Poco::JSON::Object> parseSound(const std::string& item_name, const std::string& action);
|
||||
boost::optional<Poco::JSON::Object> parseDisplay(const std::string& item_name, const std::string& action, const std::string& score);
|
||||
boost::optional<Poco::JSON::Object> parseFlipper(const std::string& item_name, const std::string& action);
|
||||
|
||||
std::vector<std::string> getPathSegments(Poco::URI uri);
|
||||
|
||||
|
||||
@@ -14,12 +14,11 @@ namespace flippR_driver
|
||||
return input::InputDriverFactory::get_InputDriver(input_config_stream, matrix_config_stream);
|
||||
}
|
||||
|
||||
std::shared_ptr<output::OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& lamp_config,
|
||||
std::shared_ptr<output::OutputDriver> get_OutputDriver(std::istream& lamp_config,
|
||||
std::istream& solenoid_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config)
|
||||
{
|
||||
return output::OutputDriverFactory::get_OutputDriver(output_pin_config, lamp_config, solenoid_config, sound_config, display_config);
|
||||
return output::OutputDriverFactory::get_OutputDriver(lamp_config, solenoid_config, sound_config, display_config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,12 @@ void PinController::initialize_port_expander(const uint8_t i2c_address, const ui
|
||||
}
|
||||
|
||||
|
||||
void PinController::initialize_pins_output(const uint8_t pin_base, std::map<std::string, uint8_t>::iterator begin, std::map<std::string, uint8_t>::iterator end)
|
||||
{
|
||||
for(;begin != end; begin++)
|
||||
{
|
||||
initialize_output_pin(pin_base + begin->second);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -32,6 +33,8 @@ protected:
|
||||
|
||||
static bool read_pin(uint8_t address);
|
||||
|
||||
static void initialize_pins_output(const uint8_t pin_base, std::map<std::string, uint8_t>::iterator begin, std::map<std::string, uint8_t>::iterator end);
|
||||
|
||||
public:
|
||||
static std::once_flag GPIO_LIB_INITIALIZED;
|
||||
};
|
||||
|
||||
@@ -6,22 +6,32 @@
|
||||
#define FLIPPR_DRIVER_DISPLAYPINCONTROLLER_H
|
||||
|
||||
#include "output/items/OutputDisplay.h"
|
||||
#include "OutputPinController.h"
|
||||
#include "PinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class DisplayBoardPinController : public OutputPinController
|
||||
class DisplayBoardPinController : public PinController
|
||||
{
|
||||
public:
|
||||
virtual ~DisplayBoardPinController() = default;
|
||||
explicit DisplayBoardPinController(std::map<std::string, uint8_t> pins_display);
|
||||
~DisplayBoardPinController() override = default;
|
||||
|
||||
virtual void activate_displays() const = 0;
|
||||
virtual void deactivate_displays() const = 0;
|
||||
void activate_displays() const;
|
||||
void deactivate_displays() const;
|
||||
|
||||
virtual void write_display(const items::OutputDisplay &display) const = 0;
|
||||
void write_display(const items::OutputDisplay &display) const;
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
private:
|
||||
const std::map<std::string, uint8_t> pins_display_board;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
#ifndef _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
||||
#define _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
#include "output/items/OutputDisplay.h"
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
@@ -15,12 +21,23 @@ namespace output
|
||||
|
||||
class DisplayController
|
||||
{
|
||||
|
||||
public:
|
||||
virtual ~DisplayController () = default;
|
||||
explicit DisplayController(std::vector<std::shared_ptr<items::OutputDisplay>> displays, std::unique_ptr<DisplayBoardPinController> pin_controller);
|
||||
~DisplayController();
|
||||
|
||||
virtual void activate_displays() const = 0;
|
||||
virtual void deactivate_displays() const = 0;
|
||||
void activate_displays() const;
|
||||
void deactivate_displays() const;
|
||||
|
||||
private:
|
||||
void cycle_displays() const;
|
||||
|
||||
private:
|
||||
const std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
|
||||
const std::shared_ptr<DisplayBoardPinController> pin_controller;
|
||||
|
||||
std::thread display_cycle_thread;
|
||||
bool is_running;
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifndef FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
|
||||
#include "OutputPinController.h"
|
||||
#include "PinController.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace items
|
||||
class DriverBoardItem;
|
||||
}
|
||||
|
||||
class DriverBoardPinController : public OutputPinController
|
||||
class DriverBoardPinController : public PinController
|
||||
{
|
||||
public:
|
||||
virtual ~DriverBoardPinController() = default;
|
||||
|
||||
@@ -2,22 +2,17 @@
|
||||
// Created by rhetenor on 04.10.18.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include "OutputDriverFactory.h"
|
||||
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
#include "output/detail/OutputDriver.h"
|
||||
#include "output/detail/DisplayController.h"
|
||||
|
||||
#include "output/detail/DisplayBoardPinController.h"
|
||||
#include "output/detail/SoundBoardPinController.h"
|
||||
|
||||
#include "output/DisplayController.h"
|
||||
#include "output/SoundBoardPinController.h"
|
||||
#include "output/items/detail/EightDigitDisplay.h"
|
||||
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
#include "output/items/detail/SevenDigitDisplay.h"
|
||||
#include "output/items/Flipper.h"
|
||||
#include "output/items/detail/Flipper.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -28,8 +23,7 @@ namespace OutputDriverFactory
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& solenoid_config,
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
|
||||
std::istream& lamp_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config)
|
||||
@@ -38,29 +32,21 @@ std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
|
||||
std::shared_ptr<std::mutex> output_pin_mutex;
|
||||
|
||||
json output_config;
|
||||
output_pin_config >> output_config;
|
||||
|
||||
|
||||
std::shared_ptr<DriverBoardPinController> driver_board_pin_controller(new DriverBoardPinController(output_pin_mutex));
|
||||
auto solenoids = create_solenoids(solenoid_config, driver_board_pin_controller);
|
||||
//TODO create flippers
|
||||
auto flippers = create_flippers(solenoid_config, driver_board_pin_controller);
|
||||
auto lamps = create_lamps(lamp_config, driver_board_pin_controller);
|
||||
|
||||
uint8_t sound_fire_address = get_sound_fire_address(sound_config);
|
||||
std::shared_ptr<SoundBoardPinController> sound_board_pin_controller(new detail::SoundBoardPinController(output_pin_mutex, sound_fire_address));
|
||||
std::shared_ptr<SoundBoardPinController> sound_board_pin_controller(new SoundBoardPinController(output_pin_mutex, sound_fire_address));
|
||||
auto sounds = create_sounds(sound_config, sound_board_pin_controller);
|
||||
|
||||
// json display_board_config = output_config.at("display_board");
|
||||
// std::unique_ptr<DisplayBoardPinController> display_board_pin_controller(new detail::DisplayBoardPinController(parse_pins_display_board(display_board_config)));
|
||||
// auto displays = create_displays(display_config);
|
||||
//
|
||||
// std::unique_ptr<DisplayController> display_controller(new detail::DisplayController(displays, std::move(display_board_pin_controller)));
|
||||
//
|
||||
// auto display_map = map_displays(displays);
|
||||
//
|
||||
// return std::make_shared<detail::OutputDriver>(std::move(display_controller), solenoids, lamps, sounds, display_map);
|
||||
// return std::make_shared<detail::OutputDriver>(NULL, NULL, NULL, NULL, NULL);
|
||||
std::unique_ptr<DisplayBoardPinController> display_board_pin_controller(new DisplayBoardPinController(parse_pins_display_board(display_config)));
|
||||
auto displays = create_displays(display_config);
|
||||
std::unique_ptr<DisplayController> display_controller(new DisplayController(displays, std::move(display_board_pin_controller)));
|
||||
auto display_map = map_displays(displays);
|
||||
|
||||
return std::make_shared<OutputDriver>(std::move(display_controller), solenoids, lamps, sounds, flippers, display_map);
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::istream & solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
@@ -210,7 +196,86 @@ uint8_t get_sound_fire_address(std::istream &sound_config)
|
||||
return pin_base + address;
|
||||
}
|
||||
|
||||
void initialize_port_extenders(nlohmann::json &port_extenders, PinController * pin_controller, const std::string & file_name)
|
||||
std::map<std::string, uint8_t> parse_pins_display_board(std::istream &display_config)
|
||||
{
|
||||
std::string config_file = "display_config.json";
|
||||
|
||||
json display_config_json;
|
||||
display_config >> display_config_json;
|
||||
|
||||
json display_board_config = get_element("display_board", display_config_json, config_file);
|
||||
|
||||
std::map<std::string, uint8_t> pins_display;
|
||||
|
||||
pins_display["run"] = get_value<uint8_t>("run", display_board_config, config_file);
|
||||
|
||||
json display_select = display_board_config.at("display_select");
|
||||
for(int i = 1; i < 6; i++)
|
||||
{
|
||||
pins_display["display_select" + std::to_string(i)] = get_value<uint8_t>(std::to_string(i), display_select, config_file);
|
||||
}
|
||||
|
||||
json segment_select = display_board_config.at("segment_select");
|
||||
pins_display["segment_select_A"] = get_value<uint8_t>("A", segment_select, config_file);
|
||||
pins_display["segment_select_B"] = get_value<uint8_t>("B", segment_select, config_file);
|
||||
pins_display["segment_select_C"] = get_value<uint8_t>("C", segment_select, config_file);
|
||||
|
||||
json digit_select = display_board_config.at("digit_select");
|
||||
pins_display["digit_select_A"] = get_value<uint8_t>("A", digit_select, config_file);
|
||||
pins_display["digit_select_B"] = get_value<uint8_t>("B", digit_select, config_file);
|
||||
pins_display["digit_select_C"] = get_value<uint8_t>("C", digit_select, config_file);
|
||||
pins_display["digit_select_D"] = get_value<uint8_t>("D", digit_select, config_file);;
|
||||
|
||||
return pins_display;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream &display_config)
|
||||
{
|
||||
|
||||
json display_config_json;
|
||||
display_config >> display_config_json;
|
||||
|
||||
json displays_json = get_element("displays", display_config_json, "display_config.json");
|
||||
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
for(json &display_json : displays_json)
|
||||
{
|
||||
auto display = create_display(display_json);
|
||||
displays.push_back(display);
|
||||
}
|
||||
|
||||
return displays;
|
||||
}
|
||||
|
||||
std::shared_ptr<items::OutputDisplay> create_display(json & display_json)
|
||||
{
|
||||
std::string config_file = "display_config.json";
|
||||
auto id = get_value<uint8_t>("id", display_json, config_file);
|
||||
auto address = get_value<uint8_t>("address", display_json, config_file);
|
||||
auto digits = get_value<uint8_t>("digits", display_json, config_file);
|
||||
if(digits == 8)
|
||||
return std::make_shared<items::detail::EightDigitDisplay>(address, id);
|
||||
|
||||
else if(digits == 7)
|
||||
return std::make_shared<items::detail::SevenDigitDisplay>(address, id);
|
||||
|
||||
else
|
||||
throw new std::logic_error("Display digits can either be 7 or 8");
|
||||
}
|
||||
|
||||
std::map<uint8_t, std::shared_ptr<items::Display>> map_displays(const std::vector<std::shared_ptr<items::OutputDisplay>> &displays)
|
||||
{
|
||||
std::map<uint8_t, std::shared_ptr<items::Display>> display_map;
|
||||
|
||||
for(auto &display : displays)
|
||||
{
|
||||
display_map.emplace(display->get_address(), display);
|
||||
}
|
||||
|
||||
return display_map;
|
||||
}
|
||||
|
||||
void initialize_port_extenders(json &port_extenders, PinController * pin_controller, const std::string & file_name)
|
||||
{
|
||||
|
||||
for (auto & extender_json : port_extenders)
|
||||
|
||||
@@ -23,8 +23,7 @@ namespace output
|
||||
{
|
||||
namespace OutputDriverFactory
|
||||
{
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& solenoid_config,
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
|
||||
std::istream& lamp_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config);
|
||||
@@ -42,6 +41,11 @@ std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream
|
||||
std::shared_ptr<items::detail::Sound> create_sound(nlohmann::json &sound_json, nlohmann::json &port_extenders, std::shared_ptr<SoundBoardPinController> &pin_controller, std::chrono::milliseconds &deactivation_time);
|
||||
uint8_t get_sound_fire_address(std::istream &sound_config);
|
||||
|
||||
std::map<std::string, uint8_t> parse_pins_display_board(std::istream & display_config);
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream &display_config);
|
||||
std::shared_ptr<items::OutputDisplay> create_display(nlohmann::json &display_json);
|
||||
std::map<uint8_t, std::shared_ptr<items::Display>> map_displays(const std::vector<std::shared_ptr<items::OutputDisplay>> &displays);
|
||||
|
||||
void initialize_port_extenders(nlohmann::json &port_extenders, PinController * pin_controller, const std::string & file_name);
|
||||
|
||||
uint8_t get_pin_base(nlohmann::json & object, nlohmann::json & port_extenders, const std::string & config_file_name);
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* OutputGPIOInterface.h
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include "OutputPinController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
#include "wiringPi/mcp23017.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
void OutputPinController::initialize_i2c_address(const uint8_t i2c_address, const uint8_t pin_base)
|
||||
{
|
||||
mcp23017Setup(pin_base, i2c_address);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* OutputGPIOInterface.h
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_
|
||||
|
||||
#include "PinController.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
namespace items
|
||||
{
|
||||
class DriverBoardItem;
|
||||
}
|
||||
class OutputPinController : public PinController
|
||||
{
|
||||
|
||||
public:
|
||||
virtual ~OutputPinController() = default;
|
||||
|
||||
protected:
|
||||
static void initialize_i2c_address(const uint8_t i2c_address, const uint8_t pin_base);
|
||||
static void initialize_pins_output(const uint8_t pin_base, std::map<std::string, uint8_t>::iterator begin, std::map<std::string, uint8_t>::iterator end);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,20 +6,32 @@
|
||||
#define FLIPPR_DRIVER_OUTPUT_SOUNDBOARDPINCONTROLLER_H
|
||||
|
||||
#include "output/items/detail/Sound.h"
|
||||
#include "OutputPinController.h"
|
||||
#include "PinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class SoundBoardPinController : public OutputPinController
|
||||
class SoundBoardPinController : public PinController
|
||||
{
|
||||
public:
|
||||
virtual ~SoundBoardPinController() = default;
|
||||
SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, const uint8_t & fire_address);
|
||||
~SoundBoardPinController() override = default;
|
||||
|
||||
virtual void activate(const items::detail::Sound &sound) = 0;
|
||||
virtual void deactivate(const items::detail::Sound &sound) = 0;
|
||||
void activate(const items::detail::Sound &sound);
|
||||
void deactivate(const items::detail::Sound &sound);
|
||||
|
||||
private:
|
||||
void write_sound_address(const uint8_t & address) const;
|
||||
void fire_sound() const;
|
||||
|
||||
void write_pin(const uint8_t & pin, const bool & value) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mutex> output_item_mutex;
|
||||
|
||||
uint8_t fire_address;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#include <thread>
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
#include "DisplayBoardPinController.h"
|
||||
#include <thread>
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
DisplayBoardPinController::DisplayBoardPinController(std::map<std::string, uint8_t> pins_display) :
|
||||
pins_display_board(std::move(pins_display))
|
||||
@@ -77,6 +75,5 @@ void DisplayBoardPinController::run_display(uint8_t address) const
|
||||
write_pin(pins_display_board.at("display_select_" + std::to_string(address)), 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_DISPLAYPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_OUTPUT_IMPL_DISPLAYPINCONTROLLER_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class DisplayBoardPinController : public output::DisplayBoardPinController
|
||||
{
|
||||
public:
|
||||
explicit DisplayBoardPinController(std::map<std::string, uint8_t> pins_display);
|
||||
~DisplayBoardPinController() override = default;
|
||||
|
||||
void activate_displays() const override;
|
||||
void deactivate_displays() const override;
|
||||
|
||||
void write_display(const items::OutputDisplay &display) const override;
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
private:
|
||||
const std::map<std::string, uint8_t> pins_display_board;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //FLIPPR_DRIVER_DISPLAYPINCONTROLLER_H
|
||||
@@ -5,7 +5,7 @@
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include "DisplayController.h"
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -13,8 +13,6 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
DisplayController::DisplayController(std::vector<std::shared_ptr<items::OutputDisplay>> displays, std::unique_ptr<DisplayBoardPinController> pin_controller)
|
||||
: displays(std::move(displays)), pin_controller(std::move(pin_controller)), is_running(true)
|
||||
@@ -58,4 +56,3 @@ void DisplayController::deactivate_displays() const
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* DisplayController.h
|
||||
*
|
||||
* Created on: Aug 7, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_DISPLAYCONTROLLER_H_
|
||||
#define _SRC_OUTPUT_DISPLAYCONTROLLER_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
#include "output/items/OutputDisplay.h"
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class DisplayController : public output::DisplayController
|
||||
{
|
||||
public:
|
||||
explicit DisplayController(std::vector<std::shared_ptr<items::OutputDisplay>> displays, std::unique_ptr<DisplayBoardPinController> pin_controller);
|
||||
~DisplayController() override;
|
||||
|
||||
void activate_displays() const override;
|
||||
void deactivate_displays() const override;
|
||||
|
||||
private:
|
||||
void cycle_displays() const;
|
||||
|
||||
private:
|
||||
const std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
|
||||
const std::shared_ptr<DisplayBoardPinController> pin_controller;
|
||||
|
||||
std::thread display_cycle_thread;
|
||||
bool is_running;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include "OutputDriver.h"
|
||||
#include "output/OutputDriver.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -17,13 +17,18 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
using namespace items;
|
||||
|
||||
OutputDriver::OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<Solenoid>> solenoids, std::map<std::string, std::shared_ptr<Lamp>> lamps, std::map<std::string, std::shared_ptr<Sound>> sounds, std::map<uint8_t, std::shared_ptr<items::Display>> displays)
|
||||
: display_controller(std::move(display_controller)), solenoids(std::move(solenoids)), lamps(std::move(lamps)), sounds(std::move(sounds)), displays(std::move(displays))
|
||||
OutputDriver::OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<Solenoid>> solenoids,
|
||||
std::map<std::string, std::shared_ptr<Lamp>> lamps, std::map<std::string, std::shared_ptr<Sound>> sounds,
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flippers, std::map<uint8_t, std::shared_ptr<items::Display>> displays):
|
||||
display_controller(std::move(display_controller)),
|
||||
solenoids(std::move(solenoids)),
|
||||
lamps(std::move(lamps)),
|
||||
sounds(std::move(sounds)),
|
||||
flippers(std::move(flippers)),
|
||||
displays(std::move(displays))
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created OutputDriver";
|
||||
}
|
||||
@@ -61,6 +66,16 @@ void OutputDriver::rotate_all_lamps() const
|
||||
}
|
||||
}
|
||||
|
||||
void OutputDriver::activate_all_flipper_relays() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OutputDriver::deactivate_all_flipper_relays() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Sound>> OutputDriver::get_sounds() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Sound>> sounds;
|
||||
@@ -89,6 +104,15 @@ std::vector<std::shared_ptr<Lamp>> OutputDriver::get_lamps() const
|
||||
return lamps;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<items::Flipper>> OutputDriver::get_flippers() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Flipper>> flippers;
|
||||
|
||||
boost::copy(this->flippers | boost::adaptors::map_values, std::back_inserter(flippers));
|
||||
|
||||
return flippers;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Solenoid>> OutputDriver::get_solenoids() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Solenoid>> solenoids;
|
||||
@@ -113,6 +137,11 @@ boost::optional<std::shared_ptr<items::Sound>> OutputDriver::get_sound(const std
|
||||
return this->sounds.find(name)->second;
|
||||
}
|
||||
|
||||
boost::optional<std::shared_ptr<items::Flipper>> OutputDriver::get_flipper(const std::string &name) const
|
||||
{
|
||||
return this->flippers.find(name)->second;
|
||||
}
|
||||
|
||||
boost::optional<std::shared_ptr<items::Display>> OutputDriver::get_display(uint8_t number) const
|
||||
{
|
||||
return this->displays.find(number)->second;
|
||||
@@ -121,4 +150,3 @@ boost::optional<std::shared_ptr<items::Display>> OutputDriver::get_display(uint8
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* OutputDriver.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_OUTPUTDRIVER_H_
|
||||
#define _SRC_OUTPUT_OUTPUTDRIVER_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "output/OutputDriver.h"
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class OutputDriver : public output::OutputDriver
|
||||
{
|
||||
public:
|
||||
OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids,
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamps, std::map<std::string, std::shared_ptr<items::Sound>> sounds,
|
||||
std::map<uint8_t, std::shared_ptr<output::items::Display>> displays);
|
||||
|
||||
~OutputDriver() override = default;
|
||||
|
||||
void activate_displays() const override;
|
||||
void deactivate_displays() const override;
|
||||
|
||||
void activate_all_lamps() const override;
|
||||
void deactivate_all_lamps() const override;
|
||||
void rotate_all_lamps() const override;
|
||||
|
||||
void activate_flipper_relay();
|
||||
void activate_top_flipper_relay();
|
||||
void deactivate_flipper_relay();
|
||||
void deactivate_top_flipper_relay();
|
||||
|
||||
// todo driver board run for activate/deactivate?
|
||||
// todo what is flipper_relay ?
|
||||
std::vector<std::shared_ptr<items::Lamp>> get_lamps() const override;
|
||||
std::vector<std::shared_ptr<items::Solenoid>> get_solenoids() const override;
|
||||
std::vector<std::shared_ptr<items::Sound>> get_sounds() const override;
|
||||
std::vector<std::shared_ptr<items::Display>> get_displays() const override;
|
||||
|
||||
boost::optional<std::shared_ptr<items::Lamp>> get_lamp(const std::string &name) const override;
|
||||
boost::optional<std::shared_ptr<items::Solenoid>> get_solenoid(const std::string &name) const override;
|
||||
boost::optional<std::shared_ptr<items::Sound>> get_sound(const std::string &name) const override;
|
||||
boost::optional<std::shared_ptr<items::Display>> get_display(uint8_t number) const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<output::DisplayController> display_controller;
|
||||
|
||||
const std::map<std::string, std::shared_ptr<items::Lamp>> lamps;
|
||||
const std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids;
|
||||
const std::map<std::string, std::shared_ptr<items::Sound>> sounds;
|
||||
|
||||
const std::map<uint8_t, std::shared_ptr<items::Display>> displays;
|
||||
};
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#include "SoundBoardPinController.h"
|
||||
#include "output/SoundBoardPinController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
SoundBoardPinController::SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, const uint8_t & fire_address) :
|
||||
output_item_mutex(std::move(output_item_mutex)),
|
||||
@@ -64,4 +62,3 @@ void SoundBoardPinController::write_pin(const uint8_t & pin, const bool & value)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_SOUNDBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_OUTPUT_IMPL_SOUNDBOARDPINCONTROLLER_H
|
||||
|
||||
#include "output/SoundBoardPinController.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class SoundBoardPinController : public output::SoundBoardPinController
|
||||
{
|
||||
public:
|
||||
SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, const uint8_t & fire_address);
|
||||
~SoundBoardPinController() override = default;
|
||||
|
||||
void activate(const items::detail::Sound &sound) override;
|
||||
void deactivate(const items::detail::Sound &sound) override;
|
||||
|
||||
private:
|
||||
void write_sound_address(const uint8_t & address) const;
|
||||
void fire_sound() const;
|
||||
|
||||
void write_pin(const uint8_t & pin, const bool & value) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mutex> output_item_mutex;
|
||||
|
||||
uint8_t fire_address;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //FLIPPR_DRIVER_SOUNDBOARDPINCONTROLLER_H
|
||||
@@ -17,7 +17,7 @@ namespace items
|
||||
namespace detail
|
||||
{
|
||||
|
||||
Display::Display(uint8_t address, uint8_t id) :
|
||||
Display::Display(const uint8_t & address, const uint8_t & id) :
|
||||
address(address),
|
||||
id(id)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ uint8_t Display::get_id() const
|
||||
return this->id;
|
||||
}
|
||||
|
||||
void Display::write_score(unsigned int score, unsigned int length)
|
||||
void Display::write_score(const unsigned int & score, const unsigned int & length)
|
||||
{
|
||||
auto score_string = std::to_string(score);
|
||||
|
||||
@@ -38,7 +38,7 @@ void Display::write_score(unsigned int score, unsigned int length)
|
||||
write_content(score_string, length);
|
||||
}
|
||||
|
||||
std::string Display::fit_score_string(std::string &score_string, unsigned int length)
|
||||
std::string Display::fit_score_string(std::string & score_string, const unsigned int & length)
|
||||
{
|
||||
auto score_length = score_string.length();
|
||||
|
||||
@@ -46,7 +46,6 @@ std::string Display::fit_score_string(std::string &score_string, unsigned int le
|
||||
{
|
||||
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
||||
std::string full_display;
|
||||
// TODO mach mal schöner hier wird 9999 angezeigt wenn die zahl zu groß is
|
||||
return full_display.insert(0, length, '9');
|
||||
}
|
||||
|
||||
@@ -54,7 +53,7 @@ std::string Display::fit_score_string(std::string &score_string, unsigned int le
|
||||
return score_string;
|
||||
}
|
||||
|
||||
void Display::write_content(std::string content, unsigned int length)
|
||||
void Display::write_content(std::string & content, const unsigned int & length)
|
||||
{
|
||||
if(content.size() > length)
|
||||
{
|
||||
|
||||
@@ -24,18 +24,18 @@ namespace detail
|
||||
class Display : public items::OutputDisplay
|
||||
{
|
||||
public:
|
||||
Display(uint8_t address, uint8_t id);
|
||||
Display(const uint8_t & address, const uint8_t & id);
|
||||
virtual ~Display() = default;
|
||||
|
||||
void write_score(unsigned int score, unsigned int length);
|
||||
void write_content(std::string content, unsigned int length);
|
||||
void write_score(const unsigned int & score, const unsigned int & length);
|
||||
void write_content(std::string & content, const unsigned int & length);
|
||||
|
||||
std::string get_content() const override;
|
||||
uint8_t get_address() const override;
|
||||
uint8_t get_id() const override;
|
||||
|
||||
private:
|
||||
std::string fit_score_string(std::string &score_string, unsigned int length);
|
||||
std::string fit_score_string(std::string & score_string, const unsigned int & length);
|
||||
|
||||
public:
|
||||
std::string content;
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
#include "output/DisplayController.h"
|
||||
#include "output/items/OutputDisplay.h"
|
||||
#include "output/detail/DisplayBoardPinController.h"
|
||||
#include "output/detail/DisplayController.h"
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
|
||||
@@ -23,7 +23,7 @@ SCENARIO("A Lamp gets activated")
|
||||
Fake(Dtor(pin_controller));
|
||||
Fake(Method(pin_controller, activate));
|
||||
|
||||
items::detail::Lamp lamp(std::shared_ptr<DriverBoardPinController>(&pin_controller.get()), 0, "test");
|
||||
items::detail::Lamp lamp(std::shared_ptr<DriverBoardPinController>(&pin_controller.get()), 0, 1, "test");
|
||||
|
||||
WHEN("The lamp gets activated")
|
||||
{
|
||||
@@ -50,7 +50,7 @@ SCENARIO("A Lamp gets deactivated")
|
||||
Fake(Dtor(pin_controller));
|
||||
Fake(Method(pin_controller, deactivate));
|
||||
|
||||
items::detail::Lamp lamp(std::shared_ptr<DriverBoardPinController>(&pin_controller.get()), 0, "test");
|
||||
items::detail::Lamp lamp(std::shared_ptr<DriverBoardPinController>(&pin_controller.get()), 0, 1, "test");
|
||||
|
||||
WHEN("The lamp gets deactivated")
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
// testing purposes
|
||||
#define private public
|
||||
|
||||
#include "output/detail/OutputDriver.h"
|
||||
#include "output/OutputDriver.h"
|
||||
|
||||
using namespace flippR_driver;
|
||||
using namespace flippR_driver::output;
|
||||
@@ -37,9 +37,10 @@ SCENARIO("The OutputDriver should (de)activates the displays")
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids;
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamps;
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> sounds;
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flippers;
|
||||
std::map<uint8_t, std::shared_ptr<output::items::Display>> displays;
|
||||
|
||||
output::detail::OutputDriver output_driver(std::unique_ptr<output::DisplayController>(&display_controller.get()), solenoids, lamps, sounds, displays);
|
||||
output::OutputDriver output_driver(std::unique_ptr<output::DisplayController>(&display_controller.get()), solenoids, lamps, sounds, flippers, displays);
|
||||
|
||||
WHEN("The displays get activated")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user