home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Anwendungen / Kurztests / IR-Master / ARexx / switch_on&off.rexx < prev    next >
OS/2 REXX Batch file  |  1994-10-13  |  7KB  |  276 lines

  1. /*****
  2.  
  3.     Record.rexx
  4.  
  5.     Sinn:
  6.  
  7.     TV um eine bestimmte Uhrzeit
  8.     einschalten, bestimmtes Programm
  9.     einstellen und wieder um eine bestimmte
  10.     Uhrzeit abschalten.
  11.  
  12.     Purpose:
  13.  
  14.     Switch on TV at a given time, select
  15.     channel, switch off at a different time.
  16.  
  17. -------------
  18.     this script needs:
  19.  
  20.     AmigaDOS commands: requestchoice, requestfile (shipped with OS3.0)
  21.     Selfmade commands: getstring, getnumber       (shipped with ir-master)
  22.     libs             : req.library                (shipped with ir-master)
  23.  
  24. *****/
  25.  
  26. cr = d2c(10)            /* ascii return */
  27.  
  28. /***********
  29.  
  30.     Initialize this 3 variables to your project's needs
  31.  
  32. ***********/
  33.  
  34.  
  35. power_on = "1"          /* How to switch on the tv set                 */
  36. power_off= "Power"      /* How to switch off the tv set                */
  37. mute     = "mute"       /* if you wnat to switch off volume on startup */
  38.                         /* otherwise enter "" to ignore this option    */
  39.  
  40. /**********
  41.  
  42.     This is initialized by the script
  43.  
  44. ***********/
  45. port_name = ""  /* The project's port           */
  46. channel   = ""  /* The desired channel          */
  47. start_at  = ""  /* Start at ?? o'clock          */
  48. stop_at   = ""  /* Stop at  ?? o'clock          */
  49.  
  50.  
  51. /************
  52.  
  53.     Do not edit the program as long as you do not
  54.     have experience in this
  55.  
  56. ************/
  57.  
  58.  
  59. options results
  60.  
  61. again_project:
  62. call message "Welcome to RECORD.REXX V1.0*N*N© 1994 by Michael Watzl*N*NPlease select a Project..."
  63. call getfile
  64. file = result
  65. if file = "" then do
  66.     if ask("Again?") then call again_project
  67.     exit 5
  68. end
  69. else
  70. do
  71.     /* Extract port name by file name */
  72.     port_name = file
  73.     if pos( ":",port_name ) > 0 then port_name = right( port_name , length( port_name ) - lastpos(":",port_name))
  74.     if pos( "/",port_name ) > 0 then port_name = right( port_name , length( port_name ) - lastpos("/",port_name))
  75.     port_name = left( port_name , length(port_name)-4 )"_rexx"
  76.  
  77.     /* ask for the missing parameters */
  78. again_channel:
  79.     call message "Enter channel..."
  80.     call getnumber
  81.     channel = result
  82.     if channel = "" then do
  83.         if ask("Again?") then call again_channel
  84.         exit 5
  85.     end
  86.     else
  87.     do
  88. again_start:
  89.         call message "Enter Start time...*N*NFormat: hh:mm"
  90.         call getstring
  91.         start_at = result
  92.         call valid start_at
  93.         if ~result then do
  94.             if ask( "Again?" ) then call again_start
  95.             exit 5
  96.         end
  97.         else
  98.         do
  99. again_stop:
  100.             call message "Enter stop time...*N*NFormat: hh:mm"
  101.             call getstring
  102.             stop_at = result
  103.             call valid stop_at
  104.             if ~result then do
  105.                 if ask("Again?") then call again_stop
  106.                 exit 5
  107.             end
  108.             else
  109.             do
  110.                 /*
  111.                  *     All data is now entered...
  112.                  */
  113.                 msg = "Confirm please *N*N"
  114.                 msg = msg||"Port       : "port_name"*N"
  115.                 msg = msg||"Channel    : "channel  "*N"
  116.                 msg = msg||"Start      : "start_at "*N"
  117.                 msg = msg||"Stop       : "stop_at  "*N"
  118.                 call ask msg
  119.                 if ~result then do
  120.                     if ask( "Again (all)?") then call again_project
  121.                     exit 5
  122.                 end
  123.                 else
  124.                 do
  125.                     /*
  126.                      *  start the runner
  127.                      */
  128.                     address command 'run >nil: ir-runner "'file'"'
  129.                     address command 'wait 1'
  130.                     if ~show(p,port_name) then do
  131.                         if ask("Can't locate IR-Runner or project...*N*NStart again?") then call again_project
  132.                         exit 5
  133.                     end  
  134.                     else
  135.                     do
  136.                         address value port_name
  137.                  
  138.                         /*
  139.                          *  Now the IR-Runner is activated with the correct project
  140.                          *  Ready to send commands
  141.                          */
  142.  
  143.                         /* Wait for start time */
  144.                         say "Waiting until "start_at
  145.                         address command 'wait until 'start_at
  146.  
  147.                         say "Switch on tv and wait some time"
  148.                         'IR_SEND $'power_on
  149.                         address command 'wait 1'
  150.  
  151.                         if mute ~= "" then do
  152.                             'IR_SEND $'mute     /* switch off volume */
  153.                         end
  154.                         address command 'wait 4'
  155.  
  156.                         say "Select channel "channel
  157.                         do i=1 to length( channel )
  158.                             'IR_Send $'substr( channel , i , 1 )
  159.                             address command 'wait 1'
  160.                         end
  161.  
  162.                         say "Wait 'till "stop_at
  163.                         address command 'wait until 'stop_at
  164.  
  165.                         say "Switch off and quit.."
  166.                         'IR_SEND $'power
  167.                         'IR_QUIT'
  168.                     end
  169.                 end
  170.             end
  171.         end
  172.     end
  173. end
  174.  
  175. exit 0
  176.  
  177.  
  178. /*
  179.  *  Invoke a filerequester and return selected file
  180.  */
  181. getfile:
  182.  
  183. address command
  184. 'requestfile >t:selected TITLE="IRM-Projekt auswählen" ACCEPTPATTERN="#?.IRM" NOICONS'
  185. if rc >0 then return ""
  186. if open( fh , 't:selected' , "R" ) then do
  187.     line = readln(fh)
  188.     line = compress( line , d2c(34)  )
  189.     call close( fh )
  190.     'delete t:selected quiet'
  191. end
  192. else do
  193.     line = ""
  194. end
  195. address
  196. return line
  197.  
  198.  
  199. /*
  200.  *  Invoke a (self programmed) numberrequester and return number
  201.  */
  202. getnumber:
  203. address command
  204. 'getnumber >t:number'
  205. if rc >0 then return ""
  206. if open( fh , 't:number' , "R" ) then do
  207.     line = readln( fh )
  208.     call close( fh )
  209.     'delete t:number quiet'
  210. end
  211. else do
  212.     line = ""
  213. end
  214. address
  215. return line
  216.  
  217. /*
  218.  *  Invoke a (self programmed) stringrequester and return string
  219.  */
  220. getstring:
  221. address command
  222. 'getstring >t:string'
  223. if rc >0 then return ""
  224. if open( fh , 't:string' , "R" ) then do
  225.     line = readln( fh )
  226.     call close( fh )
  227.     'delete t:string quiet'
  228. end
  229. else do
  230.     line = ""
  231. end
  232. address
  233. return line
  234.  
  235. /*
  236.  *  simple message for the user
  237.  */
  238. message:
  239. arg string
  240. address command
  241. 'requestchoice >nil: body="'string'" title=Request gadgets=ok'
  242. address
  243. return
  244.  
  245. /*
  246.  *  check validity of timestring
  247.  */
  248. valid:
  249. arg time
  250. res = 1
  251. if length(time) ~= 5 then res = 0
  252. if substr(time,3,1) ~= ":" then res = 0
  253. if datatype( substr(time,1,2)) ~= NUM then res = 0
  254. if datatype( substr(time,4,2)) ~= NUM then res = 0
  255. return res
  256.  
  257.  
  258. /*
  259.  *  ask user and return result
  260.  */
  261. ask:
  262. arg string
  263. address command
  264. 'requestchoice >t:select body="'string'" title=Request gadgets=ok|cancel'
  265. if open( fh , "t:select" , "R" ) then do
  266.     line = readln( fh )
  267.     call close( fh )
  268.     address command 'delete "t:select" quiet'
  269. end
  270. else
  271. do
  272.     line = 0
  273. end
  274. return line
  275.  
  276.