fuuuuuuuu
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user