finished input

This commit is contained in:
Jonas Zeunert
2018-04-27 01:46:43 +02:00
parent 65bf3e5958
commit 20b5be8bfa
4 changed files with 17373 additions and 21 deletions

View File

@@ -16,8 +16,8 @@
namespace Input
{
Detector::Detector(std::set<InputEvent*> events) :
input_events(events), is_running(true)
Detector::Detector(std::map<std::string, char> input_config, std::set<InputEvent> events) :
gpio(input_config), input_events(events), is_running(true)
{
detect_thread = std::thread(&Detector::detect, this);
}
@@ -46,10 +46,8 @@ void Detector::detect()
char address;
if(check_inputs(address))
{
if(InputEvent* event = find_event(address))
{
notify_handlers(*event);
}
InputEvent event = find_event(address);
notify_handlers(event);
}
}
}
@@ -77,7 +75,7 @@ bool Detector::check_inputs(char& address)
digitalWrite(gpio["COL_C"], col & 0b100);
// wait for mux to set address
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_DURATION));
std::this_thread::sleep_for(std::chrono::microseconds(SLEEP_DURATION));
if(digitalRead(gpio["INPUT"]))
{
address = pow(2, row) + col;
@@ -88,10 +86,11 @@ bool Detector::check_inputs(char& address)
return false;
}
InputEvent* Detector::find_event(char address)
InputEvent& Detector::find_event(char address)
{
// TODO this is shit
return *std::find_if(input_events.begin(), input_events.end(),
[address] (InputEvent* e) { return *e == address; }
[address] (InputEvent& e) { return e == address; }
);
}