73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
/*
|
|
* InputGPIOInterface.cpp
|
|
*
|
|
* Created on: May 31, 2018
|
|
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
|
*/
|
|
|
|
#include "InputGPIOInterface.h"
|
|
|
|
#include <thread>
|
|
|
|
#include "json/json.hpp"
|
|
#include "easylogging/easylogging++.h"
|
|
#include "utility/config.h"
|
|
|
|
namespace flippR_driver
|
|
{
|
|
namespace input
|
|
{
|
|
|
|
using namespace nlohmann;
|
|
|
|
|
|
InputGPIOInterface::InputGPIOInterface(std::map<std::string, uint8_t> pins)
|
|
: pins(pins)
|
|
{
|
|
init_pins();
|
|
}
|
|
|
|
bool InputGPIOInterface::read_data(char pin) const
|
|
{
|
|
// setting address to read
|
|
write_row(pin / INPUT_MATRIX_SIZE);
|
|
write_col(pin % INPUT_MATRIX_SIZE);
|
|
|
|
// wait for mux to set address
|
|
std::this_thread::sleep_for(std::chrono::nanoseconds(INPUT_SLEEP_DURATION_NANO));
|
|
|
|
return read_pin(this->pins.at("data_address"));
|
|
}
|
|
|
|
void InputGPIOInterface::write_row(char data) const
|
|
{
|
|
write_pin(this->pins.at("row_address_A"), data & 0b001);
|
|
write_pin(this->pins.at("row_address_B"), data & 0b010);
|
|
write_pin(this->pins.at("row_address_C"), data & 0b100);
|
|
}
|
|
|
|
void InputGPIOInterface::write_col(char data) const
|
|
{
|
|
write_pin(this->pins.at("col_address_A"), data & 0b001);
|
|
write_pin(this->pins.at("col_address_B"), data & 0b010);
|
|
write_pin(this->pins.at("col_address_C"), data & 0b100);
|
|
}
|
|
|
|
|
|
|
|
void InputGPIOInterface::init_pins() const
|
|
{
|
|
initialize_output_pin(this->pins.at("col_address_A"));
|
|
initialize_output_pin(this->pins.at("col_address_B"));
|
|
initialize_output_pin(this->pins.at("col_address_C"));
|
|
|
|
initialize_output_pin(this->pins.at("row_address_A"));
|
|
initialize_output_pin(this->pins.at("row_address_B"));
|
|
initialize_output_pin(this->pins.at("row_address_C"));
|
|
|
|
initialize_input_pin(this->pins.at("data_address"));
|
|
}
|
|
|
|
}
|
|
}
|