meeeerged
This commit is contained in:
@@ -18,6 +18,7 @@ namespace Input
|
||||
|
||||
class Event
|
||||
{
|
||||
|
||||
public:
|
||||
Event(char address, char priority, std::string name) :
|
||||
address(address), priority(priority), name(name)
|
||||
@@ -30,15 +31,16 @@ public:
|
||||
return this->name == other.name;
|
||||
}
|
||||
|
||||
bool operator<(const Event& other)
|
||||
friend bool operator<(const Event& left, const Event& right)
|
||||
{
|
||||
return this->priority < other.priority;
|
||||
return left.priority < right.priority;
|
||||
}
|
||||
|
||||
private:
|
||||
const char address;
|
||||
const char priority;
|
||||
const std::string name;
|
||||
char address;
|
||||
char priority;
|
||||
std::string name;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,13 +12,20 @@
|
||||
#ifndef INPUTEVENTHANDLER_H_
|
||||
#define INPUTEVENTHANDLER_H_
|
||||
|
||||
#include "InputDriver.hpp"
|
||||
#include "Event.hpp"
|
||||
#include "Detector.h"
|
||||
#include "../utilities/config.h"
|
||||
|
||||
#include "Event.hpp"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
class EventHandler;
|
||||
|
||||
class InputDriver
|
||||
{
|
||||
public:
|
||||
void register_event_handler(EventHandler* handler);
|
||||
void unregister_event_handler(EventHandler* handler);
|
||||
};
|
||||
|
||||
class EventHandler
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ void EventNotifier::notify()
|
||||
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
|
||||
for(auto handler : event_handler)
|
||||
{
|
||||
boost::thread handler_caller(handler, &EventHandler::handle, event);
|
||||
boost::thread handler_caller(boost::bind(&EventHandler::handle, handler, event));
|
||||
|
||||
if(!handler_caller.timed_join(boost::posix_time::milliseconds(HANDLER_TIMEOUT)))
|
||||
{
|
||||
|
||||
@@ -4,25 +4,18 @@
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#include "../utilities/config.h"
|
||||
#include "Detector.h"
|
||||
|
||||
|
||||
#ifndef SRC_INPUT_INPUTDRIVER_HPP_
|
||||
#define SRC_INPUT_INPUTDRIVER_HPP_
|
||||
|
||||
#include "../utilities/config.h"
|
||||
|
||||
#include "EventHandler.h"
|
||||
#include "EventNotifier.h"
|
||||
#include "Detector.h"
|
||||
|
||||
namespace Input
|
||||
{
|
||||
|
||||
class EventHandler
|
||||
{
|
||||
public:
|
||||
void handle(Event& event);
|
||||
};
|
||||
|
||||
class InputDriver
|
||||
{
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
void push(T const& value)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
p_queue.push_front(value);
|
||||
p_queue.push(value);
|
||||
this->d_condition.notify_one();
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
|
||||
T rc(std::move(this->p_queue.back()));
|
||||
this->p_queue.pop_back();
|
||||
T rc = *this->p_queue.end();
|
||||
this->p_queue.pop();
|
||||
return rc;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#define SRC_UTILITIES_GPIOINTERFACE_HPP_
|
||||
|
||||
#include <fstream>
|
||||
#include "config.h"
|
||||
|
||||
#include "../lib/wiringPi/wiringPi.h"
|
||||
#include "../lib/json/json.hpp"
|
||||
@@ -21,7 +22,7 @@
|
||||
class GPIOInterface
|
||||
{
|
||||
public:
|
||||
GPIOInterface(nlohmann::json config);
|
||||
GPIOInterface();
|
||||
virtual ~GPIOInterface();
|
||||
|
||||
static void write_pin(char address, char data)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
class InputGPIOInterface : GPIOInterface
|
||||
{
|
||||
public:
|
||||
InputGPIOInterface();
|
||||
InputGPIOInterface(std::string matrix_config_path);
|
||||
bool read_input_data(char pin);
|
||||
|
||||
private:
|
||||
|
||||
@@ -13,3 +13,4 @@
|
||||
#define HIGH_VERBOSITY 10
|
||||
|
||||
#define INPUT_MATRIX_SIZE 8
|
||||
#define INPUT_SLEEP_DURATION_NANO 800
|
||||
|
||||
Reference in New Issue
Block a user