meeeerged
This commit is contained in:
@@ -6,22 +6,23 @@
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
|
||||
#include "InputGPIOInterface.h"
|
||||
#include "../lib/json/json.hpp"
|
||||
#include "../lib/easylogging/easylogging++.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <string>
|
||||
using namespace nlohmann;
|
||||
|
||||
bool InputGPIOInterface::read_input_data(char pin)
|
||||
{
|
||||
// setting address to read
|
||||
write_input_row(pin / MATRIX_SIZE);
|
||||
write_input_col(pin % MATRIX_SIZE);
|
||||
write_input_row(pin / INPUT_MATRIX_SIZE);
|
||||
write_input_col(pin % INPUT_MATRIX_SIZE);
|
||||
|
||||
// wait for mux to set address
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(SLEEP_DURATION_NANO));
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(INPUT_SLEEP_DURATION_NANO));
|
||||
|
||||
return read_pin(this->input_data_address);
|
||||
}
|
||||
@@ -41,20 +42,26 @@ void InputGPIOInterface::write_input_col(char data)
|
||||
}
|
||||
|
||||
|
||||
InputGPIOInterface::InputGPIOInterface()
|
||||
InputGPIOInterface::InputGPIOInterface(std::string matrix_config_path)
|
||||
{
|
||||
std::ifstream matrix_config_stream(matrix_config_path);
|
||||
json matrix_config;
|
||||
matrix_config << matrix_config_stream;
|
||||
matrix_config_stream >> matrix_config;
|
||||
|
||||
try {
|
||||
json matrix_config_input = matrix_config.at("input");
|
||||
input_row_address_A = matrix_config.at("row").at("A");
|
||||
input_row_address_B = matrix_config.at("row").at("B");
|
||||
input_row_address_C = matrix_config.at("row").at("C");
|
||||
input_col_address_A = matrix_config.at("col").at("A");
|
||||
input_col_address_B = matrix_config.at("col").at("B");
|
||||
input_col_address_C = matrix_config.at("col").at("C");
|
||||
input_data_address = matrix_config.at("data");
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user