From ad344f50601cf0fc11a42363ef3e8cf61c7e8b13 Mon Sep 17 00:00:00 2001 From: naheedsa <97088153+naheedsa@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:52:50 +0300 Subject: [PATCH] Migrate Integra (#2022) --- drivers/rotator/integra.cpp | 167 ++++++++++++++++++------------------ drivers/rotator/integra.h | 18 ++-- 2 files changed, 94 insertions(+), 91 deletions(-) diff --git a/drivers/rotator/integra.cpp b/drivers/rotator/integra.cpp index c4533a0414..68f62667ee 100644 --- a/drivers/rotator/integra.cpp +++ b/drivers/rotator/integra.cpp @@ -90,11 +90,11 @@ bool Integra::initProperties() { INDI::Focuser::initProperties(); - IUFillNumber(&MaxPositionN[0], "FOCUSER", "Focuser", "%.f", + MaxPositionNP[FOCUSER].fill("FOCUSER", "Focuser", "%.f", 0, wellKnownIntegra85FocusMax, 0., wellKnownIntegra85FocusMax); - IUFillNumber(&MaxPositionN[1], "ROTATOR", "Rotator", "%.f", + MaxPositionNP[ROTATOR].fill("ROTATOR", "Rotator", "%.f", 0, wellKnownIntegra85RotateMax, 0., wellKnownIntegra85RotateMax); - IUFillNumberVector(&MaxPositionNP, MaxPositionN, 2, getDeviceName(), "MAX_POSITION", "Max position", + MaxPositionNP.fill(getDeviceName(), "MAX_POSITION", "Max position", SETTINGS_TAB, IP_RO, 0, IPS_IDLE); FocusSpeedN[0].min = 1; @@ -102,20 +102,20 @@ bool Integra::initProperties() FocusSpeedN[0].value = 1; // Temperature Sensor - IUFillNumber(&SensorN[SENSOR_TEMPERATURE], "TEMPERATURE", "Temperature (C)", "%.2f", -100, 100., 1., 0.); - IUFillNumberVector(&SensorNP, SensorN, 1, getDeviceName(), "SENSORS", "Sensors", MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE ); + SensorNP[SENSOR_TEMPERATURE].fill("TEMPERATURE", "Temperature (C)", "%.2f", -100, 100., 1., 0.); + SensorNP.fill(getDeviceName(), "SENSORS", "Sensors", MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE ); // Home Find - IUFillSwitch(&FindHomeS[HOMING_IDLE], "HOMING_IDLE", "Idle", ISS_ON); - IUFillSwitch(&FindHomeS[HOMING_START], "HOMING_START", "Start", ISS_OFF); - IUFillSwitch(&FindHomeS[HOMING_ABORT], "HOMING_ABORT", "Abort", ISS_OFF); - IUFillSwitchVector(&FindHomeSP, FindHomeS, HOMING_COUNT, getDeviceName(), "HOMING", "Home at Center", SETTINGS_TAB, IP_RW, + FindHomeSP[HOMING_IDLE].fill("HOMING_IDLE", "Idle", ISS_ON); + FindHomeSP[HOMING_START].fill("HOMING_START", "Start", ISS_OFF); + FindHomeSP[HOMING_ABORT].fill("HOMING_ABORT", "Abort", ISS_OFF); + FindHomeSP.fill(getDeviceName(), "HOMING", "Home at Center", SETTINGS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); // Relative and absolute movement FocusAbsPosN[0].min = 0; - FocusAbsPosN[0].max = MaxPositionN[0].value; - FocusAbsPosN[0].step = MaxPositionN[0].value / 50.0; + FocusAbsPosN[0].max = MaxPositionNP[FOCUSER].getValue(); + FocusAbsPosN[0].step = MaxPositionNP[ROTATOR].getValue() / 50.0; FocusAbsPosN[0].value = 0; FocusRelPosN[0].min = 0; @@ -126,10 +126,10 @@ bool Integra::initProperties() RI::initProperties(ROTATOR_TAB); // Rotator Ticks - IUFillNumber(&RotatorAbsPosN[0], "ROTATOR_ABSOLUTE_POSITION", "Ticks", "%.f", 0., 61802., 1., 0.); - IUFillNumberVector(&RotatorAbsPosNP, RotatorAbsPosN, 1, getDeviceName(), "ABS_ROTATOR_POSITION", "Goto", ROTATOR_TAB, IP_RW, + RotatorAbsPosNP[0].fill("ROTATOR_ABSOLUTE_POSITION", "Ticks", "%.f", 0., 61802., 1., 0.); + RotatorAbsPosNP.fill(getDeviceName(), "ABS_ROTATOR_POSITION", "Goto", ROTATOR_TAB, IP_RW, 0, IPS_IDLE ); - RotatorAbsPosN[0].min = 0; + RotatorAbsPosNP[0].setMin(0); addDebugControl(); @@ -150,26 +150,26 @@ bool Integra::updateProperties() if (isConnected()) { - defineProperty(&MaxPositionNP); + defineProperty(MaxPositionNP); // Focus - defineProperty(&SensorNP); - defineProperty(&FindHomeSP); + defineProperty(SensorNP); + defineProperty(FindHomeSP); // Rotator RI::updateProperties(); - defineProperty(&RotatorAbsPosNP); + defineProperty(RotatorAbsPosNP); } else { - deleteProperty(MaxPositionNP.name); + deleteProperty(MaxPositionNP.getName()); // Focus - deleteProperty(SensorNP.name); - deleteProperty(FindHomeSP.name); + deleteProperty(SensorNP.getName()); + deleteProperty(FindHomeSP.getName()); // Rotator RI::updateProperties(); - deleteProperty(RotatorAbsPosNP.name); + deleteProperty(RotatorAbsPosNP.getName()); } return true; @@ -252,7 +252,7 @@ bool Integra::getFirmware() bool Integra::getFocuserType() { int focus_max = int(FocusAbsPosN[0].max); - int rotator_max = int(RotatorAbsPosN[0].max); + int rotator_max = int(RotatorAbsPosNP[0].getMax()); if (focus_max != wellKnownIntegra85FocusMax) { LOGF_ERROR("This is no Integra85 because focus max position %d != %d, trying to continue still", focus_max, @@ -271,8 +271,8 @@ bool Integra::getFocuserType() if (strcmp(resp, "Integra85") == 0) { // RotatorAbsPosN[0].max is already set by getMaxPosition - rotatorTicksPerDegree = RotatorAbsPosN[0].max / 360.0; - rotatorDegreesPerTick = 360.0 / RotatorAbsPosN[0].max; + rotatorTicksPerDegree = RotatorAbsPosNP[0].getMax() / 360.0; + rotatorDegreesPerTick = 360.0 / RotatorAbsPosNP[0].getMax(); } return true; @@ -292,11 +292,11 @@ bool Integra::relativeGotoMotor(MotorType type, int32_t relativePosition) { if (relativePosition > 0) { - if (lastFocuserPosition + relativePosition > MaxPositionN[MOTOR_FOCUS].value) + if (lastFocuserPosition + relativePosition > MaxPositionNP[MOTOR_FOCUS].getValue()) { - int newRelativePosition = (int32_t)floor(MaxPositionN[MOTOR_FOCUS].value) - lastFocuserPosition; + int newRelativePosition = (int32_t)floor(MaxPositionNP[MOTOR_FOCUS].getValue()) - lastFocuserPosition; LOGF_INFO("Focus position change %d clipped to %d to stay at MAX %d", - relativePosition, newRelativePosition, MaxPositionN[MOTOR_FOCUS].value); + relativePosition, newRelativePosition, MaxPositionNP[MOTOR_FOCUS].getValue()); relativePosition = newRelativePosition; } } @@ -315,21 +315,21 @@ bool Integra::relativeGotoMotor(MotorType type, int32_t relativePosition) { if (relativePosition > 0) { - if (lastRotatorPosition + relativePosition > MaxPositionN[MOTOR_ROTATOR].value) + if (lastRotatorPosition + relativePosition > MaxPositionNP[MOTOR_ROTATOR].getValue()) { - int newRelativePosition = (int32_t)floor(MaxPositionN[MOTOR_ROTATOR].value) - lastRotatorPosition; + int newRelativePosition = (int32_t)floor(MaxPositionNP[MOTOR_ROTATOR].getValue()) - lastRotatorPosition; LOGF_INFO("Rotator position change %d clipped to %d to stay at MAX %d", - relativePosition, newRelativePosition, MaxPositionN[MOTOR_ROTATOR].value); + relativePosition, newRelativePosition, MaxPositionNP[MOTOR_ROTATOR].getValue()); relativePosition = newRelativePosition; } } else { - if (lastRotatorPosition + relativePosition < - MaxPositionN[MOTOR_ROTATOR].value) + if (lastRotatorPosition + relativePosition < - MaxPositionNP[MOTOR_ROTATOR].getValue()) { - int newRelativePosition = - (int32_t)floor(MaxPositionN[MOTOR_ROTATOR].value) - lastRotatorPosition; + int newRelativePosition = - (int32_t)floor(MaxPositionNP[MOTOR_ROTATOR].getValue()) - lastRotatorPosition; LOGF_INFO("Rotator position change %d clipped to %d to stay at MIN %d", - relativePosition, newRelativePosition, - MaxPositionN[MOTOR_ROTATOR].value); + relativePosition, newRelativePosition, - MaxPositionNP[MOTOR_ROTATOR].getValue()); relativePosition = newRelativePosition; } } @@ -386,9 +386,9 @@ bool Integra::getPosition(MotorType type) } else if (type == MOTOR_ROTATOR) { - if (RotatorAbsPosN[0].value != position) + if (RotatorAbsPosNP[0].getValue() != position) { - auto position_from = (int) RotatorAbsPosN[0].value; + auto position_from = (int) RotatorAbsPosNP[0].getValue(); int position_to = position; if (haveReadRotatorPositionAtLeastOnce) { @@ -400,7 +400,7 @@ bool Integra::getPosition(MotorType type) LOGF_DEBUG("Rotator angle is %.2f, position is %d", rotatorTicksToDegrees(position_to), position_to); } - RotatorAbsPosN[0].value = position; + RotatorAbsPosNP[0].setValue(position); } } else @@ -419,52 +419,53 @@ bool Integra::ISNewSwitch (const char * dev, const char * name, ISState * states { if(strcmp(dev, getDeviceName()) == 0) { - if (strcmp(name, FindHomeSP.name) == 0) + if (FindHomeSP.isNameMatch(name)) { - IUUpdateSwitch(&FindHomeSP, states, names, n); - int index = IUFindOnSwitchIndex(&FindHomeSP); + FindHomeSP.update(states, names, n); + int index = FindHomeSP.findOnSwitchIndex(); switch (index) { case HOMING_IDLE: LOG_INFO("Homing state is IDLE"); - FindHomeS[HOMING_IDLE].s = ISS_ON; - FindHomeSP.s = IPS_OK; + FindHomeSP[HOMING_IDLE].setState(ISS_ON); + FindHomeSP.setState(IPS_OK); break; case HOMING_START: if (findHome()) { - FindHomeSP.s = IPS_BUSY; - FindHomeS[HOMING_START].s = ISS_ON; + FindHomeSP.setState(IPS_BUSY); + FindHomeSP[HOMING_START].setState(ISS_ON); DEBUG(INDI::Logger::DBG_WARNING, "Homing process can take up to 2 minutes. You cannot control the unit until the process is fully complete."); } else { - FindHomeSP.s = IPS_ALERT; - FindHomeS[HOMING_START].s = ISS_OFF; + FindHomeSP.setState(IPS_ALERT); + FindHomeSP[HOMING_START].setState(ISS_OFF); LOG_ERROR("Failed to start homing process."); } break; case HOMING_ABORT: if (abortHome()) { - FindHomeSP.s = IPS_IDLE; - FindHomeS[HOMING_ABORT].s = ISS_ON; + FindHomeSP.setState(IPS_IDLE); + FindHomeSP[HOMING_ABORT].setState(ISS_ON); LOG_WARN("Homing aborted"); } else { - FindHomeSP.s = IPS_ALERT; - FindHomeS[HOMING_ABORT].s = ISS_OFF; + FindHomeSP.setState(IPS_ALERT); + FindHomeSP[HOMING_ABORT].setState(ISS_OFF); LOG_ERROR("Failed to abort homing process."); } break; default: - FindHomeSP.s = IPS_ALERT; - IDSetSwitch(&FindHomeSP, "Unknown homing index %d", index); + FindHomeSP.setState(IPS_ALERT); + LOG_INFO("Unknown homing index %d"); + FindHomeSP.apply(); return false; } - IDSetSwitch(&FindHomeSP, nullptr); + FindHomeSP.apply(); return true; } else if (strstr(name, "ROTATOR")) @@ -481,11 +482,11 @@ bool Integra::ISNewNumber (const char * dev, const char * name, double values[], { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (strcmp(name, RotatorAbsPosNP.name) == 0) + if (RotatorAbsPosNP.isNameMatch(name)) { - RotatorAbsPosNP.s = (gotoMotor(MOTOR_ROTATOR, static_cast(values[0])) ? IPS_BUSY : IPS_ALERT); - IDSetNumber(&RotatorAbsPosNP, nullptr); - if (RotatorAbsPosNP.s == IPS_BUSY) + RotatorAbsPosNP.setState((gotoMotor(MOTOR_ROTATOR, static_cast(values[0])) ? IPS_BUSY : IPS_ALERT)); + RotatorAbsPosNP.apply(); + if (RotatorAbsPosNP.getState() == IPS_BUSY) LOGF_DEBUG("Rotator moving from %d to %.f ticks...", lastRotatorPosition, values[0]); return true; } @@ -547,21 +548,21 @@ void Integra::TimerHit() bool savePositionsToEEPROM = false; // sanity check warning ... - if (int(FocusAbsPosN[0].max) != wellKnownIntegra85FocusMax || int(RotatorAbsPosN[0].max) != wellKnownIntegra85RotateMax) + if (int(FocusAbsPosN[0].max) != wellKnownIntegra85FocusMax || int(RotatorAbsPosNP[0].getMax()) != wellKnownIntegra85RotateMax) { LOGF_WARN("Warning: Focus motor max position %d should be %d and Rotator motor max position %d should be %d", int(FocusAbsPosN[0].max), wellKnownIntegra85FocusMax, - int(RotatorAbsPosN[0].max), wellKnownIntegra85RotateMax); + int(RotatorAbsPosNP[0].getMax()), wellKnownIntegra85RotateMax); } // #1 If we're homing, we check if homing is complete as we cannot check for anything else - if (FindHomeSP.s == IPS_BUSY) + if (FindHomeSP.getState() == IPS_BUSY) { if (isHomingComplete()) { - FindHomeS[0].s = ISS_OFF; - FindHomeSP.s = IPS_OK; - IDSetSwitch(&FindHomeSP, nullptr); + FindHomeSP[HOMING_IDLE].setState(ISS_OFF); + FindHomeSP.setState(IPS_OK); + FindHomeSP.apply(); LOG_INFO("Homing is complete"); // Next read positions and save to EEPROM : @@ -579,7 +580,7 @@ void Integra::TimerHit() // #2 Get Temperature, only read this when no motors are active, and about once per minute if (FocusAbsPosNP.s != IPS_BUSY && FocusRelPosNP.s != IPS_BUSY - && RotatorAbsPosNP.s != IPS_BUSY + && RotatorAbsPosNP.getState() != IPS_BUSY && timeToReadTemperature <= 0) { rc = getTemperature(); @@ -588,10 +589,10 @@ void Integra::TimerHit() if (rc) { timeToReadTemperature = INTEGRA_TEMPERATURE_LOOP_SKIPS; - if (fabs(SensorN[SENSOR_TEMPERATURE].value - lastTemperature) > INTEGRA_TEMPERATURE_TRESHOLD_IN_C) + if (fabs(SensorNP[SENSOR_TEMPERATURE].getValue() - lastTemperature) > INTEGRA_TEMPERATURE_TRESHOLD_IN_C) { - lastTemperature = SensorN[SENSOR_TEMPERATURE].value; - IDSetNumber(&SensorNP, nullptr); + lastTemperature = SensorNP[SENSOR_TEMPERATURE].getValue(); + SensorNP.apply(); } } } @@ -639,22 +640,22 @@ void Integra::TimerHit() } // #6 Rotator Position & Status - if (!haveReadRotatorPositionAtLeastOnce || RotatorAbsPosNP.s == IPS_BUSY) + if (!haveReadRotatorPositionAtLeastOnce || RotatorAbsPosNP.getState() == IPS_BUSY) { if ( ! isMotorMoving(MOTOR_ROTATOR)) { LOG_DEBUG("Rotator stopped"); - RotatorAbsPosNP.s = IPS_OK; + RotatorAbsPosNP.setState(IPS_OK); GotoRotatorNP.s = IPS_OK; rc = getPosition(MOTOR_ROTATOR); if (rc) { - if (RotatorAbsPosN[0].value != lastRotatorPosition) + if (RotatorAbsPosNP[0].getValue() != lastRotatorPosition) { - lastRotatorPosition = RotatorAbsPosN[0].value; + lastRotatorPosition = RotatorAbsPosNP[0].getValue(); GotoRotatorN[0].value = rotatorTicksToDegrees( lastRotatorPosition); //range360(RotatorAbsPosN[0].value / rotatorTicksPerDegree); - IDSetNumber(&RotatorAbsPosNP, nullptr); + RotatorAbsPosNP.apply( ); IDSetNumber(&GotoRotatorNP, nullptr); if (haveReadRotatorPositionAtLeastOnce) LOGF_INFO("Rotator reached requested angle %.2f, position %d", @@ -754,22 +755,22 @@ bool Integra::getMaxPosition(MotorType type) return false; } int position = atoi(res); - if (MaxPositionN[type].value == position) + if (MaxPositionNP[type].getValue() == position) { LOGF_INFO("%s motor max position is %d", (type == MOTOR_FOCUS) ? "Focuser" : "Rotator", position); } else { LOGF_WARN("Updated %s motor max position from %d to %d", - (type == MOTOR_FOCUS) ? "Focuser" : "Rotator", MaxPositionN[type].value, position); - MaxPositionN[type].value = position; + (type == MOTOR_FOCUS) ? "Focuser" : "Rotator", MaxPositionNP[type].getValue(), position); + MaxPositionNP[type].setValue(position); if (type == MOTOR_FOCUS) { - FocusAbsPosN[0].max = MaxPositionN[type].value; + FocusAbsPosN[0].max = MaxPositionNP[type].getValue(); } else if (type == MOTOR_ROTATOR) { - RotatorAbsPosN[0].max = MaxPositionN[type].value; + RotatorAbsPosNP[0].setMax(MaxPositionNP[type].getValue()); } else { @@ -789,7 +790,7 @@ bool Integra::getTemperature() char res[16] = {0}; if (integraGetCommand(__FUNCTION__, get_temperature, res ) ) { - SensorN[SENSOR_TEMPERATURE].value = strtod(res, nullptr); + SensorNP[SENSOR_TEMPERATURE].setValue(strtod(res, nullptr)); return true; } return false; @@ -835,8 +836,8 @@ IPState Integra::MoveRotator(double angle) bool rc = relativeGotoMotor(MOTOR_ROTATOR, p2 - p1); if (rc) { - RotatorAbsPosNP.s = IPS_BUSY; - IDSetNumber(&RotatorAbsPosNP, nullptr); + RotatorAbsPosNP.setState(IPS_BUSY); + RotatorAbsPosNP.apply(); return IPS_BUSY; } @@ -846,10 +847,10 @@ IPState Integra::MoveRotator(double angle) bool Integra::AbortRotator() { bool rc = stopMotor(MOTOR_ROTATOR); - if (rc && RotatorAbsPosNP.s != IPS_OK) + if (rc && RotatorAbsPosNP.getState() != IPS_OK) { - RotatorAbsPosNP.s = IPS_OK; - IDSetNumber(&RotatorAbsPosNP, nullptr); + RotatorAbsPosNP.setState(IPS_OK); + RotatorAbsPosNP.apply(); } return rc; diff --git a/drivers/rotator/integra.h b/drivers/rotator/integra.h index 89c6f41115..c5829b91df 100644 --- a/drivers/rotator/integra.h +++ b/drivers/rotator/integra.h @@ -90,18 +90,20 @@ class Integra : public INDI::Focuser, public INDI::RotatorInterface uint32_t rotatorDegreesToTicks(double angle); double rotatorTicksToDegrees(uint32_t ticks); - INumber MaxPositionN[2]; - INumberVectorProperty MaxPositionNP; + // INumber MaxPositionN[2]; + INDI::PropertyNumber MaxPositionNP {2}; + enum + { + FOCUSER, + ROTATOR + }; - INumber SensorN[2]; - INumberVectorProperty SensorNP; + INDI::PropertyNumber SensorNP {1}; enum { SENSOR_TEMPERATURE }; - ISwitch FindHomeS[HOMING_COUNT]; - ISwitchVectorProperty FindHomeSP; + INDI::PropertySwitch FindHomeSP {3}; - INumber RotatorAbsPosN[1]; - INumberVectorProperty RotatorAbsPosNP; + INDI::PropertyNumber RotatorAbsPosNP {1}; double lastTemperature { 0 }; int timeToReadTemperature = 0;