home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CHIP_CD_2004-07.iso / software / nncron_hit / files / nncron189.exe / plugins / winlirc.spf < prev   
Text File  |  2003-06-26  |  3KB  |  128 lines

  1. \ File:         winlirc.spf
  2. \ Author:       Nicholas Nemtsev
  3. \ Date:         08.04.03
  4. \ Modified:     17.04.03 (LIRC-TASK waits winlirc start)
  5. \ Description:  Monitors remote control commands from winlirc (http://winlirc.sourceforge.net/).
  6. \ Words: WatchLirc:
  7. \ Usage: WatchLirc: <command-pattern>
  8. \        <command-pattern> is wild card or regexp
  9. \ Example:
  10. \ * <%
  11. \ * : SEND2WINAMP ( n -- )
  12. \ *    WIN-EXIST: "Winamp v1.x"
  13. \ *    IF
  14. \ *      0 SWAP 273 WIN-HWND SendMessageA DROP
  15. \ *    ELSE
  16. \ *      DROP
  17. \ *    THEN
  18. \ * ;
  19. \ * %>
  20. \ * #( play-winamp
  21. \ * WatchLirc: play
  22. \ * Action:
  23. \ *     40045 SEND2WINAMP
  24. \ * )#
  25.  
  26. \ * Others WinAmp's codes:
  27. \ *    Next track button 40048
  28. \ *    Play button 40045
  29. \ *    Pause/Unpause button 40046
  30. \ *    Stop button 40047
  31. \ *    ...
  32.  
  33.  
  34. DECIMAL
  35. 8765 CONSTANT LIRC-PORT
  36. VARIABLE LIRC-LIST
  37. : WATCH-LIRC-START ( a u -- h )
  38.     GLOBAL WATCH-OBJECT-S! LOCAL
  39.     GLOBAL CUR-WATCH LIRC-LIST AppendNode LOCAL
  40.     0
  41. ;
  42.  
  43. : WatchLirc:
  44.     POSTPONE WATCH:
  45.     eval-string, POSTPONE WATCH-LIRC-START
  46.     POSTPONE END-WATCH
  47. ; IMMEDIATE
  48.  
  49. SocketLine POINTER sLIRC \ socket
  50. CREATE LIRC-WORD 64 ALLOT
  51. : LIRC-READ ( -- )
  52.     BEGIN
  53.         [NONAME sLIRC ReadLine NONAME] CATCH ?DUP
  54.         IF
  55.             DUP 10060 ( WSAETIMEDOUT) =
  56.             IF DROP FALSE ELSE THROW THEN
  57.         ELSE TRUE THEN
  58.     UNTIL
  59. DBG( ." LIRC: " 2DUP TYPE )
  60.     LIRC-WORD 0!
  61.     <TIB
  62.         NextWord 2DROP
  63.         NextWord 2DROP
  64.         NextWord LIRC-WORD ZPLACE
  65.     TIB>
  66. ;
  67. : LIRC-FIT? { w -- ? }
  68.     LIRC-WORD ASCIIZ>
  69.     w WATCH-OBJECT @ ASCIIZ>
  70.     WC|RE-COMPARE
  71. ;
  72. : LIRC-LAUNCH ( w -- )
  73.     WATCH-CRON-NODE @ SP@ LAUNCH DROP
  74. ;
  75.  
  76. : LIRC-TEST
  77.     [NONAME
  78.         NodeValue DUP LIRC-FIT?
  79.         IF
  80.             LIRC-LAUNCH
  81.         ELSE DROP THEN
  82.     NONAME] LIRC-LIST DoList
  83. ;
  84.  
  85. :NONAME
  86.     DBG( ." LIRC start" CR )
  87.     SocketLine NEW TO sLIRC
  88.     [NONAME
  89.         S" 127.0.0.1" sLIRC Addr!
  90.         LIRC-PORT sLIRC vPort !
  91.         sLIRC Create
  92. \        sLIRC Connect
  93.         BEGIN
  94.             sLIRC IPAddr sLIRC vPort @ sLIRC Sock ConnectSocket DUP
  95.             10061 =     \ WSAECONNREFUSED     Connection refused.
  96.         WHILE
  97.             DROP
  98.             10000 PAUSE
  99.         REPEAT
  100.         THROW
  101.         BEGIN
  102.             LIRC-READ
  103.             LIRC-TEST
  104.         AGAIN
  105.     NONAME] CATCH
  106.     DBG( ." LIRC stop=" DUP . CR )
  107.     DROP
  108. ; TASK: LIRC-TASK
  109.  
  110. WARNING @ WARNING 0!
  111. : AfterCrontabLoading
  112.     LIRC-LIST @ 0<>
  113.     IF
  114.         LIRC-TASK START
  115.     THEN
  116.     AfterCrontabLoading
  117. ;
  118.  
  119. : BeforeCrontabLoading
  120.     LIRC-LIST @ 0<>
  121.     IF
  122.         sLIRC Close
  123.         GLOBAL LIRC-LIST FreeList LOCAL
  124.         LIRC-LIST 0!
  125.     THEN
  126.     BeforeCrontabLoading
  127. ;
  128. WARNING !