Skip to content

Commit

Permalink
Update TemperatureNP and TemperatureSettingNP
Browse files Browse the repository at this point in the history
  • Loading branch information
naheedsa committed Feb 22, 2024
1 parent 1da05e2 commit a3d26b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
44 changes: 22 additions & 22 deletions drivers/focuser/moonlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ bool MoonLite::initProperties()
IPS_IDLE);

// Focuser temperature
IUFillNumber(&TemperatureN[0], "TEMPERATURE", "Celsius", "%6.2f", -50, 70., 0., 0.);
IUFillNumberVector(&TemperatureNP, TemperatureN, 1, getDeviceName(), "FOCUS_TEMPERATURE", "Temperature",
TemperatureNP[TEMPERATURE].fill("TEMPERATURE", "Celsius", "%6.2f", -50, 70., 0., 0.);
TemperatureNP.fill(getDeviceName(), "FOCUS_TEMPERATURE", "Temperature",
MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE);

// Temperature Settings
IUFillNumber(&TemperatureSettingN[0], "Calibration", "", "%6.2f", -100, 100, 0.5, 0);
IUFillNumber(&TemperatureSettingN[1], "Coefficient", "", "%6.2f", -100, 100, 0.5, 0);
IUFillNumberVector(&TemperatureSettingNP, TemperatureSettingN, 2, getDeviceName(), "T. Settings", "",
TemperatureSettingNP[Calibration].fill("Calibration", "", "%6.2f", -100, 100, 0.5, 0);
TemperatureSettingNP[Coefficient].fill("Coefficient", "", "%6.2f", -100, 100, 0.5, 0);
TemperatureSettingNP.fill(getDeviceName(), "T. Settings", "",
OPTIONS_TAB, IP_RW, 0, IPS_IDLE);

// Compensate for temperature
Expand Down Expand Up @@ -94,9 +94,9 @@ bool MoonLite::updateProperties()

if (isConnected())
{
defineProperty(&TemperatureNP);
defineProperty(TemperatureNP);
defineProperty(StepModeSP);
defineProperty(&TemperatureSettingNP);
defineProperty(TemperatureSettingNP);
defineProperty(&TemperatureCompensateSP);

GetFocusParams();
Expand All @@ -105,9 +105,9 @@ bool MoonLite::updateProperties()
}
else
{
deleteProperty(TemperatureNP.name);
deleteProperty(TemperatureNP.getName());
deleteProperty(StepModeSP.getName());
deleteProperty(TemperatureSettingNP.name);
deleteProperty(TemperatureSettingNP.getName());
deleteProperty(TemperatureCompensateSP.name);
}

Expand Down Expand Up @@ -195,7 +195,7 @@ bool MoonLite::readTemperature()
int rc = sscanf(res, "%X", &temp);
if (rc > 0)
// Signed hex
TemperatureN[0].value = static_cast<int16_t>(temp) / 2.0;
TemperatureNP[TEMPERATURE].setValue(static_cast<int16_t>(temp) / 2.0);
else
{
LOGF_ERROR("Unknown error: focuser temperature value (%s)", res);
Expand Down Expand Up @@ -397,19 +397,19 @@ bool MoonLite::ISNewNumber(const char * dev, const char * name, double values[],
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
{
// Temperature Settings
if (strcmp(name, TemperatureSettingNP.name) == 0)
if (TemperatureSettingNP.isNameMatch(name))
{
IUUpdateNumber(&TemperatureSettingNP, values, names, n);
if (!setTemperatureCalibration(TemperatureSettingN[0].value) ||
!setTemperatureCoefficient(TemperatureSettingN[1].value))
TemperatureSettingNP.update(values, names, n);
if (!setTemperatureCalibration(TemperatureSettingNP[Calibration].getValue()) ||
!setTemperatureCoefficient(TemperatureSettingNP[Coefficient].getValue()))
{
TemperatureSettingNP.s = IPS_ALERT;
IDSetNumber(&TemperatureSettingNP, nullptr);
TemperatureSettingNP.setState(IPS_ALERT);
TemperatureSettingNP.apply();
return false;
}

TemperatureSettingNP.s = IPS_OK;
IDSetNumber(&TemperatureSettingNP, nullptr);
TemperatureSettingNP.setState(IPS_OK);
TemperatureSettingNP.apply();
return true;
}
}
Expand All @@ -423,7 +423,7 @@ void MoonLite::GetFocusParams()
IDSetNumber(&FocusAbsPosNP, nullptr);

if (readTemperature())
IDSetNumber(&TemperatureNP, nullptr);
TemperatureNP.apply();

if (readSpeed())
IDSetNumber(&FocusSpeedNP, nullptr);
Expand Down Expand Up @@ -518,10 +518,10 @@ void MoonLite::TimerHit()
rc = readTemperature();
if (rc)
{
if (fabs(lastTemperature - TemperatureN[0].value) >= 0.5)
if (fabs(lastTemperature - TemperatureNP[TEMPERATURE].value) >= 0.5)
{
IDSetNumber(&TemperatureNP, nullptr);
lastTemperature = static_cast<uint32_t>(TemperatureN[0].value);
TemperatureNP.apply();
lastTemperature = static_cast<uint32_t>(TemperatureNP[TEMPERATURE].value);
}
}

Expand Down
15 changes: 11 additions & 4 deletions drivers/focuser/moonlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,22 @@ class MoonLite : public INDI::Focuser
uint32_t targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 };

// Read Only Temperature Reporting
INumber TemperatureN[1];
INumberVectorProperty TemperatureNP;
INDI::PropertyNumber TemperatureNP {1};
enum
{
TEMPERATURE
};

// Full/Half Step modes
INDI::PropertySwitch StepModeSP {2};

// Temperature Settings
INumber TemperatureSettingN[2];
INumberVectorProperty TemperatureSettingNP;
INDI::PropertyNumber TemperatureSettingNP {2};
enum
{
Calibration,
Coefficient
};

// Temperature Compensation Enable/Disable
ISwitch TemperatureCompensateS[2];
Expand Down

0 comments on commit a3d26b6

Please sign in to comment.