Пример #1
0
    }
}
// stored schedule
$schedule_storedSchedule = new Schedule();
// check if anything has been posted
if ($_POST) {
    // load the schedule from file
    schedule_loadScheduleFromFile($schedule_storedSchedule, $schedule_configurationFileName);
    // update the schedule with data from the form
    schedule_loadPostedFormToSchedule($schedule_storedSchedule);
    // check if a turn on/off button has been pressed
    for ($valveIndex = 0; $valveIndex < $schedule_numberOfValves; ++$valveIndex) {
        // check if a valve has been turned on
        if (isset($_POST['valve' . $valveIndex . '_turnOn'])) {
            // set teh valve manual time to now
            $schedule_storedSchedule->valves[$valveIndex]->manualStartTime = operateValves_getCurrentMinutesOffsetIntoWeek();
            break;
        }
        if (isset($_POST['valve' . $valveIndex . '_turnOff'])) {
            // reset the valve manual time
            $schedule_storedSchedule->valves[$valveIndex]->manualStartTime = -1;
            break;
        }
    }
    // save to file
    if (schedule_saveScheduleToFile($schedule_storedSchedule, $schedule_configurationFileName)) {
        // operate the valves now, don't wait for cron
        operateValves_performActions($schedule_storedSchedule);
    }
} else {
    // check if valve configuration exists
Пример #2
0
function operateValves_getListOfValvesCurrentlyRequiredOpen($weeklyValveSchedule)
{
    // result array
    $valvesRequiredToBeOpen = array();
    // add one TimeRanges to each valve
    for ($valveIndex = 0; $valveIndex < count($weeklyValveSchedule); $valveIndex++) {
        // set default valves to off
        $valvesRequiredToBeOpen[$valveIndex] = 0;
    }
    // get current time
    $currentOffsetMinutesIntoWeek = operateValves_getCurrentMinutesOffsetIntoWeek();
    // iterate through valves, find valves with a range holding the current offset
    for ($valveIndex = 0; $valveIndex < count($weeklyValveSchedule); $valveIndex++) {
        // iterate over valve ranges
        for ($timeRangeIndex = 0; $timeRangeIndex < count($weeklyValveSchedule[$valveIndex]->timeRanges); $timeRangeIndex++) {
            // get current range
            $currentRange = $weeklyValveSchedule[$valveIndex]->timeRanges[$timeRangeIndex];
            // check if current offset falls inside the range
            if ($currentOffsetMinutesIntoWeek >= $currentRange->start && $currentOffsetMinutesIntoWeek <= $currentRange->end) {
                // add this valve to the list
                $valvesRequiredToBeOpen[$valveIndex] = 1;
            }
        }
    }
    // return result array
    return $valvesRequiredToBeOpen;
}