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

#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_DRIVERBOARDPINCONTROLLER_H
#define FLIPPR_DRIVER_OUTPUT_IMPL_DRIVERBOARDPINCONTROLLER_H

#include "output/DriverBoardPinController.h"

#include <map>
#include <memory>
#include <mutex>

namespace flippR_driver
{
namespace output
{
namespace detail
{

class DriverBoardPinController : public output::DriverBoardPinController
{
public:
  virtual ~DriverBoardPinController() = default;

  DriverBoardPinController(std::shared_ptr<std::mutex> output_item_mutex);

  void activate(items::DriverBoardItem & driver_board_item);
  void deactivate(items::DriverBoardItem & driver_board_item);
  void clear();

  void set_address_pins(std::array<uint8_t, 3> address_pins);
  void set_mux_pins(std::array<uint8_t, 13> mux_enable_pins);
  void set_data_pin(uint8_t data_pin);
  void set_run_pin(uint8_t run_pin);

private:
  void deselect_all_muxes();
  void select_mux(uint8_t mux);
  void select_address(uint8_t address);

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

  std::array<uint8_t, 3> address_pins;
  std::array<uint8_t, 13> mux_enable_pins;
  uint8_t data_pin;
  uint8_t run_pin;
};

}
}
}

#endif //FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
