Skip to content

Commit ceeb2b9

Browse files
committed
reduced unnecessary readings from ADC
1 parent 6485812 commit ceeb2b9

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

src/globals.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
// --- Global Variable Definitions ---
55

6+
double temperature1 = 0, temperature2 = 0;
7+
68
// System State
79
unsigned long gHoldButtonCounter = 0;
810
bool b_TempAlarmFiring = false;

src/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "pins.h"
3030

3131
// --- Global Variables ---
32+
extern double temperature1, temperature2;
3233

3334
// System State
3435
extern unsigned long gHoldButtonCounter;

src/main.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void SaveConfig(const Settings& s) {
9797

9898
void InitializeTasks() {
9999
xTaskCreate(MonitorStatesTask, "MonitorStates", 4096, NULL, 6, NULL);
100-
xTaskCreate(ReadTemperaturesTask, "ReadTemps", 6144, NULL, 5, NULL);
100+
xTaskCreate(ReadTemperaturesTask, "ReadTemps", 4096, NULL, 5, NULL);
101101
xTaskCreate(PlayLedsTask, "PlayLEDs", 4096, NULL, 4, NULL);
102102
xTaskCreate(DisplayDataTask, "DisplayData", 4096, NULL, 3, NULL);
103103
xTaskCreate(NativeUsbTelemetryTask, "UsbTelTask", 2048, NULL, 2, NULL);
@@ -119,7 +119,7 @@ void InitializeFanCurves() {
119119

120120
DeserializationError error = deserializeJson(fan_doc, fan_curves);
121121

122-
if (error || fan_curves == "{}") {
122+
if (error || fan_curves == "{}" || fan_curves == "[]") {
123123
Serial.printf("No/Invalid settings for %s, using defaults.\n", fan_key.c_str());
124124
m_SensorSettings[fan_id].sensor_name = "TEMP_1";
125125
m_SensorSettings[fan_id].temperature_alarm_threshold = 999;
@@ -158,8 +158,8 @@ void InitializeFanCurves() {
158158
}
159159

160160
// Set initial fan speeds based on current temps
161-
const double t1 = ReadTemperature(0);
162-
const double t2 = ReadTemperature(1);
161+
double t1 = ReadTemperature(0);
162+
double t2 = ReadTemperature(1);
163163

164164
for (int i = 0; i < ACTIVE_FANS; i++) {
165165
int fan_id = a_FanIds[i];
@@ -239,6 +239,10 @@ void loop() {
239239
taskScheduler.execute();
240240
LoopMqttClient();
241241
}
242+
243+
temperature1 = ReadTemperature(0);
244+
temperature2 = ReadTemperature(1);
245+
242246
vTaskDelay(pdMS_TO_TICKS(250)); // Yield, let tasks run
243247
}
244248

@@ -278,8 +282,8 @@ void MonitorStatesTask(void *pvParameters) {
278282
// --- Monitor Alarms ---
279283
bool temp_alarm_active = false;
280284
bool rpm_alarm_active = false;
281-
const double t1 = ReadTemperature(0);
282-
const double t2 = ReadTemperature(1);
285+
const double t1 = temperature1;
286+
const double t2 = temperature2;
283287

284288
for (int i = 0; i < ACTIVE_FANS; ++i) {
285289
int fan_id = a_FanIds[i];
@@ -323,8 +327,8 @@ void PlayAlarmsTask(void *pvParameters) {
323327
void ReadTemperaturesTask(void *pvParameters) {
324328
while (true) {
325329

326-
const double t1 = ReadTemperature(0);
327-
const double t2 = ReadTemperature(1);
330+
const double t1 = temperature1;
331+
const double t2 = temperature2;
328332

329333
if (DEBUG_ENABLED && DEBUG_DATA_ENABLED) {
330334
Serial.printf("T1: %.2f C; T2: %.2f C\n", t1, t2);
@@ -423,8 +427,8 @@ void DisplayDataTask(void *pvParameters) {
423427

424428
case ScreenView::Temperatures:
425429
{
426-
double t1 = ReadTemperature(0);
427-
double t2 = ReadTemperature(1);
430+
double t1 = temperature1;
431+
double t2 = temperature2;
428432

429433
if (systemSettings.units == "F") {
430434
if (t1 > -90.0) t1 = (t1 * 1.8) + 32;
@@ -496,8 +500,8 @@ void SendUsbTelemetry() {
496500
}
497501

498502
std::string PrepareTelemetryPayload(const std::string& event) {
499-
double t1 = ReadTemperature(0);
500-
double t2 = ReadTemperature(1);
503+
double t1 = temperature1;
504+
double t2 = temperature2;
501505

502506
if (systemSettings.units == "F") {
503507
if (t1 > -90.0) t1 = (t1 * 1.8) + 32;

src/peripherals_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ double ReadTemperature(int channel) {
3636

3737
double celsius = kelvin - 273.15;
3838

39-
printf("Temperature on channel %d: %.2f C (Resistance: %.2f Ohm)\n", channel, celsius, resistance);
39+
// printf("Temperature on channel %d: %.2f C (Resistance: %.2f Ohm)\n", channel, celsius, resistance);
4040

4141
return celsius;
4242
}

0 commit comments

Comments
 (0)