Skip to content

CAUX: fix non-persistant cord wrap settings across driver restarts - #1356

Open
jochym wants to merge 6 commits into
indilib:masterfrom
jochym:fix/cordwrap-persistence
Open

jochym wants to merge 6 commits into
indilib:masterfrom
jochym:fix/cordwrap-persistence

Conversation

@jochym

@jochym jochym commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Cord wrap properties (toggle, position, base mode) were not being saved to config when changed via the UI. This caused settings to be lost on driver restart.

Root cause: ISNewSwitch handlers for CORDWRAP, CORDWRAP_POS, and CW_BASE were missing saveConfig() calls after updating properties.

Changes:

  • Add saveConfig() calls to all three cord wrap ISNewSwitch handlers
  • Add loadConfig() calls in ISGetProperties() to restore settings
  • Fix CORDWRAP_NE default from ISS_ON to ISS_OFF in initProperties()
  • Add error handling for getCordWrapEnabled/getCordWrapPosition
  • Update updateProperties() to fallback to config on mount query failure
  • Add isCordWrapSkyMode() helper method
  • Add comprehensive cord wrap persistence tests (7 tests)

Follows the same pattern as ApproachDirectionSP, PortTypeSP, and GuidePulseMode which already call saveConfig() in their handlers.

Tested in simulation and on real mount with HC and HBG3 and over network.

@jochym
jochym requested a review from Copilot July 22, 2026 12:25
@jochym jochym changed the title CAUX: fix cordwrap persist cord wrap settings across driver restarts CAUX: fix non-persistant cord wrap settings across driver restarts Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses loss of cord-wrap settings across driver restarts by persisting cord-wrap toggle/position/base-mode to the INDI config and restoring them during property initialization, aligning cord-wrap behavior with other persisted driver options.

Changes:

  • Persist cord-wrap properties by saving config from ISNewSwitch handlers and loading config in ISGetProperties().
  • Add mount read/write helpers and error handling around cord-wrap queries, with fallback to saved config when mount queries fail.
  • Add a system test suite covering cord-wrap config persistence behavior and update the simulator/test plan/versioning.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
indi-celestronaux/celestronaux.cpp Loads/saves cord-wrap config, adds mount read/write helpers, and updates switch handlers/error paths.
indi-celestronaux/celestronaux.h Updates cord-wrap API signatures and adds helper/utility declarations.
indi-celestronaux/tests/system/test_cordwrap.py Adds system tests that validate cord-wrap config values are written as expected.
indi-celestronaux/simulator/nse_simulator.py Adjusts entrypoint behavior to avoid curses in headless/test mode.
indi-celestronaux/TEST_PLAN.md Documents a new test phase for cord-wrap persistence.
indi-celestronaux/CMakeLists.txt Bumps the driver minor version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread indi-celestronaux/celestronaux.cpp
Comment thread indi-celestronaux/celestronaux.cpp Outdated
Comment thread indi-celestronaux/celestronaux.cpp
Comment thread indi-celestronaux/celestronaux.cpp
Comment thread indi-celestronaux/simulator/nse_simulator.py Outdated
Comment thread indi-celestronaux/tests/system/test_cordwrap.py
Comment thread indi-celestronaux/tests/system/test_cordwrap.py
@knro

knro commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Please note the values of an INDI property can be loaded like this:

CordWrapToggleSP.load();

However, this would ONLY load the values from config in this property, it's not going to trigger ISNewSwitch(...). Just wanted to share this as it may be what you wanted to use instead of loadConfig(true, CordWrapToggleSP.getName());

The full loadConfig version would call ISNewXXX functions.

@jochym

jochym commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Please note the values of an INDI property can be loaded like this:

CordWrapToggleSP.load();

However, this would ONLY load the values from config in this property, it's not going to trigger ISNewSwitch(...). Just wanted to share this as it may be what you wanted to use instead of loadConfig(true, CordWrapToggleSP.getName());

The full loadConfig version would call ISNewXXX functions.

I am not sure - I wanted UI to reflect the state of the driver so I think triggering ISNewSwitch is ok. I am a little rusty on the INDI UI conventions - I was following the patterns of other parts of the driver and other drivers. When I finish with co-pilot review I would appreciate your review as well before I merge.

