Skip to content

Commit 4d53619

Browse files
committed
Added logic for using PC817
1 parent f760fad commit 4d53619

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

data/fans.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ <h1>Fan Curves</h1>
184184
}
185185

186186
for (const key in fan_data) {
187-
createChart(key, fan_data[key]['curves'], fan_data[key]['sensor'], fan_data[key]['temp_th'], fan_data[key]['duty_th'], fan_data[key]['sud_dur'], units);
187+
createChart(key, fan_data[key]['curves'], fan_data[key]['sensor'], fan_data[key]['temp_th'], fan_data[key]['duty_th'], fan_data[key]['sud_dur'], fan_data[key]['halt_on'], units);
188188
}
189189
}
190190
});
@@ -212,6 +212,11 @@ <h1>Fan Curves</h1>
212212
fan_data['FAN_2']['sud_dur'] = $('#step-FAN_2').val();
213213
fan_data['FAN_3']['sud_dur'] = $('#step-FAN_3').val();
214214

215+
fan_data['FAN_0']['halt_on'] = $('#halt_on-FAN_0').val();
216+
fan_data['FAN_1']['halt_on'] = $('#halt_on-FAN_1').val();
217+
fan_data['FAN_2']['halt_on'] = $('#halt_on-FAN_2').val();
218+
fan_data['FAN_3']['halt_on'] = $('#halt_on-FAN_3').val();
219+
215220
$('#FAN_0').val(JSON.stringify(fan_data["FAN_0"]));
216221
$('#FAN_1').val(JSON.stringify(fan_data["FAN_1"]));
217222
$('#FAN_2').val(JSON.stringify(fan_data["FAN_2"]));
@@ -234,7 +239,7 @@ <h1>Fan Curves</h1>
234239
});
235240
});
236241

