Skip to content

Conversation

@elecpower
Copy link
Collaborator

@elecpower elecpower commented Jan 18, 2026

Partially Fixes #7005 and some housekeeping

Applies to 2.11, 2.12 and 3.0

@elecpower elecpower added bug 🪲 Something isn't working companion Related to the companion software labels Jan 18, 2026
Comment on lines 407 to 420
bool mod = false;

if (value < range.min) {
value = round((range.min - range.offset) / range.step);
mod = true;
} else if (value > range.max) {
value = round((range.max - range.offset) / range.step);
mod = true;
}

if (mod) {
model->logicalSw[i].val2 = value;
emit modified();
}
Copy link
Member

@pfeerick pfeerick Jan 18, 2026

Choose a reason for hiding this comment

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

If it doesn't make it more confusing, you can use a ternary operator to remove the need for flags... ie.

Suggested change
bool mod = false;
if (value < range.min) {
value = round((range.min - range.offset) / range.step);
mod = true;
} else if (value > range.max) {
value = round((range.max - range.offset) / range.step);
mod = true;
}
if (mod) {
model->logicalSw[i].val2 = value;
emit modified();
}
if (value < range.min || value > range.max) {
value = (value < range.min)
? round((range.min - range.offset) / range.step)
: round((range.max - range.offset) / range.step);
model->logicalSw[i].val2 = value;
emit modified();
}

Just a suggestion, whatever works best ;) There is also a std::clamp that came in in C++ '17, but lets not go there just yet. 🤭

@pfeerick pfeerick added this to the 2.11.5 milestone Jan 18, 2026
@philmoz
Copy link
Collaborator

philmoz commented Jan 19, 2026

I don't think this will work correctly for the ABS and DELTA logical switch functions.

For ABS allowable range must always be positive.
For DELTA allowable range should be between (min - max) and (max - min).
For ABS DELTA allowable range should be between 0 and (max - min).

@elecpower
Copy link
Collaborator Author

I don't think this will work correctly for the ABS and DELTA logical switch functions.

For ABS allowable range must always be positive. For DELTA allowable range should be between (min - max) and (max - min). For ABS DELTA allowable range should be between 0 and (max - min).

Yes and UI widget minimum and maximum also need fixing for these functions too

@elecpower
Copy link
Collaborator Author

I'm still testing the latest commit and trying to fix the lack of value acceleration.

@pfeerick pfeerick marked this pull request as draft January 20, 2026 02:36
@elecpower
Copy link
Collaborator Author

Testing complete subject to someone finding me out. Tried many approaches and asked Google but to date unable to solve the lack of value Acceleration.

@elecpower elecpower marked this pull request as ready for review January 20, 2026 10:21
@pfeerick pfeerick merged commit 3573a80 into main Jan 25, 2026
3 of 4 checks passed
@pfeerick pfeerick deleted the elecpower/fix-cpn-ls-gv branch January 25, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working companion Related to the companion software

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global variables initial value can be outside configured range

4 participants