/* AmigaTemp V1.2 ARexx                                            */
/* Lists names, temperatures and max/min for all connected sensors */

/* Start */
st = Show(P, 'AmigaTemp')              /* Is program running? */
if st == 0 then                        /* No... */
do
   Address COMMAND                     
   
   'AmigaTemp CX_POPUP=NO'             /* Start AmigaTemp. Don't POPUP */
   if rc > 0 then do                   /* Program not found... */
      Say "Can't start AmigaTemp"
      exit
   end   
   
   do 2 while ~Show(P, 'AmigaTemp')    /* Wait until program has started or at least 20 sek */
      'waitforport AmigaTemp'
   end
   
   if ~Show(P, 'AmigaTemp') then do    /* Something is wrong... */
      Say "No contact with ARexx Port"
      exit
   end
end   

/* Main */
Options RESULTS                        /* Retrive the string result field */
Address 'AmigaTemp'                    /* Portname for AmigaTemp (Case sensitive) */
   
'Version'; Say result                  /* Write name and version */

                                       /* Celsius or Fahrenheit? */
'DegreeType'; Say 'Temperature in ' || result

'NumSensor'; numsensor = result        /* Number Of Sensors */

Say 'Name                Temp Tend   Max Date            Min Date'
Say '--------------------------------------------------------------------'

do i=1 to numsensor
   'Name' i                            /* Name of sensor */
   If rc == 0 then                     /* rc == 0 if sensor is connected */
   do
      name = left(result, 18)          /* Name of sensor */
      'Temp'     i; temp = result      /* Current temperature */
      'Tendency' i; tend = result      /* Temperature tendency (+,-,' ') */
      'Max'      i; max = result       /* Max temperature */
      'DateMax'  i; maxdate = result   /* Date for max temperature */
      'Min'      i; min = result       /* Min temperature */
      'DateMin'  i; mindate = result   /* Date for min temperature */
      Say name || temp || ' ' || tend || '   ' || max || ' ' || maxdate || ' ' || min || ' ' || mindate;
   end   
end i

if st == 0 then 'Quit'                 /* Quit AmigaTemp if we started it */


