Changed displays from id to name

This commit is contained in:
Johannes Wendel
2020-01-09 22:33:23 +01:00
parent 5b422d9849
commit 4986eb5368
12 changed files with 28 additions and 35 deletions

View File

@@ -21,7 +21,7 @@ class SevenDigitDisplay : public virtual Display
public:
virtual ~SevenDigitDisplay() = default;
virtual void write_content(std::string content) = 0;
virtual void write_content(std::string & content) = 0;
};
}

View File

@@ -10,7 +10,6 @@
#include "output/items/detail/SevenDigitDisplay.h"
#include "DisplayFactory.h"
namespace flippR_driver
{
namespace output
@@ -29,13 +28,13 @@ std::map<std::string, std::shared_ptr<items::Display>> DisplayFactory::getItemMa
auto displays = this->object.at(config_path::display_list);
for (auto & display : displays)
{
auto id = display.at(config_path::item_identifier).get<uint8_t>();
auto name = display.at(config_path::item_name).get<std::string>();
auto address = display.at(config_path::item_address).get<uint8_t>();
auto digits = display.at(config_path::display_digits).get<uint8_t>();
if (digits == 8)
display_map.emplace(std::string{static_cast<char>(id)}, std::dynamic_pointer_cast<items::Display>(std::make_shared<items::detail::EightDigitDisplay>(address, id)));
display_map.emplace(name, std::dynamic_pointer_cast<items::Display>(std::make_shared<items::detail::EightDigitDisplay>(address, name)));
else if (digits == 7)
display_map.emplace(std::string{static_cast<char>(id)}, std::dynamic_pointer_cast<items::Display>(std::make_shared<items::detail::SevenDigitDisplay>(address, id)));
display_map.emplace(name, std::dynamic_pointer_cast<items::Display>(std::make_shared<items::detail::SevenDigitDisplay>(address, name)));
else
throw new std::logic_error{"Display digits can either be 7 or 8"};
}
@@ -47,12 +46,6 @@ void DisplayFactory::create_pin_map()
nlohmann::json board_config = this->object.at(config_path::display_board);
this->pin_map["run"] = board_config.at(config_path::run_pin);
nlohmann::json display_select = board_config.at(config_path::display_select);
for(int i = 1; i < 6; i++)
{
this->pin_map["display_select" + std::to_string(i)] = display_select.at(std::to_string(i));
}
nlohmann::json segment_select = board_config.at(config_path::display_segement_select);
this->pin_map["segment_select_A"] = segment_select.at("A");
this->pin_map["segment_select_B"] = segment_select.at("B");

View File

@@ -19,7 +19,7 @@ namespace output
class DisplayFactory : ItemFactory
{
public:
explicit DisplayFactory(nlohmann::json & object, std::shared_ptr<DisplayBoardPinController> pin_controller);
DisplayFactory(nlohmann::json & object, std::shared_ptr<DisplayBoardPinController> pin_controller);
std::map<std::string, std::shared_ptr<items::Display>> getItemMap();

View File

@@ -20,7 +20,7 @@ namespace output
class FlipperFactory : ItemFactory
{
public:
explicit FlipperFactory(nlohmann::json & object, std::shared_ptr<DriverBoardPinController> pin_controller);
FlipperFactory(nlohmann::json & object, std::shared_ptr<DriverBoardPinController> pin_controller);
std::map <std::string, std::shared_ptr<items::Flipper>> getItemMap();
};

View File

@@ -20,7 +20,7 @@ namespace output
class LampFactory : ItemFactory
{
public:
explicit LampFactory(nlohmann::json & object, std::shared_ptr<DriverBoardPinController> pin_controller);
LampFactory(nlohmann::json & object, std::shared_ptr<DriverBoardPinController> pin_controller);
std::map<std::string, std::shared_ptr<items::Lamp>> getItemMap();
};

View File

@@ -20,7 +20,7 @@ namespace output
class SolenoidFactory : public ItemFactory
{
public:
explicit SolenoidFactory(nlohmann::json &object, std::shared_ptr<DriverBoardPinController> pin_controller);
SolenoidFactory(nlohmann::json &object, std::shared_ptr<DriverBoardPinController> pin_controller);
std::map<std::string, std::shared_ptr<items::Solenoid>> getItemMap();

View File

@@ -20,7 +20,7 @@ namespace output
class SoundFactory : ItemFactory
{
public:
explicit SoundFactory(nlohmann::json & object, std::shared_ptr<SoundBoardPinController> pin_controller);
SoundFactory(nlohmann::json & object, std::shared_ptr<SoundBoardPinController> pin_controller);
std::map<std::string, std::shared_ptr<items::Sound>> getItemMap();
private:

View File

@@ -28,7 +28,7 @@ public:
virtual ~OutputDisplay() = default;
virtual uint8_t get_address() const = 0;
virtual uint8_t get_id() const = 0;
virtual std::string get_name() const = 0;
virtual std::string get_content() const = 0;
};

View File

@@ -17,16 +17,16 @@ namespace items
namespace detail
{
Display::Display(const uint8_t & address, const uint8_t & id) :
address(address),
id(id)
Display::Display(const uint8_t & address, const std::string & name) :
address{address},
name{name}
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Created display with id " << int{id} << " and address " << int{address} << ".";
CLOG(DEBUG, OUTPUT_LOGGER) << "Created display " << name << " with address " << int{address} << ".";
}
uint8_t Display::get_id() const
std::string Display::get_name() const
{
return this->id;
return this->name;
}
void Display::write_score(const unsigned int & score, const unsigned int & length)

View File

@@ -24,7 +24,7 @@ namespace detail
class Display : public virtual items::OutputDisplay
{
public:
Display(const uint8_t & address, const uint8_t & id);
Display(const uint8_t & address, const std::string & name);
virtual ~Display() = default;
void write_score(const unsigned int & score, const unsigned int & length);
@@ -32,7 +32,7 @@ public:
std::string get_content() const override;
uint8_t get_address() const override;
uint8_t get_id() const override;
std::string get_name() const override;
private:
std::string fit_score_string(std::string & score_string, const unsigned int & length);
@@ -41,7 +41,7 @@ public:
std::string content;
protected:
const uint8_t id;
const std::string name;
const uint8_t address;
};

View File

@@ -23,10 +23,10 @@ namespace detail
class EightDigitDisplay : public virtual items::detail::Display, public virtual items::EightDigitDisplay
{
public:
EightDigitDisplay(uint8_t address, uint8_t id) :
detail::Display(address, id)
EightDigitDisplay(const uint8_t & address, const std::string & name) :
detail::Display(address, name)
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Created EightDigitDisplay with address " << int{this->address} << " and id: " << int{id};
CLOG(DEBUG, OUTPUT_LOGGER) << "Created EightDigitDisplay " << name << " with address " << int{this->address};
}
~EightDigitDisplay() override = default;
@@ -43,7 +43,7 @@ public:
std::string get_name() const override
{
return "EightDigitDisplay " + this->id;
return "EightDigitDisplay " + name;
}
};

View File

@@ -21,17 +21,17 @@ namespace detail
class SevenDigitDisplay : public virtual items::detail::Display, public virtual items::SevenDigitDisplay
{
public:
SevenDigitDisplay(uint8_t address, uint8_t id) :
detail::Display(address, id)
SevenDigitDisplay(const uint8_t & address, const std::string & name) :
detail::Display(address, name)
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Created SevenDigitDisplay with address " << int{this->address} << " and id: " << int{id};
CLOG(DEBUG, OUTPUT_LOGGER) << "Created SevenDigitDisplay " << name << " with address " << int{this->address};
}
void write_score(unsigned int score) override
{
detail::Display::write_score(score, 7);
}
void write_content(std::string content) override
void write_content(std::string & content) override
{
detail::Display::write_content(content, 7);
}
@@ -40,7 +40,7 @@ public:
std::string get_name() const override
{
return "EightDigitDisplay " + this->id;
return "EightDigitDisplay " + name;
}
};