key-test.4th 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. \ function key tests
  2. base @ decimal
  3. 9 constant pos-1
  4. 7 dup pos-1 + dup
  5. constant pos-2
  6. + constant pos-3
  7. : show-message ( flag pos -- )
  8. lcd-text-rows 1- lcd-at-xy
  9. case
  10. 0 of s" " endof
  11. 1 of s" Press " endof
  12. 2 of s" Release" endof
  13. endcase
  14. lcd-type
  15. ;
  16. variable keys-timeout
  17. 25000 constant debounce-delay
  18. 1000 constant millisec
  19. 30000 constant max-key-wait
  20. : test-key-button ( -- u )
  21. 0 keys-timeout !
  22. begin
  23. ctp-pos? if
  24. ctp-flush
  25. then
  26. key? if
  27. key-flush
  28. then
  29. button? if
  30. button
  31. debounce-delay delay-us
  32. begin
  33. button?
  34. while
  35. drop button
  36. repeat
  37. exit
  38. then
  39. millisec delay-us
  40. 1 keys-timeout +!
  41. keys-timeout @ max-key-wait >
  42. if
  43. -1 \ all normal keys are positive
  44. exit
  45. then
  46. again
  47. ;
  48. : check-button ( c-addr u c-addr u button -- flag )
  49. test-key-button = dup >r
  50. if
  51. ." PASS: "
  52. else
  53. ." FAIL: "
  54. then
  55. type ." button " type cr
  56. r>
  57. ;
  58. : test-keys-stage-1 ( -- flag )
  59. 1 pos-1 show-message
  60. s" pressed" s" left" button-left check-button
  61. 0 pos-1 show-message
  62. dup
  63. if
  64. 2 pos-1 show-message
  65. s" released" s" left" button-none check-button
  66. 0 pos-1 show-message
  67. and
  68. then
  69. ;
  70. : test-keys-stage-2 ( -- flag )
  71. 1 pos-2 show-message
  72. s" pressed" s" centre" button-centre check-button
  73. 0 pos-2 show-message
  74. dup
  75. if
  76. 2 pos-2 show-message
  77. s" released" s" centre" button-none check-button
  78. 0 pos-2 show-message
  79. and
  80. then
  81. ;
  82. : test-keys-stage-3 ( -- flag )
  83. 1 pos-3 show-message
  84. s" pressed" s" right" button-right check-button
  85. 0 pos-3 show-message
  86. dup
  87. if
  88. 2 pos-3 show-message
  89. s" released" s" right" button-none check-button
  90. 0 pos-3 show-message
  91. and
  92. then
  93. ;
  94. : test-keys-sequence ( -- flag )
  95. lcd-cls
  96. button-flush
  97. ctp-flush
  98. key-flush
  99. s" KEY TESTS" lcd-type
  100. lcd-cr lcd-cr
  101. s" Press and release each key in" lcd-type
  102. s" sequence as indicated by the" lcd-type
  103. s" prompts above the keys." lcd-type
  104. test-keys-stage-1
  105. test-keys-stage-2 and
  106. test-keys-stage-3 and
  107. ;
  108. : test-keys-main ( -- )
  109. lcd-cls
  110. test-keys-sequence if
  111. s" PASS"
  112. else
  113. s" FAIL"
  114. then
  115. lcd-cls
  116. s" Key Test" lcd-type
  117. lcd-text-columns 2/ lcd-text-rows 2/ lcd-at-xy
  118. 2dup lcd-type
  119. 500000 delay-us
  120. type ." : KEY test" cr
  121. ;
  122. base !