Skip to content

Commit c4e8fda

Browse files
committed
chore: don't need double precision for fan power/tacho
1 parent b516807 commit c4e8fda

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/gatt/fan.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ void fan_power_set(BLE::Percentage8 power, sensors::Sensors const& sensors = sen
9292

9393
} // namespace
9494

95-
double fan_rpm() {
95+
float fan_rpm() {
9696
return g_tachometer.revolutions_per_second() * 60;
9797
}
9898

99-
double fan_power() {
99+
float fan_power() {
100+
// NOLINTNEXTLINE(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
100101
return g_fan_power.value_or(0);
101102
}
102103

src/gatt/fan.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ bool init();
1717
void disconnected(hci_con_handle_t);
1818

1919
// Current fan power. [0, 100]
20-
double fan_power();
21-
double fan_rpm();
20+
float fan_power();
21+
float fan_rpm();
2222

2323
void fan_power_override(BLE::Percentage8 power); // `NOT_KNOWN` to clear override
2424
BLE::Percentage8 fan_power_override();

src/sensors/tachometer.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct Tachometer final : SensorPeriodic {
4848
this->pulses_per_revolution = pulses_per_revolution;
4949
}
5050

51-
[[nodiscard]] double revolutions_per_second() const {
51+
[[nodiscard]] auto revolutions_per_second() const {
5252
return revolutions_per_second_;
5353
}
5454

@@ -67,7 +67,8 @@ struct Tachometer final : SensorPeriodic {
6767
auto end = std::chrono::steady_clock::now();
6868

6969
auto duration_sec =
70-
std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>>>(end - begin);
70+
std::chrono::duration_cast<std::chrono::duration<float, std::ratio<1>>>(end - begin);
71+
// NOLINTNEXTLINE(bugprone-narrowing-conversions, cppcoreguidelines-narrowing-conversions)
7172
revolutions_per_second_ = pulses / duration_sec.count() / pulses_per_revolution;
7273

7374
// printf("tachometer_measure dur=%f s cnt=%u rev-per-sec=%f rpm=%f\n", duration_sec.count(),
@@ -145,8 +146,8 @@ struct Tachometer final : SensorPeriodic {
145146

146147
Pins::GPIOs pins;
147148
std::bitset<Pins::ALTERNATIVES_MAX> state;
148-
uint pulses_per_revolution = 1;
149-
double revolutions_per_second_ = 0;
149+
uint32_t pulses_per_revolution = 1;
150+
float revolutions_per_second_ = 0;
150151
};
151152

152153
} // namespace nevermore::sensors

0 commit comments

Comments
 (0)