Finsihed adding reset, limit, and interlock event handlers

This commit is contained in:
Rob Giseburt
2018-03-04 17:35:01 -06:00
parent 9b46efbb8a
commit b833230278
2 changed files with 63 additions and 19 deletions

View File

@@ -105,6 +105,10 @@ void controller_init()
cs.controller_state = CONTROLLER_CONNECTED;
}
// 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);
}
void controller_request_enquiry()
@@ -462,8 +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
* _limit_switch_handler() - shut down system if limit switch fired
* _limit_listener - a gpioDigitalInputListener to capture pin change events
* _interlock_handler() - feedhold and resume depending on edge
* _interlock_listener - a gpioDigitalInputListener to capture pin change events
*
* Some handlers return EAGAIN causing the control loop to never advance beyond that point.
*
@@ -472,6 +479,19 @@ static stat_t _sync_to_planner()
* - safety_interlock_requested == INPUT_EDGE_LEADING is interlock onset
* - safety_interlock_requested == INPUT_EDGE_TRAILING is interlock offset
*/
gpioDigitalInputListener _shutdown_listener {
[&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) {
if (edge != INPUT_EDGE_LEADING) { return false; }
cm.shutdown_requested = triggering_pin_number;
return false; // allow others to see this notice
},
5, // priority
nullptr // next - nullptr to start with
};
static stat_t _shutdown_handler(void)
{
if (cm.shutdown_requested != 0) { // request may contain the (non-zero) input number
@@ -483,6 +503,18 @@ static stat_t _shutdown_handler(void)
return(STAT_OK);
}
gpioDigitalInputListener _limit_listener {
[&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) {
if (edge != INPUT_EDGE_LEADING) { return false; }
cm.limit_requested = triggering_pin_number;
return false; // allow others to see this notice
},
5, // priority
nullptr // next - nullptr to start with
};
static stat_t _limit_switch_handler(void)
{
auto machine_state = cm_get_machine_state();
@@ -501,6 +533,20 @@ static stat_t _limit_switch_handler(void)
return (STAT_OK);
}
gpioDigitalInputListener _interlock_listener {
[&](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) {
if (edge == INPUT_EDGE_LEADING) {
cm.safety_interlock_disengaged = triggering_pin_number;
} else { // edge == INPUT_EDGE_TRAILING
cm.safety_interlock_reengaged = triggering_pin_number;
}
return false; // allow others to see this notice
},
5, // priority
nullptr // next - nullptr to start with
};
static stat_t _interlock_handler(void)
{
if (cm.safety_interlock_enable) {