meeeerged

This commit is contained in:
Jonas Zeunert
2018-06-07 23:29:15 +02:00
parent 1f0fd916cc
commit f87e7c4c6f
9 changed files with 50 additions and 39 deletions

View File

@@ -18,6 +18,7 @@ namespace Input
class Event class Event
{ {
public: public:
Event(char address, char priority, std::string name) : Event(char address, char priority, std::string name) :
address(address), priority(priority), name(name) address(address), priority(priority), name(name)
@@ -30,15 +31,16 @@ public:
return this->name == other.name; 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: private:
const char address; char address;
const char priority; char priority;
const std::string name; std::string name;
}; };
} }

View File

@@ -12,13 +12,20 @@
#ifndef INPUTEVENTHANDLER_H_ #ifndef INPUTEVENTHANDLER_H_
#define INPUTEVENTHANDLER_H_ #define INPUTEVENTHANDLER_H_
#include "InputDriver.hpp"
#include "Event.hpp"
#include "Detector.h"
#include "../utilities/config.h" #include "../utilities/config.h"
#include "Event.hpp"
namespace Input namespace Input
{ {
class EventHandler;
class InputDriver
{
public:
void register_event_handler(EventHandler* handler);
void unregister_event_handler(EventHandler* handler);
};
class EventHandler class EventHandler
{ {

View File

@@ -56,7 +56,7 @@ void EventNotifier::notify()
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex); std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
for(auto handler : event_handler) 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))) if(!handler_caller.timed_join(boost::posix_time::milliseconds(HANDLER_TIMEOUT)))
{ {

View File

@@ -4,25 +4,18 @@
* Created on: May 31, 2018 * Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
*/ */
#include "../utilities/config.h"
#include "Detector.h"
#ifndef SRC_INPUT_INPUTDRIVER_HPP_ #ifndef SRC_INPUT_INPUTDRIVER_HPP_
#define SRC_INPUT_INPUTDRIVER_HPP_ #define SRC_INPUT_INPUTDRIVER_HPP_
#include "../utilities/config.h"
#include "EventHandler.h"
#include "EventNotifier.h" #include "EventNotifier.h"
#include "Detector.h"
namespace Input namespace Input
{ {
class EventHandler
{
public:
void handle(Event& event);
};
class InputDriver class InputDriver
{ {

View File

@@ -26,7 +26,7 @@ public:
void push(T const& value) void push(T const& value)
{ {
std::unique_lock<std::mutex> lock(this->d_mutex); std::unique_lock<std::mutex> lock(this->d_mutex);
p_queue.push_front(value); p_queue.push(value);
this->d_condition.notify_one(); this->d_condition.notify_one();
} }
@@ -34,8 +34,8 @@ public:
{ {
std::unique_lock<std::mutex> lock(this->d_mutex); std::unique_lock<std::mutex> lock(this->d_mutex);
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); }); this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
T rc(std::move(this->p_queue.back())); T rc = *this->p_queue.end();
this->p_queue.pop_back(); this->p_queue.pop();
return rc; return rc;
} }
}; };

View File

@@ -14,6 +14,7 @@
#define SRC_UTILITIES_GPIOINTERFACE_HPP_ #define SRC_UTILITIES_GPIOINTERFACE_HPP_
#include <fstream> #include <fstream>
#include "config.h"
#include "../lib/wiringPi/wiringPi.h" #include "../lib/wiringPi/wiringPi.h"
#include "../lib/json/json.hpp" #include "../lib/json/json.hpp"
@@ -21,7 +22,7 @@
class GPIOInterface class GPIOInterface
{ {
public: public:
GPIOInterface(nlohmann::json config); GPIOInterface();
virtual ~GPIOInterface(); virtual ~GPIOInterface();
static void write_pin(char address, char data) static void write_pin(char address, char data)

View File

@@ -6,22 +6,23 @@
*/ */
#include <fstream> #include <fstream>
#include <thread>
#include "InputGPIOInterface.h" #include "InputGPIOInterface.h"
#include "../lib/json/json.hpp" #include "../lib/json/json.hpp"
#include "../lib/easylogging/easylogging++.h" #include "../lib/easylogging/easylogging++.h"
#include "config.h" #include "config.h"
#include <string>
using namespace nlohmann; using namespace nlohmann;
bool InputGPIOInterface::read_input_data(char pin) bool InputGPIOInterface::read_input_data(char pin)
{ {
// setting address to read // setting address to read
write_input_row(pin / MATRIX_SIZE); write_input_row(pin / INPUT_MATRIX_SIZE);
write_input_col(pin % MATRIX_SIZE); write_input_col(pin % INPUT_MATRIX_SIZE);
// wait for mux to set address // 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); 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); std::ifstream matrix_config_stream(matrix_config_path);
json matrix_config; json matrix_config;
matrix_config << matrix_config_stream; matrix_config_stream >> matrix_config;
try { try {
json matrix_config_input = matrix_config.at("input"); 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"); json row_json = matrix_config.at("row");
input_row_address_C = matrix_config.at("row").at("C"); input_row_address_A = row_json.at("A").get<json::number_integer_t>();
input_col_address_A = matrix_config.at("col").at("A"); input_row_address_B = row_json.at("B").get<json::number_integer_t>();
input_col_address_B = matrix_config.at("col").at("B"); input_row_address_C = row_json.at("C").get<json::number_integer_t>();
input_col_address_C = matrix_config.at("col").at("C");
input_data_address = matrix_config.at("data"); 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) { } catch (json::type_error& e) {
CLOG(ERROR, INPUT_LOGGER) << "ERROR"; CLOG(ERROR, INPUT_LOGGER) << "ERROR";
} catch (json::out_of_range& e) { } catch (json::out_of_range& e) {

View File

@@ -15,7 +15,7 @@
class InputGPIOInterface : GPIOInterface class InputGPIOInterface : GPIOInterface
{ {
public: public:
InputGPIOInterface(); InputGPIOInterface(std::string matrix_config_path);
bool read_input_data(char pin); bool read_input_data(char pin);
private: private:

View File

@@ -13,3 +13,4 @@
#define HIGH_VERBOSITY 10 #define HIGH_VERBOSITY 10
#define INPUT_MATRIX_SIZE 8 #define INPUT_MATRIX_SIZE 8
#define INPUT_SLEEP_DURATION_NANO 800