forked from coders-school/fan_controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFan.cpp
More file actions
39 lines (32 loc) · 729 Bytes
/
Fan.cpp
File metadata and controls
39 lines (32 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "Fan.hpp"
#include <stdexcept>
#include <cmath>
Fan::Fan() {
rpm = 0;
}
Fan::Fan(Fan&& other) : rpm(std::move(other.rpm)) {}
Fan::Fan(const Fan& other) : rpm(other.rpm) {}
void Fan::setSpeed(int newRpm) {
if ((newRpm < 1000 and newRpm != 0) or newRpm > 3000) {
throw std::invalid_argument("Invalid speed");
}
auto difference = std::abs(newRpm - rpm);
for (auto i = 0; i < difference; ++i) {
if (newRpm - rpm > 0) {
rpm++;
} else {
rpm--;
}
}
}
int Fan::getSpeed() {
return rpm;
}
bool Fan::disable() {
rpm = 0;
return true;
}
bool Fan::enable() {
rpm = 1000;
return true;
}