refactored InputName
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
namespace Input
|
||||
{
|
||||
|
||||
Detector::Detector(InputGPIOInterface* in_gpio_interface, std::map<char, InputEvent> events, InputEventNotifier* input_event_notifier) :
|
||||
in_gpio_interface(in_gpio_interface), input_events(events), is_running(true), input_event_notifier(input_event_notifier)
|
||||
Detector::Detector(InputGPIOInterface* input_gpio_interface, std::map<char, Event> events, EventNotifier* event_notifier) :
|
||||
input_gpio_interface(input_gpio_interface), events(events), is_running(true), event_notifier(event_notifier)
|
||||
{
|
||||
detect_thread = std::thread(&Detector::detect, this);
|
||||
}
|
||||
@@ -24,13 +24,13 @@ Detector::~Detector()
|
||||
is_running = false;
|
||||
|
||||
detect_thread.join();
|
||||
delete this->in_gpio_interface;
|
||||
this->in_gpio_interface = NULL;
|
||||
delete this->input_event_notifier;
|
||||
this->input_event_notifier = NULL;
|
||||
delete this->input_gpio_interface;
|
||||
this->input_gpio_interface = NULL;
|
||||
delete this->event_notifier;
|
||||
this->event_notifier = NULL;
|
||||
}
|
||||
|
||||
// Cycles over all inputs and enqueues an input event if detected.
|
||||
// Cycles over all s and enqueues an event if detected.
|
||||
void Detector::detect()
|
||||
{
|
||||
while(is_running)
|
||||
@@ -40,8 +40,8 @@ void Detector::detect()
|
||||
{
|
||||
try
|
||||
{
|
||||
InputEvent& event = input_events.at(address);
|
||||
input_event_notifier->distribute_event(event);
|
||||
Event& event = events.at(address);
|
||||
event_notifier->distribute_event(event);
|
||||
}
|
||||
catch(std::out_of_range& e)
|
||||
{
|
||||
@@ -53,24 +53,16 @@ void Detector::detect()
|
||||
|
||||
bool Detector::check_inputs(char& address)
|
||||
{
|
||||
for(int row = 0; row < 8; row++)
|
||||
for(int pin = 0; pin < MATRIX_SIZE * MATRIX_SIZE; pin++)
|
||||
{
|
||||
in_gpio_interface->write_input_row(row);
|
||||
|
||||
for(int col = 0; col < 8; col++)
|
||||
if(input_gpio_interface->read_input_data(pin))
|
||||
{
|
||||
in_gpio_interface->write_input_col(col);
|
||||
|
||||
// wait for mux to set address
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(SLEEP_DURATION_NANO));
|
||||
if(in_gpio_interface->read_input_data())
|
||||
{
|
||||
address = pow(2, row) + col;
|
||||
return true;
|
||||
}
|
||||
address = pin;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user