weis nimmer
This commit is contained in:
43
FlippR-Driver/src/utilities/BlockingQueue.hpp
Normal file
43
FlippR-Driver/src/utilities/BlockingQueue.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* BlockingQueue.hpp
|
||||
*
|
||||
* Created on: May 17, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#ifndef SRC_UTILITIES_BLOCKINGQUEUE_HPP_
|
||||
#define SRC_UTILITIES_BLOCKINGQUEUE_HPP_
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
|
||||
template <typename T>
|
||||
class BlockingQueue
|
||||
{
|
||||
private:
|
||||
std::mutex d_mutex;
|
||||
std::condition_variable d_condition;
|
||||
std::priority_queue<T> d_queue;
|
||||
public:
|
||||
void push(T const& value) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
d_queue.push_front(value);
|
||||
}
|
||||
this->d_condition.notify_one();
|
||||
}
|
||||
|
||||
T pop() {
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
this->d_condition.wait(lock, [=]{ return !this->d_queue.empty(); });
|
||||
T rc(std::move(this->d_queue.back()));
|
||||
this->d_queue.pop_back();
|
||||
return rc;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SRC_UTILITIES_BLOCKINGQUEUE_HPP_ */
|
||||
48
FlippR-Driver/src/utilities/GPIOInterface.cpp
Normal file
48
FlippR-Driver/src/utilities/GPIOInterface.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
/*
|
||||
* GPIOInterface.cpp
|
||||
*
|
||||
* Created on: May 17, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#include "GPIOInterface.h"
|
||||
|
||||
#include "../lib/wiringPi/wiringPi.h"
|
||||
|
||||
GPIOInterface::GPIOInterface(std::string config_path)
|
||||
{
|
||||
}
|
||||
|
||||
GPIOInterface::~GPIOInterface()
|
||||
{
|
||||
}
|
||||
|
||||
bool GPIOInterface::read_input_data()
|
||||
{
|
||||
return read_input_pin(input_data_address);
|
||||
}
|
||||
|
||||
void GPIOInterface::write_input_row(char data)
|
||||
{
|
||||
write_pin(input_row_address, data & 0b001);
|
||||
write_pin(input_row_address, data & 0b010);
|
||||
write_pin(input_row_address, data & 0b100);
|
||||
}
|
||||
|
||||
void GPIOInterface::write_input_col(char data)
|
||||
{
|
||||
write_pin(input_col_address, data & 0b001);
|
||||
write_pin(input_col_address, data & 0b010);
|
||||
write_pin(input_col_address, data & 0b100);
|
||||
}
|
||||
|
||||
void GPIOInterface::write_pin(char address, bool data)
|
||||
{
|
||||
digitalWrite(address, data);
|
||||
}
|
||||
|
||||
bool GPIOInterface::read_input_pin(char address)
|
||||
{
|
||||
return digitalRead(address);
|
||||
}
|
||||
@@ -10,12 +10,11 @@
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
#ifndef SRC_UTILITIES_GPIOINTERFACE_HPP_
|
||||
#define SRC_UTILITIES_GPIOINTERFACE_HPP_
|
||||
#ifndef SRC_UTILITIES_GPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_GPIOINTERFACE_H_
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <../lib/wiringPi/wiringPi.h>
|
||||
#include "../lib/json/json.hpp"
|
||||
|
||||
using namespace nlohmann;
|
||||
@@ -26,18 +25,24 @@ public:
|
||||
GPIOInterface(std::string config_path);
|
||||
~GPIOInterface();
|
||||
|
||||
void write_address();
|
||||
void read_pin();
|
||||
void write_input_row(char data);
|
||||
void write_input_col(char data);
|
||||
bool read_input_data();
|
||||
|
||||
private:
|
||||
static void write_pin(char address, bool data);
|
||||
static bool read_input_pin(char address);
|
||||
|
||||
public:
|
||||
// todo some mapping class interface shit that a user can ask for what is actually usable \
|
||||
something like: A has gpio interface at gpio -> gpio.input.column. just dont work with strings
|
||||
private:
|
||||
json config;
|
||||
|
||||
char input_row_address;
|
||||
char input_col_address;
|
||||
char input_data_address;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* SRC_UTILITIES_GPIOINTERFACE_HPP_ */
|
||||
#endif /* SRC_UTILITIES_GPIOINTERFACE_H_ */
|
||||
Reference in New Issue
Block a user