//
// Created by rhetenor on 14.12.18.
//

#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_SOUNDBOARDPINCONTROLLER_H
#define FLIPPR_DRIVER_OUTPUT_IMPL_SOUNDBOARDPINCONTROLLER_H

#include "output/SoundBoardPinController.h"

#include <map>

namespace flippR_driver
{
namespace output
{
namespace detail
{

class SoundBoardPinController : public output::SoundBoardPinController
{
public:
  SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, uint8_t fire_address, const std::vector<uint8_t> address_pins);
  ~SoundBoardPinController() override = default;

  void activate(const items::detail::Sound &sound);
  void deactivate(const items::detail::Sound &sound);

private:
  void write_sound_address(const uint8_t & address) const;
  void fire_sound() const;

  void write_pin(const uint8_t & pin, const bool & value) const;

private:
  std::shared_ptr<std::mutex> output_item_mutex;

  uint8_t pin_base;
  uint8_t fire_address;
  std::vector<uint8_t> address_pins;
};

}
}
}
#endif //FLIPPR_DRIVER_SOUNDBOARDPINCONTROLLER_H
