diff --git a/indi-aok/lx200aok.cpp b/indi-aok/lx200aok.cpp index 64e3fcebd..98846e83d 100644 --- a/indi-aok/lx200aok.cpp +++ b/indi-aok/lx200aok.cpp @@ -111,12 +111,12 @@ void LX200Skywalker::ISGetProperties(const char *dev) LX200Telescope::ISGetProperties(dev); if (isConnected()) { - if (HasTrackMode() && TrackModeS != nullptr) - defineProperty(&TrackModeSP); + if (HasTrackMode() && TrackModeSP.isValid()) + defineProperty(TrackModeSP); if (CanControlTrack()) - defineProperty(&TrackStateSP); + defineProperty(TrackStateSP); if (HasTrackRate()) - defineProperty(&TrackRateNP); + defineProperty(TrackRateNP); } /* if (isConnected()) @@ -155,11 +155,11 @@ bool LX200Skywalker::ISNewSwitch(const char *dev, const char *name, ISState *sta if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { // tracking state - if (!strcmp(name, TrackStateSP.name)) + if (TrackStateSP.isNameMatch(name)) { - if (IUUpdateSwitch(&TrackStateSP, states, names, n) < 0) + if (TrackStateSP.update( states, names, n) == false) return false; - int trackState = IUFindOnSwitchIndex(&TrackStateSP); + int trackState = TrackStateSP.findOnSwitchIndex(); bool result = false; if (INDI::Telescope::TrackState != SCOPE_PARKED) @@ -180,16 +180,16 @@ bool LX200Skywalker::ISNewSwitch(const char *dev, const char *name, ISState *sta else LOG_WARN("Mount still parked"); - TrackStateSP.s = result ? IPS_OK : IPS_ALERT; - IDSetSwitch(&TrackStateSP, nullptr); + TrackStateSP.setState(result ? IPS_OK : IPS_ALERT); + TrackStateSP.apply(); return result; } // tracking mode - else if (!strcmp(name, TrackModeSP.name)) + else if (TrackModeSP.isNameMatch(name)) { - if (IUUpdateSwitch(&TrackModeSP, states, names, n) < 0) + if (TrackModeSP.update(states, names, n) == false) return false; - int trackMode = IUFindOnSwitchIndex(&TrackModeSP); + int trackMode = TrackModeSP.findOnSwitchIndex(); bool result = false; switch (trackMode) // ToDo: Custom tracking @@ -211,8 +211,8 @@ bool LX200Skywalker::ISNewSwitch(const char *dev, const char *name, ISState *sta break; } - TrackModeSP.s = result ? IPS_OK : IPS_ALERT; - IDSetSwitch(&TrackModeSP, nullptr); + TrackModeSP.setState(result ? IPS_OK : IPS_ALERT); + TrackModeSP.apply(); return result; } // mount state @@ -245,12 +245,12 @@ bool LX200Skywalker::ISNewSwitch(const char *dev, const char *name, ISState *sta IDSetSwitch(&MountStateSP, nullptr); return result; } - if (!strcmp(name, ParkSP.name)) + if (ParkSP.isNameMatch(name)) { if (LX200Telescope::ISNewSwitch(dev, name, states, names, n)) { - ParkSP.s = IPS_OK; //INDI::Telescope::SetParked(false) sets IPS_IDLE (!?) - IDSetSwitch(&ParkSP, nullptr); + ParkSP.setState(IPS_OK); //INDI::Telescope::SetParked(false) sets IPS_IDLE (!?) + ParkSP.apply(); return true; } else @@ -263,8 +263,8 @@ bool LX200Skywalker::ISNewSwitch(const char *dev, const char *name, ISState *sta if (index == -1) return false; ParkOptionSP.reset(); - if ((TrackState != SCOPE_IDLE && TrackState != SCOPE_TRACKING) || MovementNSSP.s == IPS_BUSY || - MovementWESP.s == IPS_BUSY) + if ((TrackState != SCOPE_IDLE && TrackState != SCOPE_TRACKING) || MovementNSSP.getState() == IPS_BUSY || + MovementWESP.getState() == IPS_BUSY) { LOG_WARN("Mount slewing or already parked..."); ParkOptionSP.setState(IPS_ALERT); @@ -421,8 +421,8 @@ void LX200Skywalker::getBasicData() if (INDI::Telescope::capability & TELESCOPE_CAN_PARK) { - ParkSP.s = IPS_OK; - IDSetSwitch(&ParkSP, nullptr); + ParkSP.setState(IPS_OK); + ParkSP.apply(); } if (genericCapability & LX200_HAS_ALIGNMENT_TYPE) @@ -450,11 +450,11 @@ void LX200Skywalker::getBasicData() if (INDI::Telescope::capability & TELESCOPE_HAS_TRACK_MODE) { - int trackMode = IUFindOnSwitchIndex(&TrackModeSP); + int trackMode = TrackModeSP.findOnSwitchIndex(); //int modes = sizeof(TelescopeTrackMode); (enum Sidereal, Solar, Lunar, Custom) int modes = TRACK_LUNAR; // ToDo: Custom tracking - TrackModeSP.s = (trackMode <= modes) ? IPS_OK : IPS_ALERT; - IDSetSwitch(&TrackModeSP, nullptr); + TrackModeSP.setState((trackMode <= modes) ? IPS_OK : IPS_ALERT); + TrackModeSP.apply(); } if (InitPark()) { @@ -465,8 +465,8 @@ void LX200Skywalker::getBasicData() { notifyMountLock(true); notifyTrackState(SCOPE_TRACKING); - ParkSP.s = IPS_OK; - IDSetSwitch(&ParkSP, nullptr); + ParkSP.setState(IPS_OK); + ParkSP.apply(); //LOG_INFO("Mount is working"); } else @@ -664,19 +664,19 @@ void LX200Skywalker::notifyTrackState(INDI::Telescope::TelescopeStatus state) { if (state == SCOPE_TRACKING) { - TrackStateS[TRACK_ON].s = ISS_ON; - TrackStateS[TRACK_OFF].s = ISS_OFF; - TrackStateSP.s = IPS_OK; + TrackStateSP[TRACK_ON].setState(ISS_ON); + TrackStateSP[TRACK_OFF].setState(ISS_OFF); + TrackStateSP.setState(IPS_OK); INDI::Telescope::TrackState = state; } else { - TrackStateS[TRACK_ON].s = ISS_OFF; - TrackStateS[TRACK_OFF].s = ISS_ON; - TrackStateSP.s = IPS_OK; + TrackStateSP[TRACK_ON].setState(ISS_OFF); + TrackStateSP[TRACK_OFF].setState(ISS_ON); + TrackStateSP.setState(IPS_OK); INDI::Telescope::TrackState = state; } - IDSetSwitch(&TrackStateSP, nullptr); + TrackStateSP.apply(); } /********************************************************************************* @@ -789,8 +789,8 @@ bool LX200Skywalker::SetCurrentPark() // Current mount position is copied into p // Libnova south = 0, west = 90, north = 180, east = 270 ln_lnlat_posn observer; - observer.lat = LocationN[LOCATION_LATITUDE].value; - observer.lng = LocationN[LOCATION_LONGITUDE].value; + observer.lat = LocationNP[LOCATION_LATITUDE].getValue(); + observer.lng = LocationNP[LOCATION_LONGITUDE].getValue(); if (observer.lng > 180) observer.lng -= 360; @@ -876,13 +876,14 @@ bool LX200Skywalker::SetSlewRate(int index) if (!isSimulation() && !setSlewMode(index)) { - SlewRateSP.s = IPS_ALERT; - IDSetSwitch(&SlewRateSP, "Error setting slew mode."); + SlewRateSP.setState(IPS_ALERT); + LOG_ERROR("Error setting slew mode."); + SlewRateSP.apply(); return false; } - SlewRateSP.s = IPS_OK; - IDSetSwitch(&SlewRateSP, nullptr); + SlewRateSP.setState(IPS_OK); + SlewRateSP.apply(); return true; } @@ -931,8 +932,9 @@ bool LX200Skywalker::setObjectCoords(double ra, double dec) // These commands receive a response without a terminating # if(!sendQuery(RAStr, response, '1', 2) || !sendQuery(DecStr, response, '1', 2) ) { - EqNP.s = IPS_ALERT; - IDSetNumber(&EqNP, "Error setting RA/DEC."); + EqNP.setState(IPS_ALERT); + LOG_ERROR("Error setting RA/DEC."); + EqNP.apply(); return false; } @@ -1026,28 +1028,31 @@ bool LX200Skywalker::Goto(double ra, double dec) fs_sexa(DecStr, targetDEC, 2, fracbase); // If moving, let's stop it first. - if (EqNP.s == IPS_BUSY) + if (EqNP.getState() == IPS_BUSY) { if (!isSimulation() && !Abort()) { - AbortSP.s = IPS_ALERT; - IDSetSwitch(&AbortSP, "Abort slew failed."); + AbortSP.setState(IPS_ALERT); + LOG_ERROR("Abort slew failed."); + AbortSP.apply(); return false; } - AbortSP.s = IPS_OK; - EqNP.s = IPS_IDLE; - IDSetSwitch(&AbortSP, "Slew aborted."); - IDSetNumber(&EqNP, nullptr); + AbortSP.setState(IPS_OK); + EqNP.setState(IPS_IDLE); + LOG_ERROR("Slew aborted."); + AbortSP.apply(); + EqNP.apply(); - if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY) + if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY) { - MovementNSSP.s = MovementWESP.s = IPS_IDLE; - EqNP.s = IPS_IDLE; - IUResetSwitch(&MovementNSSP); - IUResetSwitch(&MovementWESP); - IDSetSwitch(&MovementNSSP, nullptr); - IDSetSwitch(&MovementWESP, nullptr); + MovementNSSP.setState(IPS_IDLE); + MovementWESP.setState(IPS_IDLE); + EqNP.setState(IPS_IDLE); + MovementNSSP.reset(); + MovementWESP.reset(); + MovementNSSP.apply(); + MovementWESP.apply(); } // sleep for 100 mseconds @@ -1072,7 +1077,7 @@ bool LX200Skywalker::Goto(double ra, double dec) } TrackState = SCOPE_SLEWING; - EqNP.s = IPS_BUSY; + EqNP.setState(IPS_BUSY); LOGF_INFO("Slewing to RA: %s / DEC: %s", RAStr, DecStr); @@ -1125,8 +1130,9 @@ bool LX200Skywalker::Sync(double ra, double dec) if (!isSimulation() && !sendQuery(":CM#", response)) { - EqNP.s = IPS_ALERT; - IDSetNumber(&EqNP, "Synchronization failed."); + EqNP.setState(IPS_ALERT); + LOG_ERROR("Synchronization failed"); + EqNP.apply(); return false; } @@ -1135,7 +1141,7 @@ bool LX200Skywalker::Sync(double ra, double dec) LOG_INFO("Synchronization successful."); - EqNP.s = IPS_OK; + EqNP.setState(IPS_OK); NewRaDec(currentRA, currentDEC); @@ -1158,11 +1164,11 @@ bool LX200Skywalker::Sync(double ra, double dec) IDSetSwitch(&MountStateSP, nullptr); if (SetTrackEnabled(false)) { - TrackStateS[TRACK_ON].s = ISS_ON; - TrackStateS[TRACK_OFF].s = ISS_OFF; - TrackStateSP.s = IPS_ALERT; + TrackStateSP[TRACK_ON].setState(ISS_ON); + TrackStateSP[TRACK_OFF].setState(ISS_OFF); + TrackStateSP.setState(IPS_ALERT); // INDI::Telescope::TrackState = SCOPE_PARKED; // ALWAYS set status! - IDSetSwitch(&TrackStateSP, nullptr); + TrackStateSP.apply(); LOG_WARN("Telescope still parked!"); return false; } @@ -1175,11 +1181,11 @@ bool LX200Skywalker::Sync(double ra, double dec) // set tracking if (MountTracking()) // Normally tracking is set by TCS on syncing { - TrackStateS[TRACK_ON].s = ISS_ON; - TrackStateS[TRACK_OFF].s = ISS_OFF; - TrackStateSP.s = IPS_OK; + TrackStateSP[TRACK_ON].setState(ISS_ON); + TrackStateSP[TRACK_OFF].setState(ISS_OFF); + TrackStateSP.setState(IPS_OK); INDI::Telescope::TrackState = SCOPE_TRACKING; // ALWAYS set status! - IDSetSwitch(&TrackStateSP, nullptr); + TrackStateSP.apply(); } else { @@ -1216,8 +1222,8 @@ bool LX200Skywalker::UnPark() // INDI::Telescope::SetParked(false) sets TrackState = SCOPE_IDLE but TCS is tracking notifyTrackState(SCOPE_TRACKING); // INDI::Telescope::SetParked(false) sets ParkSP.S = IPS_IDLE but mount IS unparked! - ParkSP.s = IPS_OK; - IDSetSwitch(&ParkSP, nullptr); + ParkSP.setState(IPS_OK); + ParkSP.apply(); return SyncDefaultPark(); } else @@ -1258,8 +1264,8 @@ bool LX200Skywalker::SyncDefaultPark() // Saved mount position is loaded and syn ln_lnlat_posn observer; - observer.lat = LocationN[LOCATION_LATITUDE].value; - observer.lng = LocationN[LOCATION_LONGITUDE].value; + observer.lat = LocationNP[LOCATION_LATITUDE].getValue(); + observer.lng = LocationNP[LOCATION_LONGITUDE].getValue(); if (observer.lng > 180) observer.lng -= 360; @@ -1323,7 +1329,7 @@ bool LX200Skywalker::Abort() IPState LX200Skywalker::GuideNorth(uint32_t ms) { LOGF_DEBUG("%s %dms", __FUNCTION__, ms); - if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY) + if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY) { LOG_ERROR("Cannot guide while moving."); return IPS_ALERT; @@ -1334,7 +1340,7 @@ IPState LX200Skywalker::GuideNorth(uint32_t ms) IPState LX200Skywalker::GuideSouth(uint32_t ms) { LOGF_DEBUG("%s %dms", __FUNCTION__, ms); - if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY) + if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY) { LOG_ERROR("Cannot guide while moving."); return IPS_ALERT; @@ -1345,7 +1351,7 @@ IPState LX200Skywalker::GuideSouth(uint32_t ms) IPState LX200Skywalker::GuideEast(uint32_t ms) { LOGF_DEBUG("%s %dms", __FUNCTION__, ms); - if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY) + if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY) { LOG_ERROR("Cannot guide while moving."); return IPS_ALERT; @@ -1356,7 +1362,7 @@ IPState LX200Skywalker::GuideEast(uint32_t ms) IPState LX200Skywalker::GuideWest(uint32_t ms) { LOGF_DEBUG("%s %dms", __FUNCTION__, ms); - if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY) + if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY) { LOG_ERROR("Cannot guide while moving."); return IPS_ALERT; diff --git a/indi-avalon/lx200stargo.cpp b/indi-avalon/lx200stargo.cpp index 047c1ddcb..1544462a5 100644 --- a/indi-avalon/lx200stargo.cpp +++ b/indi-avalon/lx200stargo.cpp @@ -165,11 +165,11 @@ bool LX200StarGo::ISNewSwitch(const char *dev, const char *name, ISState *states return setParkPosition(states, names, n); } // tracking mode - else if (!strcmp(name, TrackModeSP.name)) + else if (TrackModeSP.isNameMatch(name)) { - if (IUUpdateSwitch(&TrackModeSP, states, names, n) < 0) + if (TrackModeSP.update(states, names, n) == false) return false; - uint8_t trackMode = static_cast(IUFindOnSwitchIndex(&TrackModeSP)); + uint8_t trackMode = static_cast(TrackModeSP.findOnSwitchIndex()); bool result = SetTrackMode(trackMode); @@ -185,9 +185,9 @@ bool LX200StarGo::ISNewSwitch(const char *dev, const char *name, ISState *states LOG_INFO("Lunar tracking rate selected"); break; } - TrackModeSP.s = result ? IPS_OK : IPS_ALERT; + TrackModeSP.setState(result ? IPS_OK : IPS_ALERT); - IDSetSwitch(&TrackModeSP, nullptr); + TrackModeSP.apply(); return result; } else if (!strcmp(name, ST4StatusSP.name)) @@ -923,13 +923,13 @@ bool LX200StarGo::sendScopeLocation() LOG_WARN("Failed to get site longitude from device."); return false; } - LocationNP.np[LOCATION_LATITUDE].value = siteLat; - LocationNP.np[LOCATION_LONGITUDE].value = siteLong; + LocationNP[LOCATION_LATITUDE].setValue(siteLat); + LocationNP[LOCATION_LONGITUDE].setValue(siteLong); - LOGF_DEBUG("Mount Controller Latitude: %lg Longitude: %lg", LocationN[LOCATION_LATITUDE].value, - LocationN[LOCATION_LONGITUDE].value); + LOGF_DEBUG("Mount Controller Latitude: %lg Longitude: %lg", LocationNP[LOCATION_LATITUDE].getValue(), + LocationNP[LOCATION_LONGITUDE].getValue()); - IDSetNumber(&LocationNP, nullptr); + LocationNP.apply(); if(!setLocalSiderealTime(siteLong)) { LOG_ERROR("Error setting local sidereal time"); @@ -1967,13 +1967,14 @@ bool LX200StarGo::SetSlewRate(int index) if (!isSimulation() && !setSlewMode(index)) { - SlewRateSP.s = IPS_ALERT; - IDSetSwitch(&SlewRateSP, "Error setting slew mode."); + SlewRateSP.setState(IPS_ALERT); + LOG_ERROR("Error setting slew mode."); + SlewRateSP.apply(); return false; } - SlewRateSP.s = IPS_OK; - IDSetSwitch(&SlewRateSP, nullptr); + SlewRateSP.setState(IPS_OK); + SlewRateSP.apply(); return true; } bool LX200StarGo::setSlewMode(int slewMode) @@ -2169,16 +2170,16 @@ bool LX200StarGo::GetMeridianFlipMode(int* index) IPState LX200StarGo::GuideNorth(uint32_t ms) { LOGF_DEBUG("%s %dms %d", __FUNCTION__, ms, usePulseCommand); - if (usePulseCommand && (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY)) + if (usePulseCommand && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)) { LOG_ERROR("Cannot guide while moving."); return IPS_ALERT; } // If already moving (no pulse command), then stop movement - if (MovementNSSP.s == IPS_BUSY) + if (MovementNSSP.getState() == IPS_BUSY) { - int dir = IUFindOnSwitchIndex(&MovementNSSP); + int dir = MovementNSSP.findOnSwitchIndex(); MoveNS(dir == 0 ? DIRECTION_NORTH : DIRECTION_SOUTH, MOTION_STOP); } @@ -2197,19 +2198,20 @@ IPState LX200StarGo::GuideNorth(uint32_t ms) { if (!setSlewMode(LX200_SLEW_GUIDE)) { - SlewRateSP.s = IPS_ALERT; - IDSetSwitch(&SlewRateSP, "Error setting slew mode."); + SlewRateSP.setState(IPS_ALERT); + LOG_ERROR("Error setting slew mode."); + SlewRateSP.apply(); return IPS_ALERT; } - MovementNSS[DIRECTION_NORTH].s = ISS_ON; + MovementNSSP[DIRECTION_NORTH].setState(ISS_ON); MoveNS(DIRECTION_NORTH, MOTION_START); } // Set slew to guiding - IUResetSwitch(&SlewRateSP); - SlewRateS[SLEW_GUIDE].s = ISS_ON; - IDSetSwitch(&SlewRateSP, nullptr); + SlewRateSP.reset(); + SlewRateSP[SLEW_GUIDE].setState(ISS_ON); + SlewRateSP.apply(); guide_direction_ns = LX200_NORTH; GuideNSTID = IEAddTimer(static_cast(ms), guideTimeoutHelperNS, this); return IPS_BUSY; @@ -2218,16 +2220,16 @@ IPState LX200StarGo::GuideNorth(uint32_t ms) IPState LX200StarGo::GuideSouth(uint32_t ms) { LOGF_DEBUG("%s %dms %d", __FUNCTION__, ms, usePulseCommand); - if (usePulseCommand && (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY)) + if (usePulseCommand && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)) { LOG_ERROR("Cannot guide while moving."); return IPS_ALERT; } // If already moving (no pulse command), then stop movement - if (MovementNSSP.s == IPS_BUSY) + if (MovementNSSP.getState() == IPS_BUSY) { - int dir = IUFindOnSwitchIndex(&MovementNSSP); + int dir = MovementNSSP.findOnSwitchIndex(); MoveNS(dir == 0 ? DIRECTION_NORTH : DIRECTION_SOUTH, MOTION_STOP); } @@ -2246,19 +2248,20 @@ IPState LX200StarGo::GuideSouth(uint32_t ms) { if (!setSlewMode(LX200_SLEW_GUIDE)) { - SlewRateSP.s = IPS_ALERT; - IDSetSwitch(&SlewRateSP, "Error setting slew mode."); + SlewRateSP.setState(IPS_ALERT); + LOG_ERROR("Error setting slew mode."); + SlewRateSP.apply(); return IPS_ALERT; } - MovementNSS[DIRECTION_SOUTH].s = ISS_ON; + MovementNSSP[DIRECTION_SOUTH].setState(ISS_ON); MoveNS(DIRECTION_SOUTH, MOTION_START); } // Set slew to guiding - IUResetSwitch(&SlewRateSP); - SlewRateS[SLEW_GUIDE].s = ISS_ON; - IDSetSwitch(&SlewRateSP, nullptr); + SlewRateSP.reset(); + SlewRateSP[SLEW_GUIDE].setState(ISS_ON); + SlewRateSP.apply(); guide_direction_ns = LX200_SOUTH; GuideNSTID = IEAddTimer(static_cast(ms), guideTimeoutHelperNS, this); return IPS_BUSY; @@ -2267,16 +2270,16 @@ IPState LX200StarGo::GuideSouth(uint32_t ms) IPState LX200StarGo::GuideEast(uint32_t ms) { LOGF_DEBUG("%s %dms %d", __FUNCTION__, ms, usePulseCommand); - if (usePulseCommand && (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY)) + if (usePulseCommand && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)) { LOG_ERROR("Cannot guide while moving."); return IPS_ALERT; } // If already moving (no pulse command), then stop movement - if (MovementWESP.s == IPS_BUSY) + if (MovementWESP.getState() == IPS_BUSY) { - int dir = IUFindOnSwitchIndex(&MovementWESP); + int dir = MovementWESP.findOnSwitchIndex(); MoveWE(dir == 0 ? DIRECTION_WEST : DIRECTION_EAST, MOTION_STOP); } @@ -2295,12 +2298,13 @@ IPState LX200StarGo::GuideEast(uint32_t ms) { if (!setSlewMode(LX200_SLEW_GUIDE)) { - SlewRateSP.s = IPS_ALERT; - IDSetSwitch(&SlewRateSP, "Error setting slew mode."); + SlewRateSP.setState(IPS_ALERT); + LOG_ERROR("Error setting slew mode."); + SlewRateSP.apply(); return IPS_ALERT; } - MovementWES[DIRECTION_EAST].s = ISS_ON; + MovementWESP[DIRECTION_EAST].setState(ISS_ON); MoveWE(DIRECTION_EAST, MOTION_START); } @@ -2308,9 +2312,9 @@ IPState LX200StarGo::GuideEast(uint32_t ms) updateGuidingStatistics(LX200_EAST, ms); // Set slew to guiding - IUResetSwitch(&SlewRateSP); - SlewRateS[SLEW_GUIDE].s = ISS_ON; - IDSetSwitch(&SlewRateSP, nullptr); + SlewRateSP.reset(); + SlewRateSP[SLEW_GUIDE].setState(ISS_ON); + SlewRateSP.apply(); guide_direction_we = LX200_EAST; GuideWETID = IEAddTimer(static_cast(ms), guideTimeoutHelperWE, this); return IPS_BUSY; @@ -2319,16 +2323,16 @@ IPState LX200StarGo::GuideEast(uint32_t ms) IPState LX200StarGo::GuideWest(uint32_t ms) { LOGF_DEBUG("%s %dms %d", __FUNCTION__, ms, usePulseCommand); - if (usePulseCommand && (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY)) + if (usePulseCommand && (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)) { LOG_ERROR("Cannot guide while moving."); return IPS_ALERT; } // If already moving (no pulse command), then stop movement - if (MovementWESP.s == IPS_BUSY) + if (MovementWESP.getState() == IPS_BUSY) { - int dir = IUFindOnSwitchIndex(&MovementWESP); + int dir = MovementWESP.findOnSwitchIndex(); MoveWE(dir == 0 ? DIRECTION_WEST : DIRECTION_EAST, MOTION_STOP); } @@ -2347,21 +2351,22 @@ IPState LX200StarGo::GuideWest(uint32_t ms) { if (!setSlewMode(LX200_SLEW_GUIDE)) { - SlewRateSP.s = IPS_ALERT; - IDSetSwitch(&SlewRateSP, "Error setting slew mode."); + SlewRateSP.setState(IPS_ALERT); + LOG_ERROR("Error setting slew mode."); + SlewRateSP.apply(); return IPS_ALERT; } - MovementWES[DIRECTION_WEST].s = ISS_ON; + MovementWESP[DIRECTION_WEST].setState(ISS_ON); MoveWE(DIRECTION_WEST, MOTION_START); } // update statistics for tracking optimization updateGuidingStatistics(LX200_WEST, ms); // Set slew to guiding - IUResetSwitch(&SlewRateSP); - SlewRateS[SLEW_GUIDE].s = ISS_ON; - IDSetSwitch(&SlewRateSP, nullptr); + SlewRateSP.reset(); + SlewRateSP[SLEW_GUIDE].setState(ISS_ON); + SlewRateSP.apply(); guide_direction_we = LX200_WEST; GuideWETID = IEAddTimer(static_cast(ms), guideTimeoutHelperWE, this); return IPS_BUSY; @@ -2459,10 +2464,10 @@ void LX200StarGo::ISGetProperties(const char *dev) LX200Telescope::ISGetProperties(dev); if (isConnected()) { - if (HasTrackMode() && TrackModeS != nullptr) - defineProperty(&TrackModeSP); + if (HasTrackMode() && TrackModeSP) + defineProperty(TrackModeSP); if (CanControlTrack()) - defineProperty(&TrackStateSP); + defineProperty(TrackStateSP); // if (HasTrackRate()) // defineProperty(&TrackRateNP); } @@ -2509,28 +2514,31 @@ bool LX200StarGo::Goto(double ra, double dec) // fs_sexa(DecStr, targetDEC, 2, fracbase); // If moving, let's stop it first. - if (EqNP.s == IPS_BUSY) + if (EqNP.getState() == IPS_BUSY) { if (!isSimulation() && !Abort()) { - AbortSP.s = IPS_ALERT; - IDSetSwitch(&AbortSP, "Abort slew failed."); + AbortSP.setState(IPS_ALERT); + LOG_ERROR("Abort slew failed."); + SlewRateSP.apply(); return false; } - AbortSP.s = IPS_OK; - EqNP.s = IPS_IDLE; - IDSetSwitch(&AbortSP, "Slew aborted."); - IDSetNumber(&EqNP, nullptr); + AbortSP.setState(IPS_OK); + EqNP.setState(IPS_IDLE); + LOG_ERROR("Slew aborted."); + SlewRateSP.apply(); + EqNP.apply(); - if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY) + if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY) { - MovementNSSP.s = MovementWESP.s = IPS_IDLE; - EqNP.s = IPS_IDLE; - IUResetSwitch(&MovementNSSP); - IUResetSwitch(&MovementWESP); - IDSetSwitch(&MovementNSSP, nullptr); - IDSetSwitch(&MovementWESP, nullptr); + MovementNSSP.setState(IPS_IDLE); + MovementWESP.setState(IPS_IDLE); + EqNP.setState(IPS_IDLE); + MovementNSSP.reset(); + MovementWESP.reset(); + MovementNSSP.apply(); + MovementWESP.apply(); } // sleep for 100 mseconds @@ -2651,8 +2659,9 @@ bool LX200StarGo::Sync(double ra, double dec) if (!isSimulation() && !sendQuery(":CM#", response)) { - EqNP.s = IPS_ALERT; - IDSetNumber(&EqNP, "Synchronization failed."); + EqNP.setState(IPS_ALERT); + LOG_ERROR("Synchronization failed."); + EqNP.apply(); return false; } @@ -2661,7 +2670,7 @@ bool LX200StarGo::Sync(double ra, double dec) LOG_INFO("Synchronization successful."); - EqNP.s = IPS_OK; + EqNP.setState(IPS_OK); NewRaDec(currentRA, currentDEC); @@ -2687,8 +2696,9 @@ bool LX200StarGo::setObjectCoords(double ra, double dec) // These commands receive a response without a terminating # if(!sendQuery(RAStr, response, '1', 2) || !sendQuery(DecStr, response, '1', 2) ) { - EqNP.s = IPS_ALERT; - IDSetNumber(&EqNP, "Error setting RA/DEC."); + EqNP.setState(IPS_ALERT); + LOG_ERROR("Error setting RA/DEC."); + EqNP.apply(); return false; } diff --git a/indi-avalonud/indi_avalonud_telescope.cpp b/indi-avalonud/indi_avalonud_telescope.cpp index 6e38a0921..3b96a3538 100644 --- a/indi-avalonud/indi_avalonud_telescope.cpp +++ b/indi-avalonud/indi_avalonud_telescope.cpp @@ -175,11 +175,11 @@ bool AUDTELESCOPE::initProperties() ParkOptionSP.fill(getDeviceName(), "TELESCOPE_PARK_OPTION", "Park Options", SITE_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE); // Since we have 4 slew rates, let's fill them out - IUFillSwitch(&SlewRateS[SLEW_GUIDE], "SLEW_GUIDE", "Guide", ISS_OFF); - IUFillSwitch(&SlewRateS[SLEW_CENTERING], "SLEW_CENTER", "Center", ISS_OFF); - IUFillSwitch(&SlewRateS[SLEW_FIND], "SLEW_FIND", "Find", ISS_OFF); - IUFillSwitch(&SlewRateS[SLEW_MAX], "SLEW_MAX", "Max", ISS_ON); - IUFillSwitchVector(&SlewRateSP, SlewRateS, 4, getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB, IP_RW, + SlewRateSP[SLEW_GUIDE].fill("SLEW_GUIDE", "Guide", ISS_OFF); + SlewRateSP[SLEW_CENTERING].fill("SLEW_CENTER", "Center", ISS_OFF); + SlewRateSP[SLEW_FIND].fill("SLEW_FIND", "Find", ISS_OFF); + SlewRateSP[SLEW_MAX].fill( "SLEW_MAX", "Max", ISS_ON); + SlewRateSP.fill(getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); // Add Tracking Modes. If you have SOLAR, LUNAR..etc, add them here as well. @@ -433,10 +433,10 @@ bool AUDTELESCOPE::Connect() free(IPaddress); return false; } - j["longitude"].get_to(LocationN[LOCATION_LONGITUDE].value); - j["latitude"].get_to(LocationN[LOCATION_LATITUDE].value); - j["elevation"].get_to(LocationN[LOCATION_ELEVATION].value); - IDSetNumber(&LocationNP, nullptr); + j["longitude"].get_to(LocationNP[LOCATION_LONGITUDE].value); + j["latitude"].get_to(LocationNP[LOCATION_LATITUDE].value); + j["elevation"].get_to(LocationNP[LOCATION_ELEVATION].value); + LocationNP.apply(); } else { @@ -776,7 +776,7 @@ bool AUDTELESCOPE::ReadScopeStatus() MeridianFlipHANP.apply(); setPierSide((TelescopePierSide)pierside); - if (LocalEqNP[LEQ_HA].value != ha || LocalEqNP[LEQ_DEC].value != dec || LocalEqNP.getState() != EqNP.s) + if (LocalEqNP[LEQ_HA].value != ha || LocalEqNP[LEQ_DEC].value != dec || LocalEqNP.getState() != EqNP.getState()) { LocalEqNP[LEQ_HA].value = ha; LocalEqNP[LEQ_DEC].value = dec; @@ -784,7 +784,7 @@ bool AUDTELESCOPE::ReadScopeStatus() LocalEqNP.apply(); } - if (AltAzNP[ALTAZ_AZ].value != az || AltAzNP[ALTAZ_ALT].value != alt || AltAzNP.getState() != EqNP.s) + if (AltAzNP[ALTAZ_AZ].value != az || AltAzNP[ALTAZ_ALT].value != alt || AltAzNP.getState() != EqNP.getState()) { AltAzNP[ALTAZ_AZ].value = az; AltAzNP[ALTAZ_ALT].value = alt; @@ -888,14 +888,14 @@ bool AUDTELESCOPE::Park() answer = sendCommand("ASTRO_PARK"); if ( !answer ) { - ParkSP.s = IPS_BUSY; - IDSetSwitch(&ParkSP, NULL); + ParkSP.setState(IPS_BUSY); + ParkSP.apply(); TrackState = SCOPE_PARKING; DEBUG(INDI::Logger::DBG_SESSION, "Start telescope park completed"); return true; } - ParkSP.s = IPS_ALERT; - IDSetSwitch(&ParkSP, NULL); + ParkSP.setState(IPS_ALERT); + ParkSP.apply(); TrackState = SCOPE_IDLE; DEBUGF(INDI::Logger::DBG_WARNING, "Start telescope park failed due to %s", answer); free(answer); @@ -1093,8 +1093,8 @@ bool AUDTELESCOPE::SetTrackMode(uint8_t mode) trackspeeddec = 0; break; case TRACK_CUSTOM: - trackspeedra = TrackRateN[AXIS_RA].value; - trackspeeddec = TrackRateN[AXIS_DE].value; + trackspeedra = TrackRateNP[AXIS_RA].getValue(); + trackspeeddec = TrackRateNP[AXIS_DE].getValue(); break; } if ( TrackState == SCOPE_TRACKING ) @@ -1115,18 +1115,18 @@ bool AUDTELESCOPE::SetTrackRate(double raRate, double deRate) } DEBUGF(INDI::Logger::DBG_SESSION, "Tracking change to RA:%f\"/s Dec:%f\"/s ...", raRate, deRate); - TrackStateSP.s = IPS_BUSY; + TrackStateSP.setState(IPS_BUSY); answer = sendCommand("ASTRO_TRACK %.8f %.8f", raRate / 3600.0, deRate / 3600.0); if ( !answer ) { if ( ( raRate == 0 ) && ( deRate == 0 ) ) - TrackStateSP.s = IPS_IDLE; + TrackStateSP.setState(IPS_IDLE); else - TrackStateSP.s = IPS_OK; + TrackStateSP.setState(IPS_OK); DEBUGF(INDI::Logger::DBG_SESSION, "Tracking change to RA:%f\"/s Dec:%f\"/s completed", raRate, deRate); return true; } - TrackStateSP.s = IPS_ALERT; + TrackStateSP.setState(IPS_ALERT); DEBUGF(INDI::Logger::DBG_WARNING, "Tracking change to RA:%f\"/s Dec:%f\"/s failed due to %s", raRate, deRate, answer); free(answer); return false; @@ -1139,7 +1139,7 @@ bool AUDTELESCOPE::SetTrackEnabled(bool enabled) DEBUGF(INDI::Logger::DBG_SESSION, "Change tracking to %s...", ((enabled) ? "ENABLED" : "DISABLED")); if ( enabled ) { - int mode = IUFindOnSwitchIndex(&TrackModeSP); + int mode = TrackModeSP.findOnSwitchIndex(); SetTrackMode(mode); if ( TrackState != SCOPE_TRACKING ) rc = SetTrackRate( trackspeedra, trackspeeddec ); @@ -1167,8 +1167,8 @@ bool AUDTELESCOPE::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) return false; } - speedIndex = IUFindOnSwitchIndex(&SlewRateSP); - MovementNSSP.s = IPS_BUSY; + speedIndex = SlewRateSP.findOnSwitchIndex(); + MovementNSSP.setState(IPS_BUSY); if ( command == MOTION_START ) { // force tracking after motion @@ -1188,12 +1188,12 @@ bool AUDTELESCOPE::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) if ( !answer ) { if ( command == MOTION_START ) - MovementNSSP.s = IPS_OK; + MovementNSSP.setState(IPS_OK); else - MovementNSSP.s = IPS_IDLE; + MovementNSSP.setState(IPS_IDLE); return true; } - MovementNSSP.s = IPS_ALERT; + MovementNSSP.setState(IPS_ALERT); DEBUGF(INDI::Logger::DBG_WARNING, "MoveNS command failed due to %s", answer); free(answer); return false; @@ -1212,8 +1212,8 @@ bool AUDTELESCOPE::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) return false; } - speedIndex = IUFindOnSwitchIndex(&SlewRateSP); - MovementWESP.s = IPS_BUSY; + speedIndex = SlewRateSP.findOnSwitchIndex(); + MovementWESP.setState(IPS_BUSY); if ( command == MOTION_START ) { // force tracking after motion @@ -1233,12 +1233,12 @@ bool AUDTELESCOPE::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) if ( !answer ) { if ( command == MOTION_START ) - MovementWESP.s = IPS_OK; + MovementWESP.setState(IPS_OK); else - MovementWESP.s = IPS_IDLE; + MovementWESP.setState(IPS_IDLE); return true; } - MovementWESP.s = IPS_ALERT; + MovementWESP.setState(IPS_ALERT); DEBUGF(INDI::Logger::DBG_WARNING, "MoveWE command failed due to %s", answer); free(answer); return false; @@ -1368,7 +1368,7 @@ bool AUDTELESCOPE::Abort() return false; } - AbortSP.s = IPS_OK; + AbortSP.setState(IPS_OK); DEBUG(INDI::Logger::DBG_SESSION, "Telescope abort ..."); @@ -1379,9 +1379,9 @@ bool AUDTELESCOPE::Abort() free(answer); } - AbortSP.s = IPS_IDLE; - IUResetSwitch(&AbortSP); - IDSetSwitch(&AbortSP, NULL); + AbortSP.setState(IPS_IDLE); + AbortSP.reset(); + AbortSP.apply(); slewState = IPS_IDLE; @@ -1396,7 +1396,7 @@ void AUDTELESCOPE::TimerHit() return; ReadScopeStatus(); - IDSetNumber(&EqNP, NULL); + EqNP.apply(); SetTimer(getCurrentPollingPeriod()); } diff --git a/indi-celestronaux/celestronaux.cpp b/indi-celestronaux/celestronaux.cpp index 7d9848a03..26325aff6 100644 --- a/indi-celestronaux/celestronaux.cpp +++ b/indi-celestronaux/celestronaux.cpp @@ -1204,7 +1204,7 @@ void CelestronAUX::syncCoordWrapPosition() ///////////////////////////////////////////////////////////////////////////////////// bool CelestronAUX::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) { - int rate = IUFindOnSwitchIndex(&SlewRateSP) + 1; + int rate = SlewRateSP.findOnSwitchIndex() + 1; m_AxisDirection[AXIS_ALT] = (dir == DIRECTION_NORTH) ? FORWARD : REVERSE; m_AxisStatus[AXIS_ALT] = (command == MOTION_START) ? SLEWING : STOPPED; ScopeStatus = SLEWING_MANUAL; @@ -1223,7 +1223,7 @@ bool CelestronAUX::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) ///////////////////////////////////////////////////////////////////////////////////// bool CelestronAUX::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) { - int rate = IUFindOnSwitchIndex(&SlewRateSP) + 1; + int rate = SlewRateSP.findOnSwitchIndex() + 1; if (isNorthHemisphere()) m_AxisDirection[AXIS_AZ] = (dir == DIRECTION_WEST) ? FORWARD : REVERSE; else @@ -1495,7 +1495,7 @@ bool CelestronAUX::ReadScopeStatus() // For equatorial mounts, engage tracking. if (m_MountType != ALT_AZ) - SetTrackMode(IUFindOnSwitchIndex(&TrackModeSP)); + SetTrackMode(TrackModeSP.findOnSwitchIndex()); LOG_INFO("Tracking started."); } else @@ -1808,10 +1808,10 @@ bool CelestronAUX::enforceSlewLimits() Abort(); - if (EqNP.s != IPS_IDLE) + if (EqNP.getState() != IPS_IDLE) { - EqNP.s = IPS_ALERT; - IDSetNumber(&EqNP, nullptr); + EqNP.setState(IPS_ALERT); + EqNP.apply(); } if (HorizontalCoordsNP.getState() != IPS_IDLE) @@ -1826,23 +1826,23 @@ bool CelestronAUX::enforceSlewLimits() HomeSP.apply(); } - if (MovementNSSP.s != IPS_IDLE) + if (MovementNSSP.getState() != IPS_IDLE) { - MovementNSSP.s = IPS_ALERT; - IDSetSwitch(&MovementNSSP, nullptr); + MovementNSSP.setState(IPS_ALERT); + MovementNSSP.apply(); } - if (MovementWESP.s != IPS_IDLE) + if (MovementWESP.getState() != IPS_IDLE) { - MovementWESP.s = IPS_ALERT; - IDSetSwitch(&MovementWESP, nullptr); + MovementWESP.setState(IPS_ALERT); + MovementWESP.apply(); } - if (TrackStateSP.s != IPS_IDLE) + if (TrackStateSP.getState() != IPS_IDLE) { - TrackStateSP.s = IPS_ALERT; - IDSetSwitch(&TrackStateSP, nullptr); + TrackStateSP.setState(IPS_ALERT); + TrackStateSP.apply(); } return false; @@ -1877,8 +1877,8 @@ void CelestronAUX::TimerHit() m_ManualMotionActive = false; // If we slewed manually using NSWE keys, then we need to restart tracking // whatever point we are AT now. We need to update the SkyTrackingTarget accordingly. - m_SkyTrackingTarget.rightascension = EqN[AXIS_RA].value; - m_SkyTrackingTarget.declination = EqN[AXIS_DE].value; + m_SkyTrackingTarget.rightascension = EqNP[AXIS_RA].getValue(); + m_SkyTrackingTarget.declination = EqNP[AXIS_DE].getValue(); resetTracking(); } // If we're manually moving by WESN controls, update the tracking coordinates. @@ -2176,7 +2176,7 @@ void CelestronAUX::EncodersToRADE(INDI::IEquatorialCoordinates &coords, Telescop auto deEncoder = 360.0 - (EncoderNP[AXIS_DE].getValue() / STEPS_PER_REVOLUTION) * 360.0; // Northern Hemisphere - if (LocationN[LOCATION_LATITUDE].value >= 0) + if (LocationNP[LOCATION_LATITUDE].getValue() >= 0) { pierSide = PIER_UNKNOWN; if (deEncoder >= 270) @@ -2216,14 +2216,14 @@ void CelestronAUX::EncodersToRADE(INDI::IEquatorialCoordinates &coords, Telescop // Pier Side West range: +90 to -90 (Mechanically 2^24*0.25 to 2^24*0.75) auto deEncoder = (EncoderNP[AXIS_DE].getValue() / STEPS_PER_REVOLUTION) * 360.0; - de = LocationN[LOCATION_LATITUDE].value >= 0 ? deEncoder : -deEncoder; - ha = LocationN[LOCATION_LATITUDE].value >= 0 ? range24(haEncoder / 15.0) : range24((180 - haEncoder) / 15.0); + de = LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? deEncoder : -deEncoder; + ha = LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? range24(haEncoder / 15.0) : range24((180 - haEncoder) / 15.0); //pierSide = LocationN[LOCATION_LATITUDE].value >= 0 ? PIER_EAST : PIER_WEST; pierSide = PIER_EAST; // "Normal" Pointing State (West, looking East) - if ( (LocationN[LOCATION_LATITUDE].value >= 0 && (deEncoder < 90 || deEncoder > 270)) || - (LocationN[LOCATION_LATITUDE].value < 0 && deEncoder > 90 && deEncoder < 270)) + if ( (LocationNP[LOCATION_LATITUDE].getValue() >= 0 && (deEncoder < 90 || deEncoder > 270)) || + (LocationNP[LOCATION_LATITUDE].getValue() < 0 && deEncoder > 90 && deEncoder < 270)) { pierSide = PIER_WEST; de = rangeDec(180 - de); @@ -2235,7 +2235,7 @@ void CelestronAUX::EncodersToRADE(INDI::IEquatorialCoordinates &coords, Telescop de = (de + 180) * -1; } - double lst = get_local_sidereal_time(LocationN[LOCATION_LONGITUDE].value); + double lst = get_local_sidereal_time(LocationNP[LOCATION_LONGITUDE].getValue()); double ra = range24(lst - ha); coords.rightascension = ra; @@ -2264,13 +2264,13 @@ void CelestronAUX::EncodersToRADE(INDI::IEquatorialCoordinates &coords, Telescop ///////////////////////////////////////////////////////////////////////////////////// void CelestronAUX::RADEToEncoders(const INDI::IEquatorialCoordinates &coords, uint32_t &haEncoder, uint32_t &deEncoder) { - double lst = get_local_sidereal_time(LocationN[LOCATION_LONGITUDE].value); + double lst = get_local_sidereal_time(LocationNP[LOCATION_LONGITUDE].getValue()); double dHA = rangeHA(lst - coords.rightascension); double de = 0, ha = 0; if (m_MountType == EQ_FORK) { - if (LocationN[LOCATION_LATITUDE].value >= 0) + if (LocationNP[LOCATION_LATITUDE].getValue() >= 0) { if (coords.declination < 0) de = -coords.declination; @@ -2302,7 +2302,7 @@ void CelestronAUX::RADEToEncoders(const INDI::IEquatorialCoordinates &coords, ui else { // Northern Hemisphere - if (LocationN[LOCATION_LATITUDE].value >= 0) + if (LocationNP[LOCATION_LATITUDE].getValue() >= 0) { // "Normal" Pointing State (East, looking West) @@ -2772,13 +2772,13 @@ bool CelestronAUX::SetTrackEnabled(bool enabled) { TrackState = SCOPE_TRACKING; resetTracking(); - m_SkyTrackingTarget.rightascension = EqN[AXIS_RA].value; - m_SkyTrackingTarget.declination = EqN[AXIS_DE].value; + m_SkyTrackingTarget.rightascension = EqNP[AXIS_RA].getValue(); + m_SkyTrackingTarget.declination = EqNP[AXIS_DE].getValue(); - if (IUFindOnSwitchIndex(&TrackModeSP) == TRACK_CUSTOM) - return SetTrackRate(TrackRateN[AXIS_AZ].value, TrackRateN[AXIS_ALT].value); + if (TrackModeSP.findOnSwitchIndex() == TRACK_CUSTOM) + return SetTrackRate(TrackRateNP[AXIS_AZ].getValue(), TrackRateNP[AXIS_ALT].getValue()); else - return SetTrackMode(IUFindOnSwitchIndex(&TrackModeSP)); + return SetTrackMode(TrackModeSP.findOnSwitchIndex()); } else { @@ -2830,8 +2830,8 @@ bool CelestronAUX::SetTrackMode(uint8_t mode) m_TrackRates[AXIS_AZ] = TRACKRATE_LUNAR; else if (mode == TRACK_CUSTOM) { - m_TrackRates[AXIS_AZ] = TrackRateN[AXIS_RA].value; - m_TrackRates[AXIS_ALT] = TrackRateN[AXIS_DE].value; + m_TrackRates[AXIS_AZ] = TrackRateNP[AXIS_RA].getValue(); + m_TrackRates[AXIS_ALT] = TrackRateNP[AXIS_DE].getValue(); } if (TrackState == SCOPE_TRACKING) @@ -2911,13 +2911,13 @@ void CelestronAUX::emulateGPS(AUXCommand &m) case GPS_GET_LAT: case GPS_GET_LONG: { - LOGF_DEBUG("GPS: Sending LAT/LONG Lat:%f Lon:%f", LocationN[LOCATION_LATITUDE].value, - LocationN[LOCATION_LONGITUDE].value); + LOGF_DEBUG("GPS: Sending LAT/LONG Lat:%f Lon:%f", LocationNP[LOCATION_LATITUDE].getValue(), + LocationNP[LOCATION_LONGITUDE].getValue()); AUXCommand cmd(m.command(), GPS, m.source()); if (m.command() == GPS_GET_LAT) - cmd.setData(STEPS_PER_DEGREE * LocationN[LOCATION_LATITUDE].value); + cmd.setData(STEPS_PER_DEGREE * LocationNP[LOCATION_LATITUDE].getValue()); else - cmd.setData(STEPS_PER_DEGREE * LocationN[LOCATION_LONGITUDE].value); + cmd.setData(STEPS_PER_DEGREE * LocationNP[LOCATION_LONGITUDE].getValue()); sendAUXCommand(cmd); //readAUXResponse(cmd); break; diff --git a/indi-eqmod/eqmodbase.cpp b/indi-eqmod/eqmodbase.cpp index ff9bcf365..ba56c98b7 100644 --- a/indi-eqmod/eqmodbase.cpp +++ b/indi-eqmod/eqmodbase.cpp @@ -188,12 +188,16 @@ const char *EQMod::getDefaultName() double EQMod::getLongitude() { - return (IUFindNumber(&LocationNP, "LONG")->value); + auto number = LocationNP.findWidgetByName("LONG"); + if(number) + return number->getValue(); } double EQMod::getLatitude() { - return (IUFindNumber(&LocationNP, "LAT")->value); + auto number = LocationNP.findWidgetByName("LAT"); + if(number) + return number->getValue(); } double EQMod::getJulianDate() @@ -290,19 +294,21 @@ bool EQMod::initProperties() void EQMod::initSlewRates() { - for (int i = 0; i < SlewRateSP.nsp - 1; i++) + for (size_t i = 0; i < SlewRateSP.count() - 1; i++) { - SlewRateSP.sp[i].s = ISS_OFF; - sprintf(SlewRateSP.sp[i].label, "%.fx", slewspeeds[i]); - SlewRateSP.sp[i].aux = (void *)&slewspeeds[i]; + SlewRateSP[i].setState(ISS_OFF); + SlewRateSP[i].setLabel(std::to_string(slewspeeds[i]) + "x"); + + SlewRateSP[i].setAux((void *)&slewspeeds[i]); } // Since last item is NOT maximum (but custom), let's set item before custom to SLEWMAX - SlewRateSP.sp[SlewRateSP.nsp - 2].s = ISS_ON; - strncpy(SlewRateSP.sp[SlewRateSP.nsp - 2].name, "SLEW_MAX", MAXINDINAME); + SlewRateSP[SlewRateSP.count() - 2].setState(ISS_ON); + SlewRateSP[SlewRateSP.count() -2].setName("SLEW_MAX"); // Last is custom - strncpy(SlewRateSP.sp[SlewRateSP.nsp - 1].name, "SLEWCUSTOM", MAXINDINAME); - strncpy(SlewRateSP.sp[SlewRateSP.nsp - 1].label, "Custom", MAXINDILABEL); + SlewRateSP[SlewRateSP.count() -1].setName("SLEWCUSTOM"); + SlewRateSP[SlewRateSP.count() -1].setLabel("Custom"); + } void EQMod::ISGetProperties(const char *dev) @@ -590,11 +596,11 @@ bool EQMod::updateProperties() parkRAEncoder = GetAxis1Park(); parkDEEncoder = GetAxis2Park(); - INumber *latitude = IUFindNumber(&LocationNP, "LAT"); - INumber *longitude = IUFindNumber(&LocationNP, "LONG"); - INumber *elevation = IUFindNumber(&LocationNP, "ELEV"); + auto latitude = LocationNP.findWidgetByName("LAT"); + auto longitude = LocationNP.findWidgetByName("LONG"); + auto elevation = LocationNP.findWidgetByName("ELEV"); if (latitude && longitude && elevation) - updateLocation(latitude->value, longitude->value, elevation->value); + updateLocation(latitude->getValue(), longitude->getValue(), elevation->getValue()); sendTimeFromSystem(); } @@ -777,8 +783,8 @@ void EQMod::TimerHit() if (rc == false) { // read was not good - EqNP.s = IPS_ALERT; - IDSetNumber(&EqNP, nullptr); + EqNP.setState(IPS_ALERT); + EqNP.apply(); } SetTimer(getCurrentPollingPeriod()); @@ -1012,7 +1018,7 @@ bool EQMod::ReadScopeStatus() if (RememberTrackState == SCOPE_TRACKING) { - sw = IUFindOnSwitch(&TrackModeSP); + sw = TrackModeSP.findOnSwitch(); name = sw->name; mount->StartRATracking(GetRATrackRate()); mount->StartDETracking(GetDETrackRate()); @@ -1647,7 +1653,7 @@ double EQMod::GetRATrackRate() { double rate = 0.0; ISwitch *sw; - sw = IUFindOnSwitch(&TrackModeSP); + sw = TrackModeSP.findOnSwitch(); if (!sw) return 0.0; if (!strcmp(sw->name, "TRACK_SIDEREAL")) @@ -1664,7 +1670,9 @@ double EQMod::GetRATrackRate() } else if (!strcmp(sw->name, "TRACK_CUSTOM")) { - rate = IUFindNumber(&TrackRateNP, "TRACK_RATE_RA")->value; + auto number = TrackRateNP.findWidgetByName("TRACK_RATE_RA"); + if(number) + rate = number->getValue(); } else return 0.0; @@ -1677,7 +1685,7 @@ double EQMod::GetDETrackRate() { double rate = 0.0; ISwitch *sw; - sw = IUFindOnSwitch(&TrackModeSP); + sw = TrackModeSP.findOnSwitch(); if (!sw) return 0.0; if (!strcmp(sw->name, "TRACK_SIDEREAL")) @@ -1694,7 +1702,9 @@ double EQMod::GetDETrackRate() } else if (!strcmp(sw->name, "TRACK_CUSTOM")) { - rate = IUFindNumber(&TrackRateNP, "TRACK_RATE_DE")->value; + auto number = TrackRateNP.findWidgetByName("TRACK_RATE_DE"); + if(number) + rate = number->getValue(); } else return 0.0; @@ -1706,25 +1716,26 @@ double EQMod::GetDETrackRate() double EQMod::GetDefaultRATrackRate() { double rate = 0.0; - ISwitch *sw; - sw = TrackDefaultSP.findOnSwitch(); - if (!sw) + auto element = TrackDefaultSP.findOnSwitch(); + if (!element) return 0.0; - if (!strcmp(sw->name, "TRACK_SIDEREAL")) + if (element->isNameMatch("TRACK_SIDEREAL")) { rate = TRACKRATE_SIDEREAL; } - else if (!strcmp(sw->name, "TRACK_LUNAR")) + else if (element->isNameMatch("TRACK_LUNAR")) { rate = TRACKRATE_LUNAR; } - else if (!strcmp(sw->name, "TRACK_SOLAR")) + else if (element->isNameMatch("TRACK_SOLAR")) { rate = TRACKRATE_SOLAR; } - else if (!strcmp(sw->name, "TRACK_CUSTOM")) + else if (element->isNameMatch("TRACK_CUSTOM")) { - rate = IUFindNumber(&TrackRateNP, "TRACK_RATE_RA")->value; + auto number = TrackRateNP.findWidgetByName("TRACK_RATE_RA"); + if(number) + rate = number->getValue(); } else return 0.0; @@ -1754,7 +1765,9 @@ double EQMod::GetDefaultDETrackRate() } else if (!strcmp(sw->name, "TRACK_CUSTOM")) { - rate = IUFindNumber(&TrackRateNP, "TRACK_RATE_DE")->value; + auto number = TrackRateNP.findWidgetByName("TRACK_RATE_DE"); + if(number) + rate = number->getValue(); } else return 0.0; @@ -1975,8 +1988,8 @@ bool EQMod::Park() if (TrackState == SCOPE_SLEWING) { LOG_INFO("Can not park while slewing..."); - ParkSP.s = IPS_ALERT; - IDSetSwitch(&ParkSP, nullptr); + ParkSP.setState(IPS_ALERT); + ParkSP.apply(); return false; } @@ -3046,7 +3059,7 @@ double EQMod::GetRASlew() { ISwitch *sw; double rate = 1.0; - sw = IUFindOnSwitch(&SlewRateSP); + sw = SlewRateSP.findOnSwitch(); if (!strcmp(sw->name, "SLEWCUSTOM")) rate = SlewSpeedsNP.findWidgetByName("RASLEW")->getValue(); else @@ -3058,7 +3071,7 @@ double EQMod::GetDESlew() { ISwitch *sw; double rate = 1.0; - sw = IUFindOnSwitch(&SlewRateSP); + sw = SlewRateSP.findOnSwitch(); if (!strcmp(sw->name, "SLEWCUSTOM")) rate = SlewSpeedsNP.findWidgetByName("DESLEW")->getValue(); else @@ -3584,7 +3597,7 @@ bool EQMod::SetTrackEnabled(bool enabled) { if (enabled) { - LOGF_INFO("Start Tracking (%s).", IUFindOnSwitch(&TrackModeSP)->label); + LOGF_INFO("Start Tracking (%s).", TrackModeSP.findOnSwitch()->getLabel()); TrackState = SCOPE_TRACKING; RememberTrackState = TrackState; mount->StartRATracking(GetRATrackRate()); @@ -3592,7 +3605,7 @@ bool EQMod::SetTrackEnabled(bool enabled) } else if (enabled == false) { - LOGF_WARN("Stopping Tracking (%s).", IUFindOnSwitch(&TrackModeSP)->label); + LOGF_WARN("Stopping Tracking (%s).", TrackModeSP.findOnSwitch()->getLabel()); TrackState = SCOPE_IDLE; RememberTrackState = TrackState; mount->StopRA(); diff --git a/indi-starbook-ten/indi_starbook_ten.cpp b/indi-starbook-ten/indi_starbook_ten.cpp index e6af841d4..3ce661158 100644 --- a/indi-starbook-ten/indi_starbook_ten.cpp +++ b/indi-starbook-ten/indi_starbook_ten.cpp @@ -146,16 +146,16 @@ INDIStarbookTen::initProperties() IUFillTextVector(&StateTP, StateT, MS_LAST, getDeviceName(), "MOUNT_STATE", "Status", MOUNT_TAB, IP_RO, 60, IPS_IDLE); - IUFillSwitch(&SlewRateS[0], "0.5x", "0.5x", ISS_OFF); - IUFillSwitch(&SlewRateS[1], "1x", "1x", ISS_OFF); - IUFillSwitch(&SlewRateS[2], "2x", "2x", ISS_OFF); - IUFillSwitch(&SlewRateS[3], "5x", "5x", ISS_OFF); - IUFillSwitch(&SlewRateS[4], "10x", "10x", ISS_OFF); - IUFillSwitch(&SlewRateS[5], "30x", "30x", ISS_ON); - IUFillSwitch(&SlewRateS[6], "100x", "100x", ISS_OFF); - IUFillSwitch(&SlewRateS[7], "300x", "300x", ISS_OFF); - IUFillSwitch(&SlewRateS[8], "500x", "500x", ISS_OFF); - IUFillSwitchVector(&SlewRateSP, SlewRateS, 9, getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); + SlewRateSP[0].fill("0.5x", "0.5x", ISS_OFF); + SlewRateSP[1].fill("1x", "1x", ISS_OFF); + SlewRateSP[2].fill("2x", "2x", ISS_OFF); + SlewRateSP[3].fill("5x", "5x", ISS_OFF); + SlewRateSP[4].fill("10x", "10x", ISS_OFF); + SlewRateSP[5].fill("30x", "30x", ISS_ON); + SlewRateSP[6].fill("100x", "100x", ISS_OFF); + SlewRateSP[7].fill("300x", "300x", ISS_OFF); + SlewRateSP[8].fill("500x", "500x", ISS_OFF); + SlewRateSP.fill(getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); IUFillNumber(&GuideRateN[GR_RA], "RA_GUIDE_RATE", "RA (arcsec/sec)", "%.0f", 0, 30, 1, 15); IUFillNumber(&GuideRateN[GR_DE], "DE_GUIDE_RATE", "DEC (arcsec/sec)", "%.0f", 0, 30, 1, 15); @@ -342,22 +342,22 @@ INDIStarbookTen::fetchStartupInfo() IDSetText(&InfoTP, nullptr); double lon = std::get<1>(loc); - LocationN[LOCATION_LATITUDE].value = std::get<0>(loc); - LocationN[LOCATION_LONGITUDE].value = (lon < 0) ? (lon + 360) : lon; - LocationNP.s = IPS_OK; - IDSetNumber(&LocationNP, nullptr); + LocationNP[LOCATION_LATITUDE].setValue(std::get<0>(loc)); + LocationNP[LOCATION_LONGITUDE].setValue((lon < 0) ? (lon + 360) : lon); + LocationNP.setState(IPS_OK); + LocationNP.apply(); char str[128]; snprintf(str, sizeof(str) - 1, "%04d-%02d-%02dT%02d:%02d:%02d", zdt.years, zdt.months, zdt.days, zdt.hours, zdt.minutes, (int)zdt.seconds); - IUSaveText(&TimeT[0], str); + TimeTP[0].setText(str); snprintf(str, sizeof(str) - 1, "%.2f", (zdt.gmtoff / 3600.0)); - IUSaveText(&TimeT[1], str); + TimeTP[1].setText(str); - TimeTP.s = IPS_OK; - IDSetText(&TimeTP, nullptr); + TimeTP.setState(IPS_OK); + TimeTP.apply(); return updateStarbookState(stat); } @@ -485,7 +485,7 @@ INDIStarbookTen::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) { if (command == MOTION_START) { - double absrate = StarbookTen::slewRates[IUFindOnSwitchIndex(&SlewRateSP)]; + double absrate = StarbookTen::slewRates[SlewRateSP.findOnSwitchIndex()]; double rate = (dir == DIRECTION_NORTH) ? absrate : -absrate; return retry(2, &StarbookTen::move, starbook, StarbookTen::AXIS_SECONDARY, rate); } @@ -509,7 +509,7 @@ INDIStarbookTen::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) { if (command == MOTION_START) { - double absrate = StarbookTen::slewRates[IUFindOnSwitchIndex(&SlewRateSP)]; + double absrate = StarbookTen::slewRates[SlewRateSP.findOnSwitchIndex()]; double rate = (dir == DIRECTION_EAST) ? absrate : -absrate; return retry(2, &StarbookTen::move, starbook, StarbookTen::AXIS_PRIMARY, rate); } diff --git a/indi-starbook/indi_starbook.cpp b/indi-starbook/indi_starbook.cpp index 4bfaeb9e2..854871077 100644 --- a/indi-starbook/indi_starbook.cpp +++ b/indi-starbook/indi_starbook.cpp @@ -299,7 +299,7 @@ bool StarbookDriver::updateLocation(double latitude, double longitude, double el LOGF_WARN("Cannot update location in %s state", starbook::STATE_TO_STR.at(last_known_state).c_str()); return false; } - if (TimeT[1].text == nullptr) + if (TimeTP[1].getText() == nullptr) { LOG_WARN("Cannot update location before time"); return false; @@ -309,7 +309,7 @@ bool StarbookDriver::updateLocation(double latitude, double longitude, double el if (longitude > 180) longitude -= 360; - auto utc_offset = static_cast(std::floor(std::strtof(TimeT[1].text, nullptr))); + auto utc_offset = static_cast(std::floor(std::strtof(TimeTP[1].getText(), nullptr))); LOGF_WARN("UTC offset for location: %i", utc_offset); starbook::LnLat posn(longitude, latitude); starbook::ResponseCode rc = cmd_interface->SetPlace(posn, utc_offset);