fixed multiple events at a time

This commit is contained in:
Jonas Zeunert
2018-09-21 01:15:57 +02:00
parent 96e76f7180
commit 3f771d275e
2 changed files with 8 additions and 7 deletions

View File

@@ -37,8 +37,8 @@ void Detector::detect()
{ {
while(this->is_running) while(this->is_running)
{ {
char address; std::vector<char> detected_addresses = check_inputs();
if(this->check_inputs(address)) for(auto& address : detected_addresses)
{ {
try try
{ {
@@ -55,18 +55,18 @@ void Detector::detect()
} }
} }
bool Detector::check_inputs(char& address) std::vector<char> Detector::check_inputs()
{ {
std::vector<char> detected_addresses;
for(char pin = 0; pin < (INPUT_MATRIX_SIZE * INPUT_MATRIX_SIZE); pin++) for(char pin = 0; pin < (INPUT_MATRIX_SIZE * INPUT_MATRIX_SIZE); pin++)
{ {
if(input_gpio_interface->read_data(pin)) if(input_gpio_interface->read_data(pin))
{ {
CLOG(TRACE, INPUT_LOGGER) << "Pin " << std::to_string(pin) << " is triggered."; CLOG(TRACE, INPUT_LOGGER) << "Pin " << std::to_string(pin) << " is triggered.";
address = pin; detected_addresses.push_back(pin);
return true;
} }
} }
return false; return detected_addresses;
} }
} }

View File

@@ -16,6 +16,7 @@
#include <thread> #include <thread>
#include <vector>
#include <map> #include <map>
#include "utilities/IInputGPIOInterface.h" #include "utilities/IInputGPIOInterface.h"
@@ -38,7 +39,7 @@ public:
private: private:
void detect(); void detect();
bool check_inputs(char& address); std::vector<char> check_inputs();
private: private:
std::unique_ptr<IInputGPIOInterface> input_gpio_interface; std::unique_ptr<IInputGPIOInterface> input_gpio_interface;