mirror of
https://github.com/synthetos/g2.git
synced 2026-02-06 11:11:57 +08:00
Finsihed adding reset, limit, and interlock event handlers
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user