237-
function createChart(key, data, active_sensor, active_temp_th, active_duty_th, active_sud_duration, units) {
242+
function createChart(key, data, active_sensor, active_temp_th, active_duty_th, active_sud_duration, halt_on, units) {
238243
const chartControlsContainer = $('<div>').addClass('chart-controls-container').attr('id', `chart-controls-${key}`);
239244

240245
const chartContainer = $('<div>').addClass('chart-container').attr('id', `chart-${key}`);
@@ -279,6 +284,15 @@ <h1>Fan Curves</h1>
279284
temp_select_label.appendTo(chartControlsContainer);
280285
temp_select.appendTo(chartControlsContainer);
281286

287+
const halt_select_label = $(`<label for="halt_on-${key}">Halt PC on:</label>`);
288+
const halt_select = $(`<select style="bottom: 10px; right: 100px;"></select><br>`).attr('id', `halt-${key}`);
289+
halt_select.append($('<option>', { value: 0, text : 'No halt', selected: halt_on == 0 }));
290+
halt_select.append($('<option>', { value: 1, text : 'Halt on fan speed alarm', selected: halt_on == 1 }));
291+
halt_select.append($('<option>', { value: 2, text : 'Halt on temperature alarm', selected: halt_on == 2 }));
292+
halt_select.append($('<option>', { value: 3, text : 'Halt on both', selected: halt_on == 3 }));
293+
halt_select_label.appendTo(chartControlsContainer);
294+
halt_select.appendTo(chartControlsContainer);
295+
282296
const stepupdown_select_label = $(`<label for="step-${key}">Step up/down duration:</label>`);
283297
const stepupdown_select = $(`<select style="bottom: 10px; right: 100px;"></select><br>`).attr('id', `step-${key}`);
284298
for (_s = 1; _s <= 100; _s+=1) {

src/config_constants.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,11 @@ constexpr int MAX_LEDS_PER_STRIP = 64;
4141
constexpr int ACTIVE_THERMISTORS = 2;
4242
constexpr int ACTIVE_FANS = 4;
4343

44+
45+
// --- Other Constants ---
46+
constexpr int HALT_ON_ALARM_NONE = 0;
47+
constexpr int HALT_ON_ALARM_FAN = 1;
48+
constexpr int HALT_ON_ALARM_TEMP = 2;
49+
constexpr int HALT_ON_ALARM_BOTH = 3;
50+
4451
#endif // CONFIG_CONSTANTS_H

src/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void InitializeFanCurves() {
141141
fan_doc["temp_th"] = m_SensorSettings[fan_id].temperature_alarm_threshold;
142142
fan_doc["duty_th"] = m_SensorSettings[fan_id].rpm_alarm_threshold;
143143
fan_doc["sud_dur"] = m_SensorSettings[fan_id].step_duration_seconds;
144+
fan_doc["halt_on"] = m_SensorSettings[fan_id].halt_on;
144145

145146
String settings_json;
146147
serializeJson(fan_doc, settings_json);
@@ -150,6 +151,7 @@ void InitializeFanCurves() {
150151
m_SensorSettings[fan_id].temperature_alarm_threshold = fan_doc["temp_th"].as<int>();
151152
m_SensorSettings[fan_id].rpm_alarm_threshold = fan_doc["duty_th"].as<int>();
152153
m_SensorSettings[fan_id].step_duration_seconds = fan_doc["sud_dur"].as<uint8_t>();
154+
m_SensorSettings[fan_id].halt_on = fan_doc["halt_on"].as<uint8_t>();
153155
m_SensorSettings[fan_id].fan_speed_curve.clear();
154156
for (auto const& setting : fan_doc["curves"].as<JsonArray>()) {
155157
m_SensorSettings[fan_id].fan_speed_curve.push_back({setting["temp"].as<float>(), setting["fan"].as<int>()});
@@ -293,12 +295,20 @@ void MonitorStatesTask(void *pvParameters) {
293295

294296
// Temperature Alarm
295297
if (temp > 0 && settings.temperature_alarm_threshold > 0 && temp >= settings.temperature_alarm_threshold) {
298+
if(settings.halt_on == HALT_ON_ALARM_TEMP || settings.halt_on == HALT_ON_ALARM_BOTH) {
299+
Serial.println("Halting system due to alarm condition.");
300+
digitalWrite(PIN_PWR, HIGH); // Cut power
301+
}
296302
temp_alarm_active = true;
297303
if (!b_TempAlarmFiring) Serial.printf("ALARM: Temp high on %s (%.1fC)\n", settings.sensor_name.c_str(), temp);
298304
}
299305

300306
// RPM Alarm (only if threshold is set, > 0)
301307
if (settings.rpm_alarm_threshold >= 0 && current_rpm < (unsigned long)settings.rpm_alarm_threshold) {
308+
if(settings.halt_on == HALT_ON_ALARM_FAN || settings.halt_on == HALT_ON_ALARM_BOTH) {
309+
Serial.println("Halting system due to alarm condition.");
310+
digitalWrite(PIN_PWR, HIGH); // Cut power
311+
}
302312
rpm_alarm_active = true;
303313
if (!b_RpmAlarmFiring) Serial.printf("ALARM: RPM low on FAN_%d (%lu RPM)\n", fan_id, current_rpm);
304314
}
@@ -319,6 +329,7 @@ void PlayAlarmsTask(void *pvParameters) {
319329
vTaskDelay(pdMS_TO_TICKS(1000));
320330
} else {
321331
noTone(PIN_BUZZER);
332+
digitalWrite(PIN_PWR, LOW); // Stop cutting power, alarm turned off.
322333
vTaskDelay(pdMS_TO_TICKS(250));
323334
}
324335
}
@@ -726,6 +737,7 @@ void InitializeHttpServer() {
726737
doc[fkey]["temp_th"] = value.temperature_alarm_threshold;
727738
doc[fkey]["duty_th"] = value.rpm_alarm_threshold;
728739
doc[fkey]["sud_dur"] = value.step_duration_seconds;
740+
doc[fkey]["halt_on"] = value.halt_on;
729741
doc[fkey]["units"] = systemSettings.units;
730742
JsonArray curves = doc[fkey]["curves"].to<JsonArray>();
731743
for (const auto& setting : value.fan_speed_curve) {
@@ -758,6 +770,7 @@ void InitializeHttpServer() {
758770
m_SensorSettings[fan_id].temperature_alarm_threshold = fan_doc["temp_th"].as<int>();
759771
m_SensorSettings[fan_id].rpm_alarm_threshold = fan_doc["duty_th"].as<int>();
760772
m_SensorSettings[fan_id].step_duration_seconds = fan_doc["sud_dur"].as<uint8_t>();
773+
m_SensorSettings[fan_id].halt_on = fan_doc["halt_on"].as<uint8_t>();
761774
m_SensorSettings[fan_id].fan_speed_curve.clear();
762775
for (const auto& setting : fan_doc["curves"].as<JsonArray>()) {
763776
m_SensorSettings[fan_id].fan_speed_curve.push_back({setting["temp"].as<float>(), setting["fan"].as<int>()});

src/peripherals_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void InitializeOutputs() {
5959
pinMode(PIN_LED_HEADER_1, OUTPUT);
6060
pinMode(PIN_LED_HEADER_2, OUTPUT);
6161
pinMode(PIN_BUZZER, OUTPUT);
62+
pinMode(PIN_PWR, OUTPUT);
63+
digitalWrite(PIN_PWR, LOW);
6264

6365
pinMode(PIN_LED_EXT_CTRL_1, OUTPUT);
6466
digitalWrite(PIN_LED_EXT_CTRL_1, LOW);

src/pins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// --- System Pins ---
99
constexpr uint8_t PIN_RESET_SETTINGS = 3;
1010
constexpr uint8_t PIN_BUZZER = 39;
11+
constexpr uint8_t PIN_PWR = 40; // Power control
1112

1213
// --- I2C / Screen Pins ---
1314
constexpr int8_t PIN_SDA = 16; // GPIO8 as I2C SDA

src/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct TemperatureSensorSettings {
3939
int temperature_alarm_threshold = 999;
4040
int rpm_alarm_threshold = -1;
4141
uint8_t step_duration_seconds = 1;
42+
uint8_t halt_on = 0; // 0: No halt, 1: Halt on fan speed alarm, 2: Halt on temperature alarm
4243
std::vector<FanSpeedPoint> fan_speed_curve;
4344
};
4445

0 commit comments

Comments
 (0)