function timerSettings(&$s20Table, $mac, $actionValue) { // // Implements the actions selected in the web timer page. // $actionType = $_POST['actionType']; if ($actionValue == "clearSwitchOff" || $actionValue == "clearCountdown") { $h = $m = $s = 0; $act = $s20Table[$mac]['st']; } else { $action = $_POST['action']; $h = $_POST['hours']; $m = $_POST['minutes']; $s = $_POST['seconds']; $act = $action == "on" ? 1 : 0; } $sec = $h * 3600 + $m * 60 + $s; if ($actionValue == "clearCountdown" || $actionValue == "setCountdown" && $actionType == "now") { // // Update regular countdown timer // // Set setTimer($mac, $h, $m, $s, $act, $s20Table); // Confirm $s20Table[$mac]['timerVal'] = checkTimerSec($mac, $s20Table, $action); $s20Table[$mac]['timerAction'] = $action; if ($s20Table[$mac]['timerVal'] != $sec || $s20Table[$mac]['timerAction'] != $act) { error_log("Unexpected inconsistency in timerSettings function: " . $mac . " Set=(" . $sec . "," . $act . ") Res=(" . $s20Table[$mac]['timerVal'] . "," . $s20Table[$mac]['timerAction'] . ")\n"); return 1; } } else { // // Update automatic switch off after on timer // if (setSwitchOffTimer($mac, $sec, $s20Table) != $sec) { error_log("Set switch off unsuccessfull in timersettings (wrote " . $sec . " something else read..."); return 1; } } return 0; }
function timerSettings(&$s20Table, $actionValue) { // // Implements the actions selected in the web timer page. // $actionType = $_POST['actionType']; $name = $_POST['name']; $mac = getMacFromName($name, $s20Table); if ($actionValue == "clearSwitchOff" || $actionValue == "clearCountdown") { $h = $m = $s = 0; $act = $s20Table[$mac]['st']; } else { $action = $_POST['action']; $h = $_POST['hours']; $m = $_POST['minutes']; $s = $_POST['seconds']; $act = $action == "on" ? 1 : 0; } $sec = $h * 3600 + $m * 60 + $s; if ($actionValue == "clearCountdown" || $actionValue == "setCountdown" && $actionType == "now") { // // Update regular countdown timer // // Set setTimer($mac, $h, $m, $s, $act, $s20Table); // Confirm $s20Table[$mac]['timerVal'] = checkTimerSec($mac, $s20Table, $action); $s20Table[$mac]['timerAction'] = $action; if ($s20Table[$mac]['timerVal'] != $sec || $s20Table[$mac]['timerAction'] != $act) { return 1; } } else { // // Update automatic switch off after on timer // if (setSwitchOffTimer($mac, $sec, $s20Table) != $sec) { return 1; } } return 0; }
break; } else { echo sprintf("%02d:%02d:%02d to => %s, current is %s\n", $h, $m, $s, actionToTxt($action), actionToTxt($st)); } ob_flush(); sleep(2); } } // // Test automatic switch off after on first device. // echo "\n\n\nTesting automatic switch off after on using switch " . $name . "\n"; $initValue = getSwitchOffTimer($mac, $s20Table); $setOff = 1800; $res = setSwitchOffTimer($mac, $setOff, $s20Table); if ($res == $setOff) { echo "\nSetting automatic switch off timer to " . $setOff . "s OK\n"; } else { echo "\nSet automatic switch off timer failed\n"; } $setOff = 0; $res = setSwitchOffTimer($mac, $setOff, $s20Table); if ($res == $setOff) { echo "\nResetting automatic switch off timer OK\n"; } else { echo "\nReset automatic switch off timer " . $name . " failed\n"; } // Program again the initial value $res = setSwitchOffTimer($mac, $initValue, $s20Table); echo "\nSetting automatic switch off timer " . $name . " to initial value (" . $res . "s)\n"; echo "\n\nTest finished, check if everything seems OK\n";