/************************************************************************************ * * ***********************************************************************************/ bool ScopeDome::SetupParms() { targetAz = 0; readU32(GetImpPerTurn, stepsPerTurn); LOGF_INFO("Steps per turn read as %d", stepsPerTurn); StepsPerRevolutionN[0].value = stepsPerTurn; StepsPerRevolutionNP.s = IPS_OK; IDSetNumber(&StepsPerRevolutionNP, nullptr); readS32(GetHomeSensorPosition, homePosition); LOGF_INFO("Home position read as %d", homePosition); if (UpdatePosition()) IDSetNumber(&DomeAbsPosNP, nullptr); if (UpdateShutterStatus()) IDSetSwitch(&DomeShutterSP, nullptr); UpdateSensorStatus(); UpdateRelayStatus(); if (InitPark()) { // If loading parking data is successful, we just set the default parking // values. SetAxis1ParkDefault(0); } else { // Otherwise, we set all parking data to default in case no parking data is // found. SetAxis1Park(0); SetAxis1ParkDefault(0); } uint8_t calibrationNeeded = false; readU8(IsFullSystemCalReq, calibrationNeeded); CalibrationNeededS[0].s = calibrationNeeded ? ISS_ON : ISS_OFF; CalibrationNeededSP.s = IPS_OK; IDSetSwitch(&CalibrationNeededSP, nullptr); uint16_t fwVersion; readU16(GetVersionFirmware, fwVersion); FirmwareVersionsN[0].value = fwVersion / 100.0; uint8_t fwVersionRotary; readU8(GetVersionFirmwareRotary, fwVersionRotary); FirmwareVersionsN[1].value = (fwVersionRotary + 9) / 10.0; FirmwareVersionsNP.s = IPS_OK; IDSetNumber(&FirmwareVersionsNP, nullptr); return true; }
/************************************************************************************ * * ***********************************************************************************/ void ScopeDome::TimerHit() { if (!isConnected()) return; // No need to reset timer if we are not connected anymore readU16(GetStatus, currentStatus); // LOGF_INFO("Status: %x", currentStatus); UpdatePosition(); UpdateShutterStatus(); IDSetSwitch(&DomeShutterSP, nullptr); UpdateRelayStatus(); if (status == DOME_HOMING) { if ((currentStatus & 8) == 0 && getInputState(IN_HOME)) { // Found home status = DOME_READY; targetAz = DomeHomePositionN[0].value; // Reset counter writeCmd(ResetCounter); FindHomeSP.s = IPS_OK; DomeAbsPosNP.s = IPS_OK; IDSetSwitch(&FindHomeSP, nullptr); } IDSetNumber(&DomeAbsPosNP, nullptr); } else if (status == DOME_DEROTATING) { if ((currentStatus & 2) == 0) { readS32(GetCounterExt, currentRotation); LOGF_INFO("Current rotation is %d", currentRotation); if (abs(currentRotation) < 100) { // Close enough status = DOME_READY; DerotateSP.s = IPS_OK; DomeAbsPosNP.s = IPS_OK; IDSetSwitch(&DerotateSP, nullptr); } else { if (currentRotation < 0) { writeU16(CCWRotation, compensateInertia(-currentRotation)); } else { writeU16(CWRotation, compensateInertia(currentRotation)); } } } IDSetNumber(&DomeAbsPosNP, nullptr); } else if (DomeAbsPosNP.s == IPS_BUSY) { if ((currentStatus & 2) == 0) { // Rotation idle, are we close enough? double azDiff = targetAz - DomeAbsPosN[0].value; if (azDiff > 180) { azDiff -= 360; } if (azDiff < -180) { azDiff += 360; } if (fabs(azDiff) <= DomeParamN[0].value) { DomeAbsPosN[0].value = targetAz; DomeAbsPosNP.s = IPS_OK; LOG_INFO("Dome reached requested azimuth angle."); if (getDomeState() == DOME_PARKING) { if (ParkShutterS[0].s == ISS_ON && getInputState(IN_CLOSED1) == ISS_OFF) { ControlShutter(SHUTTER_CLOSE); } else { SetParked(true); } } else if (getDomeState() == DOME_UNPARKING) SetParked(false); else setDomeState(DOME_SYNCED); } else { // Refine azimuth MoveAbs(targetAz); } } IDSetNumber(&DomeAbsPosNP, nullptr); } else IDSetNumber(&DomeAbsPosNP, nullptr); // Read temperatures only every 10th time static int tmpCounter = 0; if (--tmpCounter <= 0) { UpdateSensorStatus(); tmpCounter = 10; } SetTimer(POLLMS); }