finishing inputgpiointerface
This commit is contained in:
@@ -15,56 +15,75 @@
|
||||
#include <string>
|
||||
using namespace nlohmann;
|
||||
|
||||
bool InputGPIOInterface::read_input_data(char pin)
|
||||
bool InputGPIOInterface::read_data(char pin)
|
||||
{
|
||||
// setting address to read
|
||||
write_input_row(pin / INPUT_MATRIX_SIZE);
|
||||
write_input_col(pin % INPUT_MATRIX_SIZE);
|
||||
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->input_data_address);
|
||||
return read_pin(this->data_address);
|
||||
}
|
||||
|
||||
void InputGPIOInterface::write_input_row(char data)
|
||||
void InputGPIOInterface::write_row(char data)
|
||||
{
|
||||
write_pin(this->input_row_address_A, data & 0b001);
|
||||
write_pin(this->input_row_address_B, data & 0b010);
|
||||
write_pin(this->input_row_address_C, data & 0b100);
|
||||
write_pin(this->row_address_A, data & 0b001);
|
||||
write_pin(this->row_address_B, data & 0b010);
|
||||
write_pin(this->row_address_C, data & 0b100);
|
||||
}
|
||||
|
||||
void InputGPIOInterface::write_input_col(char data)
|
||||
void InputGPIOInterface::write_col(char data)
|
||||
{
|
||||
write_pin(this->input_col_address_A, data & 0b001);
|
||||
write_pin(this->input_col_address_B, data & 0b010);
|
||||
write_pin(this->input_col_address_C, data & 0b100);
|
||||
write_pin(this->col_address_A, data & 0b001);
|
||||
write_pin(this->col_address_B, data & 0b010);
|
||||
write_pin(this->col_address_C, data & 0b100);
|
||||
}
|
||||
|
||||
|
||||
InputGPIOInterface::InputGPIOInterface(std::istream& matrix_config_stream)
|
||||
{
|
||||
json matrix_config;
|
||||
matrix_config_stream >> matrix_config;
|
||||
|
||||
try {
|
||||
json matrix_config_input = matrix_config.at("input");
|
||||
|
||||
json row_json = matrix_config.at("row");
|
||||
input_row_address_A = row_json.at("A").get<json::number_integer_t>();
|
||||
input_row_address_B = row_json.at("B").get<json::number_integer_t>();
|
||||
input_row_address_C = row_json.at("C").get<json::number_integer_t>();
|
||||
|
||||
json col_json = matrix_config.at("col");
|
||||
input_col_address_A = col_json.at("A").get<json::number_integer_t>();
|
||||
input_col_address_B = col_json.at("B").get<json::number_integer_t>();
|
||||
input_col_address_C = col_json.at("C").get<json::number_integer_t>();
|
||||
|
||||
input_data_address = matrix_config.at("data").get<nlohmann::json::number_integer_t>();
|
||||
} catch (json::type_error& e) {
|
||||
CLOG(ERROR, INPUT_LOGGER) << "ERROR";
|
||||
} catch (json::out_of_range& e) {
|
||||
CLOG(ERROR, INPUT_LOGGER) << "ANOTHER ERROR!";
|
||||
}
|
||||
init_members(matrix_config_stream);
|
||||
|
||||
init_pins();
|
||||
}
|
||||
|
||||
void InputGPIOInterface::init_members(std::istream &matrix_config_stream)
|
||||
{
|
||||
json matrix_config;
|
||||
matrix_config_stream >> matrix_config;
|
||||
|
||||
try {
|
||||
json matrix_config_input = matrix_config.at("input");
|
||||
|
||||
json row_json = matrix_config.at("row");
|
||||
row_address_A = row_json.at("A").get<json::number_integer_t>();
|
||||
row_address_B = row_json.at("B").get<json::number_integer_t>();
|
||||
row_address_C = row_json.at("C").get<json::number_integer_t>();
|
||||
|
||||
json col_json = matrix_config.at("col");
|
||||
col_address_A = col_json.at("A").get<json::number_integer_t>();
|
||||
col_address_B = col_json.at("B").get<json::number_integer_t>();
|
||||
col_address_C = col_json.at("C").get<json::number_integer_t>();
|
||||
|
||||
data_address = matrix_config.at("data").get<nlohmann::json::number_integer_t>();
|
||||
} catch (json::type_error& e) {
|
||||
CLOG(ERROR, INPUT_LOGGER) << "ERROR";
|
||||
} catch (json::out_of_range& e) {
|
||||
CLOG(ERROR, INPUT_LOGGER) << "ANOTHER ERROR!";
|
||||
}
|
||||
}
|
||||
|
||||
void InputGPIOInterface::init_pins()
|
||||
{
|
||||
initialize_output_pin(col_address_A);
|
||||
initialize_output_pin(col_address_B);
|
||||
initialize_output_pin(col_address_C);
|
||||
|
||||
initialize_output_pin(row_address_A);
|
||||
initialize_output_pin(row_address_B);
|
||||
initialize_output_pin(row_address_C);
|
||||
|
||||
initialize_input_pin(data_address);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user