Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
- Fixed rpm selection bug
Browse files Browse the repository at this point in the history
Signed-off-by: Hayden Briese <[email protected]>
  • Loading branch information
hbriese committed Aug 7, 2020
1 parent 4673ce5 commit ad5ea79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/build-debug/
/.idea/
/src/proto/

/aur/
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fancon (0.23.0) UNRELEASED; urgency=low
fancon (0.23.1) UNRELEASED; urgency=low

* Initial release. Closes: #00000

Expand Down
15 changes: 10 additions & 5 deletions src/FanInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ void fc::FanInterface::update() {
const Pwm target = find_closest_pwm(rpm);
set_pwm(target);

// Recover control if the PWM changes (after sleeping) from the target
sleep_for_interval();

// Recover control if the PWM changes (after sleeping) from the target
// if (get_pwm() != target) {
// LOG(llvl::debug) << *this << ": mismatch (t, a) = (" << target
// << ", " << get_pwm() << ")";
Expand Down Expand Up @@ -80,10 +81,14 @@ Pwm fc::FanInterface::find_closest_pwm(Rpm rpm) {
return ge_it->second;

const auto le_it = next(ge_it, -1); // <= rpm

// Choose the closer of two points, choosing the lower point if tied
Pwm pwm = ((rpm - le_it->first) <= (ge_it->first - rpm)) ? le_it->second
: ge_it->second;
Pwm pwm;
if (ge_it != rpm_to_pwm.end()) {
// Choose the closer of two points
pwm = ((rpm - le_it->first) <= (ge_it->first - rpm)) ? le_it->second
: ge_it->second;
} else {
pwm = le_it->second;
}

const bool needs_starting = pwm > 0 && pwm < start_pwm && get_rpm() == 0;
return (needs_starting) ? start_pwm : pwm;
Expand Down

0 comments on commit ad5ea79

Please sign in to comment.