diff --git a/indi-toupbase/indi_toupwheel.cpp b/indi-toupbase/indi_toupwheel.cpp index ad54a239e..39d52efe6 100644 --- a/indi-toupbase/indi_toupwheel.cpp +++ b/indi-toupbase/indi_toupwheel.cpp @@ -74,6 +74,7 @@ void ToupWheel::ISGetProperties(const char *dev) { INDI::FilterWheel::ISGetProperties(dev); defineProperty(SlotsSP); + defineProperty(SpinningDirectionSP); } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -83,6 +84,9 @@ bool ToupWheel::initProperties() { INDI::FilterWheel::initProperties(); + // Add Debug Control. + addDebugControl(); + VersionTP[TC_FW_VERSION].fill("FIRMWARE", "Firmware", nullptr); VersionTP[TC_HW_VERSION].fill("HARDWARE", "Hardware", nullptr); VersionTP[TC_REV].fill("REVISION", "Revision", nullptr); @@ -118,10 +122,18 @@ bool ToupWheel::updateProperties() IUSaveText(&VersionTP[TC_REV], tmpBuffer); defineProperty(VersionTP); + + SpinningDirectionSP[TCFW_SD_CLOCKWISE].fill("CLOCKWISE", "Clockwise", ISS_ON); + SpinningDirectionSP[TCFW_SD_AUTO].fill("AUTO", "Auto Direction", ISS_OFF); + SpinningDirectionSP.fill(getDeviceName(), "SPINNINGDIRECTION", "Spinning Direction", FILTER_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); + SpinningDirectionSP.load(); + + defineProperty(SpinningDirectionSP); } else { deleteProperty(VersionTP); + deleteProperty(SpinningDirectionSP); } return true; @@ -149,6 +161,7 @@ bool ToupWheel::Connect() FilterSlotN[0].max = slot; FP(put_Option(m_Handle, CP(OPTION_FILTERWHEEL_SLOT), slot)); + TargetFilter = 1; // if desconnected during spinning, TargetFilter must be initialize when reconnect. SelectFilter(0); LOGF_INFO("%s is connected.", getDeviceName()); @@ -174,6 +187,8 @@ void ToupWheel::TimerHit() QueryFilter(); + LOGF_DEBUG("TimerHit: CurrentFilter=%d, TargetFilter=%d", CurrentFilter, TargetFilter); + if (CurrentFilter != TargetFilter) { SetTimer(getCurrentPollingPeriod()); @@ -203,6 +218,21 @@ bool ToupWheel::ISNewSwitch(const char *dev, const char *name, ISState *states, saveConfig(SlotsSP); return true; } + else if (SpinningDirectionSP.isNameMatch(name)) + { + SpinningDirectionSP.update(states, names, n); + SpinningDirectionSP.setState(IPS_OK); + SpinningDirectionSP.apply(); + + auto currentSpinningDirection = SpinningDirectionSP.findOnSwitchIndex(); + if (currentSpinningDirection == TCFW_SD_AUTO) + SpinningDirection = 0x100; // auto direction spinning + else + SpinningDirection = 0; // clockwise spinning + + saveConfig(SpinningDirectionSP); + return true; + } } return INDI::FilterWheel::ISNewSwitch(dev, name, states, names, n); @@ -213,7 +243,7 @@ bool ToupWheel::ISNewSwitch(const char *dev, const char *name, ISState *states, ////////////////////////////////////////////////////////////////////////////////////////////////// bool ToupWheel::SelectFilter(int targetFilter) { - HRESULT rc = FP(put_Option(m_Handle, CP(OPTION_FILTERWHEEL_POSITION), targetFilter - 1)); + HRESULT rc = FP(put_Option(m_Handle, CP(OPTION_FILTERWHEEL_POSITION), SpinningDirection | (targetFilter - 1))); if (FAILED(rc)) { LOGF_ERROR("Failed to select filter wheel %d. %s", targetFilter, errorCodes(rc).c_str()); @@ -251,5 +281,6 @@ bool ToupWheel::saveConfigItems(FILE * fp) INDI::FilterWheel::saveConfigItems(fp); SlotsSP.save(fp); + SpinningDirectionSP.save(fp); return true; } diff --git a/indi-toupbase/indi_toupwheel.h b/indi-toupbase/indi_toupwheel.h index ab7640d4f..1f64df5a2 100644 --- a/indi-toupbase/indi_toupwheel.h +++ b/indi-toupbase/indi_toupwheel.h @@ -67,6 +67,14 @@ class ToupWheel : public INDI::FilterWheel SLOTS_8 }; + INDI::PropertySwitch SpinningDirectionSP {2}; + enum + { + TCFW_SD_CLOCKWISE, + TCFW_SD_AUTO + }; + int SpinningDirection = 0; + THAND m_Handle { nullptr }; const XP(DeviceV2) *m_Instance; };