コード例 #1
0
ファイル: timer_settings.php プロジェクト: intfrr/orvfms
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;
}
コード例 #2
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;
}
コード例 #3
0
ファイル: test.php プロジェクト: JonTheNiceGuy/orvfms
 $mac = array_keys($s20Table)[0];
 $ip = $s20Table[$mac]['ip'];
 $name = $s20Table[$mac]['name'];
 echo "\n\n ***  Testing timer in " . $name . " *** \n\n";
 $st = checkStatus($mac, $s20Table);
 echo " Initital status: " . actionToTxt($st) . "\n\n";
 if ($st) {
     $action = 0;
 } else {
     $action = 1;
 }
 $h = 0;
 $m = 0;
 $s = 10;
 echo "setting timer: " . $name . ' -> ' . actionToTxt($action) . " Time=" . sprintf("%02d:%02d:%02d\n", $h, $m, $s);
 if (!setTimer($mac, $h, $m, $s, $action, $s20Table)) {
     echo "Set timer succeed\n";
 } else {
     echo "Some problem on set timer\n";
 }
 //
 //Let us check
 //
 while (1) {
     $timer = checkTimer($mac, $s20Table, $h, $m, $s, $action);
     $st = checkStatus($mac, $s20Table);
     if (!$timer) {
         echo "Timer is off, status = " . actionToTxt($st) . "\n";
         break;
     } else {
         echo sprintf("%02d:%02d:%02d to => %s, current is %s\n", $h, $m, $s, actionToTxt($action), actionToTxt($st));