fuuuuuuuu
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,9 +1,11 @@
|
||||
{
|
||||
"port_extender" :
|
||||
"port_extenders" :
|
||||
[
|
||||
"name" : "extender_1",
|
||||
"i2c_address" : 33,
|
||||
"pin_base" : 82
|
||||
{
|
||||
"name" : "extender_1",
|
||||
"i2c_address" : 33,
|
||||
"pin_base" : 82
|
||||
}
|
||||
],
|
||||
"lamps" :
|
||||
[
|
||||
|
||||
@@ -1,66 +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
|
||||
}
|
||||
|
||||
},
|
||||
"sound_board" :
|
||||
{
|
||||
"i2c_address" : 33,
|
||||
"pin_base" : 81,
|
||||
"fire" : 7,
|
||||
"sound_address_select" :
|
||||
{
|
||||
"A" : 0,
|
||||
"B" : 1,
|
||||
"C" : 2,
|
||||
"D" : 3,
|
||||
"E" : 4,
|
||||
"F" : 5,
|
||||
"G" : 6
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
{
|
||||
"port_extenders" :
|
||||
[
|
||||
"name" : "extender_0",
|
||||
"i2c_address" : 32,
|
||||
"pin_base" : 65
|
||||
{
|
||||
"name" : "extender_0",
|
||||
"i2c_address" : 32,
|
||||
"pin_base" : 65
|
||||
}
|
||||
],
|
||||
"deactivation_time_milliseconds" : 10,
|
||||
"flippers" :
|
||||
|
||||
@@ -1,151 +1,193 @@
|
||||
{
|
||||
"deactivation_time_milliseconds" : 10,
|
||||
"port_extenders" :
|
||||
[
|
||||
{
|
||||
"name" : "extender_0",
|
||||
"i2c_address" : 33,
|
||||
"pin_base" : 81
|
||||
}
|
||||
],
|
||||
"fire_pin" :
|
||||
{
|
||||
"address" : 7,
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
"sounds" :
|
||||
[
|
||||
{
|
||||
"id" : 0,
|
||||
"address" : "22",
|
||||
"description" : "Sound 1"
|
||||
"description" : "Sound 1",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 1,
|
||||
"address" : "23",
|
||||
"description" : "Sound 2"
|
||||
"description" : "Sound 2",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 2,
|
||||
"address" : "24",
|
||||
"description" : "Sound 3"
|
||||
"description" : "Sound 3",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 3,
|
||||
"address" : "25",
|
||||
"description" : "Sound 4"
|
||||
"description" : "Sound 4",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 4,
|
||||
"address" : "26",
|
||||
"description" : "Sound 5"
|
||||
"description" : "Sound 5",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 5,
|
||||
"address" : "27",
|
||||
"description" : "Sound 6"
|
||||
"description" : "Sound 6",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 6,
|
||||
"address" : "28",
|
||||
"description" : "Sound 7"
|
||||
"description" : "Sound 7",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 7,
|
||||
"address" : "29",
|
||||
"description" : "Sound 8"
|
||||
"description" : "Sound 8",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 8,
|
||||
"address" : "30",
|
||||
"description" : "Sound 9"
|
||||
"description" : "Sound 9",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 9,
|
||||
"address" : "31",
|
||||
"description" : "Sound 10"
|
||||
"description" : "Sound 10",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 10,
|
||||
"address" : "32",
|
||||
"description" : "Sound 11"
|
||||
"description" : "Sound 11",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 11,
|
||||
"address" : "33",
|
||||
"description" : "Sound 12"
|
||||
"description" : "Sound 12",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 12,
|
||||
"address" : "34",
|
||||
"description" : "Sound 13"
|
||||
"description" : "Sound 13",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 13,
|
||||
"address" : "35",
|
||||
"description" : "Sound 14"
|
||||
"description" : "Sound 14",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 14,
|
||||
"address" : "36",
|
||||
"description" : "Sound 15"
|
||||
"description" : "Sound 15",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 15,
|
||||
"address" : "37",
|
||||
"description" : "Sound 16"
|
||||
"description" : "Sound 16",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 16,
|
||||
"address" : "38",
|
||||
"description" : "Sound 17"
|
||||
"description" : "Sound 17",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 17,
|
||||
"address" : "39",
|
||||
"description" : "Sound 18"
|
||||
"description" : "Sound 18",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 18,
|
||||
"address" : "40",
|
||||
"description" : "Sound 19"
|
||||
"description" : "Sound 19",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 19,
|
||||
"address" : "41",
|
||||
"description" : "Sound 20"
|
||||
"description" : "Sound 20",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 20,
|
||||
"address" : "42",
|
||||
"description" : "Sound 21"
|
||||
"description" : "Sound 21",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 21,
|
||||
"address" : "43",
|
||||
"description" : "Sound 22"
|
||||
"description" : "Sound 22",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 22,
|
||||
"address" : "44",
|
||||
"description" : "Sound 23"
|
||||
"description" : "Sound 23",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 23,
|
||||
"address" : "45",
|
||||
"description" : "Sound 24"
|
||||
"description" : "Sound 24",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 24,
|
||||
"address" : "46",
|
||||
"description" : "Sound 25"
|
||||
"description" : "Sound 25",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 25,
|
||||
"address" : "47",
|
||||
"description" : "Sound 26"
|
||||
"description" : "Sound 26",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 26,
|
||||
"address" : "48",
|
||||
"description" : "Sound 27"
|
||||
"description" : "Sound 27",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 27,
|
||||
"address" : "49",
|
||||
"description" : "Sound 28"
|
||||
"description" : "Sound 28",
|
||||
"extender" : "extender_0"
|
||||
},
|
||||
{
|
||||
"id" : 28,
|
||||
"address" : "50",
|
||||
"description" : "Speech 1: \"You're good! But I'm still the Champ!\""
|
||||
"description" : "Speech 1: \"You're good! But I'm still the Champ!\"",
|
||||
"extender" : "extender_0"
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"input-config" :"../../contrib/json_example/input/Input_Pin_Config.json",
|
||||
"matrix-config" :"../../contrib/json_example/input/Input_Matrix_Config.json",
|
||||
"output-pin-config" :"../../contrib/json_example/output/Output_Pin_Config.json",
|
||||
"lamp-config" :"../../contrib/json_example/output/Lamp_Config.json",
|
||||
"solenoid-config" :"../../contrib/json_example/output/Solenoid_Config.json",
|
||||
"sound-config" :"../../contrib/json_example/output/Sound_Config.json",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "utility/config.h"
|
||||
|
||||
#include "wiringPi/wiringPi.h"
|
||||
#include "wiringPi/mcp23017.h"
|
||||
|
||||
#include "json/json.hpp"
|
||||
|
||||
namespace flippR_driver
|
||||
@@ -42,5 +44,18 @@ bool PinController::read_pin(uint8_t address)
|
||||
return PULLDOWN == digitalRead(address);
|
||||
}
|
||||
|
||||
void PinController::initialize_port_expander(const uint8_t i2c_address, const uint8_t pin_base)
|
||||
{
|
||||
mcp23017Setup(pin_base, i2c_address);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
@@ -23,6 +24,7 @@ public:
|
||||
virtual ~PinController() = default;
|
||||
|
||||
static void initialize_output_pin(const uint8_t address);
|
||||
void initialize_port_expander(const uint8_t i2c_address, const uint8_t pin_base);
|
||||
|
||||
protected:
|
||||
static void initialize_input_pin(uint8_t address);
|
||||
@@ -31,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,14 +6,14 @@
|
||||
#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;
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
#ifndef FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
|
||||
#include "OutputPinController.h"
|
||||
|
||||
#include <memory>
|
||||
#include "PinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -19,21 +17,13 @@ namespace items
|
||||
class DriverBoardItem;
|
||||
}
|
||||
|
||||
class DriverBoardPinController : public OutputPinController
|
||||
class DriverBoardPinController : public PinController
|
||||
{
|
||||
public:
|
||||
virtual ~DriverBoardPinController() = default;
|
||||
|
||||
DriverBoardPinController(std::shared_ptr<std::mutex> output_item_mutex);
|
||||
|
||||
void activate(items::DriverBoardItem & driver_board_item);
|
||||
void deactivate(items::DriverBoardItem & driver_board_item);
|
||||
|
||||
private:
|
||||
void write_pin(uint8_t pin, bool value) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mutex> output_item_mutex;
|
||||
virtual void activate(items::DriverBoardItem &driver_board_item) = 0;
|
||||
virtual void deactivate(items::DriverBoardItem &driver_board_item) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,23 +4,16 @@
|
||||
|
||||
#include "OutputDriverFactory.h"
|
||||
|
||||
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
#include "output/detail/OutputDriver.h"
|
||||
#include "output/detail/DisplayController.h"
|
||||
|
||||
#include "output/detail/SoundBoardPinController.h"
|
||||
#include "output/detail/DisplayBoardPinController.h"
|
||||
#include "output/detail/DriverBoardPinController.h"
|
||||
#include "output/detail/SoundBoardPinController.h"
|
||||
|
||||
#include "output/items/detail/EightDigitDisplay.h"
|
||||
#include "output/items/detail/SevenDigitDisplay.h"
|
||||
#include "output/items/Flipper.h"
|
||||
#include "output/items/detail/Flipper.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -29,348 +22,223 @@ namespace output
|
||||
namespace OutputDriverFactory
|
||||
{
|
||||
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& solenoid_config,
|
||||
std::istream& lamp_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config)
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
|
||||
std::istream& lamp_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config)
|
||||
{
|
||||
utility::LoggerFactory::CreateOutputLogger();
|
||||
|
||||
std::shared_ptr<std::mutex> output_pin_mutex;
|
||||
|
||||
json output_config;
|
||||
output_pin_config >> output_config;
|
||||
|
||||
json driver_board_config = output_config.at("driver_board");
|
||||
std::shared_ptr<DriverBoardPinController> driver_board_pin_controller(new detail::DriverBoardPinController(output_pin_mutex));
|
||||
auto solenoids = create_solenoids(solenoid_config, driver_board_pin_controller);
|
||||
auto flippers = create_flippers(solenoid_config, driver_board_pin_controller);
|
||||
auto lamps = create_lamps(lamp_config, driver_board_pin_controller);
|
||||
|
||||
json sound_board_config = output_config.at("sound_board");
|
||||
std::shared_ptr<SoundBoardPinController> sound_board_pin_controller(new detail::SoundBoardPinController(parse_pins_sound_board(sound_board_config), output_pin_mutex));
|
||||
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));
|
||||
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)));
|
||||
std::unique_ptr<DisplayBoardPinController> display_board_pin_controller(new detail::DisplayBoardPinController(parse_pins_display_board(display_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<OutputDriver>(std::move(display_controller), solenoids, lamps, sounds, flippers, display_map);
|
||||
}
|
||||
|
||||
std::map<std::string, uint8_t> parse_pins_sound_board(json &sound_board_config)
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::istream & solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
{
|
||||
std::map<std::string, uint8_t> pins_sound;
|
||||
try
|
||||
{
|
||||
pins_sound["i2c_address"] = sound_board_config.at("i2c_address").get<uint8_t>();
|
||||
pins_sound["pin_base"] = sound_board_config.at("pin_base").get<uint8_t>();
|
||||
pins_sound["fire"] = sound_board_config.at("fire").get<uint8_t>();
|
||||
|
||||
json sound_address = sound_board_config.at("sound_address_select");
|
||||
pins_sound["A"] = sound_address.at("A").get<uint8_t>();
|
||||
pins_sound["B"] = sound_address.at("B").get<uint8_t>();
|
||||
pins_sound["C"] = sound_address.at("C").get<uint8_t>();
|
||||
pins_sound["D"] = sound_address.at("D").get<uint8_t>();
|
||||
pins_sound["E"] = sound_address.at("E").get<uint8_t>();
|
||||
pins_sound["F"] = sound_address.at("F").get<uint8_t>();
|
||||
pins_sound["G"] = sound_address.at("G").get<uint8_t>();
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output pin config file at sound_board corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return pins_sound;
|
||||
}
|
||||
|
||||
std::map<std::string, uint8_t> parse_pins_display_board(json &display_board_config)
|
||||
{
|
||||
std::map<std::string, uint8_t> pins_display;
|
||||
try
|
||||
{
|
||||
pins_display["run"] = display_board_config.at("run");
|
||||
|
||||
json display_select = display_board_config.at("display_select");
|
||||
for(json::iterator it = display_select.begin(); it != display_select.end(); it++)
|
||||
{
|
||||
pins_display["display_select" + it.key()] = it.value().get<uint8_t>();
|
||||
}
|
||||
|
||||
json segment_select = display_board_config.at("segment_select");
|
||||
pins_display["segment_select_A"] = segment_select.at("A").get<uint8_t>();
|
||||
pins_display["segment_select_B"] = segment_select.at("B").get<uint8_t>();
|
||||
pins_display["segment_select_C"] = segment_select.at("C").get<uint8_t>();
|
||||
|
||||
json digit_select = display_board_config.at("digit_select");
|
||||
pins_display["digit_select_A"] = digit_select.at("A").get<uint8_t>();
|
||||
pins_display["digit_select_B"] = digit_select.at("B").get<uint8_t>();
|
||||
pins_display["digit_select_C"] = digit_select.at("C").get<uint8_t>();
|
||||
pins_display["digit_select_D"] = digit_select.at("D").get<uint8_t>();
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output pin config file at display_board corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return pins_display;
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<DriverBoardPinController> &output_gpio_interface)
|
||||
{
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids;
|
||||
|
||||
json solenoid_config_json;
|
||||
solenoid_config >> solenoid_config_json;
|
||||
|
||||
auto deactivation_time = get_deactivation_time(solenoid_config_json);
|
||||
json port_extenders = get_element("port_extenders", solenoid_config_json, "");
|
||||
|
||||
initialize_port_extenders(solenoid_config_json, output_gpio_interface);
|
||||
initialize_port_extenders(port_extenders, pin_controller.get(), "solenoid_config.json");
|
||||
|
||||
json solenoids_json;
|
||||
|
||||
try
|
||||
{
|
||||
solenoids_json = solenoid_config_json.at("solenoids");
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output solenoids config file corrupted: Key \"solenoids\" of type array needed. \n" << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
json solenoids_json = get_element("solenoids", solenoid_config_json, "solenoid_config.json");
|
||||
std::chrono::milliseconds deactivation_time{ get_value<int>("deactivation_time_milliseconds", solenoid_config_json, "solenoid_config.json") };
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids;
|
||||
for(auto &solenoid_json : solenoids_json)
|
||||
{
|
||||
auto solenoid = create_solenoid(solenoid_json, output_gpio_interface, deactivation_time);
|
||||
auto solenoid = create_solenoid(solenoid_json, port_extenders, pin_controller, deactivation_time);
|
||||
solenoids.emplace(solenoid->get_name(), solenoid);
|
||||
}
|
||||
|
||||
return solenoids;
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> create_flippers(std::istream &flipper_config, std::shared_ptr<DriverBoardPinController> &output_gpio_interface)
|
||||
std::shared_ptr<items::detail::Solenoid> create_solenoid(nlohmann::json &solenoid_json, nlohmann::json &port_extenders, std::shared_ptr<DriverBoardPinController> &pin_controller, std::chrono::milliseconds deactivation_time)
|
||||
{
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flippers;
|
||||
std::string config_file_name = "solenoid_config.json";
|
||||
|
||||
json flipper_config_json;
|
||||
flipper_config >> flipper_config_json;
|
||||
uint8_t pin_base = get_pin_base(solenoid_json, port_extenders, config_file_name);
|
||||
|
||||
json flippers_json;
|
||||
|
||||
try
|
||||
{
|
||||
flippers_json = flipper_config_json.at("flippers");
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output solenoids config file corrupted: Key \"flippers\" of type array needed. \n" << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for(auto &flipper_json : flippers_json)
|
||||
{
|
||||
auto flipper = create_flipper(flipper_json, output_gpio_interface);
|
||||
flippers.emplace(flipper->get_name(), flipper);
|
||||
}
|
||||
|
||||
return flippers;
|
||||
}
|
||||
|
||||
std::shared_ptr<items::detail::Flipper> create_flipper(nlohmann::json &flipper_json, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string name = flipper_json.at("name");
|
||||
auto address = flipper_json.at("address").get<uint8_t>();
|
||||
|
||||
return std::make_shared<items::detail::Flipper>(pin_controller, address, name);
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output solenoid config file corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<DriverBoardPinController> &output_gpio_interface)
|
||||
{
|
||||
//TODO initialize portextender
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamps;
|
||||
|
||||
json lamp_config_json;
|
||||
lamp_config >> lamp_config_json;
|
||||
|
||||
json lamps_json;
|
||||
|
||||
try
|
||||
{
|
||||
lamps_json = lamp_config_json.at("lamps");
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output lamp config file corrupted: Key \"lamps\" of type array needed. \n" << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for(auto &lamp_json : lamps_json)
|
||||
{
|
||||
auto lamp = create_lamp(lamp_json, output_gpio_interface);
|
||||
lamps.emplace(lamp->get_name(), lamp);
|
||||
}
|
||||
|
||||
return lamps;
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream &sound_config, std::shared_ptr<SoundBoardPinController> &output_gpio_interface)
|
||||
{
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> sounds;
|
||||
|
||||
json sounds_config_json;
|
||||
sound_config >> sounds_config_json;
|
||||
|
||||
auto deactivation_time = get_deactivation_time(sounds_config_json);
|
||||
|
||||
json sounds_json;
|
||||
|
||||
try
|
||||
{
|
||||
sounds_json = sounds_config_json.at("sounds");
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output sound config file corrupted: Key \"sounds\" of type array needed. \n" << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for(auto &sound_json : sounds_json)
|
||||
{
|
||||
auto sound = create_sound(sound_json, output_gpio_interface, deactivation_time);
|
||||
sounds.emplace(sound->Item::get_name(), sound);
|
||||
}
|
||||
|
||||
return sounds;
|
||||
}
|
||||
|
||||
void initialize_port_extenders(nlohmann::json &json_stream, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
{
|
||||
json port_extenders;
|
||||
|
||||
try
|
||||
{
|
||||
port_extenders = json_stream.at("port_extenders");
|
||||
}
|
||||
catch (json::exception & e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output solenoids config file corrupted: Key \"port_extenders\" of type array needed. \n" << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (auto & extender_json : port_extenders)
|
||||
{
|
||||
pin_controller->initialize_port_expander(extender_json.at("i2c_address").get<uint8_t>(), extender_json.at("pin_base").get<uint8_t>());
|
||||
}
|
||||
}
|
||||
|
||||
std::chrono::milliseconds get_deactivation_time(nlohmann::json &json)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto deactivation_time = json.at("deactivation_time_milliseconds").get<uint>();
|
||||
return std::chrono::milliseconds(deactivation_time);
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output config file at deactivation_time_milliseconds corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<items::detail::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<DriverBoardPinController> &pin_controller, std::chrono::milliseconds &deactivation_time)
|
||||
{
|
||||
try
|
||||
{
|
||||
uint8_t address = 0;
|
||||
if(solenoid_json.find("extender") != solenoid_json.end())
|
||||
{
|
||||
address += solenoid_json.at("extender").get<uint8_t>();
|
||||
}
|
||||
|
||||
std::string name = solenoid_json.at("name");
|
||||
address += solenoid_json.at("address").get<uint8_t>();
|
||||
auto name = get_value<std::string>("name", solenoid_json, config_file_name);
|
||||
auto address = get_value<uint8_t>("address", solenoid_json, config_file_name);
|
||||
|
||||
if(solenoid_json.find("deactivation_time_milliseconds") != solenoid_json.end())
|
||||
{
|
||||
deactivation_time = get_deactivation_time(solenoid_json);
|
||||
deactivation_time = std::chrono::milliseconds(get_value<uint8_t>("deactivation_time_milliseconds", solenoid_json, config_file_name));
|
||||
}
|
||||
|
||||
return std::make_shared<items::detail::Solenoid>(pin_controller, address, name, deactivation_time);
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output solenoid config file corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return std::make_shared<items::detail::Solenoid>(pin_controller, address, pin_base, name, deactivation_time);
|
||||
}
|
||||
|
||||
std::shared_ptr<items::detail::Lamp> create_lamp(nlohmann::json &lamp_json, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> create_flippers(std::istream &solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
{
|
||||
try
|
||||
json solenoid_config_json;
|
||||
solenoid_config >> solenoid_config_json;
|
||||
|
||||
json port_extenders = get_element("port_extenders", solenoid_config_json, "solenoid_config.json");
|
||||
|
||||
json flippers_json = get_element("flippers", solenoid_config_json, "solenoid_config.json");
|
||||
std::chrono::milliseconds deactivation_time{ get_value<int>("deactivation_time_milliseconds", solenoid_config_json, "solenoid_config.json") };
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flippers;
|
||||
for(auto &flipper_json : flippers_json)
|
||||
{
|
||||
std::string name = lamp_json.at("name");
|
||||
auto address = lamp_json.at("address").get<uint8_t>();
|
||||
return std::make_shared<items::detail::Lamp>(pin_controller, address, name);
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output lamp config file corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
auto flipper = create_flipper(flipper_json, port_extenders, pin_controller);
|
||||
flippers.emplace(flipper->get_name(), flipper);
|
||||
}
|
||||
return flippers;
|
||||
}
|
||||
|
||||
std::shared_ptr<items::detail::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<SoundBoardPinController> &pin_controller, std::chrono::milliseconds &deactivation_time)
|
||||
std::shared_ptr<items::detail::Flipper> create_flipper(nlohmann::json &flipper_json, json &port_extenders, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto id = sound_json.at("id").get<uint>();
|
||||
std::string description = sound_json.at("description");
|
||||
auto address = sound_json.at("address").get<uint8_t>();
|
||||
return std::make_shared<items::detail::Sound>(pin_controller, address, description, deactivation_time, id);
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output sound config file corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
std::string config_file_name = "solenoid_config.json";
|
||||
|
||||
uint8_t pin_base = get_pin_base(flipper_json, port_extenders, config_file_name);
|
||||
auto address = get_value<uint8_t>("address", flipper_json, config_file_name);
|
||||
auto name = get_value<std::string>("name", flipper_json, config_file_name);
|
||||
|
||||
return std::make_shared<items::detail::Flipper>(pin_controller, address, pin_base, name);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream &display_config)
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
{
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
json lamp_config_json;
|
||||
lamp_config >> lamp_config_json;
|
||||
|
||||
json port_extenders = get_element("port_extenders", lamp_config_json, "lamp_config.json");
|
||||
|
||||
initialize_port_extenders(port_extenders, pin_controller.get(), "lamp_config.json");
|
||||
|
||||
json solenoids_json = get_element("lamps", lamp_config_json, "lamp_config.json");
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamps;
|
||||
for(auto &solenoid_json : solenoids_json)
|
||||
{
|
||||
auto solenoid = create_lamp(solenoid_json, port_extenders, pin_controller);
|
||||
lamps.emplace(solenoid->get_name(), solenoid);
|
||||
}
|
||||
return lamps;
|
||||
}
|
||||
|
||||
std::shared_ptr<items::detail::Lamp> create_lamp(json &lamp_json, json & port_extenders, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
{
|
||||
std::string config_file_name = "lamps_config.json";
|
||||
|
||||
uint8_t pin_base = get_pin_base(lamp_json, port_extenders, config_file_name);
|
||||
auto address = get_value<uint8_t>("address", lamp_json, config_file_name);
|
||||
auto name = get_value<std::string>("name", lamp_json, config_file_name);
|
||||
|
||||
return std::make_shared<items::detail::Lamp>(pin_controller, address, pin_base, name);
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream &sound_config, std::shared_ptr<SoundBoardPinController> &pin_controller)
|
||||
{
|
||||
json sound_config_json;
|
||||
sound_config >> sound_config_json;
|
||||
|
||||
json port_extenders = get_element("port_extenders", sound_config_json, "sound_config.json");
|
||||
|
||||
initialize_port_extenders(port_extenders, pin_controller.get(), "sound_config.json");
|
||||
|
||||
std::chrono::milliseconds deactivation_time{ get_value<int>("deactivation_time_milliseconds", sound_config_json, "solenoid_config.json") };
|
||||
|
||||
json solenoids_json = get_element("sounds", sound_config_json, "sound_config.json");
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> sounds;
|
||||
for(auto &solenoid_json : solenoids_json)
|
||||
{
|
||||
auto solenoid = create_sound(solenoid_json, port_extenders, pin_controller, deactivation_time);
|
||||
sounds.emplace(solenoid->get_name(), solenoid);
|
||||
}
|
||||
return sounds;
|
||||
}
|
||||
|
||||
std::shared_ptr<items::detail::Sound> create_sound(json &sound_json, json &port_extenders, std::shared_ptr<SoundBoardPinController> &pin_controller, std::chrono::milliseconds &deactivation_time)
|
||||
{
|
||||
std::string config_file_name = "sound_config.json";
|
||||
|
||||
uint8_t pin_base = get_pin_base(sound_json, port_extenders, config_file_name);
|
||||
auto address = get_value<uint8_t>("address", sound_json, config_file_name);
|
||||
auto name = get_value<std::string>("name", sound_json, config_file_name);
|
||||
auto id = get_value<uint>("id", sound_json, config_file_name);
|
||||
|
||||
return std::make_shared<items::detail::Sound>(pin_controller, address, pin_base, name, deactivation_time, id);
|
||||
}
|
||||
|
||||
uint8_t get_sound_fire_address(std::istream &sound_config)
|
||||
{
|
||||
json sound_config_json;
|
||||
sound_config >> sound_config_json;
|
||||
|
||||
json port_extenders = get_element("port_extenders", sound_config_json, "sound_config.json");
|
||||
|
||||
json fire_pin = get_element("fire_pin", sound_config_json, "sound_config.json");
|
||||
auto pin_base = get_pin_base(fire_pin, port_extenders, "sound_config.json");
|
||||
auto address = get_value<uint8_t>("address", fire_pin, "sound_config.json");
|
||||
|
||||
return pin_base + address;
|
||||
}
|
||||
|
||||
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 displays_json;
|
||||
json display_board_config = get_element("display_board", display_config_json, config_file);
|
||||
|
||||
try
|
||||
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++)
|
||||
{
|
||||
displays_json = display_config_json.at("displays");
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output display config file corrupted: Key \"displays\" of type array needed. \n" << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
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);
|
||||
@@ -380,32 +248,20 @@ std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream
|
||||
return displays;
|
||||
}
|
||||
|
||||
std::shared_ptr<items::OutputDisplay> create_display(nlohmann::json &display_json)
|
||||
std::shared_ptr<items::OutputDisplay> create_display(json & display_json)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto id = display_json.at("id").get<uint8_t>();
|
||||
auto address = display_json.at("address").get<uint8_t>();
|
||||
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);
|
||||
|
||||
auto digits = display_json.at("digits").get<uint8_t>();
|
||||
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");
|
||||
}
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "Output display config file corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
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)
|
||||
@@ -420,6 +276,68 @@ std::map<uint8_t, std::shared_ptr<items::Display>> map_displays(const std::vecto
|
||||
return display_map;
|
||||
}
|
||||
|
||||
void initialize_port_extenders(json &port_extenders, PinController * pin_controller, const std::string & file_name)
|
||||
{
|
||||
|
||||
for (auto & extender_json : port_extenders)
|
||||
{
|
||||
auto i2c_address = get_value<uint8_t>("i2c_address", extender_json, file_name);
|
||||
auto pin_base = get_value<uint8_t>("pin_base", extender_json, file_name);
|
||||
pin_controller->initialize_port_expander(i2c_address, pin_base);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t get_pin_base(json & object, json & port_extenders, const std::string & config_file_name)
|
||||
{
|
||||
uint8_t pin_base{ 0 };
|
||||
|
||||
if(object.find("extender") != object.end())
|
||||
{
|
||||
auto extender_name = get_value<std::string>("extender", object, config_file_name);
|
||||
for (auto & extender : port_extenders)
|
||||
{
|
||||
auto actual_extender = get_value<std::string>("name", extender, config_file_name);
|
||||
if (actual_extender == extender_name)
|
||||
{
|
||||
pin_base = get_value<uint8_t>("pin_base", extender, config_file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pin_base;
|
||||
}
|
||||
|
||||
json get_element(const std::string & name, json & object, const std::string & file_name)
|
||||
{
|
||||
json sub_object;
|
||||
|
||||
try
|
||||
{
|
||||
sub_object = object.at(name);
|
||||
return sub_object;
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "File " << file_name << " seems to be corrupted at " << name << ": " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
type get_value(const std::string & name, json & object, const std::string & file_name)
|
||||
{
|
||||
try
|
||||
{
|
||||
type element = object.at(name).get<type>();
|
||||
return element;
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, OUTPUT_LOGGER) << "File " << file_name << " seems to be corrupted at " << name << ": " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
|
||||
// Created by rhetenor on 04.10.18.
|
||||
//
|
||||
|
||||
@@ -23,35 +23,36 @@ namespace output
|
||||
{
|
||||
namespace OutputDriverFactory
|
||||
{
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& solenoid_config,
|
||||
std::istream& lamp_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config);
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
|
||||
std::istream& lamp_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config);
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::istream& solenoid_config, std::shared_ptr<DriverBoardPinController> &driverBoardPinController);
|
||||
std::shared_ptr<items::detail::Solenoid> create_solenoid(nlohmann::json &solenoid_json, nlohmann::json &port_extenders, std::shared_ptr<DriverBoardPinController> &pin_controller, std::chrono::milliseconds deactivation_time);
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
std::shared_ptr<items::detail::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<DriverBoardPinController> &pin_controller, std::chrono::milliseconds &deactivation_time);
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> create_flippers(std::istream &solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
std::shared_ptr<items::detail::Flipper> create_flipper(nlohmann::json &flipper_json, nlohmann::json &port_extenders, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
std::shared_ptr<items::detail::Lamp> create_lamp(nlohmann::json &lamp_json, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
std::shared_ptr<items::detail::Lamp> create_lamp(nlohmann::json &lamp_json, nlohmann::json & port_extenders, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> create_flippers(std::istream &solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
std::shared_ptr<items::detail::Flipper> create_flipper(nlohmann::json &flipper_json, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream &sound_config, std::shared_ptr<SoundBoardPinController> &pin_controller);
|
||||
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, std::shared_ptr<items::Sound>> create_sounds(std::istream &sound_config, std::shared_ptr<SoundBoardPinController> &pin_controller);
|
||||
std::shared_ptr<items::detail::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<SoundBoardPinController> &pin_controller, std::chrono::milliseconds &deactivation_time);
|
||||
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 &json, std::shared_ptr<DriverBoardPinController> &pin_controller);
|
||||
void initialize_port_extenders(nlohmann::json &port_extenders, PinController * pin_controller, const std::string & file_name);
|
||||
|
||||
std::chrono::milliseconds get_deactivation_time(nlohmann::json &json);
|
||||
uint8_t get_pin_base(nlohmann::json & object, nlohmann::json & port_extenders, const std::string & config_file_name);
|
||||
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream &display_config);
|
||||
std::map<uint8_t, std::shared_ptr<items::Display>> map_displays(const std::vector<std::shared_ptr<items::OutputDisplay>> &displays);
|
||||
std::shared_ptr<items::OutputDisplay> create_display(nlohmann::json &display_json);
|
||||
|
||||
std::map<std::string, uint8_t> parse_pins_sound_board(nlohmann::json &sound_board_config);
|
||||
std::map<std::string, uint8_t> parse_pins_display_board(nlohmann::json &display_board_config);
|
||||
nlohmann::json get_element(const std::string & name, nlohmann::json & object, const std::string & file_name);
|
||||
template<typename type>
|
||||
type get_value(const std::string & name, nlohmann::json & object, const std::string & file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +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);
|
||||
}
|
||||
|
||||
void OutputPinController::initialize_port_expander(const uint8_t i2c_address, const uint8_t pin_base)
|
||||
{
|
||||
mcp23017Setup(pin_base, i2c_address);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,41 +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;
|
||||
|
||||
void initialize_port_expander(const uint8_t i2c_address, const uint8_t pin_base);
|
||||
|
||||
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,14 +6,14 @@
|
||||
#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;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#include <thread>
|
||||
#include "output/detail/DisplayBoardPinController.h"
|
||||
|
||||
#include "DisplayBoardPinController.h"
|
||||
#include <thread>
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -37,7 +37,7 @@ void DisplayBoardPinController::write_display(const items::OutputDisplay &displa
|
||||
{
|
||||
std::string content = display.get_content();
|
||||
|
||||
for(uint8_t i = 0; i < content.size(); i++)
|
||||
for (uint8_t i = 0; i < content.size(); i++)
|
||||
{
|
||||
write_display_digit(display.get_address(), content.at(i), i);
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ 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 activate_displays() const;
|
||||
void deactivate_displays() const;
|
||||
|
||||
void write_display(const items::OutputDisplay &display) const override;
|
||||
void write_display(const items::OutputDisplay &display) const;
|
||||
|
||||
private:
|
||||
void write_display_digit(uint8_t display_address, uint8_t content, uint8_t position) const;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include "DisplayController.h"
|
||||
#include "output/detail/DisplayController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -16,8 +16,10 @@ 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)
|
||||
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)
|
||||
{
|
||||
this->display_cycle_thread = std::thread(&DisplayController::cycle_displays, this);
|
||||
|
||||
@@ -35,9 +37,9 @@ DisplayController::~DisplayController()
|
||||
|
||||
void DisplayController::cycle_displays() const
|
||||
{
|
||||
while(is_running)
|
||||
while (is_running)
|
||||
{
|
||||
for(auto &display : this->displays)
|
||||
for (auto &display : this->displays)
|
||||
{
|
||||
pin_controller->write_display(*display);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#include "DriverBoardPinController.h"
|
||||
#include "output/detail/DriverBoardPinController.h"
|
||||
|
||||
#include "output/items/DriverBoardItem.h"
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
DriverBoardPinController::DriverBoardPinController(std::shared_ptr<std::mutex> output_item_mutex) :
|
||||
output_item_mutex(std::move(output_item_mutex))
|
||||
@@ -41,3 +43,4 @@ void DriverBoardPinController::write_pin(uint8_t pin, bool value) const
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
42
FlippR-Driver/src/output/detail/DriverBoardPinController.h
Normal file
42
FlippR-Driver/src/output/detail/DriverBoardPinController.h
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_DRIVERBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_OUTPUT_IMPL_DRIVERBOARDPINCONTROLLER_H
|
||||
|
||||
#include "output/DriverBoardPinController.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class DriverBoardPinController : public output::DriverBoardPinController
|
||||
{
|
||||
public:
|
||||
virtual ~DriverBoardPinController() = default;
|
||||
|
||||
DriverBoardPinController(std::shared_ptr<std::mutex> output_item_mutex);
|
||||
|
||||
void activate(items::DriverBoardItem & driver_board_item);
|
||||
void deactivate(items::DriverBoardItem & driver_board_item);
|
||||
|
||||
private:
|
||||
void write_pin(uint8_t pin, bool value) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mutex> output_item_mutex;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
@@ -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/detail/SoundBoardPinController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -13,17 +13,13 @@ namespace output
|
||||
namespace detail
|
||||
{
|
||||
|
||||
SoundBoardPinController::SoundBoardPinController(std::map<std::string, uint8_t> pins_sound, std::shared_ptr<std::mutex> output_item_mutex) :
|
||||
pins_sound(std::move(pins_sound)), output_item_mutex(std::move(output_item_mutex))
|
||||
SoundBoardPinController::SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex,
|
||||
const uint8_t &fire_address
|
||||
) :
|
||||
output_item_mutex(std::move(output_item_mutex)),
|
||||
fire_address(fire_address)
|
||||
{
|
||||
uint8_t i2c_address = pins_sound.at("i2c_address");
|
||||
uint8_t pin_base = pins_sound.at("pin_base");
|
||||
|
||||
initialize_i2c_address(i2c_address, pin_base);
|
||||
initialize_pins_output(pin_base, pins_sound.begin(), pins_sound.end());
|
||||
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created SoundBoardPinController with i2c_address 0x" << std::hex << i2c_address << " and pin_base " << std::dec << pin_base;
|
||||
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created SoundBoardPinController";
|
||||
}
|
||||
|
||||
void SoundBoardPinController::activate(const items::detail::Sound &sound)
|
||||
@@ -45,27 +41,27 @@ void SoundBoardPinController::deactivate(const items::detail::Sound &sound)
|
||||
}
|
||||
|
||||
|
||||
void SoundBoardPinController::write_sound_address(uint8_t address) const
|
||||
void SoundBoardPinController::write_sound_address(const uint8_t &address) const
|
||||
{
|
||||
write_pin(pins_sound.at("A"), address & 0b0000001u);
|
||||
write_pin(pins_sound.at("B"), address & 0b0000010u);
|
||||
write_pin(pins_sound.at("C"), address & 0b0000100u);
|
||||
write_pin(pins_sound.at("D"), address & 0b0001000u);
|
||||
write_pin(pins_sound.at("E"), address & 0b0010000u);
|
||||
write_pin(pins_sound.at("F"), address & 0b0100000u);
|
||||
write_pin(pins_sound.at("G"), address & 0b1000000u);
|
||||
// write_pin(pins_sound.at("A"), address & 0b0000001u);
|
||||
// write_pin(pins_sound.at("B"), address & 0b0000010u);
|
||||
// write_pin(pins_sound.at("C"), address & 0b0000100u);
|
||||
// write_pin(pins_sound.at("D"), address & 0b0001000u);
|
||||
// write_pin(pins_sound.at("E"), address & 0b0010000u);
|
||||
// write_pin(pins_sound.at("F"), address & 0b0100000u);
|
||||
// write_pin(pins_sound.at("G"), address & 0b1000000u);
|
||||
}
|
||||
|
||||
void SoundBoardPinController::fire_sound() const
|
||||
{
|
||||
PinController::write_pin(pins_sound.at("fire"), true);
|
||||
|
||||
PinController::write_pin(pins_sound.at("fire"), false);
|
||||
// PinController::write_pin(pins_sound.at("fire"), true);
|
||||
//
|
||||
// PinController::write_pin(pins_sound.at("fire"), false);
|
||||
}
|
||||
|
||||
void SoundBoardPinController::write_pin(uint8_t pin, bool value) const
|
||||
void SoundBoardPinController::write_pin(const uint8_t &pin, const bool &value) const
|
||||
{
|
||||
PinController::write_pin(pins_sound.at("pin_base") + pin, value);
|
||||
// PinController::write_pin(pins_sound.at("pin_base") + pin, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,23 +19,22 @@ namespace detail
|
||||
class SoundBoardPinController : public output::SoundBoardPinController
|
||||
{
|
||||
public:
|
||||
SoundBoardPinController(std::map<std::string, uint8_t> pins_sound, std::shared_ptr<std::mutex> output_item_mutex);
|
||||
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;
|
||||
void activate(const items::detail::Sound &sound);
|
||||
void deactivate(const items::detail::Sound &sound);
|
||||
|
||||
private:
|
||||
void write_sound_address(uint8_t address) const;
|
||||
void write_sound_address(const uint8_t & address) const;
|
||||
void fire_sound() const;
|
||||
|
||||
void write_pin(uint8_t pin, bool value) const;
|
||||
void write_pin(const uint8_t & pin, const bool & value) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mutex> output_item_mutex;
|
||||
|
||||
const std::map<std::string, uint8_t> pins_sound;
|
||||
|
||||
uint8_t fire_address;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace flippR_driver::output;
|
||||
|
||||
items::detail::DriverBoardItem::DriverBoardItem(std::shared_ptr<PinController> pin_controller, const uint8_t address, const uint8_t pin_base) :
|
||||
items::detail::DriverBoardItem::DriverBoardItem(std::shared_ptr<PinController> pin_controller, const uint8_t & address, const uint8_t & pin_base) :
|
||||
address(pin_base + address)
|
||||
{
|
||||
pin_controller->initialize_output_pin(this->address);
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace detail
|
||||
class DriverBoardItem : public output::items::DriverBoardItem
|
||||
{
|
||||
public:
|
||||
DriverBoardItem(std::shared_ptr<PinController> pin_controller, const uint8_t address, const uint8_t pin_base);
|
||||
DriverBoardItem(std::shared_ptr<PinController> pin_controller, const uint8_t & address, const uint8_t & pin_base);
|
||||
|
||||
~DriverBoardItem() override = default;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace items
|
||||
namespace detail
|
||||
{
|
||||
|
||||
Flipper::Flipper(std::shared_ptr<DriverBoardPinController> pin_controller, uint8_t address, std::string name) :
|
||||
Item(std::move(name)), DriverBoardItem(address), pin_controller(std::move(pin_controller))
|
||||
Flipper::Flipper(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name) :
|
||||
Item(std::move(name)), DriverBoardItem(pin_controller, address, pin_base), pin_controller(std::move(pin_controller))
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created Flipper relay " << this->name << " with address " << this->address;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace detail
|
||||
class Flipper : public detail::Item, public items::Flipper, public detail::DriverBoardItem
|
||||
{
|
||||
public:
|
||||
Flipper(std::shared_ptr<DriverBoardPinController> pin_controller, uint8_t address, std::string name);
|
||||
Flipper(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name);
|
||||
~Flipper() override;
|
||||
|
||||
void activate() override;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace items
|
||||
namespace detail
|
||||
{
|
||||
|
||||
Lamp::Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t address, const uint8_t pin_base, const std::string name) :
|
||||
Lamp::Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name) :
|
||||
detail::Item(std::move(name)), DriverBoardItem(pin_controller, address, pin_base), pin_controller(std::move(pin_controller)), activated(false)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created lamp " << name << " with address " << address;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace detail
|
||||
class Lamp : public detail::DriverBoardItem, public detail::Item, public items::Lamp
|
||||
{
|
||||
public:
|
||||
Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t address, const uint8_t pin_base, const std::string name);
|
||||
Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name);
|
||||
~Lamp() override = default;
|
||||
|
||||
void activate() override;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace items
|
||||
namespace detail
|
||||
{
|
||||
|
||||
Solenoid::Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t address, const uint8_t pin_base, const std::string name, std::chrono::milliseconds deactivation_time)
|
||||
Solenoid::Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name, const std::chrono::milliseconds & deactivation_time)
|
||||
: detail::Item(std::move(name)), DriverBoardItem(pin_controller, address, pin_base), pin_controller(pin_controller), deactivation_time(deactivation_time)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created solenoid " << name << " with address " << address;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace detail
|
||||
class Solenoid : public DriverBoardItem, public detail::Item, public items::Solenoid
|
||||
{
|
||||
public:
|
||||
Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t address, const uint8_t pin_base, const std::string name, std::chrono::milliseconds deactivation_time);
|
||||
Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name, const std::chrono::milliseconds & deactivation_time);
|
||||
~Solenoid() override = default;
|
||||
|
||||
void trigger() override;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace items
|
||||
namespace detail
|
||||
{
|
||||
|
||||
Sound::Sound(std::shared_ptr<SoundBoardPinController> pin_controller, const uint8_t address, const uint8_t pin_base, const std::string name, std::chrono::milliseconds deactivation_time, u_int id)
|
||||
Sound::Sound(std::shared_ptr<SoundBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name, const std::chrono::milliseconds & deactivation_time, const u_int id)
|
||||
: detail::Item(std::move(name)), DriverBoardItem(pin_controller, address, pin_base), pin_controller(std::move(pin_controller)), deactivation_time(deactivation_time), id(id)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created sound " << id << " with name " << name << " and address " << address;
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
u_int id;
|
||||
|
||||
public:
|
||||
Sound(std::shared_ptr<SoundBoardPinController> pin_controller, const uint8_t address, const uint8_t pin_base, const std::string name, std::chrono::milliseconds deactivation_time, u_int id);
|
||||
Sound(std::shared_ptr<SoundBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name, const std::chrono::milliseconds & deactivation_time, const u_int id);
|
||||
~Sound() override = default;
|
||||
|
||||
void play() override;
|
||||
|
||||
@@ -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