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

#include "output/detail/DriverBoardPinController.h"

#include "output/items/DriverBoardItem.h"

#include "utility/config.h"

namespace flippR_driver
{
namespace output
{
namespace detail
{

DriverBoardPinController::DriverBoardPinController(std::shared_ptr<std::mutex> output_item_mutex) :
  output_item_mutex(std::move(output_item_mutex))
{
  CLOG(INFO, OUTPUT_LOGGER) << "Created DriverBoardPinController.";
}

void DriverBoardPinController::activate(items::DriverBoardItem &driver_board_item)
{
  std::lock_guard<std::mutex> guard(*output_item_mutex);

  write_pin(driver_board_item.get_address(), true);
}

void DriverBoardPinController::deactivate(items::DriverBoardItem &driver_board_item)
{
  std::lock_guard<std::mutex> guard(*output_item_mutex);

  write_pin(driver_board_item.get_address(), false);
}

void DriverBoardPinController::write_pin(uint8_t pin, bool value) const
{
  PinController::write_pin(pin, value);
}

}
}
}