diff --git a/FlippR-Driver/src/input/Detector.cpp b/FlippR-Driver/src/input/Detector.cpp index b321c29..f0e82ff 100644 --- a/FlippR-Driver/src/input/Detector.cpp +++ b/FlippR-Driver/src/input/Detector.cpp @@ -13,8 +13,8 @@ namespace Input { -Detector::Detector(GPIOInterface& gpio_interface, std::map 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 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; diff --git a/FlippR-Driver/src/input/Detector.h b/FlippR-Driver/src/input/Detector.h index 00bcf11..2d01784 100644 --- a/FlippR-Driver/src/input/Detector.h +++ b/FlippR-Driver/src/input/Detector.h @@ -37,7 +37,7 @@ class Detector { public: - Detector(GPIOInterface& gpio_interface, std::map events, InputEventNotifier& input_event_notifier); + Detector(GPIOInterface* in_gpio_interface, std::map 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 input_events; - InputEventNotifier& input_event_notifier; + InputEventNotifier* input_event_notifier; bool is_running; std::thread detect_thread;