made references to pointers
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
namespace Input
|
||||
{
|
||||
|
||||
Detector::Detector(GPIOInterface& gpio_interface, std::map<char, InputEvent> events, InputEventNotifier& input_event_notifier) :
|
||||
gpio_interface(gpio_interface), input_events(events), is_running(true), input_event_notifier(input_event_notifier)
|
||||
Detector::Detector(GPIOInterface* 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)
|
||||
{
|
||||
detect_thread = std::thread(&Detector::detect, this);
|
||||
}
|
||||
@@ -24,6 +24,10 @@ 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;
|
||||
}
|
||||
|
||||
// Cycles over all inputs and enqueues an input event if detected.
|
||||
@@ -37,7 +41,7 @@ void Detector::detect()
|
||||
try
|
||||
{
|
||||
InputEvent& event = input_events.at(address);
|
||||
input_event_notifier.distribute_event(event);
|
||||
input_event_notifier->distribute_event(event);
|
||||
}
|
||||
catch(std::out_of_range& e)
|
||||
{
|
||||
@@ -51,15 +55,15 @@ bool Detector::check_inputs(char& address)
|
||||
{
|
||||
for(int row = 0; row < 8; row++)
|
||||
{
|
||||
gpio_interface.write_input_row(row);
|
||||
in_gpio_interface->write_input_row(row);
|
||||
|
||||
for(int col = 0; col < 8; col++)
|
||||
{
|
||||
gpio_interface.write_input_col(col);
|
||||
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(gpio_interface.read_input_data())
|
||||
if(in_gpio_interface->read_input_data())
|
||||
{
|
||||
address = pow(2, row) + col;
|
||||
return true;
|
||||
|
||||
@@ -37,7 +37,7 @@ class Detector
|
||||
{
|
||||
|
||||
public:
|
||||
Detector(GPIOInterface& gpio_interface, std::map<char, InputEvent> events, InputEventNotifier& input_event_notifier);
|
||||
Detector(GPIOInterface* in_gpio_interface, std::map<char, InputEvent> events, InputEventNotifier* input_event_notifier);
|
||||
~Detector();
|
||||
|
||||
private:
|
||||
@@ -45,11 +45,11 @@ private:
|
||||
bool check_inputs(char& address);
|
||||
|
||||
private:
|
||||
GPIOInterface& gpio_interface;
|
||||
GPIOInterface* in_gpio_interface;
|
||||
|
||||
std::map<char, InputEvent> input_events;
|
||||
|
||||
InputEventNotifier& input_event_notifier;
|
||||
InputEventNotifier* input_event_notifier;
|
||||
|
||||
bool is_running;
|
||||
std::thread detect_thread;
|
||||
|
||||
Reference in New Issue
Block a user