From 8a07cee6650abdc35bb9f070acadfccccf373579 Mon Sep 17 00:00:00 2001 From: Rob Giseburt Date: Sun, 4 Mar 2018 17:39:47 -0600 Subject: [PATCH] Renaming "Listener" to "Handler" --- g2core/canonical_machine.cpp | 32 +++++++-------- g2core/controller.cpp | 18 ++++----- g2core/cycle_homing.cpp | 8 ++-- g2core/cycle_probing.cpp | 8 ++-- g2core/gpio.cpp | 2 +- g2core/gpio.h | 78 ++++++++++++++++++------------------ 6 files changed, 73 insertions(+), 73 deletions(-) diff --git a/g2core/canonical_machine.cpp b/g2core/canonical_machine.cpp index b8cfe55a..bda76410 100644 --- a/g2core/canonical_machine.cpp +++ b/g2core/canonical_machine.cpp @@ -761,12 +761,12 @@ void canonical_machine_init() ACTIVE_MODEL = MODEL; // setup initial Gcode model pointer cm_arc_init(); // Note: spindle and coolant inits are independent - din_listeners[INPUT_ACTION_STOP].registerListener(&_hold_listener); - din_listeners[INPUT_ACTION_FAST_STOP].registerListener(&_hold_listener); - din_listeners[INPUT_ACTION_HALT].registerListener(&_halt_listener); - din_listeners[INPUT_ACTION_ALARM].registerListener(&_alarm_listener); - din_listeners[INPUT_ACTION_PANIC].registerListener(&_panic_listener); - din_listeners[INPUT_ACTION_RESET].registerListener(&_reset_listener); + din_handlers[INPUT_ACTION_STOP].registerHandler(&_hold_handler); + din_handlers[INPUT_ACTION_FAST_STOP].registerHandler(&_hold_handler); + din_handlers[INPUT_ACTION_HALT].registerHandler(&_halt_handler); + din_handlers[INPUT_ACTION_ALARM].registerHandler(&_alarm_handler); + din_handlers[INPUT_ACTION_PANIC].registerHandler(&_panic_handler); + din_handlers[INPUT_ACTION_RESET].registerHandler(&_reset_handler); } void canonical_machine_reset_rotation() { @@ -880,10 +880,10 @@ stat_t cm_clr(nvObj_t *nv) // clear alarm or shutdown from comman } /* - * _alarm_listener - a gpioDigitalInputListener to capture pin change events + * _alarm_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputListener _alarm_listener { +gpioDigitalInputHandler _alarm_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge != INPUT_EDGE_LEADING) { return false; } @@ -964,10 +964,10 @@ void cm_halt_motion(void) } /* - * _hold_listener - a gpioDigitalInputListener to capture pin change events + * _hold_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputListener _halt_listener { +gpioDigitalInputHandler _halt_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge != INPUT_EDGE_LEADING) { return false; } @@ -1090,10 +1090,10 @@ stat_t cm_panic(const stat_t status, const char *msg) } /* - * _panic_listener - a gpioDigitalInputListener to capture pin change events + * _panic_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputListener _panic_listener { +gpioDigitalInputHandler _panic_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge != INPUT_EDGE_LEADING) { return false; } @@ -1108,10 +1108,10 @@ gpioDigitalInputListener _panic_listener { }; /* - * _reset_listener - a gpioDigitalInputListener to capture pin change events + * _reset_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputListener _reset_listener { +gpioDigitalInputHandler _reset_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge != INPUT_EDGE_LEADING) { return false; } @@ -2021,10 +2021,10 @@ void cm_queue_flush() } /* - * _hold_listener - a gpioDigitalInputListener to capture pin change events + * _hold_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputListener _hold_listener { +gpioDigitalInputHandler _hold_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge != INPUT_EDGE_LEADING) { return false; } diff --git a/g2core/controller.cpp b/g2core/controller.cpp index ec873fd3..63b778a0 100644 --- a/g2core/controller.cpp +++ b/g2core/controller.cpp @@ -106,9 +106,9 @@ void controller_init() } // IndicatorLed.setFrequency(100000); - din_listeners[INPUT_ACTION_SHUTDOWN].registerListener(&_shutdown_listener); - din_listeners[INPUT_ACTION_LIMIT].registerListener(&_limit_listener); - din_listeners[INPUT_ACTION_INTERLOCK].registerListener(&_interlock_listener); + din_handlers[INPUT_ACTION_SHUTDOWN].registerHandler(&_shutdown_handler); + din_handlers[INPUT_ACTION_LIMIT].registerHandler(&_limit_handler); + din_handlers[INPUT_ACTION_INTERLOCK].registerHandler(&_interlock_handler); } void controller_request_enquiry() @@ -466,11 +466,11 @@ static stat_t _sync_to_planner() /* ALARM STATE HANDLERS * * _shutdown_handler() - put system into shutdown state - * _shutdown_listener - a gpioDigitalInputListener to capture pin change events + * _shutdown_handler - a gpioDigitalInputHandler to capture pin change events * _limit_switch_handler() - shut down system if limit switch fired - * _limit_listener - a gpioDigitalInputListener to capture pin change events + * _limit_handler - a gpioDigitalInputHandler to capture pin change events * _interlock_handler() - feedhold and resume depending on edge - * _interlock_listener - a gpioDigitalInputListener to capture pin change events + * _interlock_handler - a gpioDigitalInputHandler to capture pin change events * * Some handlers return EAGAIN causing the control loop to never advance beyond that point. * @@ -480,7 +480,7 @@ static stat_t _sync_to_planner() * - safety_interlock_requested == INPUT_EDGE_TRAILING is interlock offset */ -gpioDigitalInputListener _shutdown_listener { +gpioDigitalInputHandler _shutdown_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge != INPUT_EDGE_LEADING) { return false; } @@ -503,7 +503,7 @@ static stat_t _shutdown_handler(void) return(STAT_OK); } -gpioDigitalInputListener _limit_listener { +gpioDigitalInputHandler _limit_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge != INPUT_EDGE_LEADING) { return false; } @@ -533,7 +533,7 @@ static stat_t _limit_switch_handler(void) return (STAT_OK); } -gpioDigitalInputListener _interlock_listener { +gpioDigitalInputHandler _interlock_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge == INPUT_EDGE_LEADING) { cm.safety_interlock_disengaged = triggering_pin_number; diff --git a/g2core/cycle_homing.cpp b/g2core/cycle_homing.cpp index 63a976b6..c05767d9 100644 --- a/g2core/cycle_homing.cpp +++ b/g2core/cycle_homing.cpp @@ -97,10 +97,10 @@ static stat_t _set_homing_func(stat_t (*func)(int8_t axis)) { } /* - * _homing_listener - a gpioDigitalInputListener to capture pin change events + * _homing_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered only during homing mode - see gpio.h for more info */ -gpioDigitalInputListener _homing_listener { +gpioDigitalInputHandler _homing_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (cm.cycle_state != CYCLE_HOMING) { return false; } if (triggering_pin_number != hm.homing_input) { return false; } @@ -263,7 +263,7 @@ static stat_t _homing_axis_start(int8_t axis) { // Nothing to do about direction now that direction is explicit // However, here's a good place to stash the homing_switch: hm.homing_input = cm.a[axis].homing_input; - din_listeners[INPUT_ACTION_INTERNAL].registerListener(&_homing_listener); + din_handlers[INPUT_ACTION_INTERNAL].registerHandler(&_homing_handler); hm.axis = axis; // persist the axis hm.search_velocity = std::abs(cm.a[axis].search_velocity); // search velocity is always positive @@ -349,7 +349,7 @@ static stat_t _homing_axis_set_position(int8_t axis) // set axis zero / max and } cm_set_axis_jerk(axis, hm.saved_jerk); // restore the max jerk value - din_listeners[INPUT_ACTION_INTERNAL].deregisterListener(&_homing_listener); // end homing mode + din_handlers[INPUT_ACTION_INTERNAL].deregisterHandler(&_homing_handler); // end homing mode return (_set_homing_func(_homing_axis_start)); } diff --git a/g2core/cycle_probing.cpp b/g2core/cycle_probing.cpp index c003217a..20464a01 100644 --- a/g2core/cycle_probing.cpp +++ b/g2core/cycle_probing.cpp @@ -124,10 +124,10 @@ static void _motion_end_callback(float* vect, bool* flag) } /* - * _probing_listener - a gpioDigitalInputListener to capture pin change events + * _probing_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered only during homing mode - see gpio.h for more info */ -gpioDigitalInputListener _probing_listener { +gpioDigitalInputHandler _probing_handler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (cm.cycle_state != CYCLE_PROBE) { return false; } if (triggering_pin_number != pb.probe_input) { return false; } @@ -289,7 +289,7 @@ static uint8_t _probing_start() return(_probing_exception_exit(STAT_PROBE_TRAVEL_TOO_SMALL)); } - din_listeners[INPUT_ACTION_INTERNAL].registerListener(&_probing_listener); + din_handlers[INPUT_ACTION_INTERNAL].registerHandler(&_probing_handler); // Get initial probe state, and don't probe if we're already tripped. // If the initial input is the same as the trip_sense it's an error. @@ -351,7 +351,7 @@ static stat_t _probe_move(const float target[], const bool flags[]) static void _probe_restore_settings() { - din_listeners[INPUT_ACTION_INTERNAL].deregisterListener(&_probing_listener); + din_handlers[INPUT_ACTION_INTERNAL].deregisterHandler(&_probing_handler); for (uint8_t axis = 0; axis < AXES; axis++) { // restore axis jerks cm.a[axis].jerk_max = pb.saved_jerk[axis]; diff --git a/g2core/gpio.cpp b/g2core/gpio.cpp index 34bd5719..7d7c0557 100644 --- a/g2core/gpio.cpp +++ b/g2core/gpio.cpp @@ -168,7 +168,7 @@ gpioDigitalOutputReader out14; gpioDigitalOutputReader* const out_r[14] = {&out1 ,&out2 ,&out3 ,&out4 ,&out5 ,&out6 ,&out7 ,&out8 ,&out9 ,&out10 ,&out11 ,&out12 ,&out13 ,&out14}; // lists for the various inputAction events -gpioDigitalInputListenerList din_listeners[INPUT_ACTION_ACTUAL_MAX+1]; +gpioDigitalInputHandlerList din_handlers[INPUT_ACTION_ACTUAL_MAX+1]; /* diff --git a/g2core/gpio.h b/g2core/gpio.h index 75c220ec..97ceb7ce 100644 --- a/g2core/gpio.h +++ b/g2core/gpio.h @@ -103,7 +103,7 @@ struct gpioDigitalInputReader; extern gpioDigitalInputReader* const in_r[14]; /* - * gpioDigitalInputListener - superclass of objects that wish to be informed of + * gpioDigitalInputHandler - superclass of objects that wish to be informed of * digital input changes * * Notes about the callback function: @@ -111,12 +111,12 @@ extern gpioDigitalInputReader* const in_r[14]; * The second parameter is the inputEdgeFlag value * The third parameter is the external number (N in `diN`) of the pin that changed * The return value indicates if it has been "handled" - return true and no other - * gpioDigitalInputListener callbacks will be triggered *for this event* + * gpioDigitalInputHandler callbacks will be triggered *for this event* * Generally, return false unless there is a good reason to stop propagation. * - * Example gpioDigitalInputListener object creation: + * Example gpioDigitalInputHandler object creation: - gpioDigitalInputListener limitListener { + gpioDigitalInputHandler limitHandler { [&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { if (edge != INPUT_EDGE_LEADING) { return; } limit_requested = true; // record that a limit was requested for later processing @@ -127,79 +127,79 @@ extern gpioDigitalInputReader* const in_r[14]; }; // register this listener for limit events: - din_listeners[INPUT_ACTION_LIMIT].registerListener(limitListener); + din_handlers[INPUT_ACTION_LIMIT].registerHandler(limitHandler); */ -struct gpioDigitalInputListener { +struct gpioDigitalInputHandler { // const means it must be provided at compile time const std::function callback; // the function to call const int8_t priority; // higher is higher - gpioDigitalInputListener *next; // form a simple linked list + gpioDigitalInputHandler *next; // form a simple linked list }; -struct gpioDigitalInputListenerList { - gpioDigitalInputListener * _first_listener; +struct gpioDigitalInputHandlerList { + gpioDigitalInputHandler * _first_handler; - void registerListener(gpioDigitalInputListener * const new_listener) { - if (!_first_listener) { + void registerHandler(gpioDigitalInputHandler * const new_handler) { + if (!_first_handler) { // there is only one - now - _first_listener = new_listener; + _first_handler = new_handler; return; - } else if (new_listener->priority > _first_listener->priority) { + } else if (new_handler->priority > _first_handler->priority) { // this is the new first one - new_listener->next = _first_listener; - _first_listener = new_listener; + new_handler->next = _first_handler; + _first_handler = new_handler; return; } - gpioDigitalInputListener * current_listener = _first_listener; + gpioDigitalInputHandler * current_handler = _first_handler; - while (current_listener != nullptr) { - if (new_listener->priority <= current_listener->priority) { - // new_listener will be immediately after current_listener - new_listener->next = current_listener->next; - current_listener->next = new_listener; + while (current_handler != nullptr) { + if (new_handler->priority <= current_handler->priority) { + // new_handler will be immediately after current_handler + new_handler->next = current_handler->next; + current_handler->next = new_handler; return; } - current_listener = current_listener->next; + current_handler = current_handler->next; } }; - void deregisterListener(gpioDigitalInputListener * const old_listener) { - if (!_first_listener) { + void deregisterHandler(gpioDigitalInputHandler * const old_handler) { + if (!_first_handler) { return; - } else if (_first_listener == old_listener) { - _first_listener = _first_listener->next; + } else if (_first_handler == old_handler) { + _first_handler = _first_handler->next; return; } - gpioDigitalInputListener * current_listener = _first_listener; + gpioDigitalInputHandler * current_handler = _first_handler; - while (current_listener->next != nullptr) { - if (current_listener->next == old_listener) { - current_listener->next = old_listener->next; + while (current_handler->next != nullptr) { + if (current_handler->next == old_handler) { + current_handler->next = old_handler->next; return; } - current_listener = current_listener->next; + current_handler = current_handler->next; } }; bool call(const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { - gpioDigitalInputListener * current_listener = _first_listener; - while (current_listener != nullptr) { - if (current_listener->callback(state, edge, triggering_pin_number)) { + gpioDigitalInputHandler * current_handler = _first_handler; + while (current_handler != nullptr) { + if (current_handler->callback(state, edge, triggering_pin_number)) { return true; } - current_listener = current_listener->next; + current_handler = current_handler->next; } return false; } }; // lists for the various inputAction events -extern gpioDigitalInputListenerList din_listeners[INPUT_ACTION_ACTUAL_MAX+1]; +extern gpioDigitalInputHandlerList din_handlers[INPUT_ACTION_ACTUAL_MAX+1]; /* * gpioDigitalInput - digital input base class @@ -507,8 +507,8 @@ struct gpioDigitalInputPin final : gpioDigitalInput { } // start with INPUT_ACTION_INTERNAL for transient event processing like homing and probing - if (!din_listeners[INPUT_ACTION_INTERNAL].call(pin_value_corrected, edge, ext_pin_number)) { - din_listeners[action].call(pin_value_corrected, edge, ext_pin_number); + if (!din_handlers[INPUT_ACTION_INTERNAL].call(pin_value_corrected, edge, ext_pin_number)) { + din_handlers[action].call(pin_value_corrected, edge, ext_pin_number); } #if 0 // TODO - refactor homing_mode and probing_mode out to use a dynamically @@ -570,7 +570,7 @@ struct gpioDigitalInputPin final : gpioDigitalInput { if (input_function == INPUT_ACTION_LIMIT) { cm.limit_requested = ext_pin_number; - } else if (input_function == INPUT_FUNCTION_SHUTDOWN) { + } else if (input_function == INPUT_ACTION_SHUTDOWN) { cm.shutdown_requested = ext_pin_number; } else if (input_function == INPUT_FUNCTION_INTERLOCK) {