mtbf.4th 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. \ run some tests for mtbf test
  2. base @ decimal
  3. : within-box ( x y x0 y0 x1 y1 -- flag )
  4. swap >r rot >r \ x y y0 y1
  5. within \ x flag
  6. swap r> r> \ flag x x0 x1
  7. within and
  8. ;
  9. variable sector
  10. variable error-count
  11. : scan-sd-sector ( -- )
  12. sector @ 1+ $fffff and dup sector !
  13. 8 lcd-text-rows 3 - lcd-at-xy
  14. dup lcd-number
  15. >r here 1024 + 1 r> read-sectors ?dup
  16. if
  17. drop
  18. 8 lcd-text-rows 2 - lcd-at-xy
  19. 1 error-count +! error-count @ lcd-number
  20. filesystem-init
  21. then
  22. ;
  23. 50 constant box-width
  24. 50 constant box-height
  25. lcd-width-pixels 2/ 15 - dup
  26. constant touch-x0
  27. box-width +
  28. constant touch-x1
  29. lcd-height-pixels 2/ 15 - dup
  30. constant touch-y0
  31. box-height +
  32. constant touch-y1
  33. 1 constant event-no-touch
  34. 2 constant event-touch
  35. 3 constant event-release
  36. 4 constant event-k1
  37. 5 constant event-k2
  38. 6 constant event-k3
  39. variable touched
  40. : read-event ( -- e )
  41. begin
  42. ctp-pos? if
  43. ctp-pos dup 0<
  44. if
  45. 2drop
  46. touched @
  47. if
  48. false touched !
  49. touch-x0 touch-y0 lcd-move-to
  50. 2 2 lcd-move-rel
  51. box-width 4 - box-height 4 - lcd-white lcd-box
  52. lcd-black
  53. event-no-touch exit
  54. then
  55. else
  56. touch-x0 touch-y0
  57. touch-x1 touch-y1
  58. within-box
  59. touched @ 0= and
  60. if
  61. true touched !
  62. touch-x0 touch-y0 lcd-move-to
  63. 2 2 lcd-move-rel
  64. box-width 4 - box-height 4 - lcd-box
  65. event-touch exit
  66. then
  67. then
  68. then
  69. button? if
  70. button
  71. case
  72. button-none of
  73. event-release exit
  74. endof
  75. button-left of
  76. event-k1 exit
  77. endof
  78. button-centre of
  79. event-k2 exit
  80. endof
  81. button-right of
  82. event-k3 exit
  83. endof
  84. endcase
  85. then
  86. key? if
  87. key-flush
  88. then
  89. scan-sd-sector
  90. again
  91. ;
  92. variable bitset
  93. variable time-limit
  94. : mtbf-clear-log ( -- )
  95. 12 6 ?do
  96. 0 i lcd-at-xy s" " lcd-type
  97. loop
  98. ;
  99. : mtbf-test ( -- )
  100. false touched !
  101. 0 bitset !
  102. 0 time-limit !
  103. begin
  104. 1 time-limit +!
  105. time-limit @ 500 >
  106. if
  107. 0 bitset !
  108. 0 time-limit !
  109. mtbf-clear-log
  110. then
  111. read-event
  112. case
  113. event-no-touch of
  114. 0 time-limit !
  115. 0 7 lcd-at-xy s" CTP release" lcd-type
  116. $01 bitset @ or bitset !
  117. endof
  118. event-touch of
  119. 0 time-limit !
  120. 0 6 lcd-at-xy s" CTP touch " lcd-type
  121. 0 7 lcd-at-xy s" " lcd-type
  122. $02 bitset @ or bitset !
  123. $01 invert bitset @ and bitset !
  124. endof
  125. event-release of
  126. 0 time-limit !
  127. 0 8 lcd-at-xy s" Key release" lcd-type
  128. $04 bitset @ or bitset !
  129. endof
  130. event-k1 of
  131. 0 time-limit !
  132. 0 8 lcd-at-xy s" " lcd-type
  133. 0 9 lcd-at-xy s" Key 1 " lcd-type
  134. $08 bitset @ or bitset !
  135. $04 invert bitset @ and bitset !
  136. endof
  137. event-k2 of
  138. 0 time-limit !
  139. 0 8 lcd-at-xy s" " lcd-type
  140. 0 10 lcd-at-xy s" Key 2 " lcd-type
  141. $10 bitset @ or bitset !
  142. $04 invert bitset @ and bitset !
  143. endof
  144. event-k3 of
  145. 0 time-limit !
  146. 0 8 lcd-at-xy s" " lcd-type
  147. 0 11 lcd-at-xy s" Key 3 " lcd-type
  148. $20 bitset @ or bitset !
  149. $04 invert bitset @ and bitset !
  150. endof
  151. endcase
  152. bitset @ $3f and $3f =
  153. until
  154. 25 6 lcd-at-xy s" PASS" lcd-type
  155. 800000 delay-us
  156. 25 6 lcd-at-xy s" " lcd-type
  157. ;
  158. : mtbf-main ( -- )
  159. button-flush
  160. key-flush
  161. ctp-flush
  162. lcd-cls
  163. s" MTBF Testing" lcd-type
  164. lcd-cr lcd-cr
  165. s" 1. Check errors" lcd-type lcd-cr
  166. s" 2. Touch square" lcd-type lcd-cr
  167. s" 3. Press/release each key" lcd-type lcd-cr
  168. 10 lcd-text-rows 1- lcd-at-xy s" Key1" lcd-type
  169. 17 lcd-text-rows 1- lcd-at-xy s" Key2" lcd-type
  170. 24 lcd-text-rows 1- lcd-at-xy s" Key3" lcd-type
  171. 0 lcd-text-rows 3 - lcd-at-xy
  172. s" sector: 00000000" lcd-type lcd-cr
  173. s" errors: 00000000" lcd-type
  174. touch-x0 touch-y0 lcd-move-to
  175. box-width box-height lcd-box
  176. begin
  177. mtbf-clear-log
  178. mtbf-test
  179. again
  180. ;
  181. base !