Author: quozl
Date: Wed Mar 13 06:17:36 2013
New Revision: 3606
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3606
Log:
OLPC XO-4 - touchscreen test, nonlinearity test, add targets, remove guide line, begin recording when target hit, stop recording when next target hit, tune minimum points, span, stride, and threshold. Remove test from menu, access only via select /touchscreen, test-nonlinearity.
Modified:
cpu/arm/olpc/nn-touchscreen.fth
Modified: cpu/arm/olpc/nn-touchscreen.fth
==============================================================================
--- cpu/arm/olpc/nn-touchscreen.fth Wed Mar 13 06:09:24 2013 (r3605)
+++ cpu/arm/olpc/nn-touchscreen.fth Wed Mar 13 06:17:36 2013 (r3606)
@@ -900,8 +900,6 @@
until drop ( )
;
-d# 50 value #skip \ Number of initial points to ignore for line
-0 value skipping? \ Current skip count
: ev(
configure
cursor-off
@@ -910,7 +908,6 @@
blacken
.tsmsg
-1 to remaining
- #skip to skipping?
;
: )ev
@@ -925,6 +922,10 @@
\ Nonlinearity test
+d# 50 value #skip \ Number of initial points to ignore for line
+0 value skipping? \ Current skip count
+0 value starting?
+
d# 2000 constant #pts-max
#pts-max /w* value /buf
@@ -932,6 +933,37 @@
0 value ybuf
0 value #pts
+h# 80 value target-size
+
+: draw-start ( colour -- )
+ 0 screen-h target-size - target-size dup fill-rectangle-noff
+;
+
+: draw-stop ( colour -- )
+ screen-w target-size - 0 target-size dup fill-rectangle-noff
+;
+
+: in-start? ( x y -- flag )
+ screen-h target-size - screen-h between
+ swap
+ 0 target-size between
+ and
+ dup if blue draw-start then
+;
+
+: in-stop? ( x y -- flag )
+ 0 target-size between
+ swap
+ screen-w target-size - screen-w between
+ and
+ dup if blue draw-stop then
+;
+
+: draw-targets ( -- )
+ green draw-start
+ red draw-stop
+;
+
: alloc-bufs ( -- )
/buf alloc-mem to xbuf
/buf alloc-mem to ybuf
@@ -1031,8 +1063,13 @@
swap - -rot ( intercept num den )
;
+
: do-point ( x y -- )
skipping? ?dup if 1- to skipping? 2drop exit then
+ starting? if
+ 2dup in-start? if false to starting? else 2drop exit then
+ then
+ 2dup in-stop? if 0 to remaining 2drop exit then
2dup add-pt dot
;
@@ -1105,8 +1142,9 @@
;
0 value nl-max 0 value nl-loc
-d# 60 value nl-span
-d# 30 value nl-stride
+d# 160 value nl-span
+d# 10 value nl-stride
+d# 40 value nl-threshold
: max-nonlinearity ( intercept num den -- nl )
0 to nl-max ( intercept num den )
0 to nl-loc
@@ -1142,30 +1180,51 @@
magenta color-nl d# 500 ms
loop
;
+: at-5pm d# 30 d# 27 at-xy ." "(1b)[K" ;
+: .tsmsg-drag
+ at-5pm ." Drag between targets." cr
+;
+: .tsmsg-few
+ at-5pm ." Too few points. Draw the line slowly. " cr
+;
\ TODO:
\ 1) Message and retry if slope and intercept not approximately correct
\ slope can be checked with
\ ( num den ) h# 10000 -rot */ LOW HIGH within
\ ( expected slope is negative , so LOW and HIGH are negative )
-\ 2) Establish threshold for nonlinearity and fail if exceeded
\ 3) Perhaps integrate the nonlinearity test with the targets test?
+: ((test-nonlinearity))
+ ['] .tsmsg-drag to .tsmsg
+ begin ev(
+ draw-targets
+ 0 to #pts
+ #skip to skipping?
+ true to starting?
+ ['] do-point ev
+ #pts d# 400 < while
+ .tsmsg-few ['] .tsmsg-few to .tsmsg
+ d# 1000 ms
+ repeat
+;
+
+: (test-nonlinearity) ( -- nonlinearity )
+ ((test-nonlinearity))
+ linear-least-squares ( intercept num den )
+ 3dup red draw-line ( intercept num den )
+ max-nonlinearity ( nonlinearity )
+ at-5pm dup ." Nonlinearity: " .d cr ( nonlinearity )
+ show-nonlinearity ( nonlinearity )
+;
+
: test-nonlinearity
+ d# 86400.000 to test-timeout
alloc-bufs
- begin ev(
- 0 to #pts
- 0 d# 27 at-xy ." Follow the line. Type a key to exit " cr
- screen-h 6 - screen-h negate screen-w blue draw-line
- ['] do-point ev
- #pts d# 500 < while
- 0 d# 27 at-xy ." Too few points. Draw the line slowly" cr
- d# 2000 ms
- repeat
- linear-least-squares ( intercept num den )
- 3dup red draw-line ( intercept num den )
- ." Nonlinearity: " max-nonlinearity .d cr
- show-nonlinearity
+ begin
+ (test-nonlinearity)
+ nl-threshold <=
+ until
)ev
free-bufs
;
@@ -1334,7 +1393,6 @@
: mb-final ( -- error? )
open 0= if true exit then
- d# 86400.000 to test-timeout
['] test-nonlinearity catch ?dup if .error fault then
close
faults
@@ -1348,7 +1406,7 @@
test-station case
h# 1 of mb-smt exit endof
h# 2 of mb-assy exit endof
- h# 4 of mb-final exit endof
+ h# 4 of mb-smt exit endof
h# 11 of ir-pcb-smt exit endof
h# 12 of ir-pcb-assy exit endof
h# 13 of lg-tooling exit endof
Author: wmb
Date: Tue Mar 12 08:47:44 2013
New Revision: 3601
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3601
Log:
OLPC touchscreen test - linearity test improvements requested by manufacturing team.
Modified:
cpu/arm/olpc/nn-touchscreen.fth
Modified: cpu/arm/olpc/nn-touchscreen.fth
==============================================================================
--- cpu/arm/olpc/nn-touchscreen.fth Fri Mar 8 21:43:38 2013 (r3600)
+++ cpu/arm/olpc/nn-touchscreen.fth Tue Mar 12 08:47:44 2013 (r3601)
@@ -900,6 +900,8 @@
until drop ( )
;
+d# 50 value #skip \ Number of initial points to ignore for line
+0 value skipping? \ Current skip count
: ev(
configure
cursor-off
@@ -908,6 +910,7 @@
blacken
.tsmsg
-1 to remaining
+ #skip to skipping?
;
: )ev
@@ -940,7 +943,7 @@
: +w@ ( adr index -- w ) wa+ w@ ;
: +w! ( w adr index -- ) wa+ w! ;
-: add-pt ( w.x w.y -- )
+: add-pt ( w.x w.y -- )
#pts #pts-max u< if
ybuf #pts +w!
xbuf #pts +w!
@@ -1024,7 +1027,10 @@
swap - -rot ( intercept num den )
;
-: do-point ( x y -- ) 2dup add-pt dot ;
+: do-point ( x y -- )
+ skipping? ?dup if 1- to skipping? 2drop exit then
+ 2dup add-pt dot
+;
\ draw line across screen from left to right
: line-in-x ( intercept num den -- )
@@ -1044,7 +1050,7 @@
screen-h 0 do ( den num intercept )
3dup i swap - ( den num intercept den num y-b )
-rot */ ( den num intercept point-x )
- dup 1 screen-w within if ( den num intercept point-y )
+ dup 1 screen-w within if ( den num intercept point-x )
i dot ( den num intercept )
else ( den num intercept point-y )
drop ( den num intercept )
@@ -1058,6 +1064,7 @@
;
0 value err2
+0 [if]
: nonlinearity ( intercept num den -- mean-sq-nonlinearity )
0 to err2 ( intercept num den )
#pts 0 ?do ( intercept num den )
@@ -1071,6 +1078,66 @@
3drop ( )
err2 #pts / ( Serror2/#pts )
;
+[then]
+
+0 value this-#pts
+: short-nonlinearity ( intercept num den index #pts -- mean-sq-nonlinearity )
+ dup to this-#pts ( intercept num den index #pts )
+ 0 to err2 ( intercept num den index #pts )
+ bounds ?do ( intercept num den )
+ 3dup ( intercept num den intercept num den )
+ xbuf i +w@ ( intercept num den intercept num den x )
+ -rot */ + ( intercept num den predicted-y )
+ ybuf i +w@ - ( intercept num den error )
+ dup * ( intercept num den error^2 )
+ err2 + to err2 ( intercept num den )
+ loop ( intercept num den )
+ 3drop ( )
+ err2 this-#pts / ( Serror2/#pts )
+;
+
+: overall-nonlinearity ( intercept num den -- mean-sq )
+ 0 #pts short-nonlinearity
+;
+
+0 value nl-max 0 value nl-loc
+d# 60 value nl-span
+d# 30 value nl-stride
+: max-nonlinearity ( intercept num den -- nl )
+ 0 to nl-max ( intercept num den )
+ 0 to nl-loc
+ #pts 0 do ( intercept num den )
+ i nl-span + #pts > ?leave ( intercept num den )
+ 3dup i nl-span short-nonlinearity ( intercept num den nl )
+ dup nl-max > if ( intercept num den nl )
+ to nl-max i to nl-loc ( intercept num den )
+ else ( intercept num den nl )
+ drop ( intercept num den )
+ then ( intercept num den )
+ nl-stride +loop ( intercept num den )
+ 3drop nl-max ( nl )
+;
+: color-nl ( color -- )
+ pixcolor !
+ nl-loc nl-span bounds ?do
+ xbuf i +w@ ybuf i +w@ dot
+ loop
+;
+: erase-remainder ( -- )
+ #pts 0 do
+ i nl-loc dup nl-span + within 0= if
+ black pixcolor !
+ xbuf i +w@ ybuf i +w@ dot
+ then
+ loop
+;
+: show-nonlinearity ( -- )
+ erase-remainder
+ d# 8 0 do
+ yellow color-nl d# 500 ms
+ magenta color-nl d# 500 ms
+ loop
+;
\ TODO:
\ 1) Message and retry if slope and intercept not approximately correct
@@ -1082,14 +1149,19 @@
: scribble
alloc-bufs
- ev(
- 0 d# 27 at-xy ." Follow the line. Type a key to exit" cr
- screen-h 6 - screen-h negate screen-w blue draw-line
- ['] do-point ev
+ begin ev(
+ 0 to #pts
+ 0 d# 27 at-xy ." Follow the line. Type a key to exit " cr
+ screen-h 6 - screen-h negate screen-w blue draw-line
+ ['] do-point ev
+ #pts d# 500 < while
+ 0 d# 27 at-xy ." Too few points. Draw the line slowly" cr
+ d# 2000 ms
+ repeat
linear-least-squares ( intercept num den )
3dup red draw-line ( intercept num den )
- ." Nonlinearity: " nonlinearity .d cr
- d# 5000 ms
+ ." Nonlinearity: " max-nonlinearity .d cr
+ show-nonlinearity
)ev
free-bufs
;
Author: wmb
Date: Fri Mar 8 03:22:11 2013
New Revision: 3598
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3598
Log:
Neonode touchscreen - added nonlinearity test.
Modified:
cpu/arm/olpc/nn-touchscreen.fth
Modified: cpu/arm/olpc/nn-touchscreen.fth
==============================================================================
--- cpu/arm/olpc/nn-touchscreen.fth Thu Mar 7 10:10:51 2013 (r3597)
+++ cpu/arm/olpc/nn-touchscreen.fth Fri Mar 8 03:22:11 2013 (r3598)
@@ -916,11 +916,188 @@
['] (.tsmsg) to .tsmsg
;
+\ Nonlinearity test
+
+d# 2000 constant #pts-max
+
+#pts-max /w* value /buf
+0 value xbuf
+0 value ybuf
+0 value #pts
+
+: alloc-bufs ( -- )
+ /buf alloc-mem to xbuf
+ /buf alloc-mem to ybuf
+ 0 to #pts
+;
+
+: free-bufs ( -- )
+ xbuf /buf free-mem
+ ybuf /buf free-mem
+ 0 to #pts
+;
+
+: +w@ ( adr index -- w ) wa+ w@ ;
+: +w! ( w adr index -- ) wa+ w! ;
+
+: add-pt ( w.x w.y -- )
+ #pts #pts-max u< if
+ ybuf #pts +w!
+ xbuf #pts +w!
+ #pts 1+ to #pts
+ else
+ 2drop
+ then
+;
+
+: list-pts ( -- )
+ #pts 0 ?do
+ i . ." : " xbuf i +w@ . ybuf i +w@ . cr
+ loop
+;
+
+: sum-over ( buf size -- sum )
+ 0 -rot /w* bounds ?do ( sum )
+ i w@ + ( sum' )
+ /w +loop ( sum )
+;
+
+\ Maximum values, assuming max-x = 1200, max-y = 900, #pts = 2000
+\ max-x2 = 1200 * 1200 = 1,440,000
+\ max-xy = 1200 * 900 = 1,080,000
+\ max-Sx = 1200 * 2000 = 2,400,000
+\ max-Sy = 900 * 2000 = 1,800,000
+\ max-Sx2 = max-x2 * 2000 = 2,880,000,000
+\ max-Sxy = max-xy * 2000 = 2,160,000,000
+
+\ The max value for the denominator Sx2 - (Sx)2/n occurs when
+\ half the samples are 0 and the other half are max-x
+\ max-denom = max-Sx2 / 4 = 720,000,000
+
+\ A similar argument applies to the numerator, except that it
+\ can be either negative or positive. But its maximum absolute
+\ value is of the same order of magnitude as max-denom
+
+\ calculate the sum over x^2 (a double int)
+\ The maximum value is max-x * max-x * #pts
+\ For max-x = 1200 and #pts = 2000, max-Sx2 is 2,880,000,000
+: sum-x2 ( -- Sx2 )
+ 0 #pts 0 ?do ( Sx2 )
+ xbuf i +w@ ( Sx2 x )
+ dup u* + ( Sx2' )
+ loop ( Sx2 )
+;
+
+\ calculate the sum over xy (a double int)
+: sum-xy ( -- Sxy )
+ 0 #pts 0 ?do ( S )
+ xbuf i +w@ ( S x )
+ ybuf i +w@ ( S x y )
+ u* + ( S' )
+ loop ( S )
+;
+
+0 value sum-x
+0 value sum-y
+: linear-least-squares ( -- intercept num den )
+ xbuf #pts sum-over to sum-x
+ ybuf #pts sum-over to sum-y
+
+ \ Slope numerator: SUM(xy) - (SUM(x)*SUM(y) / #pts)
+
+ \ Sx max is #pts * xmax
+ \ Sy max is #pts * ymax
+ \ (Sx * Sy)/#pts max is xmax * ymax * #pts
+ sum-x sum-y #pts */ ( Sx*Sy/#pts )
+ sum-xy swap - ( num )
+
+ \ Slope denominator: SUM(x^2) - (SUM(x)^2 / #pts)
+ sum-x sum-x #pts */ ( num Sx*Sx/#pts )
+ sum-x2 swap - ( num den )
+ \ Avoid division by 0
+ dup 0= if 1+ then ( num den )
+
+ \ Calculate the intercept
+ 2dup sum-x #pts / -rot */ ( num den slope*Sx )
+
+ sum-y #pts / ( num den slope*Sx mean-y )
+ swap - -rot ( intercept num den )
+;
+
+: do-point ( x y -- ) 2dup add-pt dot ;
+
+\ draw line across screen from left to right
+: line-in-x ( intercept num den -- )
+ screen-w 0 do ( intercept num den )
+ 3dup i -rot */ + ( intercept num den point-y )
+ dup 1 screen-h within if ( intercept num den point-y )
+ i swap dot ( intercept num den )
+ else ( intercept num den point-y )
+ drop ( intercept num den )
+ then ( intercept num den )
+ loop ( intercept num den )
+ 3drop ( )
+;
+\ draw line from top to bottom of screen
+: line-in-y ( intercept num den -- )
+ swap rot ( den num intercept )
+ screen-h 0 do ( den num intercept )
+ 3dup i swap - ( den num intercept den num y-b )
+ -rot */ ( den num intercept point-x )
+ dup 1 screen-w within if ( den num intercept point-y )
+ i dot ( den num intercept )
+ else ( den num intercept point-y )
+ drop ( den num intercept )
+ then ( den num intercept )
+ loop ( den num intercept )
+ 3drop ( )
+;
+: draw-line ( intercept num den color -- )
+ pixcolor ! ( intercept num den )
+ 2 pick abs 2 pick abs > if line-in-y else line-in-x then
+;
+
+0 value err2
+: nonlinearity ( intercept num den -- mean-sq-nonlinearity )
+ 0 to err2 ( intercept num den )
+ #pts 0 ?do ( intercept num den )
+ 3dup ( intercept num den intercept num den )
+ xbuf i +w@ ( intercept num den intercept num den x )
+ -rot */ + ( intercept num den predicted-y )
+ ybuf i +w@ - ( intercept num den error )
+ dup * ( intercept num den error^2 )
+ err2 + to err2 ( intercept num den )
+ loop ( intercept num den )
+ 3drop ( )
+ err2 #pts / ( Serror2/#pts )
+;
+
+\ TODO:
+\ 1) Message and retry if slope and intercept not approximately correct
+\ slope can be checked with
+\ ( num den ) h# 10000 -rot */ LOW HIGH within
+\ ( expected slope is negative , so LOW and HIGH are negative )
+\ 2) Establish threshold for nonlinearity and fail if exceeded
+\ 3) Perhaps integrate the nonlinearity test with the targets test?
: scribble
- ev( ['] dot ev )ev
+ alloc-bufs
+ ev(
+ 0 d# 27 at-xy ." Follow the line. Type a key to exit" cr
+ screen-h 6 - screen-h negate screen-w blue draw-line
+ ['] do-point ev
+ linear-least-squares ( intercept num den )
+ 3dup red draw-line ( intercept num den )
+ ." Nonlinearity: " nonlinearity .d cr
+ d# 5000 ms
+ )ev
+ free-bufs
;
+\ : scribble
+\ ev( ['] dot ev )ev
+\ ;
+
0 value dx
0 value dy