Files
flippr-code/FlippR-Driver/src/output/impl/SoundBoardPinController.cpp
2018-12-14 01:58:05 +01:00

63 lines
1.4 KiB
C++

//
// Created by rhetenor on 14.12.18.
//
#include "SoundBoardPinController.h"
namespace flippR_driver
{
namespace output
{
namespace impl
{
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))
{
}
void SoundBoardPinController::activate(items::Sound &sound)
{
std::lock_guard<std::mutex> guard(*output_item_mutex);
write_sound_address(sound.get_address());
fire_sound(true);
}
void SoundBoardPinController::deactivate(items::Sound &sound)
{
std::lock_guard<std::mutex> guard(*output_item_mutex);
write_sound_address(sound.get_address());
fire_sound(false);
}
void SoundBoardPinController::write_sound_address(uint8_t address)
{
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(bool fire)
{
PinController::write_pin(pins_sound.at("fire"), fire);
}
void SoundBoardPinController::write_pin(uint8_t pin, bool value)
{
PinController::write_pin(pins_sound.at("pin_base") + pin, value);
}
}
}
}