Skip to content

Commit

Permalink
Merge pull request #1 from naheedsa/feature/migrate-dome-drivers
Browse files Browse the repository at this point in the history
Migrate Baader dome
  • Loading branch information
knro authored May 19, 2024
2 parents f88eb2c + 987aa5b commit bbe7b60
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 55 deletions.
105 changes: 54 additions & 51 deletions drivers/dome/baader_dome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ bool BaaderDome::initProperties()
{
INDI::Dome::initProperties();

IUFillSwitch(&CalibrateS[0], "Start", "", ISS_OFF);
IUFillSwitchVector(&CalibrateSP, CalibrateS, 1, getDeviceName(), "Calibrate", "", MAIN_CONTROL_TAB, IP_RW,
CalibrateSP[0].fill("Start", "", ISS_OFF);
CalibrateSP.fill(getDeviceName(), "Calibrate", "", MAIN_CONTROL_TAB, IP_RW,
ISR_ATMOST1, 0, IPS_IDLE);

IUFillSwitch(&DomeFlapS[0], "FLAP_OPEN", "Open", ISS_OFF);
IUFillSwitch(&DomeFlapS[1], "FLAP_CLOSE", "Close", ISS_ON);
IUFillSwitchVector(&DomeFlapSP, DomeFlapS, 2, getDeviceName(), "DOME_FLAP", "Flap", MAIN_CONTROL_TAB, IP_RW,
DomeFlapSP[FLAP_OPEN].fill("FLAP_OPEN", "Open", ISS_OFF);
DomeFlapSP[FLAP_CLOSE].fill("FLAP_CLOSE", "Close", ISS_ON);
DomeFlapSP.fill(getDeviceName(), "DOME_FLAP", "Flap", MAIN_CONTROL_TAB, IP_RW,
ISR_1OFMANY, 60, IPS_OK);

SetParkDataType(PARK_AZ);
Expand All @@ -92,7 +92,7 @@ bool BaaderDome::SetupParms()
DomeShutterSP.apply();

if (UpdateFlapStatus())
IDSetSwitch(&DomeFlapSP, nullptr);
DomeFlapSP.apply(nullptr);

if (InitPark())
{
Expand Down Expand Up @@ -134,15 +134,15 @@ bool BaaderDome::updateProperties()

if (isConnected())
{
defineProperty(&DomeFlapSP);
defineProperty(&CalibrateSP);
defineProperty(DomeFlapSP);
defineProperty(CalibrateSP);

SetupParms();
}
else
{
deleteProperty(DomeFlapSP.name);
deleteProperty(CalibrateSP.name);
deleteProperty(DomeFlapSP);
deleteProperty(CalibrateSP);
}

return true;
Expand All @@ -155,25 +155,25 @@ bool BaaderDome::ISNewSwitch(const char *dev, const char *name, ISState *states,
{
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
{
if (strcmp(name, CalibrateSP.name) == 0)
if (CalibrateSP.isNameMatch(name))
{
IUResetSwitch(&CalibrateSP);
CalibrateSP.reset();

if (status == DOME_READY)
{
CalibrateSP.s = IPS_OK;
CalibrateSP.setState(IPS_OK);
LOG_INFO("Dome is already calibrated.");
IDSetSwitch(&CalibrateSP, nullptr);
CalibrateSP.apply();
return true;
}

if (CalibrateSP.s == IPS_BUSY)
if (CalibrateSP.getState() == IPS_BUSY)
{
Abort();
LOG_INFO("Calibration aborted.");
status = DOME_UNKNOWN;
CalibrateSP.s = IPS_IDLE;
IDSetSwitch(&CalibrateSP, nullptr);
CalibrateSP.setState(IPS_IDLE);
CalibrateSP.apply();
return true;
}

Expand All @@ -192,37 +192,37 @@ bool BaaderDome::ISNewSwitch(const char *dev, const char *name, ISState *states,

if (MoveAbs(calibrationTarget1) == IPS_IDLE)
{
CalibrateSP.s = IPS_ALERT;
CalibrateSP.setState(IPS_ALERT);
LOG_ERROR("Calibration failure due to dome motion failure.");
status = DOME_UNKNOWN;
IDSetSwitch(&CalibrateSP, nullptr);
CalibrateSP.apply();
return false;
}

DomeAbsPosNP.setState(IPS_BUSY);
CalibrateSP.s = IPS_BUSY;
CalibrateSP.setState(IPS_BUSY);
LOGF_INFO("Calibration is in progress. Moving to position %g.", calibrationTarget1);
IDSetSwitch(&CalibrateSP, nullptr);
CalibrateSP.apply();
return true;
}

if (strcmp(name, DomeFlapSP.name) == 0)
if (DomeFlapSP.isNameMatch(name))
{
int ret = 0;
int prevStatus = IUFindOnSwitchIndex(&DomeFlapSP);
IUUpdateSwitch(&DomeFlapSP, states, names, n);
int FlapDome = IUFindOnSwitchIndex(&DomeFlapSP);
int prevStatus = DomeFlapSP.findOnSwitchIndex();
DomeFlapSP.update(states, names, n);
int FlapDome = DomeFlapSP.findOnSwitchIndex();

// No change of status, let's return
if (prevStatus == FlapDome)
{
DomeFlapSP.s = IPS_OK;
IDSetSwitch(&DomeFlapSP, nullptr);
DomeFlapSP.setState(IPS_OK);
DomeFlapSP.apply();
}

// go back to prev status in case of failure
IUResetSwitch(&DomeFlapSP);
DomeFlapS[prevStatus].s = ISS_ON;
DomeFlapSP.reset();
DomeFlapSP[prevStatus].setState(ISS_ON);

if (FlapDome == 0)
ret = ControlDomeFlap(FLAP_OPEN);
Expand All @@ -231,23 +231,26 @@ bool BaaderDome::ISNewSwitch(const char *dev, const char *name, ISState *states,

if (ret == 0)
{
DomeFlapSP.s = IPS_OK;
IUResetSwitch(&DomeFlapSP);
DomeFlapS[FlapDome].s = ISS_ON;
IDSetSwitch(&DomeFlapSP, "Flap is %s.", (FlapDome == 0 ? "open" : "closed"));
DomeFlapSP.setState(IPS_OK);
DomeFlapSP.reset();
DomeFlapSP[FlapDome].s = ISS_ON;
LOGF_INFO("Flap is %s", (FlapDome == 0 ? "open" : "closed"));
DomeFlapSP.apply();
return true;
}
else if (ret == 1)
{
DomeFlapSP.s = IPS_BUSY;
IUResetSwitch(&DomeFlapSP);
DomeFlapS[FlapDome].s = ISS_ON;
IDSetSwitch(&DomeFlapSP, "Flap is %s...", (FlapDome == 0 ? "opening" : "closing"));
DomeFlapSP.setState(IPS_BUSY);
DomeFlapSP.reset();
DomeFlapSP[FlapDome].setState(ISS_ON);
LOGF_INFO("Flap is %s", (FlapDome == 0 ? "opening" : "closing"));
DomeFlapSP.apply();
return true;
}

DomeFlapSP.s = IPS_ALERT;
IDSetSwitch(&DomeFlapSP, "Flap failed to %s.", (FlapDome == 0 ? "open" : "close"));
DomeFlapSP.setState(IPS_ALERT);
LOGF_INFO("Flap failed to %s", (FlapDome == 0 ? "open" : "close"));
DomeFlapSP.apply();
return false;
}
}
Expand Down Expand Up @@ -432,16 +435,16 @@ bool BaaderDome::UpdatePosition()
status = DOME_READY;
calibrationStage = CALIBRATION_COMPLETE;
LOG_INFO("Dome is calibrated.");
CalibrateSP.s = IPS_OK;
IDSetSwitch(&CalibrateSP, nullptr);
CalibrateSP.setState(IPS_OK);
CalibrateSP.apply(nullptr);
}
else if (status == DOME_CALIBRATING)
{
status = DOME_READY;
calibrationStage = CALIBRATION_COMPLETE;
LOG_INFO("Calibration complete.");
CalibrateSP.s = IPS_OK;
IDSetSwitch(&CalibrateSP, nullptr);
CalibrateSP.setState(IPS_OK);
CalibrateSP.apply();
}

DomeAbsPosNP[0].setValue(DomeAzToMountAz(domeAz));
Expand Down Expand Up @@ -605,7 +608,7 @@ void BaaderDome::TimerHit()

UpdateFlapStatus();

if (sim && DomeFlapSP.s == IPS_BUSY)
if (sim && DomeFlapSP.getState() == IPS_BUSY)
{
if (simFlapTimer-- <= 0)
{
Expand All @@ -614,7 +617,7 @@ void BaaderDome::TimerHit()
}
}
else
IDSetSwitch(&DomeFlapSP, nullptr);
DomeFlapSP.apply();

SetTimer(getCurrentPollingPeriod());
}
Expand Down Expand Up @@ -895,34 +898,34 @@ bool BaaderDome::UpdateFlapStatus()

if (rc > 0)
{
DomeFlapSP.s = IPS_OK;
IUResetSwitch(&DomeFlapSP);
DomeFlapSP.setState(IPS_OK);
DomeFlapSP.reset();

if (strcmp(status, "ope") == 0)
{
if (flapStatus == FLAP_MOVING && targetFlap == FLAP_OPEN)
LOGF_INFO("%s", GetFlapStatusString(FLAP_OPENED));

flapStatus = FLAP_OPENED;
DomeFlapS[FLAP_OPEN].s = ISS_ON;
DomeFlapSP[FLAP_OPEN].setState(ISS_ON);
}
else if (strcmp(status, "clo") == 0)
{
if (flapStatus == FLAP_MOVING && targetFlap == FLAP_CLOSE)
LOGF_INFO("%s", GetFlapStatusString(FLAP_CLOSED));

flapStatus = FLAP_CLOSED;
DomeFlapS[FLAP_CLOSE].s = ISS_ON;
DomeFlapSP[FLAP_CLOSE].setState(ISS_ON);
}
else if (strcmp(status, "run") == 0)
{
flapStatus = FLAP_MOVING;
DomeFlapSP.s = IPS_BUSY;
DomeFlapSP.setState(IPS_BUSY);
}
else
{
flapStatus = FLAP_UNKNOWN;
DomeFlapSP.s = IPS_ALERT;
DomeFlapSP.setState(IPS_ALERT);
LOGF_ERROR("Unknown flap status: %s.", resp);
}
return true;
Expand Down
6 changes: 2 additions & 4 deletions drivers/dome/baader_dome.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ class BaaderDome : public INDI::Dome
double DomeAzToMountAz(unsigned short domeAz);
bool SetupParms();

ISwitch CalibrateS[1];
ISwitchVectorProperty CalibrateSP;
INDI::PropertySwitch CalibrateSP {1};

ISwitch DomeFlapS[2];
ISwitchVectorProperty DomeFlapSP;
INDI::PropertySwitch DomeFlapSP {2};

DomeStatus status { DOME_UNKNOWN };
FlapStatus flapStatus { FLAP_OPENED };
Expand Down

0 comments on commit bbe7b60

Please sign in to comment.