Skip to content

Commit

Permalink
Migrate Pyxis (indilib#2020)
Browse files Browse the repository at this point in the history
  • Loading branch information
naheedsa authored Mar 5, 2024
1 parent ca39f81 commit 8ed7906
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 71 deletions.
122 changes: 61 additions & 61 deletions drivers/rotator/pyxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,29 @@ bool Pyxis::initProperties()
INDI::Rotator::initProperties();

// Rotation Rate
IUFillNumber(&RotationRateN[0], "RATE", "Rate", "%.f", 0, 99, 10, 8);
IUFillNumberVector(&RotationRateNP, RotationRateN, 1, getDeviceName(), "ROTATION_RATE", "Rotation", SETTINGS_TAB, IP_RW, 0,
RotationRateNP[0].fill("RATE", "Rate", "%.f", 0, 99, 10, 8);
RotationRateNP.fill(getDeviceName(), "ROTATION_RATE", "Rotation", SETTINGS_TAB, IP_RW, 0,
IPS_IDLE);

// Stepping
IUFillSwitch(&SteppingS[FULL_STEP], "FULL_STEP", "Full", ISS_OFF);
IUFillSwitch(&SteppingS[HALF_STEP], "HALF_STEP", "Half", ISS_OFF);
IUFillSwitchVector(&SteppingSP, SteppingS, 2, getDeviceName(), "STEPPING_RATE", "Stepping", SETTINGS_TAB, IP_RW,
SteppingSP[FULL_STEP].fill("FULL_STEP", "Full", ISS_OFF);
SteppingSP[HALF_STEP].fill("HALF_STEP", "Half", ISS_OFF);
SteppingSP.fill( getDeviceName(), "STEPPING_RATE", "Stepping", SETTINGS_TAB, IP_RW,
ISR_ATMOST1, 0, IPS_IDLE);

// Power
IUFillSwitch(&PowerS[POWER_SLEEP], "POWER_SLEEP", "Sleep", ISS_OFF);
IUFillSwitch(&PowerS[POWER_WAKEUP], "POWER_WAKEUP", "Wake Up", ISS_OFF);
IUFillSwitchVector(&PowerSP, PowerS, 2, getDeviceName(), "POWER_STATE", "Power", SETTINGS_TAB, IP_RW, ISR_ATMOST1, 0,
PowerSP[POWER_SLEEP].fill("POWER_SLEEP", "Sleep", ISS_OFF);
PowerSP[POWER_WAKEUP].fill("POWER_WAKEUP", "Wake Up", ISS_OFF);
PowerSP.fill(getDeviceName(), "POWER_STATE", "Power", SETTINGS_TAB, IP_RW, ISR_ATMOST1, 0,
IPS_IDLE);

// Firmware version
IUFillText(&FirmwareT[0], "FIRMWARE_VERSION", "Version", "Unknown");
IUFillTextVector(&FirmwareTP, FirmwareT, 1, getDeviceName(), "FIRMWARE_VERSION", "Firmware", INFO_TAB, IP_RO, 0, IPS_IDLE);
FirmwareTP[0].fill("FIRMWARE_VERSION", "Version", "Unknown");
FirmwareTP.fill(getDeviceName(), "FIRMWARE_VERSION", "Firmware", INFO_TAB, IP_RO, 0, IPS_IDLE);

// Firmware version
IUFillText(&ModelT[0], "HARDWARE_MODEL", "Model", "Unknown");
IUFillTextVector(&ModelTP, ModelT, 1, getDeviceName(), "HARDWARE_MODEL", "Model", INFO_TAB, IP_RO, 0, IPS_IDLE);
ModelTP[0].fill("HARDWARE_MODEL", "Model", "Unknown");
ModelTP.fill(getDeviceName(), "HARDWARE_MODEL", "Model", INFO_TAB, IP_RO, 0, IPS_IDLE);


serialConnection->setDefaultBaudRate(Connection::Serial::B_19200);
Expand Down Expand Up @@ -109,21 +109,21 @@ bool Pyxis::updateProperties()

if (isConnected())
{
defineProperty(&RotationRateNP) ;
defineProperty(&SteppingSP);
defineProperty(&PowerSP);
defineProperty(&FirmwareTP) ;
defineProperty(&ModelTP) ;
defineProperty(RotationRateNP) ;
defineProperty(SteppingSP);
defineProperty(PowerSP);
defineProperty(FirmwareTP) ;
defineProperty(ModelTP) ;

queryParams();
}
else
{
deleteProperty(RotationRateNP.name);
deleteProperty(SteppingSP.name);
deleteProperty(PowerSP.name);
deleteProperty(FirmwareTP.name) ;
deleteProperty(ModelTP.name) ;
deleteProperty(RotationRateNP.getName());
deleteProperty(SteppingSP.getName());
deleteProperty(PowerSP.getName());
deleteProperty(FirmwareTP.getName()) ;
deleteProperty(ModelTP.getName()) ;
}

return true;
Expand All @@ -149,9 +149,9 @@ void Pyxis::queryParams()

// Firmware version parameter
std::string sversion = getVersion() ;
IUSaveText(&FirmwareT[0], sversion.c_str()) ;
FirmwareTP.s = IPS_OK;
IDSetText(&FirmwareTP, nullptr) ;
FirmwareTP[0].setText(sversion.c_str()) ;
FirmwareTP.setState(IPS_OK);
FirmwareTP.apply() ;

LOGF_DEBUG("queryParms firmware = %s", sversion.c_str()) ;

Expand All @@ -163,20 +163,20 @@ void Pyxis::queryParams()
LOGF_DEBUG("queryParms rate = %d, firmware = %s", rate, sversion.c_str()) ;
if (rc)
{
RotationRateNP.s = IPS_OK ;
RotationRateN[0].value = rate ;
IDSetNumber(&RotationRateNP, nullptr) ;
RotationRateNP.setState(IPS_OK) ;
RotationRateNP[0].setValue(rate) ;
RotationRateNP.apply() ;

IUSaveText(&ModelT[0], "Pyxis 3 Inch") ;
ModelTP.s = IPS_OK;
IDSetText(&ModelTP, nullptr) ;
ModelTP[0].setText("Pyxis 3 Inch");
ModelTP.setState(IPS_OK);
ModelTP.apply();
}
}
else
{
IUSaveText(&ModelT[0], "Pyxis 2 Inch") ;
ModelTP.s = IPS_OK;
IDSetText(&ModelTP, nullptr) ;
ModelTP[0].setText("Pyxis 2 Inch") ;
ModelTP.setState(IPS_OK);
ModelTP.apply() ;
}

}
Expand Down Expand Up @@ -224,18 +224,18 @@ bool Pyxis::ISNewNumber(const char *dev, const char *name, double values[], char
{
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
{
if (!strcmp(name, RotationRateNP.name))
if (RotationRateNP.isNameMatch(name))
{
bool rc = setRotationRate(static_cast<uint8_t>(values[0]));
if (rc)
{
RotationRateNP.s = IPS_OK;
RotationRateN[0].value = values[0];
RotationRateNP.setState(IPS_OK);
RotationRateNP[0].setValue(values[0]);
}
else
RotationRateNP.s = IPS_ALERT;
RotationRateNP.setState(IPS_ALERT);

IDSetNumber(&RotationRateNP, nullptr);
RotationRateNP.apply();
return true;
}
}
Expand All @@ -250,72 +250,72 @@ bool Pyxis::ISNewSwitch(const char *dev, const char *name, ISState *states, char
/////////////////////////////////////////////////////
// Stepping
////////////////////////////////////////////////////
if (!strcmp(name, SteppingSP.name))
if (SteppingSP.isNameMatch(name))
{
bool rc = false;
if (!strcmp(IUFindOnSwitchName(states, names, n), SteppingS[FULL_STEP].name))
if (!strcmp(IUFindOnSwitchName(states, names, n), SteppingSP[FULL_STEP].getName()))
rc = setSteppingMode(FULL_STEP);
else
rc = setSteppingMode(HALF_STEP);


if (rc)
{
IUUpdateSwitch(&SteppingSP, states, names, n);
SteppingSP.s = IPS_OK;
SteppingSP.update(states, names, n);
SteppingSP.setState(IPS_OK);
}
else
SteppingSP.s = IPS_ALERT;
SteppingSP.setState(IPS_ALERT);

IDSetSwitch(&SteppingSP, nullptr);
SteppingSP.apply();
return true;
}

/////////////////////////////////////////////////////
// Power
////////////////////////////////////////////////////
if (!strcmp(name, PowerSP.name))
if (PowerSP.isNameMatch(name))
{
bool rc = false;
if (!strcmp(IUFindOnSwitchName(states, names, n), PowerS[POWER_WAKEUP].name))
if (!strcmp(IUFindOnSwitchName(states, names, n), PowerSP[POWER_WAKEUP].getName()))
{
// If not sleeping
if (PowerS[POWER_SLEEP].s == ISS_OFF)
if (PowerSP[POWER_SLEEP].getState() == ISS_OFF)
{
PowerSP.s = IPS_OK;
PowerSP.setState(IPS_OK);
LOG_WARN("Controller is not in sleep mode.");
IDSetSwitch(&PowerSP, nullptr);
PowerSP.apply();
return true;
}

rc = wakeupController();

if (rc)
{
IUResetSwitch(&PowerSP);
PowerSP.s = IPS_OK;
PowerSP.reset();
PowerSP.setState(IPS_OK);
LOG_INFO("Controller is awake.");
}
else
PowerSP.s = IPS_ALERT;
PowerSP.setState(IPS_ALERT);

IDSetSwitch(&PowerSP, nullptr);
PowerSP.apply();
return true;
}
else
{
bool rc = sleepController();
IUResetSwitch(&PowerSP);
PowerSP.reset();
if (rc)
{
PowerSP.s = IPS_OK;
PowerS[POWER_SLEEP].s = ISS_ON;
PowerSP.setState(IPS_OK);
PowerSP[POWER_SLEEP].setState(ISS_ON);
LOG_INFO("Controller in sleep mode. No functions can be used until controller is waken up.");
}
else
PowerSP.s = IPS_ALERT;
PowerSP.setState(IPS_ALERT);

IDSetSwitch(&PowerSP, nullptr);
PowerSP.apply();
return true;
}
}
Expand Down Expand Up @@ -524,7 +524,7 @@ bool Pyxis::ReverseRotator(bool enabled)

void Pyxis::TimerHit()
{
if (!isConnected() || PowerS[POWER_SLEEP].s == ISS_ON)
if (!isConnected() || PowerSP[POWER_SLEEP].getState() == ISS_ON)
{
SetTimer(getCurrentPollingPeriod());
return;
Expand Down Expand Up @@ -573,7 +573,7 @@ bool Pyxis::isMotionComplete()
char errstr[MAXRBUF];
char res[PYXIS_3INCH_PER_DEG + 1] = { 0 };

bool pyxis3inch = atoi(FirmwareT[0].text) >= 3 ;
bool pyxis3inch = atoi(FirmwareTP[0].getText()) >= 3 ;

if ( (rc = tty_nread_section(PortFD, res, (pyxis3inch ? PYXIS_3INCH_PER_DEG : PYXIS_2INCH_PER_DEG), 'F', 1,
&nbytes_read)) != TTY_OK)
Expand Down
15 changes: 5 additions & 10 deletions drivers/rotator/pyxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,19 @@ class Pyxis : public INDI::Rotator
void queryParams();

// Rotation Rate
INumber RotationRateN[1];
INumberVectorProperty RotationRateNP;
INDI::PropertyNumber RotationRateNP {1};

// Stepping
ISwitch SteppingS[2];
ISwitchVectorProperty SteppingSP;
INDI::PropertySwitch SteppingSP {2};
enum { FULL_STEP, HALF_STEP};

// Power
ISwitch PowerS[2];
ISwitchVectorProperty PowerSP;
INDI::PropertySwitch PowerSP {2};
enum { POWER_SLEEP, POWER_WAKEUP};

// Firmware version; tells us if 2 inch or 3 inch device
IText FirmwareT[1] {};
ITextVectorProperty FirmwareTP;
IText ModelT[1] {};
ITextVectorProperty ModelTP;
INDI::PropertyText FirmwareTP {1};
INDI::PropertyText ModelTP {1};

uint16_t targetPA = {0};

Expand Down

0 comments on commit 8ed7906

Please sign in to comment.