void Cell::timerEvent(QTimerEvent * e) { if(e->timerId() == rotationTimer) { const bool start = rotationProgress ? false : true; rotate(rotationStep); if(start) emit startRotation(); if(((rotationStep > 0) && (rotationProgress > 0) && (rotationProgress < rotationStep)) || ((rotationStep < 0) && (rotationProgress < 0) && (rotationProgress > rotationStep)) || (rotationProgress == 0)) { killTimer(rotationTimer); rotationTimer = 0; rotationProgress = 0; emit finishRotation(); } } else if(e->timerId() == blinkTimer) { if(blinkProgress > 2 * width()) { killTimer(blinkTimer); blinkTimer = 0; blinkProgress = 0; } else blinkProgress += BlinkStep; changed = true; update(); } }
void LockSystemController::cmdCalibAtLockedPos() { #ifdef LOCK_SYSTEM_CONTROLLER_DEBUG debugPrintln(F("LSC:cmdCalibAtLockedPos")); #endif switch (mainState) { case Initial: // regardlesss of calibration start or end, we are at locked position, record it calibrationData.lockedPosition_xz = laObs->getLockAngleDeg(xz); calibrationData.lockedPosition_yz = laObs->getLockAngleDeg(yz); laObs->getCart(&calibrationData.lockCart); switch (initState) { case uncalibrated: case calibratingStartFromLockedPos: // we are just starting the calibration cycle #ifdef LOCK_SYSTEM_CONTROLLER_DEBUG debugPrint(F("LSC:calib start lck xz yz ")); debugPrint(calibrationData.lockedPosition_xz); debugPrint(SPACE); debugPrintln(calibrationData.lockedPosition_yz); #endif calibrationData.lastReading = calibrationData.lockCart; newInitState(calibratingStartFromLockedPos); break; case calibratingStartFromUnlockedPos: // we've recorded the other side already, do // all the calibration calculations and store // the positions setLockUnlockPositions(); // TBD settings.lockedAngle.setData(lockedPosition); // TBD settings.unlockedAngle.setData(unlockedPosition); #ifdef LOCK_SYSTEM_CONTROLLER_DEBUG debugPrint(F("LSC:calib lck end xz yz ")); debugPrint(calibrationData.lockedPosition_xz); debugPrint(SPACE); debugPrintln(calibrationData.lockedPosition_yz); #endif // TBD settings.lockedAngle.setData(lockedPosition); // TBD settings.unlockedAngle.setData(unlockedPosition); #ifdef LOCK_SYSTEM_CONTROLLER_DEBUG debugPrint(F("LSC:calibration complete lock ")); debugPrint(lockedPosition); debugPrint(F(" unlock ")); debugPrintln(unlockedPosition); debugPrintln(F("LSC:testing orientation")); #endif startRotation(CW); newInitState(waitForCW); break; } break; } }
void LockSystemController::tsInit() { switch (initState) { case uncalibrated: return; break; case calibratingStartFromUnlockedPos: case calibratingStartFromLockedPos: updateCalibData(); break; case waitForCW: { int deltaCW = laObs->getLockAngleDeg() - bearings.checkRotationStartAngle; if (abs(deltaCW) >= bearings.checkRotationMinProgress) { motorCont->cmdStop(); if (deltaCW > 0) { angleIncrCW = true; } else { angleIncrCW = false; } #ifdef LOCK_SYSTEM_CONTROLLER_DEBUG debugPrint(F("LSC:waitForCW ")); debugPrintln(angleIncrCW); #endif newInitState(calibrated); } else if (millis() - bearings.testStartTime > bearings.testTime) { motorCont->cmdStop(); newInitState(waitForCCW); startRotation(CCW); } } break; case waitForCCW: { int deltaCCW = laObs->getLockAngleDeg() - bearings.checkRotationStartAngle; if (abs(deltaCCW) >= bearings.checkRotationMinProgress) { motorCont->cmdStop(); if (deltaCCW > 0) { angleIncrCW = false; } else { angleIncrCW = true; } #ifdef LOCK_SYSTEM_CONTROLLER_DEBUG debugPrint(F("LSC:waitForCCW ")); debugPrintln(angleIncrCW); #endif newInitState(calibrated); } else if (millis() - bearings.testStartTime > bearings.testTime) { motorCont->cmdStop(); newInitState(failed); } } break; case calibrated: debugPrintln(F("calibration success")); newMainState(Automatic); cmdLock(); newAutoState(locked); break; case failed: debugPrintln(F("calibration failed")); break; } }