November 28, 2020, 10:36:50 AM

Author Topic: [bb] Accessing of Wacom Pen (Legacy serial) by Jimmy [ 1+ years ago ]  (Read 561 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Accessing of Wacom Pen (Legacy serial)
Author : Jimmy
Posted : 1+ years ago

Description : There are libraries for accessing any Wacom but for those who are interested in exact and direct access of Wacom pen (Legacy models using RS232) using their RS232 protocol.
It reads X pos, y pos, and pressure of a Wacom pen.

This I made back in 2002 but I make it available here just in case anyone has any use for it!


Code :
Code: BlitzBasic
  1. ; Access a Wacom pen, on legacy models that uses serial cable
  2. ; Reads x position, y position, and pressure
  3. ; And testing it with some simple tiles or lines.
  4. ; Uses the portio library dll (pasted in used bits directly in source instead of including)
  5.  
  6. Dim i(7)
  7. Global penx,peny,penpress,hovering
  8. Global RegsIn   = CreateBank(255)
  9. Global RegsOut  = CreateBank(255)
  10. Function DlPortWritePortUchar%( port%, value% )
  11. DebugLog "DlPortWritePortUchar " + port%
  12. DebugLog "DlPortWritePortUchar " + value%
  13. PokeInt( RegsIn, 0, port% )
  14. PokeInt( RegsIn, 4, value% )
  15. Return CallDLL("DIO","_DlPortWritePortUchar", RegsIn, RegsOut )
  16. End Function
  17. Function DlPortReadPortUchar%( port% )
  18. DebugLog "DlPortReadPortUchar" + port%
  19. PokeInt( RegsIn, 0, port% )
  20. Return CallDLL("DIO","_DlPortReadPortUchar", RegsIn, RegsOut )
  21. End Function
  22. Global  COM         = 1016
  23. Global  THR                     = 0
  24. Global  RBR                     = 0
  25. Global  DLL                     = 0
  26. Global  DLH                     = 1
  27. Global  IER                     = 1
  28. Global  FCR                     = 2
  29. Global  LCR                     = 3
  30. Global  MCR                     = 4
  31. Global  LSR                     = 5
  32. Global  MSR                     = 6
  33. Global  SCR                     = 7
  34. ; DlPortWritePortUchar( COM + 1, 0)
  35. DlPortWritePortUchar( COM + 3, 128); DLAB
  36. DlPortWritePortUchar( COM + 0, 12) ; 9600 baud
  37. DlPortWritePortUchar( COM + 1, 0)  ; baud
  38. DlPortWritePortUchar( COM + 3, 3)  ; bits
  39. DlPortWritePortUchar( COM + 2, $c7); FIFO, 07 / 0
  40. Dlportwriteportuchar( COM + 4 ,11) ; , Turn on DTR, RTS, And OUT
  41. Graphics 800,600,16
  42. SetFont LoadFont("blitz")
  43. layer=CreateImage(800,600)
  44. LoadBuffer (BackBuffer(),"Any16x16tiles.png")
  45. SetBuffer BackBuffer()
  46. Global gfx=CreateImage(16,16,64)
  47. For a=0 To 63
  48. GrabImage(gfx,a Shl 4,0,a)
  49. Next
  50. Dim map(50,38)
  51. createlevel()
  52. tool=2
  53. ; Main
  54. Repeat
  55. Repeat:e=DlPortReadPortUchar( COM + LSR ):Until e And 32
  56. DlPortWritePortUchar( COM + 0,Asc("@"))
  57. Repeat:e=DlPortReadPortUchar( COM + LSR ):Until e And 1
  58. i(0)=DlPortReadPortUchar( COM + RBR )
  59. Repeat:e=DlPortReadPortUchar( COM + LSR ):Until e And 1
  60. i(1)=DlPortReadPortUchar( COM + RBR )
  61. Repeat:e=DlPortReadPortUchar( COM + LSR ):Until e And 1
  62. i(2)=DlPortReadPortUchar( COM + RBR )
  63. Repeat:e=DlPortReadPortUchar( COM + LSR ):Until e And 1
  64. i(3)=DlPortReadPortUchar( COM + RBR )
  65. Repeat:e=DlPortReadPortUchar( COM + LSR ):Until e And 1
  66. i(4)=DlPortReadPortUchar( COM + RBR )
  67. Repeat:e=DlPortReadPortUchar( COM + LSR ):Until e And 1
  68. i(5)=DlPortReadPortUchar( COM + RBR )
  69. Repeat:e=DlPortReadPortUchar( COM + LSR ):Until e And 1
  70. i(6)=DlPortReadPortUchar( COM + RBR )
  71. penx=(i(2)+(i(1) Shl 7))/6
  72. peny=(i(5)+i(4) Shl 7)/6
  73. penpress=i(6) And 127 Xor %01000000
  74. hovering=i(0) And 64
  75. If Not hovering Then penpress=0
  76. ; test
  77. For h=0 To 37
  78. For w=0 To 49
  79. DrawBlock gfx,w Shl 4,h Shl 4,map(w,h)
  80. Next
  81. Next
  82.  
  83. Color 255,penpress,255
  84. tempxmo=penx Shr 4:tempymo=peny Shr 4
  85. tile=map(tempxmo,tempymo)
  86. ; Sense tools
  87. If mode=0 And press=0 And penpress>0 And tile=0 Then tool=1:press=1
  88. If mode=0 And press=0 And penpress>0 And tile=2 Then tool=2:press=1
  89. If mode=0 And press=0 And penpress>0 And tile=9 Then Color 255,0,0:press=1
  90. If mode=0 And press=0 And penpress>0 And tile=10 Then Color 0,255,0:press=1
  91. If mode=0 And press<>0 And penpress=0 Then press=0
  92. If mode=0 And press<>0 Then Goto notdraw
  93.  
  94. If penpress>0 And mode=0 Then mode=1:x1=penx:y1=peny
  95. If penpress=0 And mode=1 Then mode=2:x3=penx:y3=peny
  96. If penpress>0 And mode=2 Then mode=3:y2=penx:y2=peny
  97. If penpress=0 And mode=-1 Then mode=0
  98. If (tool=1 Or tool=2) And mode=1 Then Line x1,y1,penx,peny
  99. If tool=2 And mode=2 Then x2=penx:y2=peny:Line x1,y1,x2,y2:Line x2,y2,x3,y3 ; drawing two lines in a triangle like fashion
  100.  
  101. SetBuffer ImageBuffer(layer)
  102. If tool=2 And mode=3 Then bezierspline(x1,y1,x2,y2,x3,y3):mode=-1
  103. If tool=1 And mode=2 Then Line (x1,y1,x3,y3):mode=-1
  104.  
  105. .notdraw:
  106.  
  107. SetBuffer BackBuffer()
  108. DrawImage layer,0,0
  109. DrawImage gfx,penx,peny,14
  110. Plot penx,peny
  111. Flip
  112. ; If KeyHit(1) Then SaveBuffer(FrontBuffer(),"screenshot.bmp"): End
  113. Until MouseDown(2)
  114.  
  115. Function createlevel()
  116. For a=0 To 37
  117. For b=0 To 49
  118. map(b,a)=15
  119. Next
  120. Next
  121. map(0,0)=0
  122. map(1,0)=2
  123. map(2,0)=9
  124. map(3,0)=10
  125. End Function


Comments :


Jimmy(Posted 1+ years ago)

 Terribly sorry about the messy example it has some trashcode of functions not longer there, just comment those lines as I forgot I noticed.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal