Skip to content

Commit

Permalink
Refactor - use PropertyView/WidgetView (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-soja committed Dec 22, 2022
1 parent 6289ca7 commit 060d7c2
Show file tree
Hide file tree
Showing 47 changed files with 559 additions and 523 deletions.
94 changes: 47 additions & 47 deletions drivers/auxiliary/skysafari.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ void SkySafari::processCommand(std::string cmd)
// Get RA
else if (cmd == "GR")
{
INumberVectorProperty *eqCoordsNP = skySafariClient->getEquatorialCoords();
auto eqCoordsNP = skySafariClient->getEquatorialCoords();
if (eqCoordsNP == nullptr)
{
LOG_WARN("Unable to communicate with mount, is mount turned on and connected?");
Expand All @@ -458,23 +458,23 @@ void SkySafari::processCommand(std::string cmd)

int hh, mm, ss;
char output[32] = { 0 };
getSexComponents(eqCoordsNP->np[AXIS_RA].value, &hh, &mm, &ss);
getSexComponents(eqCoordsNP->at(AXIS_RA)->getValue(), &hh, &mm, &ss);
snprintf(output, 32, "%02d:%02d:%02d#", hh, mm, ss);
sendSkySafari(output);
}
// Get DE
else if (cmd == "GD")
{
INumberVectorProperty *eqCoordsNP = skySafariClient->getEquatorialCoords();
auto eqCoordsNP = skySafariClient->getEquatorialCoords();
if (eqCoordsNP == nullptr)
{
LOG_WARN("Unable to communicate with mount, is mount turned on and connected?");
return;
}
int dd, mm, ss;
char output[32] = { 0 };
getSexComponents(eqCoordsNP->np[AXIS_DE].value, &dd, &mm, &ss);
snprintf(output, 32, "%c%02d:%02d:%02d#", (eqCoordsNP->np[AXIS_DE].value >= 0) ? '+' : '-',
getSexComponents(eqCoordsNP->at(AXIS_DE)->getValue(), &dd, &mm, &ss);
snprintf(output, 32, "%c%02d:%02d:%02d#", (eqCoordsNP->at(AXIS_DE)->getValue() >= 0) ? '+' : '-',
std::abs(dd), mm, ss);
sendSkySafari(output);
}
Expand All @@ -495,57 +495,57 @@ void SkySafari::processCommand(std::string cmd)
// GOTO
else if (cmd == "MS")
{
ISwitchVectorProperty *gotoModeSP = skySafariClient->getGotoMode();
auto gotoModeSP = skySafariClient->getGotoMode();
if (gotoModeSP == nullptr)
{
sendSkySafari("2<Not Supported>#");
return;
}

// Set mode first
ISwitch *trackSW = IUFindSwitch(gotoModeSP, "TRACK");
auto trackSW = gotoModeSP->findWidgetByName("TRACK");
if (trackSW == nullptr)
{
sendSkySafari("2<Not Supported>#");
return;
}

IUResetSwitch(gotoModeSP);
trackSW->s = ISS_ON;
gotoModeSP->reset();
trackSW->setState(ISS_ON);
skySafariClient->sendGotoMode();

INumberVectorProperty *eqCoordsNP = skySafariClient->getEquatorialCoords();
eqCoordsNP->np[AXIS_RA].value = RA;
eqCoordsNP->np[AXIS_DE].value = DE;
auto eqCoordsNP = skySafariClient->getEquatorialCoords();
eqCoordsNP->at(AXIS_RA)->setValue(RA);
eqCoordsNP->at(AXIS_DE)->setValue(DE);
skySafariClient->sendEquatorialCoords();

sendSkySafari("0");
}
// Sync
else if (cmd == "CM")
{
ISwitchVectorProperty *gotoModeSP = skySafariClient->getGotoMode();
auto gotoModeSP = skySafariClient->getGotoMode();
if (gotoModeSP == nullptr)
{
sendSkySafari("Not Supported#");
return;
}

// Set mode first
ISwitch *syncSW = IUFindSwitch(gotoModeSP, "SYNC");
auto syncSW = gotoModeSP->findWidgetByName("SYNC");
if (syncSW == nullptr)
{
sendSkySafari("Not Supported#");
return;
}

IUResetSwitch(gotoModeSP);
syncSW->s = ISS_ON;
gotoModeSP->reset();
syncSW->setState(ISS_ON);
skySafariClient->sendGotoMode();

INumberVectorProperty *eqCoordsNP = skySafariClient->getEquatorialCoords();
eqCoordsNP->np[AXIS_RA].value = RA;
eqCoordsNP->np[AXIS_DE].value = DE;
auto eqCoordsNP = skySafariClient->getEquatorialCoords();
eqCoordsNP->at(AXIS_RA)->setValue(RA);
eqCoordsNP->at(AXIS_DE)->setValue(DE);
skySafariClient->sendEquatorialCoords();

sendSkySafari(" M31 EX GAL MAG 3.5 SZ178.0'#");
Expand Down Expand Up @@ -578,100 +578,100 @@ void SkySafari::processCommand(std::string cmd)
// Mn
else if (cmd == "Mn")
{
ISwitchVectorProperty *motionNSNP = skySafariClient->getMotionNS();
auto motionNSNP = skySafariClient->getMotionNS();
if (motionNSNP)
{
IUResetSwitch(motionNSNP);
motionNSNP->sp[0].s = ISS_ON;
motionNSNP->reset();
motionNSNP->at(0)->setState(ISS_ON);
skySafariClient->setMotionNS();
}
}
// Qn
else if (cmd == "Qn")
{
ISwitchVectorProperty *motionNSNP = skySafariClient->getMotionNS();
auto motionNSNP = skySafariClient->getMotionNS();
if (motionNSNP)
{
IUResetSwitch(motionNSNP);
motionNSNP->reset();
skySafariClient->setMotionNS();
}
}
// Ms
else if (cmd == "Ms")
{
ISwitchVectorProperty *motionNSNP = skySafariClient->getMotionNS();
auto motionNSNP = skySafariClient->getMotionNS();
if (motionNSNP)
{
IUResetSwitch(motionNSNP);
motionNSNP->sp[1].s = ISS_ON;
motionNSNP->reset();
motionNSNP->at(1)->setState(ISS_ON);
skySafariClient->setMotionNS();
}
}
// Qs
else if (cmd == "Qs")
{
ISwitchVectorProperty *motionNSNP = skySafariClient->getMotionNS();
auto motionNSNP = skySafariClient->getMotionNS();
if (motionNSNP)
{
IUResetSwitch(motionNSNP);
motionNSNP->reset();
skySafariClient->setMotionNS();
}
}
// Mw
else if (cmd == "Mw")
{
ISwitchVectorProperty *motionWENP = skySafariClient->getMotionWE();
auto motionWENP = skySafariClient->getMotionWE();
if (motionWENP)
{
IUResetSwitch(motionWENP);
motionWENP->sp[0].s = ISS_ON;
motionWENP->reset();
motionWENP->at(0)->setState(ISS_ON);
skySafariClient->setMotionWE();
}
}
// Qw
else if (cmd == "Qw")
{
ISwitchVectorProperty *motionWENP = skySafariClient->getMotionWE();
auto motionWENP = skySafariClient->getMotionWE();
if (motionWENP)
{
IUResetSwitch(motionWENP);
motionWENP->reset();
skySafariClient->setMotionWE();
}
}
// Me
else if (cmd == "Me")
{
ISwitchVectorProperty *motionWENP = skySafariClient->getMotionWE();
auto motionWENP = skySafariClient->getMotionWE();
if (motionWENP)
{
IUResetSwitch(motionWENP);
motionWENP->sp[1].s = ISS_ON;
motionWENP->reset();
motionWENP->at(1)->setState(ISS_ON);
skySafariClient->setMotionWE();
}
}
// Qe
else if (cmd == "Qe")
{
ISwitchVectorProperty *motionWENP = skySafariClient->getMotionWE();
auto motionWENP = skySafariClient->getMotionWE();
if (motionWENP)
{
IUResetSwitch(motionWENP);
motionWENP->reset();
skySafariClient->setMotionWE();
}
}
}

void SkySafari::sendGeographicCoords()
{
INumberVectorProperty *geographicCoords = skySafariClient->getGeographiCoords();
auto geographicCoords = skySafariClient->getGeographiCoords();
if (geographicCoords && haveLatitude && haveLongitude)
{
INumber *latitude = IUFindNumber(geographicCoords, "LAT");
INumber *longitude = IUFindNumber(geographicCoords, "LONG");
auto latitude = geographicCoords->findWidgetByName("LAT");
auto longitude = geographicCoords->findWidgetByName("LONG");
if (latitude && longitude)
{
latitude->value = siteLatitude;
longitude->value = siteLongitude;
latitude->setValue(siteLatitude);
longitude->setValue(siteLongitude);
skySafariClient->sendGeographicCoords();

// Reset
Expand Down Expand Up @@ -703,7 +703,7 @@ bool SkySafari::sendSkySafari(const char *message)

void SkySafari::sendUTCtimedate()
{
ITextVectorProperty *timeUTC = skySafariClient->getTimeUTC();
auto timeUTC = skySafariClient->getTimeUTC();
if (timeUTC && haveUTCoffset && haveUTCtime && haveUTCdate)
{
int yyyy = timeYear;
Expand All @@ -730,8 +730,8 @@ void SkySafari::sendUTCtimedate()
utcdate.minutes, (int)(utcdate.seconds));
snprintf(bufOff, 8, "%4.2f", timeUTCOffset);

IUSaveText(IUFindText(timeUTC, "UTC"), bufDT);
IUSaveText(IUFindText(timeUTC, "OFFSET"), bufOff);
timeUTC->findWidgetByName("UTC")->setText(bufDT);
timeUTC->findWidgetByName("OFFSET")->setText(bufOff);

LOGF_DEBUG("send to timedate. %s, %s", bufDT, bufOff);

Expand Down
22 changes: 11 additions & 11 deletions drivers/auxiliary/skysafariclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ bool SkySafariClient::parkMount()
if (mountParkSP == nullptr)
return false;

ISwitch *sw = IUFindSwitch(mountParkSP, "PARK");
auto sw = mountParkSP->findWidgetByName("PARK");

if (sw == nullptr)
return false;

IUResetSwitch(mountParkSP);
sw->s = ISS_ON;
mountParkSP->reset();
sw->setState(ISS_ON);

mountParkSP->s = IPS_BUSY;
mountParkSP->setState(IPS_BUSY);

sendNewSwitch(mountParkSP);

Expand All @@ -120,7 +120,7 @@ bool SkySafariClient::parkMount()
***************************************************************************************/
IPState SkySafariClient::getMountParkState()
{
return mountParkSP->s;
return mountParkSP->getState();
}

/**************************************************************************************
Expand All @@ -131,7 +131,7 @@ bool SkySafariClient::sendEquatorialCoords()
if (eqCoordsNP == nullptr)
return false;

eqCoordsNP->s = IPS_BUSY;
eqCoordsNP->setState(IPS_BUSY);
sendNewNumber(eqCoordsNP);
return true;
}
Expand All @@ -144,7 +144,7 @@ bool SkySafariClient::sendGeographicCoords()
if (geoCoordsNP == nullptr)
return false;

geoCoordsNP->s = IPS_BUSY;
geoCoordsNP->setState(IPS_BUSY);
sendNewNumber(geoCoordsNP);
return true;
}
Expand All @@ -169,7 +169,7 @@ bool SkySafariClient::abort()
if (abortSP == nullptr)
return false;

abortSP->sp[0].s = ISS_ON;
abortSP->at(0)->setState(ISS_ON);

sendNewSwitch(abortSP);
return true;
Expand All @@ -183,16 +183,16 @@ bool SkySafariClient::setSlewRate(int slewRate)
if (slewRateSP == nullptr)
return false;

int maxSlewRate = slewRateSP->nsp - 1;
int maxSlewRate = slewRateSP->count() - 1;

int finalSlewRate = slewRate;

// If slew rate is betwee min and max, we intepolate
if (slewRate > 0 && slewRate < maxSlewRate)
finalSlewRate = static_cast<int>(ceil(slewRate * maxSlewRate / 3.0));

IUResetSwitch(slewRateSP);
slewRateSP->sp[finalSlewRate].s = ISS_ON;
slewRateSP->reset();
slewRateSP->at(finalSlewRate)->setState(ISS_ON);

sendNewSwitch(slewRateSP);

Expand Down
30 changes: 15 additions & 15 deletions drivers/auxiliary/skysafariclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ class SkySafariClient : public INDI::BaseClient

void setMount(const std::string &value);

INumberVectorProperty *getEquatorialCoords()
INDI::PropertyViewNumber *getEquatorialCoords()
{
return eqCoordsNP;
}
bool sendEquatorialCoords();

INumberVectorProperty *getGeographiCoords()
INDI::PropertyViewNumber *getGeographiCoords()
{
return geoCoordsNP;
}
bool sendGeographicCoords();

ISwitchVectorProperty *getGotoMode()
INDI::PropertyViewSwitch *getGotoMode()
{
return gotoModeSP;
}
bool sendGotoMode();

ISwitchVectorProperty *getMotionNS()
INDI::PropertyViewSwitch *getMotionNS()
{
return motionNSSP;
}
bool setMotionNS();

ISwitchVectorProperty *getMotionWE()
INDI::PropertyViewSwitch *getMotionWE()
{
return motionWESP;
}
Expand All @@ -81,7 +81,7 @@ class SkySafariClient : public INDI::BaseClient

bool abort();

ITextVectorProperty *getTimeUTC()
INDI::PropertyViewText *getTimeUTC()
{
return timeUTC;
}
Expand All @@ -105,13 +105,13 @@ class SkySafariClient : public INDI::BaseClient
std::string mount;
bool isReady, mountOnline;

ISwitchVectorProperty *mountParkSP = nullptr;
ISwitchVectorProperty *gotoModeSP = nullptr;
INumberVectorProperty *eqCoordsNP = nullptr;
INumberVectorProperty *geoCoordsNP = nullptr;
ISwitchVectorProperty *abortSP = nullptr;
ISwitchVectorProperty *slewRateSP = nullptr;
ISwitchVectorProperty *motionNSSP = nullptr;
ISwitchVectorProperty *motionWESP = nullptr;
ITextVectorProperty *timeUTC = nullptr;
INDI::PropertyViewSwitch *mountParkSP = nullptr;
INDI::PropertyViewSwitch *gotoModeSP = nullptr;
INDI::PropertyViewNumber *eqCoordsNP = nullptr;
INDI::PropertyViewNumber *geoCoordsNP = nullptr;
INDI::PropertyViewSwitch *abortSP = nullptr;
INDI::PropertyViewSwitch *slewRateSP = nullptr;
INDI::PropertyViewSwitch *motionNSSP = nullptr;
INDI::PropertyViewSwitch *motionWESP = nullptr;
INDI::PropertyViewText *timeUTC = nullptr;
};
Loading

0 comments on commit 060d7c2

Please sign in to comment.