some refactor
This commit is contained in:
@@ -109,37 +109,6 @@ void OutputGPIOInterface::activate(output::items::ISound *sound)
|
|||||||
GPIOInterface::write_pin(pins_sound["fire"], 1);
|
GPIOInterface::write_pin(pins_sound["fire"], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OutputGPIOInterface::write_sound_address(u_int8_t address)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void OutputGPIOInterface::write_driver_board_address(u_int8_t address)
|
|
||||||
{
|
|
||||||
// todo schöner machen!
|
|
||||||
int latch = address / 8;
|
|
||||||
int pin = address % 8;
|
|
||||||
|
|
||||||
bool mux1 = latch / 8;
|
|
||||||
|
|
||||||
latch = mux1 ? latch : latch - 8; // substracting 8 if it is on 2nd latch
|
|
||||||
|
|
||||||
// selecting mux
|
|
||||||
write_pin(pins_driver_board["mux1"], mux1);
|
|
||||||
write_pin(pins_driver_board["mux2"], !mux1);
|
|
||||||
|
|
||||||
// selecting latch
|
|
||||||
write_pin(pins_driver_board["latch-select-A"], latch & 0b001)
|
|
||||||
write_pin(pins_driver_board["latch-select-B"], latch & 0b010)
|
|
||||||
write_pin(pins_driver_board["latch-select-C"], latch & 0b100)
|
|
||||||
|
|
||||||
// selecting address
|
|
||||||
write_pin(pins_driver_board["pin-select-A"], pin & 0b001)
|
|
||||||
write_pin(pins_driver_board["pin-select-B"], pin & 0b010)
|
|
||||||
write_pin(pins_driver_board["pin-select-C"], pin & 0b100)
|
|
||||||
}
|
|
||||||
|
|
||||||
void OutputGPIOInterface::activate(output::items::IDriverBoardItem *driver_board_item)
|
void OutputGPIOInterface::activate(output::items::IDriverBoardItem *driver_board_item)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(output_item_mutex);
|
std::lock_guard<std::mutex> guard(output_item_mutex);
|
||||||
@@ -149,11 +118,6 @@ void OutputGPIOInterface::activate(output::items::IDriverBoardItem *driver_board
|
|||||||
write_data(1);
|
write_data(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputGPIOInterface::write_data(bool data)
|
|
||||||
{
|
|
||||||
write_pin(pins_driver_board["data"], data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OutputGPIOInterface::deactivate(output::items::IDriverBoardItem *driver_board_item)
|
void OutputGPIOInterface::deactivate(output::items::IDriverBoardItem *driver_board_item)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(output_item_mutex);
|
std::lock_guard<std::mutex> guard(output_item_mutex);
|
||||||
@@ -163,5 +127,54 @@ void OutputGPIOInterface::deactivate(output::items::IDriverBoardItem *driver_boa
|
|||||||
write_data(0);
|
write_data(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OutputGPIOInterface::write_sound_address(u_int8_t address)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputGPIOInterface::write_driver_board_address(u_int8_t address)
|
||||||
|
{
|
||||||
|
int latch = address / 8;
|
||||||
|
int pin = address % 8;
|
||||||
|
|
||||||
|
select_mux(latch);
|
||||||
|
|
||||||
|
select_latch(latch);
|
||||||
|
|
||||||
|
select_pin(pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputGPIOInterface::select_mux(u_int8_t latch)
|
||||||
|
{
|
||||||
|
bool mux1 = latch / 8;
|
||||||
|
|
||||||
|
write_pin(pins_driver_board["mux1"], mux1);
|
||||||
|
write_pin(pins_driver_board["mux2"], !mux1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputGPIOInterface::select_latch(u_int8_t latch)
|
||||||
|
{
|
||||||
|
// todo not nice
|
||||||
|
if(latch > 8)
|
||||||
|
latch -= 8;
|
||||||
|
|
||||||
|
write_pin(pins_driver_board["latch-select-A"], latch & 0b001)
|
||||||
|
write_pin(pins_driver_board["latch-select-B"], latch & 0b010)
|
||||||
|
write_pin(pins_driver_board["latch-select-C"], latch & 0b100)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputGPIOInterface::write_data(bool data)
|
||||||
|
{
|
||||||
|
write_pin(pins_driver_board["data"], data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputGPIOInterface::select_pin(u_int8_t pin)
|
||||||
|
{
|
||||||
|
write_pin(pins_driver_board["pin-select-A"], pin & 0b001)
|
||||||
|
write_pin(pins_driver_board["pin-select-B"], pin & 0b010)
|
||||||
|
write_pin(pins_driver_board["pin-select-C"], pin & 0b100)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ private:
|
|||||||
void write_sound_address(u_int8_t address);
|
void write_sound_address(u_int8_t address);
|
||||||
void write_driver_board_address(u_int8_t address);
|
void write_driver_board_address(u_int8_t address);
|
||||||
|
|
||||||
|
void select_mux(u_int8_t latch);
|
||||||
|
void select_latch(u_int8_t latch);
|
||||||
|
void select_pin(u_int8_t pin);
|
||||||
void write_data(bool data);
|
void write_data(bool data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user