Skip to content

Commit

Permalink
Add isSwitchOn and findOnSwitchName convenience functions
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Aug 30, 2024
1 parent af62056 commit 79af635
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
14 changes: 13 additions & 1 deletion libs/indidevice/property/indipropertyswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,31 @@ int PropertySwitch::findOnSwitchIndex() const
return d->typedProperty.findOnSwitchIndex();
}

std::string PropertySwitch::findOnSwitchName() const
{
D_PTR(const PropertySwitch);
return d->typedProperty.findOnSwitchName();
}

INDI::WidgetViewSwitch *PropertySwitch::findOnSwitch() const
{
D_PTR(const PropertySwitch);
return d->typedProperty.findOnSwitch();
}

bool PropertySwitch::isSwitchOn(const std::string &name) const
{
D_PTR(const PropertySwitch);
return d->typedProperty.isSwitchOn(name);
}

bool PropertySwitch::update(const ISState states[], const char * const names[], int n)
{
D_PTR(PropertySwitch);
if (d->onNewValuesCallback)
{
NewValues newValues;
for (int i=0; i<n; ++i)
for (int i = 0; i < n; ++i)
{
newValues[names[i]] = states[i];
}
Expand Down
2 changes: 2 additions & 0 deletions libs/indidevice/property/indipropertyswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class PropertySwitch: public INDI::PropertyBasic<ISwitch>
public:
void reset();
int findOnSwitchIndex() const;
std::string findOnSwitchName() const;
INDI::WidgetViewSwitch *findOnSwitch() const;
bool isSwitchOn(const std::string &name) const;

public:
void setRule(ISRule rule);
Expand Down
19 changes: 18 additions & 1 deletion libs/indidevice/property/indipropertyview.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,29 @@ struct PropertyView: PROPERTYVIEW_BASE_ACCESS WidgetTraits<T>::PropertyType
return static_cast<WidgetType *>(IUFindOnSwitch(this));
}

template <typename X = T, enable_if_is_same_t<X, ISwitch> = true>
bool isSwitchOn(const std::string &name) const
{
auto onSwitch = findOnSwitch();
return (onSwitch && onSwitch->isNameMatch(name));
}

template <typename X = T, enable_if_is_same_t<X, ISwitch> = true>
int findOnSwitchIndex() const
{
return IUFindOnSwitchIndex(this);
}

template <typename X = T, enable_if_is_same_t<X, ISwitch> = true>
std::string findOnSwitchName() const
{
auto onSwitch = findOnSwitch();
if (onSwitch)
return onSwitch->getName();
else
return std::string();
}

public: // only for INumber
template <typename X = T, enable_if_is_same_t<X, INumber> = true>
void updateMinMax(); /* outside implementation - only driver side, see indipropertyview_driver.cpp */
Expand Down Expand Up @@ -472,7 +489,7 @@ struct WidgetView<IText>: PROPERTYVIEW_BASE_ACCESS IText
{
return getLabel() == otherLabel;
}

bool isEmpty() const
{
return getText()[0] == '\0';
Expand Down

0 comments on commit 79af635

Please sign in to comment.