Ejemplo n.º 1
0
	function	IPSWatering_ActivateStartTimer($CircleId, $Value=true) {
		$Name           = IPS_GetName($CircleId);
		$scriptId_Timer = IPSUtil_ObjectIDByPath('Program.IPSLibrary.app.modules.IPSWatering.IPSWatering_ActivationTimer');
		$TimerId        = @IPS_GetEventIDByName($Name, $scriptId_Timer);
		if ($TimerId === false) {
 			$TimerId = IPS_CreateEvent(1 /*Cyclic Event*/);
			IPS_SetName($TimerId, $Name);
			IPS_SetParent($TimerId, $scriptId_Timer);
			if (!IPS_SetEventCyclic($TimerId, 1 /*Once*/, 1,0,0,0,0)) {
				IPSLogger_Err(__file__, "IPS_SetEventCyclic failed for WateringCircle '$Name' Timer !!!");
				exit;
			}
		}
		if ($Value) {
			if (!IPS_SetEventCyclicDateBounds ($TimerId, get_DateTime(get_ControlId(c_Control_NextDate, $CircleId), c_Format_NextDate),0)) {
				IPSLogger_Err(__file__, "IPS_SetEventCyclicTimeBounds failed for WateringCircle '$Name' Timer !!!");
				exit;
			}
			$Time = GetValue(get_ControlId(c_Control_NextTime, $CircleId));
			if (!IPS_SetEventCyclicTimeBounds($TimerId, mktime(substr($Time,0,2), substr($Time,3,2), 0), 0)) {
				IPSLogger_Err(__file__, "IPS_SetEventCyclicTimeBounds failed for WateringCircle '$Name' Timer !!!");
				exit;
			}
		}
		IPS_SetEventActive($TimerId, $Value);
	}
	function CreateTimer ($Name, $Parent, $Hour) {
	   $TimerId = @IPS_GetEventIDByName($Name, $Parent);
	   if ($TimerId === false) {
 			$TimerId = IPS_CreateEvent(1 /*Cyclic Event*/);
   		IPS_SetName($TimerId, $Name);
   		IPS_SetParent($TimerId, $Parent);
			if (!IPS_SetEventCyclic($TimerId, 2 /**Daily*/, 1,0,0,0,0)) {
				echo "IPS_SetEventCyclic failed !!!\n";
			}
			if (!IPS_SetEventCyclicTimeBounds($TimerId, mktime($Hour, 0, 0), 0)) {
				echo "IPS_SetEventCyclicTimeBounds failed !!!\n";
			}
   		IPS_SetEventActive($TimerId, true);
			echo 'Created Timer '.$Name.'='.$TimerId."\n";
		}
		return $TimerId;
	}