Skip to content

Commit

Permalink
Fix fan_temp0 update process
Browse files Browse the repository at this point in the history
  • Loading branch information
moodeaudio committed Nov 26, 2024
1 parent dbddd67 commit b48f724
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
7 changes: 6 additions & 1 deletion www/inc/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,12 @@ function updBootConfigTxt($action, $value) {
if ($value == '#') {
sysCmd('sed -i s/^dtparam=fan_temp0/#dtparam=fan_temp0/ ' . BOOT_CONFIG_TXT);
} else {
sysCmd('sed -i s/^dtparam=fan_temp0.*/dtparam=' . $value . '/ ' . BOOT_CONFIG_TXT);
$result = sysCmd('cat ' . BOOT_CONFIG_TXT . ' | grep -c -e ^#dtparam=fan_temp0')[0];
if ($result == '0') {
sysCmd('sed -i s/^dtparam=fan_temp0.*/dtparam=' . $value . '/ ' . BOOT_CONFIG_TXT);
} else {
sysCmd('sed -i s/^#dtparam=fan_temp0.*/dtparam=' . $value . '/ ' . BOOT_CONFIG_TXT);
}
}
break;
case 'upd_disable_bt':
Expand Down
48 changes: 25 additions & 23 deletions www/sys-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,31 @@
phpSession('write', 'reduce_power', $_POST['reduce_power']);
}

if (isset($_POST['fan_temp0']) && $_POST['fan_temp0'] != $_SESSION['fan_temp0']) {
// Format is: Threshold 45-55, Target 40-50, Speed 75-125
$valid = true;
$parts = explode(',', $_POST['fan_temp0']);
if ($parts[0] < 45 || $parts[0] > 55) {
$valid = false;
$msg = 'Threshold must be between 45-55.';
} else if ($parts[1] < 40 || $parts[1] > 50) {
$valid = false;
$msg = 'Target must be between 40-50.';
} else if ($parts[1] >= $parts[0]) {
$valid = false;
$msg = 'Target must be less than threshold.';
} else if ($parts[2] < 75 || $parts[2] > 125) {
$valid = false;
$msg = 'Speed must be between 75-125.';
}
if ($valid == false) {
$_SESSION['notify']['title'] = NOTIFY_TITLE_ALERT;
$_SESSION['notify']['msg'] = $msg;
} else {
submitJob('fan_temp0', formatFanTemp0Params($_POST['fan_temp0']), NOTIFY_TITLE_INFO, NOTIFY_MSG_SYSTEM_RESTART_REQD);
phpSession('write', 'fan_temp0', $_POST['fan_temp0']);
if (isset($_POST['update_fan_temp0'])) {
if (isset($_POST['fan_temp0']) && $_POST['fan_temp0'] != $_SESSION['fan_temp0']) {
// Format is: Threshold 45-55, Target 40-50, Speed 75-125
$valid = true;
$parts = explode(',', $_POST['fan_temp0']);
if ($parts[0] < 45 || $parts[0] > 55) {
$valid = false;
$msg = 'Threshold must be between 45-55.';
} else if ($parts[1] < 40 || $parts[1] > 50) {
$valid = false;
$msg = 'Target must be between 40-50.';
} else if ($parts[1] >= $parts[0]) {
$valid = false;
$msg = 'Target must be less than threshold.';
} else if ($parts[2] < 75 || $parts[2] > 125) {
$valid = false;
$msg = 'Speed must be between 75-125.';
}
if ($valid == false) {
$_SESSION['notify']['title'] = NOTIFY_TITLE_ALERT;
$_SESSION['notify']['msg'] = $msg;
} else {
submitJob('fan_temp0', formatFanTemp0Params($_POST['fan_temp0']), NOTIFY_TITLE_INFO, NOTIFY_MSG_SYSTEM_RESTART_REQD);
phpSession('write', 'fan_temp0', $_POST['fan_temp0']);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion www/templates/sys-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ <h1 class="sys-config">System</h1>
<div class="$_fan_temp0_hide">
<label class="control-label" for="fan-temp0">Fan control</label>
<div class="controls">
<input class="config-input-large" type="text" id="fan-temp0" name="fan_temp0" value="$_select[fan_temp0]" required>
<input class="config-input-large" type="text" id="fan-temp0" name="fan_temp0" value="$_select[fan_temp0]">
<button class="btn btn-primary btn-small config-btn-set btn-submit" type="submit" name="update_fan_temp0" value="novalue"><i class="fa fa-solid fa-sharp fa-arrow-turn-down-left"></i></button>
<span class="config-help-static">
Format is: Threshold 45-55C, Target 40-50C, Speed 75-125.<br>
Expand Down

0 comments on commit b48f724

Please sign in to comment.