touch.4th 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. \ ctp testing
  2. base @ decimal
  3. 80 constant touch-box-width
  4. 40 constant touch-box-height
  5. : draw-patterns ( -- )
  6. lcd-black
  7. 60 0 do
  8. i i lcd-move-to
  9. lcd-width-pixels i 2* - lcd-height-pixels i 2* - lcd-box
  10. 5 +loop
  11. lcd-width-pixels 2/ touch-box-width 2/ -
  12. lcd-height-pixels 2/ touch-box-height 2/ -
  13. lcd-move-to
  14. touch-box-width touch-box-height lcd-box
  15. lcd-text-columns 2/ 3 - lcd-text-rows 2/ 1- lcd-at-xy
  16. s" TOUCH" lcd-type
  17. ;
  18. variable touch-down
  19. variable touch-timeout
  20. 20000 constant touch-timeout-millisec
  21. : test-touch-sequence ( -- flag )
  22. lcd-cls
  23. draw-patterns
  24. button-flush
  25. key-flush
  26. ctp-flush
  27. false touch-down !
  28. 0 touch-timeout !
  29. begin
  30. ctp-pos? if
  31. ctp-pos dup 0<
  32. if
  33. 2drop
  34. touch-down @
  35. exit
  36. else
  37. 2drop
  38. true touch-down !
  39. lcd-text-columns 2/ 4 - lcd-text-rows 2/ 1- lcd-at-xy
  40. s" RELEASE" lcd-type
  41. then
  42. then
  43. button? if
  44. button
  45. case
  46. button-left of
  47. endof
  48. button-centre of
  49. endof
  50. button-right of
  51. endof
  52. endcase
  53. then
  54. key? if
  55. key-flush
  56. then
  57. \ wait-for-event
  58. 1 touch-timeout +!
  59. touch-timeout @ touch-timeout-millisec > if
  60. false exit
  61. then
  62. 1000 delay-us
  63. again
  64. ;
  65. : test-touch-main ( -- )
  66. test-touch-sequence if
  67. s" PASS"
  68. else
  69. s" FAIL"
  70. then
  71. lcd-cls
  72. s" Touch Test" lcd-type
  73. lcd-text-columns 2/ lcd-text-rows 2/ lcd-at-xy
  74. 2dup lcd-type
  75. 500000 delay-us
  76. type ." : touch test" cr
  77. ;
  78. base !