home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 400 / STARTS5.SIS / devkit.SIS / Power (.txt) < prev    next >
Encoding:
EPOC OPL Source  |  1999-02-28  |  3.3 KB  |  156 lines

  1.  
  2.  
  3. rem PowerManagement Plugin for Start5 v0.2
  4. rem ┬⌐1998 A. Pemsel
  5.  
  6. include "system.oxh"
  7. include "systinfo.oxh"
  8. include "date.oxh"    
  9.  
  10. const KPlugInUpdateRateNever%=0
  11. const KPlugInUpdateRateNormal%=1
  12. const KPlugInUpdateRateHigh%=2
  13. const KPlugInHeight%=22
  14.  
  15. proc Power_Load:
  16. endp
  17.  
  18. proc Power_Width%:
  19.     return 22
  20. endp
  21.  
  22. proc Power_UpdateRate%:
  23.     return KPlugInUpdateRateNormal%
  24. endp
  25.  
  26. proc Power_Draw:(wid%)
  27.     Power_Update:(wid%)
  28. endp
  29.  
  30. proc Power_Update:(wid%)
  31.     local widb%,s%,cur&,total&,inuse&,exttime&,extpower&,dtime&
  32.     s%=MainBatteryStatus&:
  33.     dtime&=DTNow&:
  34.     SIBatteryCurrent:(cur&, total&, inuse&, exttime&, extpower&, dtime&)
  35.     if PlugInGlobal&(PlugInID%:("Power"))=16*extpower&+s%
  36.         DTDeleteDateTime:(dtime&)
  37.         return
  38.     else
  39.         PlugInGlobal&(PlugInID%:("Power"))=16*extpower&+s%
  40.     endif
  41.     s%=3-s%
  42.     if extpower&
  43.         s%=3
  44.     endif
  45.     widb%=gloadbit(MyDir$+"Plugins\Power.mbm",0,s%)
  46.     guse wid%
  47.     gat 1,1
  48.     gcopy widb%,0,0,20,20,3
  49.     gclose widb%
  50.     DTDeleteDateTime:(dtime&)
  51. endp
  52.  
  53. proc Power_Unload:
  54. endp
  55.  
  56. proc Power_Tapped:
  57.     local wid%,mainVolt&, mainMaxVolt&, backVolt&, backMaxVolt&
  58.     local mainStat$(20),backStat$(20),s%,etr%
  59.     local cur&, total&, inuse&, exttime&, extpower&, dtime&
  60.     wid%=gcreate(70,30,500,180,0,$211)
  61.     SetPointerCapture:(wid%,&01)
  62.     gupdate off
  63.     guse wid%
  64.     gxborder 2,$94
  65.     gfont 268435957
  66.     ggmode 0
  67.     gat 2,24
  68.     gcolor $aa,$aa,$aa
  69.     glineby 494,0
  70.     gat 3,3
  71.     gcolor $dd,$dd,$dd
  72.     gfill 494,21,0
  73.     gat 10,19
  74.     gcolor 0,0,0
  75.     gprint "PowerManagement PlugIn v1.1"
  76.     gvisible on
  77.  
  78.     if evstat%<>-49 and ev&(1)=&408 and ev&(4)=0
  79.         NextEvent:
  80.     endif
  81.         
  82.     do
  83.         ioyield
  84.         if evstat%<>-46
  85.             if evstat%<0 :raise evstat% :endif
  86.             if (ev&(1) AND &400) = 0 rem Key
  87.                 break
  88.             elseif ev&(1)=&408 rem Pen
  89.                 if ev&(4)=0
  90.                     break
  91.                 endif
  92.             else
  93.                 if ev&(1)=&402 rem moved to background
  94.                     CapKeyHnd&=CaptureKey&:(ShowBarKey&,&2080,ShowBarMod&)
  95.                     break
  96.                 endif
  97.             endif
  98.             NextEvent:
  99.         endif
  100.         dtime&=DTNow&:
  101.         SIBatteryVolts:(mainVolt&, mainMaxVolt&, backVolt&, backMaxVolt&)
  102.         SIBatteryCurrent:(cur&, total&, inuse&, exttime&, extpower&, dtime&)
  103.         s%=MainBatteryStatus&:
  104.         if s%=0
  105.             mainStat$="not present"
  106.         elseif s%=1
  107.             mainStat$="very low"
  108.         elseif s%=2
  109.             mainStat$="low"
  110.         elseif s%=3
  111.             mainStat$="good"
  112.         endif
  113.         s%=BackupBatteryStatus&:
  114.         if s%=0
  115.             backStat$="not present"
  116.         elseif s%=1
  117.             backStat$="very low"
  118.         elseif s%=2
  119.             backStat$="low"
  120.         elseif s%=3
  121.             backStat$="good"
  122.         endif
  123.         gat 10,30
  124.         gBar:("Main Batteries "+mainStat$+" at "+num$(mainVolt&,5)+"mV",480,flt(mainVolt&-1.8)/(mainMaxVolt&-1.8)*100.0)
  125.         gat 10,55
  126.         gBar:("Backup Battery "+backStat$+" at "+num$(backVolt&,5)+"mV",480,flt(backVolt&-1.8)/(backMaxVolt&-1.8)*100.0)
  127.         gat 10,95
  128.         gprintb "Battery current: "+num$(cur&,4)+"mA",230,2,2
  129.         gat 250,95
  130.         gprintb "Total consumption: "+num$(total&/3600.0,7)+"mAH",234,2,2
  131.         gat 10,110
  132.         gprintb "Hours in use: "+num$(flt(inuse&/3600.0),5),230,2,2
  133.         gat 10,160
  134.         gprintb "Tap or press key to quit",480,3,2
  135.         DTDeleteDateTime:(dtime&)
  136.         gupdate
  137.         pause 10
  138.     until 0
  139.     gclose wid%
  140. endp
  141.  
  142. proc gBar:(caption$,w%,f)
  143.     gcolor 0,0,0
  144.     gfill w%,20,1
  145.     gbox w%,20
  146.     gmove 1,1
  147.     gcolor $aa,$aa,$aa
  148.     gfill flt((w%-2)/100.0*f+1.0),18,0
  149.     gmove 9,14
  150.     gfont 268435957
  151.     gcolor 0,0,0
  152.     gprint caption$
  153. endp
  154.  
  155.  
  156.