Skip to content

Commit

Permalink
Update StepModeSP property
Browse files Browse the repository at this point in the history
  • Loading branch information
naheedsa committed Feb 22, 2024
1 parent 2d69250 commit 1da05e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
42 changes: 21 additions & 21 deletions drivers/focuser/moonlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ bool MoonLite::initProperties()
FocusSpeedN[0].value = 1;

// Step Mode
IUFillSwitch(&StepModeS[FOCUS_HALF_STEP], "FOCUS_HALF_STEP", "Half Step", ISS_OFF);
IUFillSwitch(&StepModeS[FOCUS_FULL_STEP], "FOCUS_FULL_STEP", "Full Step", ISS_ON);
IUFillSwitchVector(&StepModeSP, StepModeS, 2, getDeviceName(), "Step Mode", "", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 0,
StepModeSP[FOCUS_HALF_STEP].fill("FOCUS_HALF_STEP", "Half Step", ISS_OFF);
StepModeSP[FOCUS_FULL_STEP].fill("FOCUS_FULL_STEP", "Full Step", ISS_ON);
StepModeSP.fill(getDeviceName(), "Step Mode", "", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 0,
IPS_IDLE);

// Focuser temperature
Expand Down Expand Up @@ -95,7 +95,7 @@ bool MoonLite::updateProperties()
if (isConnected())
{
defineProperty(&TemperatureNP);
defineProperty(&StepModeSP);
defineProperty(StepModeSP);
defineProperty(&TemperatureSettingNP);
defineProperty(&TemperatureCompensateSP);

Expand All @@ -106,7 +106,7 @@ bool MoonLite::updateProperties()
else
{
deleteProperty(TemperatureNP.name);
deleteProperty(StepModeSP.name);
deleteProperty(StepModeSP.getName());
deleteProperty(TemperatureSettingNP.name);
deleteProperty(TemperatureCompensateSP.name);
}
Expand Down Expand Up @@ -158,9 +158,9 @@ bool MoonLite::readStepMode()
return false;

if (strcmp(res, "FF#") == 0)
StepModeS[FOCUS_HALF_STEP].s = ISS_ON;
StepModeSP[FOCUS_HALF_STEP].setState(ISS_ON);
else if (strcmp(res, "00#") == 0)
StepModeS[FOCUS_FULL_STEP].s = ISS_ON;
StepModeSP[FOCUS_FULL_STEP].setState(ISS_ON);
else
{
LOGF_ERROR("Unknown error: focuser step value (%s)", res);
Expand Down Expand Up @@ -337,32 +337,32 @@ bool MoonLite::ISNewSwitch(const char * dev, const char * name, ISState * states
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
{
// Focus Step Mode
if (strcmp(StepModeSP.name, name) == 0)
if (StepModeSP.isNameMatch(name))
{
int current_mode = IUFindOnSwitchIndex(&StepModeSP);
int current_mode = StepModeSP.findOnSwitchIndex();

IUUpdateSwitch(&StepModeSP, states, names, n);
StepModeSP.update(states, names, n);

int target_mode = IUFindOnSwitchIndex(&StepModeSP);
int target_mode = StepModeSP.findOnSwitchIndex();

if (current_mode == target_mode)
{
StepModeSP.s = IPS_OK;
IDSetSwitch(&StepModeSP, nullptr);
StepModeSP.setState(IPS_OK);
StepModeSP.apply();
}

bool rc = setStepMode(target_mode == 0 ? FOCUS_HALF_STEP : FOCUS_FULL_STEP);
if (!rc)
{
IUResetSwitch(&StepModeSP);
StepModeS[current_mode].s = ISS_ON;
StepModeSP.s = IPS_ALERT;
IDSetSwitch(&StepModeSP, nullptr);
StepModeSP.reset();
StepModeSP[current_mode].setState(ISS_ON);
StepModeSP.setState(IPS_ALERT);
StepModeSP.apply();
return false;
}

StepModeSP.s = IPS_OK;
IDSetSwitch(&StepModeSP, nullptr);
StepModeSP.setState(IPS_OK);
StepModeSP.apply();
return true;
}

Expand Down Expand Up @@ -429,7 +429,7 @@ void MoonLite::GetFocusParams()
IDSetNumber(&FocusSpeedNP, nullptr);

if (readStepMode())
IDSetSwitch(&StepModeSP, nullptr);
StepModeSP.apply();
}

bool MoonLite::SetFocuserSpeed(int speed)
Expand Down Expand Up @@ -550,7 +550,7 @@ bool MoonLite::saveConfigItems(FILE * fp)
{
Focuser::saveConfigItems(fp);

IUSaveConfigSwitch(fp, &StepModeSP);
StepModeSP.save(fp);

return true;
}
Expand Down
3 changes: 1 addition & 2 deletions drivers/focuser/moonlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ class MoonLite : public INDI::Focuser
INumberVectorProperty TemperatureNP;

// Full/Half Step modes
ISwitch StepModeS[2];
ISwitchVectorProperty StepModeSP;
INDI::PropertySwitch StepModeSP {2};

// Temperature Settings
INumber TemperatureSettingN[2];
Expand Down

0 comments on commit 1da05e2

Please sign in to comment.