Skip to content

Commit

Permalink
Add isUpdated property function to know if a property would be update…
Browse files Browse the repository at this point in the history
…d by the passed parameters or not. It is convenient as sometimes we need to know if there is an actual change before we call the update function or save configuration for example.
  • Loading branch information
knro committed Jan 22, 2025
1 parent a92f8d6 commit 6500b91
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"name": "Debug INDI Driver",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/indiserver/indiserver",
Expand Down
23 changes: 13 additions & 10 deletions drivers/telescope/telescope_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,16 @@ bool ScopeSim::ISNewNumber(const char *dev, const char *name, double values[], c
#ifdef USE_SIM_TAB
if (mountModelNP.isNameMatch(name))
{
mountModelNP.update(values, names, n);
if (mountModelNP.isUpdated(values, names, n))
{
mountModelNP.update(values, names, n);
alignment.setCorrections(mountModelNP[MM_IH].getValue(), mountModelNP[MM_ID].getValue(),
mountModelNP[MM_CH].getValue(), mountModelNP[MM_NP].getValue(),
mountModelNP[MM_MA].getValue(), mountModelNP[MM_ME].getValue());
saveConfig(mountModelNP);
}
mountModelNP.setState(IPS_OK);
mountModelNP.apply();
alignment.setCorrections(mountModelNP[MM_IH].getValue(), mountModelNP[MM_ID].getValue(),
mountModelNP[MM_CH].getValue(), mountModelNP[MM_NP].getValue(),
mountModelNP[MM_MA].getValue(), mountModelNP[MM_ME].getValue());
saveConfig(true, mountModelNP.getName());
return true;
}

Expand Down Expand Up @@ -492,11 +495,11 @@ bool ScopeSim::MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command)
return false;
}
mcRate = static_cast<int>(SlewRateSP.findOnSwitchIndex()) + 1;
mcRate = std::max(1,std::min(4,mcRate));
mcRate = std::max(1, std::min(4, mcRate));

int rate = (dir == INDI_DIR_NS::DIRECTION_NORTH) ? mcRate : -mcRate;
if (HasPierSide() & (currentPierSide == PIER_WEST)) // see scopesim_helper.cpp: alignment
rate = -rate;
rate = -rate;
LOGF_DEBUG("MoveNS dir %s, motion %s, rate %d", dir == DIRECTION_NORTH ? "N" : "S", command == 0 ? "start" : "stop", rate);

axisSecondary.mcRate = command == MOTION_START ? rate : 0;
Expand All @@ -513,7 +516,7 @@ bool ScopeSim::MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command)
}

mcRate = static_cast<int>(SlewRateSP.findOnSwitchIndex()) + 1;
mcRate = std::max(1,std::min(4,mcRate));
mcRate = std::max(1, std::min(4, mcRate));

int rate = (dir == INDI_DIR_WE::DIRECTION_EAST) ? -mcRate : mcRate;
LOGF_DEBUG("MoveWE dir %d, motion %s, rate %d", dir == DIRECTION_EAST ? "E" : "W", command == 0 ? "start" : "stop", rate);
Expand All @@ -526,7 +529,7 @@ IPState ScopeSim::GuideNorth(uint32_t ms)
{
double rate = GuideRateNP[DEC_AXIS].getValue();
if (HasPierSide() & (currentPierSide == PIER_WEST)) // see scopsim_helper.cpp: alignment
rate = -rate;
rate = -rate;
axisSecondary.StartGuide(rate, ms);
guidingNS = true;
return IPS_BUSY;
Expand All @@ -536,7 +539,7 @@ IPState ScopeSim::GuideSouth(uint32_t ms)
{
double rate = GuideRateNP[DEC_AXIS].getValue();
if (HasPierSide() & (currentPierSide == PIER_WEST)) // see scopsim_helper.cpp: alignment
rate = -rate;
rate = -rate;
axisSecondary.StartGuide(-rate, ms);
guidingNS = true;
return IPS_BUSY;
Expand Down
6 changes: 6 additions & 0 deletions libs/indidevice/property/indipropertynumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ void PropertyNumber::updateMinMax()
d->typedProperty.updateMinMax();
}

bool PropertyNumber::isUpdated(const double values[], const char * const names[], int n) const
{
D_PTR(const PropertyNumber);
return d->typedProperty.isUpdated(values, names, n);
}

}
1 change: 1 addition & 0 deletions libs/indidevice/property/indipropertynumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PropertyNumber: public INDI::PropertyBasic<INumber>