jochym pushed a commit to jochym/indi-3rdparty that referenced this pull request Jul 22, 2026
- Add switch clear in updateProperties to avoid multiple ON states
- Check writeCordWrapToMount return in CordWrapPositionSP and CordWrapBaseSP handlers
- Check getCordWrapEnabled return in CordWrapToggleSP handler
- Add LOGF_INFO for cord wrap enabled status after mount query
- Fix simulator to accept both -t and t flags
- Add config backup/restore fixture for system tests

Also restores LOGF_INFO for cord wrap position angle in updateProperties
which was accidentally removed by copilot's switch clear suggestion.
@jochym
jochym marked this pull request as draft July 22, 2026 14:16
@jochym

jochym commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

I discovered some more issues regarding this cordwrap - so changed to draft while I am dealing with them.

@jochym

jochym commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

This was a fairly hairy issue. Multiple code paths and strategies. Some obviously ad-hoc code too. I hope, I spotted all the paths and variants. At least it keeps the settings in three scenarios I could test (HC/HBG3/network). When it cannot read from the mount or from the settings it defaults to sane (I hope) defaults. I think it is ready for review. The intermittent build failures are due to the high server load on builders.

@jochym
jochym marked this pull request as ready for review July 22, 2026 17:18
@jochym
jochym requested review from Copilot and knro July 22, 2026 17:18
@knro

knro commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

We should delay this for next INDI release as we are too close to the next release in 1 week.

@jochym

jochym commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@knro I was hoping to sqeeze it before the release. Right now the CW code simply resets the state to North/Off at each start of the driver... The setting works but needs to be reapplied at the start of each driver session.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment on lines +638 to 643
// Sync member variables from property state
m_CordWrapActive = CordWrapToggleSP[INDI_ENABLED].s == ISS_ON;
int onIdx = CordWrapPositionSP.findOnSwitchIndex();
if (onIdx >= 0)
m_RequestedCordwrapPos = onIdx * 45;
}
Comment on lines 1517 to 1527
void CelestronAUX::syncCoordWrapPosition()
{
// No coord wrap for equatorial mounts.
if (m_MountType != ALT_AZ)
return;

uint32_t coordWrapPosition = 0;
if (CordWrapBaseSP[CW_BASE_SKY].s == ISS_ON)
coordWrapPosition = range360(m_RequestedCordwrapPos + getNorthAz()) * STEPS_PER_DEGREE;
if (isCordWrapSkyMode())
writeCordWrapToMount();
else
coordWrapPosition = range360(m_RequestedCordwrapPos) * STEPS_PER_DEGREE;
setCordWrapPosition(coordWrapPosition);
getCordWrapPosition();
readCordWrapFromMount();
}
Pawel T. Jochym and others added 5 commits July 22, 2026 18:07
Cord wrap properties (toggle, position, base mode) were not being
saved to config when changed via the UI. This caused settings to
be lost on driver restart.

Root cause: ISNewSwitch handlers for CORDWRAP, CORDWRAP_POS, and
CW_BASE were missing saveConfig() calls after updating properties.

Changes:
- Add saveConfig() calls to all three cord wrap ISNewSwitch handlers
- Add loadConfig() calls in ISGetProperties() to restore settings
- Fix CORDWRAP_NE default from ISS_ON to ISS_OFF in initProperties()
- Add error handling for getCordWrapEnabled/getCordWrapPosition
- Update updateProperties() to fallback to config on mount query failure
- Add isCordWrapSkyMode() helper method
- Add comprehensive cord wrap persistence tests (7 tests)

Follows the same pattern as ApproachDirectionSP, PortTypeSP, and
GuidePulseMode which already call saveConfig() in their handlers.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Add switch clear in updateProperties to avoid multiple ON states
- Check writeCordWrapToMount return in CordWrapPositionSP and CordWrapBaseSP handlers
- Check getCordWrapEnabled return in CordWrapToggleSP handler
- Add LOGF_INFO for cord wrap enabled status after mount query
- Fix simulator to accept both -t and t flags
- Add config backup/restore fixture for system tests

Also restores LOGF_INFO for cord wrap position angle in updateProperties
which was accidentally removed by copilot's switch clear suggestion.
- startupWithoutHC(): replace hardcoded 270° with priority lookup
  Mount → Config → North default, log in degrees
- updateProperties(): defineProperty before loadConfig for reliable
  config restore on reconnect; sync member vars from property state
- Initialize m_RequestedCordwrapPos to 0 in header

Fixes second-reconnect bug where all positions mapped to 270° (W).
@jochym

jochym commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

The last sequence is a no-op, it is a side-effect of my rearangement of branches. There were no additional changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants