home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / BATCHK.OPL < prev    next >
Text File  |  1992-04-29  |  2KB  |  96 lines

  1. REM ***************************************************************************
  2. REM * Written By Rowan Prior - Psion Technical Support                        *
  3. REM * Written On April 15th 1992                                              *
  4. REM *                                                                         *
  5. REM * Purpose - Checks the voltage of the Main and Backup Battery on the      *
  6. REM *           Series 3.  Also detects the the presents of an AC Adapter     *
  7. REM ***************************************************************************
  8.  
  9. PROC batch:
  10.     LOCAL m%(3),w%(4),a%,k%,mb,bb,l%
  11.     GLOBAL mb$(5),bb$(5)
  12.     GLOBAL km%
  13.  
  14.     REM Get high and low battery setting
  15.     a%=warn%:(addr(w%(1)))
  16.     IF a%
  17.         PRINT err$(a%)
  18.         GET
  19.         STOP
  20.     ENDIF
  21.     REM Read the battery itself
  22.     a%=bat%:(addr(m%(1)))
  23.     IF a%
  24.         PRINT ERR$(a%)
  25.         GET
  26.         STOP
  27.     ENDIF
  28.     a%=bat%:(addr(m%(1)))
  29.     IF (m%(1)<w%(1)) OR (m%(2)<w%(2))
  30.         dInit "BATTERY CHECK Version 1.00"
  31.         dText "","OPL Version",$102
  32.         dText "","WARNING",$102
  33.         IF m%(1)<w%(1)
  34.             dText "","Main Battery Low",$102
  35.         ENDIF
  36.         IF m%(2)<w%(2)
  37.             dText "","Backup Battery Low",$102
  38.         ENDIF
  39.         DIALOG
  40.     ENDIF
  41.     mb=flt(m%(1))/1000
  42.     bb=flt(m%(2))/1000
  43.     mb$=FIX$(mb,2,5)
  44.     bb$=FIX$(bb,2,5)
  45.     dInit "BATTERY CHECK Version 1.00"
  46.     dText "","OPL Version",$102
  47.     IF m%(3)
  48.         dText "","Mains Present",$100
  49.         dText "Mains",mb$+"v",$102
  50.     ELSE
  51.         dText "Main Battery",mb$,$102
  52.     ENDIF
  53.     dText "Backup Battery",bb$,$102
  54.     DIALOG
  55. ENDP
  56.  
  57. REM 
  58. REM buf% is the address of a 4 integer array 
  59. REM The first element is the main battery low voltage in mV
  60. REM The second element is the backup battery low voltage in mV
  61. REM The third element is the nominal maximum voltage of the main battery
  62. REM The fouth element is the nominal maximum voltage of the backup battery
  63. REM
  64. PROC warn%:(buf%)
  65.  
  66.     LOCAL ax%,bx%,cx%,dx%,si%,di%
  67.     bx%=buf%
  68.     ax%=$1c00
  69.     IF os($8e,ADDR(ax%)) AND 1
  70.         RETURN ax% OR $ff00
  71.     ELSE
  72.         RETURN 0
  73.     ENDIF
  74. ENDP
  75.  
  76. REM buf% is the address of a 3 integer array 
  77. REM The first element is the main battery voltage in mV
  78. REM The second element is the backup battery voltage in mV
  79. REM The third element if non zero if mains is present
  80.  
  81. PROC bat%:(buf%)
  82.     LOCAL ax%,bx%,cx%,dx%,si%,di%
  83.  
  84.     bx%=buf%
  85.     ax%=$1100
  86.     IF OS($8e,addr(ax%)) AND 1
  87.         RETURN ax% OR $ff00
  88.     ELSE
  89.         IF PEEKW(buf%+2)<1000
  90.             POKEW buf%+2,0
  91.         ENDIF
  92.         RETURN 0
  93.     ENDIF
  94. ENDP
  95.  
  96.