public:
bool update(const double values[], const char * const names[], int n);
bool isUpdated(const double values[], const char * const names[], int n) const;

void fill(
const char *device, const char *name, const char *label, const char *group,
Expand Down
6 changes: 6 additions & 0 deletions libs/indidevice/property/indipropertyswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ const char * PropertySwitch::getRuleAsString() const
return d->typedProperty.getRuleAsString();
}

bool PropertySwitch::isUpdated(const ISState states[], const char * const names[], int n) const
{
D_PTR(const PropertySwitch);
return d->typedProperty.isUpdated(states, names, n);
}

void PropertySwitch::onNewValues(const std::function<void(const INDI::PropertySwitch::NewValues &)> &callback)
{
D_PTR(PropertySwitch);
Expand Down
1 change: 1 addition & 0 deletions libs/indidevice/property/indipropertyswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PropertySwitch: public INDI::PropertyBasic<ISwitch>

public:
bool update(const ISState states[], const char * const names[], int n);
bool isUpdated(const ISState states[], const char * const names[], int n) const;
bool hasUpdateCallback() const;

void fill(
Expand Down
6 changes: 6 additions & 0 deletions libs/indidevice/property/indipropertytext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ void PropertyText::fill(
d->typedProperty.fill(device, name, label, group, permission, timeout, state);
}

bool PropertyText::isUpdated(const char * const texts[], const char * const names[], int n) const
{
D_PTR(const PropertyText);
return d->typedProperty.isUpdated(texts, names, n);
}

}
1 change: 1 addition & 0 deletions libs/indidevice/property/indipropertytext.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PropertyText: public INDI::PropertyBasic<IText>

public:
bool update(const char * const texts[], const char * const names[], int n);
bool isUpdated(const char * const texts[], const char * const names[], int n) const;

void fill(
const char *device, const char *name, const char *label, const char *group,
Expand Down
36 changes: 36 additions & 0 deletions libs/indidevice/property/indipropertyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,42 @@ void PropertyView<INumber>::updateMinMax()
WeakIUUpdateMinMax(this);
}

template <> template<>
bool PropertyView<IText>::isUpdated(const char * const texts[], const char * const names[], int n) const
{
for (int i = 0; i < n; i++)
{
auto widget = findWidgetByName(names[i]);
if (widget && strcmp(widget->getText(), texts[i]) != 0)
return true;
}
return false;
}

template <> template<>
bool PropertyView<INumber>::isUpdated(const double values[], const char * const names[], int n) const
{
for (int i = 0; i < n; i++)
{
auto widget = findWidgetByName(names[i]);
if (widget && widget->getValue() != values[i])
return true;
}
return false;
}

template <> template<>
bool PropertyView<ISwitch>::isUpdated(const ISState states[], const char * const names[], int n) const
{
for (int i = 0; i < n; i++)
{
auto widget = findWidgetByName(names[i]);
if (widget && widget->getState() != states[i])
return true;
}
return false;
}

void WidgetView<IText>::fill(const char *name, const char *label, const char *initialText)
{
IUFillText(this, name, label, initialText);
Expand Down
9 changes: 9 additions & 0 deletions libs/indidevice/property/indipropertyview.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ struct PropertyView: PROPERTYVIEW_BASE_ACCESS WidgetTraits<T>::PropertyType
const char * const names[], int n
); /* outside implementation - only driver side, see indipropertyview_driver.cpp */

template <typename X = T, enable_if_is_same_t<X, IText> = true>
bool isUpdated(const char * const texts[], const char * const names[], int n) const;

template <typename X = T, enable_if_is_same_t<X, INumber> = true>
bool isUpdated(const double values[], const char * const names[], int n) const;

template <typename X = T, enable_if_is_same_t<X, ISwitch> = true>
bool isUpdated(const ISState states[], const char * const names[], int n) const;


public:
WidgetType *begin() const
Expand Down

0 comments on commit 6500b91

Please sign in to comment.