Skip to content

Commit

Permalink
Merge pull request #7007 from s-hadinger/fade_new
Browse files Browse the repository at this point in the history
Change new Fade system much smoother, Speed now up to 40
  • Loading branch information
arendst authored Nov 23, 2019
2 parents 105771a + 3b79c1f commit 32ab18b
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 129 deletions.
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

0 comments on commit 32ab18b

Please sign in to comment.