diff --git a/firmware/axl-stepper/src/main.cpp b/firmware/axl-stepper/src/main.cpp index ae46f6bd60df3d75c743800ebc965efa63fbefe1..3b54a91277ef76d00002444f8591afb877f6c7e9 100644 --- a/firmware/axl-stepper/src/main.cpp +++ b/firmware/axl-stepper/src/main.cpp @@ -18,8 +18,11 @@ //OSAP osap("axl-stepper_z-front-right"); //OSAP osap("axl-stepper_y-left"); //OSAP osap("axl-stepper_y-right"); -OSAP osap("axl-stepper_x"); +//OSAP osap("axl-stepper_x"); //OSAP osap("axl-stepper_e"); +OSAP osap("axl-stepper_z"); +//OSAP osap("axl-stepper_rl"); +//OSAP osap("axl-stepper_rr"); VPort_ArduinoSerial vpUSBSerial(&osap, "arduinoUSBSerial", &Serial); @@ -232,6 +235,10 @@ EP_ONDATA_RESPONSES onPrecalculatedMoveData(uint8_t* data, uint16_t len){ Endpoint precalculatedMoveEP(&osap, "precalculatedMoves", onPrecalculatedMoveData); +// -------------------------------------------------------- 9: Limit Halt-Output: + +Endpoint limitHaltEP(&osap, "limitOutput"); + // -------------------------------------------------------- Arduino Setup void setup() { @@ -257,6 +264,12 @@ uint32_t lastBlink = 0; uint32_t blinkInterval = 50; // ms uint8_t dummy[128]; +uint32_t lastLimitCheck = 0; +uint32_t limitCheckInterval = 1; // ms, helps debounce +uint8_t limitStates = 0; +uint32_t errLightOnTime = 0; +boolean errLightOn = false; + void loop() { osap.loop(); stepper_hw->dacRefresh(); @@ -267,9 +280,25 @@ void loop() { updateStatesEP(); //axl_printHomeState(); } - // if(haltLightOnTime + 250 < millis()){ - // ERRLIGHT_OFF; - // } + // this, i.e, could be on the endpoint's loop code, non? + if(lastLimitCheck + limitCheckInterval < millis()){ + lastLimitCheck = millis(); + // shift left one & tack bit on the end, + limitStates = limitStates << 1; + limitStates |= axl_checkLimit() ? 1 : 0; + // this is the positive-edge mask, + if(limitStates == 0b00001111){ + ERRLIGHT_ON; + errLightOnTime = millis(); + errLightOn = true; + dummy[0] = 1; + limitHaltEP.write(dummy, 1); + } + } + if(errLightOn && errLightOnTime + 250 < millis()){ + ERRLIGHT_OFF; + errLightOn = false; + } } // -------------------------------------------------------- Small-Time Ops