home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / 1997 / 936 / PSI-ON.OPL < prev    next >
Encoding:
Text File  |  1997-02-28  |  15.3 KB  |  459 lines

  1. REM PsiOn V1.4 by Paul Hargreaves
  2. REM Please do not distribute modified
  3. REM versions of this program
  4. REM ╕1996, ╕1997 Paul Hargreaves
  5.  
  6. REM Changes for 1,4
  7. REM Reduced processor usage from once
  8. REM   every 2.5 seconds to just once
  9. REM   every 60 seconds
  10. REM Improved speed of keyboard/event so
  11. REM   that they get handled straight
  12. REM   away rather than after 2.5
  13. REM   seconds
  14. REM Allow sound to be re-enabled when
  15. REM   the password is being turned on.
  16. REM   Ideally, this should be at 4am 
  17. REM   but it means a rewrite of the 
  18. REM   bottom half of the code
  19. REM Added a new hotkey - Time.  This
  20. REM   will allow you to change your
  21. REM   Switched Off time temporarily.
  22. REM   Pressing any other key when 
  23. REM   activated will turn it off just
  24. REM   like Pause mode
  25. REM Allowed all hotkeys to be pressed
  26. REM   without the Psion key as well as
  27. REM   with
  28. REM Withdrew support for 1.2 and below
  29. REM   settings files, as so many of the
  30. REM   old settings have vanished
  31. REM Merged back in the extra procedures
  32. REM   as they were unneeded and were
  33. REM   taking up /valuable/ space
  34.  
  35. REM Changes for 1.3.3 and below have
  36. REM been moved to the end of this OPL
  37.  
  38.  
  39. APP PsiOn
  40.    EXT "ODB"
  41.    PATH "\OPD"
  42.    ICON "\OPL\PSI-ON.ICO"
  43.    TYPE $1000
  44. ENDA
  45.  
  46. PROC PsiOn:  
  47.    LOCAL whand%, wstat% :REM Handle for TIM:, status flag - both for the 60 second pause
  48.    LOCAL shand%, sstat% :REM Handle for TIM:, status flag - both for the long time sleep
  49.    LOCAL kstat%         :REM Keyboard handler status
  50.    LOCAL passwd$(8)     :REM Current unlock password
  51.    LOCAL event%(6)      :REM Checking for system events
  52.    LOCAL oscalls%(6)    :REM For OS calls
  53.    LOCAL wakeagn%       :REM 1 if next login should check time/date, 2 if should display immediately
  54.    LOCAL currday%       :REM Holds the current day
  55.    LOCAL rearmtm&       :REM Julian time to re-arm password
  56.    LOCAL runtk&         :REM 60 Second time delay
  57.    LOCAL integer%       :REM General integer   
  58.    LOCAL text$(30)      :REM General text
  59.    LOCAL pause%         :REM 0 for normal, 1 while PsiOn is pausing
  60.    LOCAL pid%           :REM Process ID of agenda
  61.    LOCAL srearm&        :REM Stores rearm& as entered from screen
  62.    LOCAL clr$(30)       :REM A clear bit of text
  63.    
  64.    LOCAL rearm&      :REM Rearm ticks
  65.    LOCAL agn%        :REM 1 if agenda not controlled, 2 if auto view after 4am, 3 to always show
  66.    LOCAL view$(1)    :REM Char to send to Agenda (e.g. w for Week view)
  67.    LOCAL snd%        :REM 2 for sound re-arming, 1 if not
  68.  
  69.    REM Rename this process to "PsiOn" for SPY etc to list
  70.    text$="PsiOn"+CHR$(0)
  71.    CALL($0c88,CALL($0088),0,0,0,UADD(ADDR(text$),1))
  72.       
  73.    REM Set a nice font, then display the header
  74.    FONT 7,0  
  75.    gFONT 7
  76.    
  77.    REM Disable PSION-ESC to exit program
  78.    ESCAPE OFF
  79.    
  80.    REM Mark program as in-active
  81.    CALL($138b)
  82.       
  83.    REM Set all defaults in-case file cannot be read
  84.    rearm& = 900 :REM Quarter of an hour 15*60
  85.    view$  = "W" :REM Week view
  86.    
  87.    REM Get the user settings from "\opd\psi-on.opd      REM Try to read a V1.3 to V1.3.3 file
  88.    text$="\OPD\PSI-ON.ODB"
  89.  
  90.    TRAP OPENR text$, A, rearm&, agn%, view$
  91.    IF ERR = 0
  92.       rearm& = A.rearm& 
  93.       agn%   = A.agn%
  94.       view$  = A.view$
  95.    ENDIF
  96.    TRAP CLOSE
  97.  
  98.    REM Try to read a V1.4 file
  99.    TRAP OPENR text$, A, rearm&, agn%, view$, snd%
  100.    IF ERR = 0
  101.       REM rearm& = A.rearm& 
  102.       REM agn%   = A.agn%
  103.       REM view$  = A.view$
  104.       snd%   = A.snd%
  105.    ENDIF
  106.    TRAP CLOSE
  107.  
  108.    REM Prompt for new settings
  109.    LOCK ON
  110.    DO
  111.       dINIT "PsiOn 1.4 ╕Paul Hargreaves"
  112.       dXINPUT passwd$,"Power on password"
  113.       dTIME   rearm& ,"Switched off time",3,120,32000 :REM 32000 is over 8 hours
  114.       dCHOICE agn%   ,"Control Agenda","No,Each morning,Every login"
  115.       dEDIT   view$  ,"Agenda view key"
  116.       dCHOICE snd%   ,"Control  sound on","No,Yes"
  117.  
  118.       REM Quit if escape pressed
  119.       IF DIALOG = 0
  120.          STOP
  121.       ENDIF      
  122.       
  123.       REM Check password is valid
  124.       integer% = CALL($2f8b, 0, 0, 0, ADDR(passwd$))
  125.       IF integer% <> 0 
  126.          GIPRINT "Wrong password"
  127.       ENDIF
  128.            
  129.    UNTIL integer% = 0 : REM Until dialog is OK.
  130.    LOCK OFF
  131.  
  132.    srearm& = rearm&
  133.       
  134.    REM Save away new settings if they have changed      REM Open the file for the current version.  If this fails, or any of the contents are different to the screen setting, then recreate the file
  135.    TRAP OPENR text$, A, rearm&, agn%, view$, snd%
  136.    integer% = ERR :REM Will be 0 if read ok or <> otherwise
  137.    IF ERR = 0
  138.       IF rearm& <> A.rearm& OR agn% <> A.agn% OR view$ <> A.view$ OR snd% <> A.snd%
  139.          integer% = 1
  140.       ENDIF
  141.    ENDIF
  142.    IF integer% <> 0
  143.       TRAP CLOSE
  144.       TRAP DELETE text$
  145.       TRAP MKDIR  "\OPD"
  146.       TRAP CREATE text$, A, rearm&, agn%, view$, snd%
  147.       IF ERR = 0
  148.          A.rearm& = rearm&
  149.          A.agn%   = agn%
  150.          A.view$  = view$
  151.          A.snd%   = snd%
  152.          APPEND
  153.       ENDIF
  154.    ENDIF
  155.    TRAP CLOSE
  156.  
  157.    REM Reduce the screen size and save LOTS of memory
  158.    gSETWIN (gWIDTH - 240) / 2, 65, 240, 31
  159.    gCLS
  160.    gAT 1, 14
  161.    clr$ = GEN$(1, -30)
  162.    gXPRINT "PsiOn V1.4 ╕Paul Hargreaves"+ clr$ ,1
  163.    WHILE 1 : REM Main loop
  164.          
  165.       REM Trap someone changing the password.  This isn't ideal, but it's a bit silly changing your password while PsiOn is runing anyway!
  166.       IF CALL($2f8b, 0, 0, 0, ADDR(passwd$)) <> 0
  167.          ALERT("PASSWORD HAS BEEN CHANGED!")
  168.          STOP
  169.       ENDIF
  170.             
  171.       REM Turn off the power-on password
  172.       oscalls%(1) = $3000
  173.       REM oscalls%(2,3,4 and 6)=0
  174.       oscalls%(5) = ADDR(passwd$)
  175.       OS($8b, ADDR(oscalls%()))
  176.          
  177.       REM Open the time device for the power off time and for the 60 sec times
  178.       IF IOOPEN(shand%, "TIM:", 0) < 0 OR  IOOPEN(whand%, "TIM:", 0) < 0
  179.          RAISE -3 :REM Quit - error
  180.       ENDIF
  181.  
  182.       REM Send the program to the background
  183.       CALL($198d, 100, 0)
  184.   
  185.       REM Ask the system for Power On events
  186.       CALL($6c8d): gUPDATE
  187.   
  188.       REM Now wait for some action!
  189.       WHILE 1 : REM Waiting Loop
  190.  
  191.          REM Fire TIM: to wake us up if switched off
  192.          IF pause% = 0
  193.             rearmtm& = DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + rearm&
  194.          ENDIF         
  195.          IOC(shand%, 2, sstat%, rearmtm&, #0)
  196.  
  197.          REM Display the current status
  198.          AT 1, 2
  199.          IF srearm& <> rearm&
  200.             PRINT "Temporary Switched off time" + clr$
  201.          ELSEIF pause% = 1
  202.             PRINT "Paused until next morning" + clr$
  203.          ELSE
  204.             PRINT CHR$(2) + "A Arm now   " + CHR$(2) + "P Pause   " + CHR$(2) + "T Time"
  205.          ENDIF
  206.  
  207.          REM Display agenda screen if required
  208.          IF wakeagn% = 2 :REM 2=Display now
  209.             wakeagn% = 0
  210.             text$ = "AGENDA" + CHR$(0)
  211.             oscalls%(1) = $0100
  212.             oscalls%(2) = UADD(ADDR(text$), 1)
  213.             IF (OS($88, ADDR(oscalls%())) AND 1) = 0 AND oscalls%(1) <> 0 :REM Found Agenda?
  214.                pid% = oscalls%(1)
  215.  
  216.                CALL($198d, 0, pid%) :gUPDATE :REM Now view agenda screen 
  217.  
  218.                event%(2) = 4 :REM Control-Space - Move to today in Day view
  219.                event%(1) = 32 
  220.                CALL($0483, pid%, 49, 0, ADDR(event%()))
  221.  
  222.                IF view$ <> "" AND view$ <> " " :REM Any other view wanted?
  223.  
  224.                   event%(2) = 10 :REM Send Key + 512(psion), and flags (Shift+Psion)
  225.                   event%(1) = 512 + ASC(view$)
  226.                   CALL($0483, pid%, 49, 0, ADDR(event%()))
  227.                ENDIF
  228.                   
  229.             ENDIF :REM OS = 0
  230.          ENDIF :REM wakeagn% = 2
  231.       
  232.          REM Check if agenda will need attn
  233.          currday% = DAY
  234.          IF HOUR < 4
  235.             wakeagn% = 1 :REM 1=go on alert, and always check time at login
  236.          ENDIF         
  237.          
  238.          REM Ask the system to let us know about events
  239.          event%(1) = 0
  240.          IOC(-2, 14, kstat%, event%(1), #0) :REM Same as GETEVENT but async
  241.                
  242.          REM Wait for 60 seconds or an event
  243.          runtk& = 600 :REM 60 * .10 of a second
  244.          IOC(whand%, 1, wstat%, runtk&, #0)
  245.  
  246.          IOWAIT
  247.          IOSIGNAL :REM Replace our signal
  248.        
  249.          IOCANCEL(-2)
  250.          IOWAITSTAT kstat% 
  251.  
  252.          IOCANCEL(whand%)
  253.          IOWAITSTAT wstat%
  254.  
  255.          REM Woke up - time to rearm pwd?  If so, break
  256.          IF sstat% <> -46
  257.             IOWAITSTAT sstat%
  258.             BREAK : REM Waiting loop
  259.          ENDIF
  260.  
  261.          REM Check for any system messages + quit if required
  262.          WHILE TESTEVENT OR event%(1) <> 0
  263.             IF event%(1) = 0
  264.                GETEVENT event%()
  265.             ENDIF
  266.             
  267.             IF event%(1) = 609 OR event%(1) = $404 OR event%(1) = 632 OR event%(1) = %a OR (event%(1) = 27 AND (event%(2) AND $FF) = 8) :REM Event QUIT or key Psion-X or Psion-Escape, or Psion-A, or lowercase a
  268.                IF event%(1) <> 609 AND event%(1) <> %a :REM Not Psion-A or lowercase a
  269.                   event%(1) = $404
  270.                ENDIF
  271.                BREAK : REM TESTEVENT Loop
  272.             ENDIF
  273.  
  274.             REM Change default time
  275.             IF event%(1) = 628 OR event%(1) = %t :REM Psion + t or t
  276.                rearm& = srearm& :REM Restore default off time
  277.                pause% = 0 :REM Disable pause mode
  278.                LOCK ON
  279.                dINIT
  280.                dTIME rearm& ,"Switched off time",3,120,32000 :REM 32000 is over 8 hours
  281.                DIALOG
  282.                LOCK OFF
  283.                event%(1) = 0
  284.                CONTINUE :REM Around testevent loop     
  285.             ENDIF
  286.  
  287.             REM Start pause if required, or cancel if not    
  288.             IF event%(1) = 624 OR event%(1) = %p :REM Psion-P (512+112) or lowercase p
  289.                rearm& = srearm& :REM Restore default off time
  290.                IF pause% = 0
  291.                   pause% = 1
  292.                   REM Work out what 04:00 is on the next day
  293.                   IF HOUR >= 4
  294.                      SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + 86400, event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer%
  295.                   ELSE
  296.                      SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND), event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer%
  297.                   ENDIF
  298.                   
  299.                   rearmtm& = DATETOSECS(event%(1), event%(2), event%(3), 4, 0, 0)               
  300.                   event%(1) = 0
  301.                   CONTINUE :REM Around the while testevent again
  302.                ENDIF :REM Pause = 0
  303.             ENDIF :REM Event = 624
  304.  
  305.             REM Cancel pause or temp switched off if not required             
  306.             IF pause% = 1 OR srearm& <> rearm&
  307.                IF event%(1) < $400
  308.                   pause% = 0
  309.                   rearm& = srearm&
  310.                ENDIF :REM Event = key
  311.             ENDIF :REM Pause = 1 or srearm& <> rearm&
  312.             event%(1) = 0            
  313.          ENDWH :REM WHILE TESTEVENT
  314.  
  315.          REM Cancel TIM: so we can start new TIM:
  316.          IOCANCEL(shand%)
  317.          IOWAITSTAT sstat%
  318.  
  319.          IF event%(1) = $404 OR event%(1) = 609 OR event%(1) = %a :REM Event QUIT or Key Psion-X or Psion-A (Re-arm now) or lowercase a (Re-arm now)
  320.             BREAK : REM Waiting Loop
  321.          ENDIF
  322.  
  323.       ENDWH : REM Waiting loop
  324.       
  325.       REM Turn password back on
  326.       oscalls%(1) = $3001
  327.       REM oscalls%(2,3,4 and 6)=0
  328.       oscalls%(5) = ADDR(passwd$)
  329.       OS($8b, ADDR(oscalls%()))
  330.  
  331.       REM Disable pause mode
  332.       pause% = 0
  333.  
  334.       REM Turn on sounds if required
  335.       IF snd% = 2
  336.          CALL($108b,CALL($0f8b) AND 32767)
  337.       ENDIF
  338.             
  339.       REM Close both TIM:
  340.       IOCLOSE(shand%)
  341.       IOCLOSE(whand%)
  342.  
  343.       REM Turn off PSION, when switched on, run again
  344.       IF event%(1) = $404 :REM Event QUIT or Psion-X
  345.          BEEP 5, 300
  346.          STOP
  347.       ENDIF
  348.       CALL($198d, 100, 0) :gUPDATE :REM Make sure PsiOn is in the background
  349.       CALL($198d, 0, 0)   :gUPDATE :REM Now bring PsiOn to the front!
  350.  
  351.       REM Catch the new "To Front" message
  352.       DO   
  353.          GETEVENT event%()
  354.       UNTIL event%(1) = $401 :REM Event TO FRONT
  355.       WHILE TESTEVENT
  356.          GETEVENT event%()
  357.       ENDWH
  358.  
  359.       REM Switch the machine off
  360.       OFF
  361.       
  362.       REM Run again when PsiOn notices that the password is entered
  363.       event%(1) = 0
  364.       WHILE event%(1) <> $401 :REM Event TO FRONT
  365.          
  366.          CALL($198d, 0, 0) :gUPDATE :REM Put PsiOn to the front!
  367.  
  368.          GETEVENT event%()
  369.          IF event%(1) = $404 :REM Event QUIT
  370.             STOP
  371.          ENDIF
  372.       ENDWH :REM Event TO FRONT
  373.      
  374.       REM See if agenda needs looking at
  375.       IF currday% <> DAY
  376.          wakeagn% = 1 :REM 1=check time on turn on
  377.       ENDIF
  378.       IF ((wakeagn% <> 0 AND HOUR >= 4) OR agn% = 3) AND agn% > 1
  379.          wakeagn% = 2 :REM 2=Display agenda
  380.       ENDIF
  381.          
  382.       REM Loop and Re-arm !!
  383.  
  384.    ENDWH : REM Main loop
  385. ENDP 
  386.  
  387.  
  388. REM Continuation of change log
  389.  
  390. REM Changes for 1.3.3
  391. REM If Pause mode was used, next day the
  392. REM   screen showed Pause mode was
  393. REM   running in error
  394. REM If Pause mode was used, and you use
  395. REM   the machine past midnight, Pause
  396. REM   sets itself up for the Next day
  397. REM   instead of today
  398. REM Changed text label for Pause mode
  399.  
  400. REM Changes for 1.3.2
  401. REM Sorted out issue where Agenda just
  402. REM   ignores any events first thing in
  403. REM   the morning.  
  404. REM   (appears that if Agenda isn't in
  405. REM   view, that it ignores key presses)
  406.  
  407. REM Changes for 1.3
  408. REM Press Psion-A in the screen, and
  409. REM   PsiOn will turn on the password 
  410. REM   and will switch the Psion off - 
  411. REM   just as if the time-out had 
  412. REM   occured.  Useful if you leave your
  413. REM   machine lying around at lunch etc.
  414. REM Press Psion-P in the screen, and
  415. REM   PsiOn will suspend it's auto
  416. REM   re-arm of the password until
  417. REM   04:00 hours the next day rather
  418. REM   than your normal time
  419. REM PsiOn will quit if Psion-Escape is
  420. REM   pressed
  421. REM Agenda control.  If selected, PsiOn
  422. REM   will look for 1 and only 1 running
  423. REM   task called Agenda.  When you next
  424. REM   log in, Agenda will be pushed to
  425. REM   the front, in the view of your
  426. REM   choice
  427. REM Instant response to Events - e.g.
  428. REM   a quit will quit in a couple of
  429. REM   seconds rather than 15
  430. REM Break the program up into different
  431. REM   procedures (slightly)
  432. REM Upgrades that change the psi-on.opd
  433. REM   file will keep your old settings
  434. REM Learned how to spell Siena <g>
  435. REM Low memory mode - removed all the
  436. REM   unneeded displays!  PsiOn uses
  437. REM   9/10k when working rather than 19k
  438. REM Removed Prompt Option, as no-one 
  439. REM   seems to need it - the Auto option
  440. REM   added in 1.2 more than replaces it
  441. REM Removed Beep Option, as it isn't
  442. REM   useful and it's now obvious when 
  443. REM   you log in that PsiOn is runing
  444. REM Removed New Auto-Off time, as PsiOn
  445. REM   /should/ be running all the time
  446. REM   the user will have the value set
  447. REM   in the standard place
  448. REM Changed all dialogs so that no
  449. REM   special dialogs or code are needed
  450. REM   for Siena's.
  451.  
  452. REM Changes for 1.2
  453. REM Auto rearm when password is entered
  454. REM More beep options
  455. REM Rename running program to PsiOn
  456. REM Siena (emulator) compatable!
  457. REM Tidy up the source a little
  458.  
  459.