Skip to content

Commit 5aa8eee

Browse files
committed
fan: minor update
1 parent d823d86 commit 5aa8eee

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

main/src/user/fan.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static uint8_t env_cnt = 0;
3333
static bool env_saved = true;
3434

3535
static double time_val = 0.0;
36+
static double time_sum = 0.0;
37+
3638
static bool first_edge = true;
3739
static bool period_done = true;
3840

@@ -135,7 +137,6 @@ static void pwm_init(void)
135137
static void fan_task(void *pvParameter)
136138
{
137139
uint8_t rpm_cnt = 0;
138-
double rpm_sum = 0.0;
139140
uint32_t fan_evt = 0;
140141

141142
tim_init();
@@ -181,23 +182,23 @@ static void fan_task(void *pvParameter)
181182
if (rpm_cnt++ == 4) {
182183
rpm_cnt = 0;
183184

184-
fan_rpm = rpm_sum / 4.0;
185+
fan_rpm = 60.0 / time_sum;
185186

186-
rpm_sum = 0.0;
187+
time_sum = 0.0;
187188
} else {
188-
rpm_sum += 15.0 / time_val;
189+
time_sum += time_val;
189190
}
190191
break;
191192
default:
192193
break;
193194
}
194195
} else {
196+
rpm_cnt = 0;
197+
fan_rpm = 0;
198+
time_sum = 0.0;
199+
195200
first_edge = true;
196201
period_done = true;
197-
198-
fan_rpm = 0;
199-
rpm_cnt = 0;
200-
rpm_sum = 0.0;
201202
}
202203

203204
if (!env_saved && env_cnt++ == 50) {

0 commit comments

Comments
 (0)