
/*
    Scheduler.rexx - ARexx program for scheduling AIR events.
    This example shows how to set up a schedule of events as follows:

        At  5:59:00 pm, Turn VCR1 On.
        At  5:59:50 pm, Start Playing VCR1.
        At  6:05:00 pm, Turn VCR1 Off.

    To test this Arexx program:

    1.  Change the "ir< >" fields on lines 70, 75, 80 to match your AIR Window.

    2.  Start this ARexx program.

    3. Run the "Time" Amiga DOS command in Prefs.
       Set the time to 5:58:00, click USE instead of SAVE.

    4. Watch the CLI window this ARexx program opened.

*/

Time_To_Turn_VCR1_On  = 17 *3600 + 59 *60 +  0
Time_To_Play_VCR1     = 17 *3600 + 59 *60 + 50
Time_To_Turn_VCR1_Off = 18 *3600 +  5 *60 +  0

call addlib('rexxsupport.library',0,-30,0)

call open out,"con://400/120/AirLink ARexx Scheduler"
if ~result then do
	say 'Open failure'
	delay( 200 )
	exit 10 
end

if ~show( 'Ports', 'AIR' ) then do
    call writech out, 'An Air program must be running.'
	delay(200)
    exit 10
end

newline = '0d 0a'x
rtn     = '0d'x
csi     = '9b'x
bell    = '07'x
down    = '84'x
up      = '8d'x
bold    = csi'3m'

call writech out, 'Time of day AirLink Scheduler'newline
call writech out, 'Use Control C to Quit 'newline newline 

options results
signal ON BREAK_C

do forever
    t = time('s')
	do while  last_t = t
		delay( 40 )
	    t = time('s')
	end
	last_t = t
	hour  =  t % 3600
	min   = (t - 3600 * hour) % 60
	sec   =  t - 3600 * hour  - 60 * min
	current_time =  hour ':' min ':' sec '   '
    call writech out, 'Current Time is  ' current_time rtn

	if t = Time_To_Turn_VCR1_On then do
		address AIR 'output ir< 1_Power >'
	    call writech out, 'VCR1 Power ON  at' current_time newline
	end

	if t = Time_To_Play_VCR1 then do
		address AIR 'output ir< 1_Play >'
	    call writech out, 'VCR1 Playing at  ' current_time newline
	end

	if t = Time_To_Turn_VCR1_Off then do
		address AIR 'output ir< 1_Power >'
	    call writech out, 'VCR1 Power OFF at' current_time newline
	end

end
exit 10

BREAK_C:
exit 10

/* End. */
