Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change new Fade system much smoother, Speed now up to 40 #7007

Merged
merged 1 commit into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tasmota/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 7.0.0.6 20191122

- Add colorpicker to WebUI by Christian Staars (#6984)
- Change new Fade system much smoother, Speed now up to 40 (#6942, #3714)

### 7.0.0.5 20191118

Expand Down
20 changes: 17 additions & 3 deletions tasmota/support_float.ino
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,23 @@ float sqrt1(const float x)
// changeUIntScale
// Change a value for range a..b to c..d, using only unsigned int math
//
// New version, you don't need the "to_min < to_max" precondition anymore
//
// PRE-CONDITIONS (if not satisfied, you may 'halt and catch fire')
// from_min < from_max (not checked)
// to_min < to_max (not checked)
// from_min <= num <= from-max (chacked)
// POST-CONDITIONS
// to_min <= result <= to_max
//
uint16_t changeUIntScale(uint16_t inum, uint16_t ifrom_min, uint16_t ifrom_max,
uint16_t ito_min, uint16_t ito_max) {
// guard-rails
if ((ito_min >= ito_max) || (ifrom_min >= ifrom_max)) {
return ito_min; // invalid input, return arbitrary value
if (ifrom_min >= ifrom_max) {
if (ito_min > ito_max) {
return ito_max;
} else {
return ito_min; // invalid input, return arbitrary value
}
}
// convert to uint31, it's more verbose but code is more compact
uint32_t num = inum;
Expand All @@ -397,6 +402,15 @@ uint16_t changeUIntScale(uint16_t inum, uint16_t ifrom_min, uint16_t ifrom_max,

// check source range
num = (num > from_max ? from_max : (num < from_min ? from_min : num));

// check to_* order
if (to_min > to_max) {
// reverse order
num = (from_max - num) + from_min;
to_min = ito_max;
to_max = ito_min;
}

uint32_t numerator = (num - from_min) * (to_max - to_min);
uint32_t result;
if (numerator >= 0x80000000L) {
Expand Down
Loading