erased some codesmells
This commit is contained in:
@@ -28,7 +28,7 @@ namespace flippR_driver {
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
char address;
|
||||
uint8_t address;
|
||||
int priority;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> last_activation;
|
||||
|
||||
|
||||
@@ -22,22 +22,22 @@ GPIOInterface::GPIOInterface()
|
||||
std::call_once(GPIO_LIB_INITIALIZED, wiringPiSetup);
|
||||
}
|
||||
|
||||
void GPIOInterface::initialize_input_pin(const char address)
|
||||
void GPIOInterface::initialize_input_pin(uint8_t address)
|
||||
{
|
||||
pinMode(address, INPUT);
|
||||
}
|
||||
|
||||
void GPIOInterface::initialize_output_pin(const char address)
|
||||
void GPIOInterface::initialize_output_pin(uint8_t address)
|
||||
{
|
||||
pinMode(address, OUTPUT);
|
||||
}
|
||||
|
||||
void GPIOInterface::write_pin(char address, char data)
|
||||
void GPIOInterface::write_pin(uint8_t address, uint8_t data)
|
||||
{
|
||||
digitalWrite(address, data);
|
||||
}
|
||||
|
||||
bool GPIOInterface::read_pin(char address)
|
||||
bool GPIOInterface::read_pin(uint8_t address)
|
||||
{
|
||||
return PULLDOWN == digitalRead(address);
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ public:
|
||||
virtual ~GPIOInterface() = default;
|
||||
|
||||
protected:
|
||||
static void initialize_input_pin(const char address);
|
||||
static void initialize_input_pin(uint8_t address);
|
||||
|
||||
static void initialize_output_pin(const char address);
|
||||
static void initialize_output_pin(uint8_t address);
|
||||
|
||||
static void write_pin(const char address, const char data);
|
||||
static void write_pin(uint8_t address, uint8_t data);
|
||||
|
||||
static bool read_pin(const char address);
|
||||
static bool read_pin(uint8_t address);
|
||||
|
||||
public:
|
||||
static std::once_flag GPIO_LIB_INITIALIZED;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#ifndef SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace input
|
||||
@@ -18,7 +20,7 @@ class IInputGPIOInterface
|
||||
public:
|
||||
virtual ~IInputGPIOInterface() = default;
|
||||
|
||||
virtual bool read_data(char pin) const = 0;
|
||||
virtual bool read_data(uint8_t pin) const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ using namespace nlohmann;
|
||||
|
||||
|
||||
InputGPIOInterface::InputGPIOInterface(std::map<std::string, uint8_t> pins)
|
||||
: pins(pins)
|
||||
: pins(std::move(pins))
|
||||
{
|
||||
init_pins();
|
||||
}
|
||||
|
||||
bool InputGPIOInterface::read_data(char pin) const
|
||||
bool InputGPIOInterface::read_data(uint8_t pin) const
|
||||
{
|
||||
// setting address to read
|
||||
write_row(pin / INPUT_MATRIX_SIZE);
|
||||
@@ -39,18 +39,18 @@ bool InputGPIOInterface::read_data(char pin) const
|
||||
return read_pin(this->pins.at("data_address"));
|
||||
}
|
||||
|
||||
void InputGPIOInterface::write_row(char data) const
|
||||
void InputGPIOInterface::write_row(u_int8_t data) const
|
||||
{
|
||||
write_pin(this->pins.at("row_address_A"), data & 0b001);
|
||||
write_pin(this->pins.at("row_address_B"), data & 0b010);
|
||||
write_pin(this->pins.at("row_address_C"), data & 0b100);
|
||||
write_pin(this->pins.at("row_address_A"), data & 0b001u);
|
||||
write_pin(this->pins.at("row_address_B"), data & 0b010u);
|
||||
write_pin(this->pins.at("row_address_C"), data & 0b100u);
|
||||
}
|
||||
|
||||
void InputGPIOInterface::write_col(char data) const
|
||||
void InputGPIOInterface::write_col(uint8_t data) const
|
||||
{
|
||||
write_pin(this->pins.at("col_address_A"), data & 0b001);
|
||||
write_pin(this->pins.at("col_address_B"), data & 0b010);
|
||||
write_pin(this->pins.at("col_address_C"), data & 0b100);
|
||||
write_pin(this->pins.at("col_address_A"), data & 0b001u);
|
||||
write_pin(this->pins.at("col_address_B"), data & 0b010u);
|
||||
write_pin(this->pins.at("col_address_C"), data & 0b100u);
|
||||
}
|
||||
|
||||
void InputGPIOInterface::init_pins() const
|
||||
|
||||
@@ -24,12 +24,12 @@ class InputGPIOInterface : public IInputGPIOInterface, GPIOInterface
|
||||
{
|
||||
public:
|
||||
explicit InputGPIOInterface(std::map<std::string, uint8_t> pins);
|
||||
bool read_data(char pin) const override;
|
||||
bool read_data(uint8_t pin) const override;
|
||||
|
||||
private:
|
||||
void init_pins() const;
|
||||
void write_row(char data) const;
|
||||
void write_col(char data) const;
|
||||
void write_row(u_int8_t data) const;
|
||||
void write_col(uint8_t data) const;
|
||||
|
||||
private:
|
||||
const std::map<std::string, uint8_t> pins;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace output
|
||||
using namespace items;
|
||||
|
||||
OutputDriver::OutputDriver(std::map<std::string, std::shared_ptr<ISolenoid>> solenoids, std::map<std::string, std::shared_ptr<ILamp>> lamps, std::map<char, std::shared_ptr<IDisplay>> displays, std::map<std::string, std::shared_ptr<ISound>> sounds)
|
||||
: solenoids(solenoids), lamps(lamps), displays(displays), sounds(sounds)
|
||||
: solenoids(std::move(solenoids)), lamps(std::move(lamps)), displays(std::move(displays)), sounds(std::move(sounds))
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class OutputDriver : public IOutputDriver
|
||||
public:
|
||||
OutputDriver(std::map<std::string, std::shared_ptr<items::ISolenoid>> solenoids, std::map<std::string, std::shared_ptr<items::ILamp>> lamps, std::map<char, std::shared_ptr<items::IDisplay>> displays, std::map<std::string, std::shared_ptr<items::ISound>> sounds);
|
||||
|
||||
virtual ~OutputDriver() = default;
|
||||
~OutputDriver() override = default;
|
||||
// todo what is flipper_relay ?
|
||||
std::vector<std::shared_ptr<items::ILamp>> get_lamps() override;
|
||||
std::vector<std::shared_ptr<items::ISolenoid>> get_solenoids() override;
|
||||
|
||||
@@ -15,7 +15,7 @@ using namespace output::items;
|
||||
using namespace nlohmann;
|
||||
|
||||
OutputGPIOInterface::OutputGPIOInterface(std::map<std::string, uint8_t> pins_driver_board, std::map<std::string, uint8_t> pins_sound, std::map<std::string, uint8_t> pins_display)
|
||||
: pins_driver_board(pins_driver_board), pins_sound(pins_sound), pins_display(pins_display)
|
||||
: pins_driver_board(std::move(pins_driver_board)), pins_sound(std::move(pins_sound)), pins_display(std::move(pins_display))
|
||||
{
|
||||
initialize_i2c_addresses();
|
||||
|
||||
@@ -51,7 +51,7 @@ void OutputGPIOInterface::activate(output::items::ISoundItem *sound)
|
||||
|
||||
write_sound_address(sound->get_address());
|
||||
|
||||
fire_sound(1);
|
||||
fire_sound(true);
|
||||
}
|
||||
|
||||
void OutputGPIOInterface::activate(output::items::IDriverBoardItem *driver_board_item)
|
||||
@@ -60,7 +60,7 @@ void OutputGPIOInterface::activate(output::items::IDriverBoardItem *driver_board
|
||||
|
||||
write_driver_board_address(driver_board_item->get_address());
|
||||
|
||||
write_data(1);
|
||||
write_data(true);
|
||||
}
|
||||
|
||||
void OutputGPIOInterface::deactivate(output::items::IDriverBoardItem *driver_board_item)
|
||||
@@ -69,7 +69,7 @@ void OutputGPIOInterface::deactivate(output::items::IDriverBoardItem *driver_boa
|
||||
|
||||
write_driver_board_address(driver_board_item->get_address());
|
||||
|
||||
write_data(0);
|
||||
write_data(false);
|
||||
}
|
||||
|
||||
void OutputGPIOInterface::deactivate(output::items::ISoundItem *sound)
|
||||
@@ -78,7 +78,7 @@ void OutputGPIOInterface::deactivate(output::items::ISoundItem *sound)
|
||||
|
||||
write_sound_address(sound->get_address());
|
||||
|
||||
fire_sound(0);
|
||||
fire_sound(false);
|
||||
}
|
||||
|
||||
void OutputGPIOInterface::write_driver_board_address(uint8_t address)
|
||||
@@ -107,9 +107,9 @@ void OutputGPIOInterface::select_latch(uint8_t latch)
|
||||
if(latch > 8)
|
||||
latch -= 8;
|
||||
|
||||
write_pin(pins_driver_board.at("latch-select-A"), latch & 0b001);
|
||||
write_pin(pins_driver_board.at("latch-select-B"), latch & 0b010);
|
||||
write_pin(pins_driver_board.at("latch-select-C"), latch & 0b100);
|
||||
write_pin(pins_driver_board.at("latch-select-A"), latch & 0b001u);
|
||||
write_pin(pins_driver_board.at("latch-select-B"), latch & 0b010u);
|
||||
write_pin(pins_driver_board.at("latch-select-C"), latch & 0b100u);
|
||||
|
||||
}
|
||||
|
||||
@@ -120,20 +120,20 @@ void OutputGPIOInterface::write_data(bool data)
|
||||
|
||||
void OutputGPIOInterface::select_pin(uint8_t pin)
|
||||
{
|
||||
write_pin(pins_driver_board.at("pin-select-A"), pin & 0b001);
|
||||
write_pin(pins_driver_board.at("pin-select-B"), pin & 0b010);
|
||||
write_pin(pins_driver_board.at("pin-select-C"), pin & 0b100);
|
||||
write_pin(pins_driver_board.at("pin-select-A"), pin & 0b001u);
|
||||
write_pin(pins_driver_board.at("pin-select-B"), pin & 0b010u);
|
||||
write_pin(pins_driver_board.at("pin-select-C"), pin & 0b100u);
|
||||
}
|
||||
|
||||
void OutputGPIOInterface::write_sound_address(uint8_t address)
|
||||
{
|
||||
write_pin(pins_sound.at("A"), address & 0b0000001);
|
||||
write_pin(pins_sound.at("B"), address & 0b0000010);
|
||||
write_pin(pins_sound.at("C"), address & 0b0000100);
|
||||
write_pin(pins_sound.at("D"), address & 0b0001000);
|
||||
write_pin(pins_sound.at("E"), address & 0b0010000);
|
||||
write_pin(pins_sound.at("F"), address & 0b0100000);
|
||||
write_pin(pins_sound.at("G"), address & 0b1000000);
|
||||
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 OutputGPIOInterface::fire_sound(bool fire)
|
||||
|
||||
@@ -29,7 +29,7 @@ class OutputGPIOInterface : public GPIOInterface, IOutputGPIOInterface
|
||||
public:
|
||||
OutputGPIOInterface(std::map<std::string, uint8_t> pins_driver_board, std::map<std::string, uint8_t> pins_sound, std::map<std::string, uint8_t> pins_display);
|
||||
|
||||
virtual ~OutputGPIOInterface() = default;
|
||||
~OutputGPIOInterface() override = default;
|
||||
|
||||
void activate(items::IDriverBoardItem *driver_board_item) override;
|
||||
void activate(items::ISoundItem *sound) override;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace items
|
||||
class IDriverBoardItem : public IItem
|
||||
{
|
||||
public:
|
||||
virtual ~IDriverBoardItem() = default;
|
||||
~IDriverBoardItem() override = default;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace items
|
||||
|
||||
Item::Item(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name) :
|
||||
address(address),
|
||||
name(name),
|
||||
gpio_interface(output_gpio_interface)
|
||||
name(std::move(name)),
|
||||
gpio_interface(std::move(output_gpio_interface))
|
||||
{}
|
||||
|
||||
uint8_t Item::get_address()
|
||||
|
||||
@@ -26,7 +26,7 @@ class Item : public IItem
|
||||
{
|
||||
public:
|
||||
Item(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name);
|
||||
virtual ~Item() = default;
|
||||
~Item() override = default;
|
||||
|
||||
uint8_t get_address() override;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace items
|
||||
|
||||
Lamp::Lamp(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name)
|
||||
:
|
||||
Item(output_gpio_interface, address, name),
|
||||
Item(std::move(output_gpio_interface), address, std::move(name)),
|
||||
activated(false)
|
||||
{}
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ class Lamp : public Item, ILamp, IDriverBoardItem
|
||||
{
|
||||
public:
|
||||
Lamp(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name);
|
||||
virtual ~Lamp() = default;
|
||||
~Lamp() override = default;
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
bool is_activated();
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
bool is_activated() override;
|
||||
|
||||
private:
|
||||
bool activated;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace items
|
||||
{
|
||||
|
||||
Solenoid::Solenoid(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time):
|
||||
Item(output_gpio_interface, address, name),
|
||||
Item(std::move(output_gpio_interface), address, std::move(name)),
|
||||
deactivation_time(deactivation_time)
|
||||
{}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ class Solenoid : public Item, ISolenoid, IDriverBoardItem
|
||||
{
|
||||
public:
|
||||
Solenoid(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, u_int8_t address, std::string name, std::chrono::milliseconds deactivation_time);
|
||||
virtual ~Solenoid() = default;
|
||||
~Solenoid() override = default;
|
||||
|
||||
void trigger();
|
||||
void trigger() override;
|
||||
|
||||
private:
|
||||
std::chrono::milliseconds deactivation_time;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace items
|
||||
{
|
||||
|
||||
Sound::Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time, u_int id) :
|
||||
Item(output_gpio_interface, address, name),
|
||||
Item(std::move(output_gpio_interface), address, std::move(name)),
|
||||
deactivation_time(deactivation_time),
|
||||
id(id)
|
||||
{}
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
|
||||
public:
|
||||
Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time, u_int id);
|
||||
virtual ~Sound() = default;
|
||||
~Sound() override = default;
|
||||
|
||||
void play() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user