view sched/sched_at.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents f7fb679637ff
children
line wrap: on
line source
% sched_abs- Use one-shot timer to schedule action
%
% sched_abs:: timer, time, (timer, timer_event => void) => void.
%
% Can only be used on a stopped timer, whereas callback executes with
% a running timer.

function x=sched_abs(f,T,nout)
	if nargin<3, nout=nargout(f); end
	rc=cell(1,nout);
	tim=timer('TimerFcn',@(t,e)timfn,'StopFcn',@stopfn,'StartDelay',quant(0.001,T-nows));
	start(tim);
	x=@()collect();

	function timfn, [rc{:}]=f(); end
	function stopfn(t,e), timer_release(t); end
	function varargout=collect(), 
		if isvalid(tim), wait(tim); end
		varargout=rc;
	end
end