Changeset 2893
- Timestamp:
- Mar 15, 2012 12:19:06 AM (15 months ago)
- Files:
-
- 1 added
- 9 edited
-
cpu/arm/olpc/build-fw.fth (modified) (1 diff)
-
cpu/arm/olpc/exc7200-touchscreen.fth (modified) (9 diffs)
-
cpu/arm/olpc/rm3150-touchscreen.fth (modified) (5 diffs)
-
cpu/arm/olpc/touchscreen-common.fth (added)
-
cpu/x86/pc/olpc/via/mfgtest.fth (modified) (1 diff)
-
ofw/gui/dialog.fth (modified) (1 diff)
-
ofw/gui/graphics.fth (modified) (2 diffs)
-
ofw/gui/iconmenu.fth (modified) (4 diffs)
-
ofw/gui/mouse.fth (modified) (4 diffs)
-
ofw/gui/textfld.fth (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cpu/arm/olpc/build-fw.fth
r2882 r2893 753 753 \+ olpc-cl3 fload ${BP}/cpu/arm/olpc/exc7200-touchscreen.fth \ Touchscreen driver and diagnostic 754 754 \+ olpc-cl3 fload ${BP}/dev/softkeyboard.fth \ On-screen keyboard 755 \+ olpc-cl3 devalias mouse /touchscreen756 755 \+ olpc-cl2 fload ${BP}/cpu/arm/olpc/rm3150-touchscreen.fth \ Touchscreen driver and diagnostic 757 756 fload ${BP}/cpu/arm/olpc/roller.fth \ Accelerometer test -
cpu/arm/olpc/exc7200-touchscreen.fth
r2789 r2893 4 4 0 0 " 4,8" " /twsi" begin-package 5 5 my-space encode-int my-address encode-int encode+ " reg" property 6 " touchscreen" name7 6 8 0 value screen-w 9 0 value screen-h 10 0 instance value invert-x? 11 0 instance value invert-y? 7 \ XXX these are really platform-related, not touchscreen-related 8 : targets? ( -- flag ) true ; \ Used to be "final-test?" 9 : .tsmsg ( -- ) 0 d# 27 at-xy ." Touchscreen test. Hit both targets to exit" cr ; 12 10 13 : dimensions ( -- w h ) screen-w screen-h ; 11 fload ${BP}/cpu/arm/olpc/touchscreen-common.fth 14 12 15 : #contacts ( -- n ) 2 ; 13 h# 7fff to touchscreen-max-x 14 h# 7fff to touchscreen-max-y 16 15 17 h# 7fff constant touchscreen-max-x 18 h# 7fff constant touchscreen-max-y 19 20 : invert-x ( x -- x' ) touchscreen-max-x swap - ; 21 : invert-y ( y -- y' ) touchscreen-max-y swap - ; 22 23 : scale-x ( x -- x' ) 24 invert-x? if invert-x then 25 screen-w touchscreen-max-x */ 26 ; 27 : scale-y ( y -- y' ) 28 invert-y? if invert-y then 29 screen-h touchscreen-max-y */ 30 ; 16 2 to #contacts 31 17 32 18 \ Try to receive a mouse report packet. If one arrives within … … 44 30 then ( flags r: z y x ) 45 31 46 r> scale-x ( flags x' r: z y ) 47 r> scale-y ( flags x y' r: z ) 32 r> r> scale-xy ( flags x' y' r: z ) 48 33 49 34 r> 3 roll ( x y z flags ) … … 52 37 true ( x y z down? contact# true ) 53 38 ; 54 true value absolute?55 39 : stream-poll? ( -- false | x y buttons true ) 56 40 pad? if ( x y z down? contact# ) … … 65 49 ; 66 50 67 h# f800 constant red68 h# 07e0 constant green69 h# 001f constant blue70 h# ffe0 constant yellow71 h# f81f constant magenta72 h# 07ff constant cyan73 h# ffff constant white74 h# 0000 constant black75 76 variable pixcolor77 78 h# 4 value y-offset79 \ 0 value /line80 \ 2 value /pixel81 82 83 variable ptr84 85 \ The following code receives and decodes touchpad packets86 87 : show-packets ( adr len -- )88 push-hex89 bounds ?do90 i 6 bounds ?do i c@ 3 u.r loop cr91 6 +loop92 pop-base93 ;94 : last-10 ( -- )95 ptr @ load-base - d# 60 > if96 ptr @ d# 60 - d# 6097 else98 load-base ptr @ over -99 then100 show-packets101 ;102 103 51 \ Display raw data from the device, stopping when a key is typed. 104 52 : show-pad ( -- ) … … 108 56 ; 109 57 110 : button ( color x -- )111 screen-h d# 50 - d# 200 d# 30 fill-rectangle-noff112 ;113 d# 300 d# 300 2constant target-wh114 : left-target ( -- x y w h ) 0 0 target-wh ;115 : right-target ( -- x y w h ) screen-w screen-h target-wh xy- target-wh ;116 false value left-hit?117 false value right-hit?118 : inside? ( mouse-x,y x y w h -- flag )119 >r >r ( mouse-x mouse-y x y r: h w )120 xy- ( dx dy )121 swap r> u< ( dy x-inside? )122 swap r> u< ( x-inside? y-inside? )123 and ( flag )124 ;125 126 : draw-left-target ( -- ) green left-target fill-rectangle-noff ;127 : draw-right-target ( -- ) red right-target fill-rectangle-noff ;128 129 : ?hit-target ( -- )130 pixcolor @ cyan = if \ touch1 ( x y )131 2dup left-target inside? if ( x y )132 yellow left-target fill-rectangle-noff ( x y )133 true to left-hit? ( x y )134 exit135 then ( x y )136 then ( x y )137 pixcolor @ yellow = if \ touch2 ( x y )138 2dup right-target inside? if ( x y )139 yellow right-target fill-rectangle-noff ( x y )140 true to right-hit? ( x y )141 exit142 then ( x y )143 then ( x y )144 ;145 146 : targets? ( -- flag ) true ; \ Used to be "final-test?"147 148 : track-init ( -- )149 \ screen-ih package( bytes/line )package to /line150 load-base ptr !151 ;152 153 : dot ( x y -- )154 swap screen-w 3 - min swap y-offset + screen-h 3 - min ( x' y' )155 pixcolor @ -rot 3 3 ( color x y w h )156 fill-rectangle-noff ( )157 ;158 159 : background ( -- )160 black 0 0 screen-w screen-h fill-rectangle-noff161 targets? if162 false to left-hit?163 false to right-hit?164 draw-left-target165 draw-right-target166 else167 0 d# 27 at-xy ." Touchscreen test. Hit both targets to exit" cr168 then169 ;170 171 : setcolor ( contact# -- )172 case173 0 of cyan endof174 1 of yellow endof175 2 of magenta endof176 3 of blue endof177 ( default ) white swap178 endcase179 180 pixcolor !181 ;182 0 value pressure183 184 : *3/5 ( n -- n' ) 3 5 */ ;185 : dimmer ( color -- color' )186 565>rgb rot *3/5 rot *3/5 rot *3/5 rgb>565187 ;188 189 58 : track ( x y z down? contact# -- ) 190 59 setcolor ( x y z down? ) 191 0= if 192 pixcolor @ dup dimmer " replace-color" $call-screen 193 3drop exit 60 0= if ( x y z ) 61 3drop undot exit ( -- ) 194 62 then ( x y z ) 195 63 to pressure ( x y ) … … 202 70 203 71 dot 204 ;205 206 : handle-key ( -- exit? )207 key upc case208 [char] P of209 cursor-on210 cr last-10211 key drop212 background213 false214 endof215 216 ( key ) true swap217 endcase218 ;219 220 false value selftest-failed? \ Success/failure flag for final test mode221 : exit-test? ( -- flag )222 targets? if ( )223 \ If the targets have been hit, we exit with successa224 left-hit? right-hit? and if ( )225 false to selftest-failed? ( )226 true ( flag )227 exit228 then ( )229 230 \ Otherwise we give the tester a chance to bail out by typing a key,231 \ thus indicating failure232 key? 0= if false exit then ( )233 key drop ( )234 true to selftest-failed? ( )235 true ( flag )236 exit237 then ( )238 239 \ If not final test mode, we only exit via a key - no targets240 key? if handle-key else false then ( exit ? )241 72 ; 242 73 : touchscreen-present? ( -- flag ) … … 254 85 \ Read once to prime the interrupt 255 86 d# 10 " get" $call-parent 4drop 4drop 2drop 256 " dimensions" $call-screen to screen-h to screen-w257 87 258 \ The "TI" tag controls the inverson of X and Y axes. 259 \ If the tag is missing, axes are not inverted. If present 260 \ and the value contains either of the letters x or y, the 261 \ corresponding axis is inverted. This is primarily for 262 \ development, using prototype touchscreens. 263 " TI" find-tag if ( adr len ) 264 begin dup while ( adr len ) 265 over c@ upc [char] x = if true to invert-x? then 266 over c@ upc [char] y = if true to invert-y? then 267 1 /string ( adr' len' ) 268 repeat ( adr len ) 269 2drop ( ) 270 then ( ) 88 set-geometry 271 89 272 90 flush … … 292 110 then 293 111 294 cursor-off track-init112 cursor-off 295 113 296 114 \ Consume already-queued keys to prevent premature exit … … 313 131 targets? if selftest-failed? else false then 314 132 ; 315 316 133 317 134 end-package -
cpu/arm/olpc/rm3150-touchscreen.fth
r2775 r2893 4 4 0 0 " 4,60" " /twsi" begin-package 5 5 my-space encode-int my-address encode-int encode+ " reg" property 6 " touchscreen" name7 6 8 0 value screen-w 9 0 value screen-h 7 \ XXX these are really platform-related, not touchscreen-related 8 : targets? ( -- flag ) final-test? ; 9 : .tsmsg ( -- ) 0 d# 27 at-xy ." Touchscreen test. Type a key to exit" cr ; 10 11 fload ${BP}/cpu/arm/olpc/touchscreen-common.fth 12 13 d# 896 to touchscreen-max-x 14 d# 672 to touchscreen-max-y 15 16 d# 10 to #contacts 10 17 11 18 : ts-b! ( b reg# -- ) " smbus-b!" $call-parent ; 12 19 : ts-b@ ( reg# -- b ) " smbus-b@" $call-parent ; 13 14 d# 896 constant touchscreen-max-x15 d# 672 constant touchscreen-max-y16 20 17 21 : 4b>xy ( x.hi x.lo y.hi y.lo -- x y ) swap bwjoin >r swap bwjoin r> ; … … 36 40 0 1 ts-b! ( okay? ) \ Set to polled mode 37 41 then ( okay? ) 38 " dimensions" $call-screen to screen-h to screen-w42 set-geometry 39 43 ; 40 44 41 : dimensions ( -- w h ) screen-w screen-h ; 45 : touched? ( -- flag ) d# 99 gpio-pin@ 0= ; 46 : #touches ( -- n ) h# 10 ts-b@ h# 7f and ; 42 47 43 : #contacts ( -- n ) d# 10 ; 44 45 : pad-events ( -- n*[ x.hi x.lo y.hi y.lo z ] #contacts ) 46 d# 99 gpio-pin@ if false exit then 47 h# 10 ts-b@ h# 7f and >r ( r: #contacts ) 48 r@ if ( r: #contacts ) 49 h# 11 1 r@ 5 * " smbus-out-in" $call-parent ( n*[ x.hi x.lo y.hi y.lo z ] r: #contacts ) 50 then ( n*[ x.hi x.lo y.hi y.lo z ] r: #contacts ) 51 r> ( n*[ x.hi x.lo y.hi y.lo z ] #contacts ) 48 : pad-events ( -- n*[ x.hi x.lo y.hi y.lo z ] #touches ) 49 touched? 0= if false exit then 50 #touches >r r@ if ( r: #touches ) 51 h# 11 1 r@ 5 * " smbus-out-in" $call-parent ( n*[ x.hi x.lo y.hi y.lo z ] r: #touches ) 52 then ( n*[ x.hi x.lo y.hi y.lo z ] r: #touches ) 53 r> ( n*[ x.hi x.lo y.hi y.lo z ] #touches ) 52 54 ; 53 54 h# f800 constant red55 h# 07e0 constant green56 h# 001f constant blue57 h# ffe0 constant yellow58 h# f81f constant magenta59 h# 07ff constant cyan60 h# ffff constant white61 h# 0000 constant black62 63 variable pixcolor64 65 h# 4 value y-offset66 0 value /line67 2 value /pixel68 69 70 variable ptr71 72 \ The following code receives and decodes touchpad packets73 74 : show-packets ( adr len -- )75 push-hex76 bounds ?do77 i 6 bounds ?do i c@ 3 u.r loop cr78 6 +loop79 pop-base80 ;81 : last-10 ( -- )82 ptr @ load-base - d# 60 > if83 ptr @ d# 60 - d# 6084 else85 load-base ptr @ over -86 then87 show-packets88 ;89 90 : scale-xy ( x y -- x' y' )91 swap screen-w touchscreen-max-x */92 swap screen-h touchscreen-max-y */93 ;94 95 0 [if]96 \ Try to receive a mouse report packet. If one arrives within97 \ 20 milliseconds, return true and the decoded information.98 \ Otherwise return false.99 : pad? ( -- false | x y z down? contact# true )100 get-touch? if ( x dy buttons )101 2>r >r scale-xy r> 2r> ( x' y' z down? contact# )102 true103 else104 false105 then106 ;107 108 : flush ( -- ) begin d# 10 ms pad? while 2drop 3drop repeat ;109 110 \ Display raw data from the device, stopping when a key is typed.111 : show-pad ( -- )112 begin113 pad? if . . . . . cr then114 key? until115 ;116 [then]117 55 118 56 : close ( -- ) … … 121 59 ; 122 60 123 : button ( color x -- ) 124 screen-h d# 50 - d# 200 d# 30 fill-rectangle-noff 125 ; 126 d# 300 d# 300 2constant target-wh 127 : left-target ( -- x y w h ) 0 0 target-wh ; 128 : right-target ( -- x y w h ) screen-w screen-h target-wh xy- target-wh ; 129 false value left-hit? 130 false value right-hit? 131 : inside? ( mouse-x,y x y w h -- flag ) 132 >r >r ( mouse-x mouse-y x y r: h w ) 133 xy- ( dx dy ) 134 swap r> u< ( dy x-inside? ) 135 swap r> u< ( x-inside? y-inside? ) 136 and ( flag ) 137 ; 138 139 : draw-left-target ( -- ) green left-target fill-rectangle-noff ; 140 : draw-right-target ( -- ) red right-target fill-rectangle-noff ; 141 142 : ?hit-target ( -- ) 143 pixcolor @ cyan = if \ touch1 ( x y ) 144 2dup left-target inside? if ( x y ) 145 yellow left-target fill-rectangle-noff ( x y ) 146 true to left-hit? ( x y ) 147 exit 148 then ( x y ) 149 then ( x y ) 150 pixcolor @ yellow = if \ touch2 ( x y ) 151 2dup right-target inside? if ( x y ) 152 yellow right-target fill-rectangle-noff ( x y ) 153 true to right-hit? ( x y ) 154 exit 155 then ( x y ) 156 then ( x y ) 157 ; 158 159 : track-init ( -- ) 160 screen-ih package( bytes/line )package to /line 161 load-base ptr ! 162 ; 163 164 : dot ( x y -- ) 165 swap screen-w 3 - min swap y-offset + screen-h 3 - min ( x' y' ) 166 pixcolor @ -rot 3 3 ( color x y w h ) 167 fill-rectangle-noff ( ) 168 ; 169 170 : background ( -- ) 171 black 0 0 screen-w screen-h fill-rectangle-noff 172 final-test? if 173 false to left-hit? 174 false to right-hit? 175 draw-left-target 176 draw-right-target 177 else 178 0 d# 27 at-xy ." Touchscreen test. Type a key to exit" cr 179 then 180 ; 181 182 : *3/5 ( n -- n' ) 3 5 */ ; 183 : dimmer ( color -- color' ) 184 565>rgb rot *3/5 rot *3/5 rot *3/5 rgb>565 185 ; 186 187 : setcolor ( contact# -- ) 188 case 189 0 of cyan endof 190 1 of yellow endof 191 2 of magenta endof 192 3 of blue endof 193 4 of red endof 194 5 of green endof 195 6 of cyan dimmer endof 196 7 of yellow dimmer endof 197 8 of magenta dimmer endof 198 9 of blue dimmer endof 199 d# 10 of red dimmer endof 200 d# 11 of green dimmer endof 201 ( default ) white swap 202 endcase 203 204 pixcolor ! 205 ; 206 0 value pressure 207 208 : track-n ( .. xhi xlo yhi ylo z #contacts -- ) 209 ?dup 0= if exit then ( .. xhi xlo yhi ylo z #contacts -- ) 61 : track-n ( .. xhi xlo yhi ylo z #touches -- ) 62 ?dup 0= if exit then ( .. xhi xlo yhi ylo z #touches -- ) 210 63 1- 0 swap do ( .. xhi xlo yhi ylo z ) 211 64 i setcolor ( .. xhi xlo yhi ylo z ) … … 213 66 4b>xy scale-xy ( .. x y ) 214 67 215 final-test? if ( .. x y ) 216 ?hit-target ( .. x y ) 217 then ( .. x y ) 68 targets? if ?hit-target then ( .. x y ) 69 218 70 dot 219 71 -1 +loop 220 72 ; 221 73 222 : handle-key ( -- exit? ) 223 key upc case 224 [char] P of 225 cursor-on 226 cr last-10 227 key drop 228 background 229 false 230 endof 231 232 ( key ) true swap 233 endcase 74 0 0 2value last-xy 75 false value last-down? 76 : no-touch ( -- false | x y buttons true ) 77 last-down? if 78 \ Return up event for last "mouse" position 79 false to last-down? 80 last-xy 0 true 81 else 82 false 83 then 234 84 ; 235 236 false value selftest-failed? \ Success/failure flag for final test mode 237 : exit-test? ( -- flag ) 238 final-test? if ( ) 239 \ If the targets have been hit, we exit with successa 240 left-hit? right-hit? and if ( ) 241 false to selftest-failed? ( ) 242 true ( flag ) 243 exit 244 then ( ) 245 246 \ Otherwise we give the tester a chance to bail out by typing a key, 247 \ thus indicating failure 248 key? 0= if false exit then ( ) 249 key drop ( ) 250 true to selftest-failed? ( ) 251 true ( flag ) 252 exit 253 then ( ) 254 255 \ If not final test mode, we only exit via a key - no targets 256 key? if handle-key else false then ( exit ? ) 85 : touch ( -- false | x y buttons true ) 86 #touches 0= if false exit then 87 h# 11 1 4 " smbus-out-in" $call-parent ( x.hi x.lo y.hi y.lo ) 88 4b>xy scale-xy ( x y ) 89 2dup to last-xy ( x y ) 90 true to last-down? ( x y ) 91 1 true ( x y buttons true ) 257 92 ; 258 93 : stream-poll? ( -- false | x y buttons true ) 94 touched? if touch else no-touch then 95 ; 259 96 : discard-n ( .. #events -- ) 5 * 0 ?do drop loop ; 260 97 … … 273 110 then 274 111 275 cursor-off track-init112 cursor-off 276 113 277 114 \ Consume already-queued keys to prevent premature exit -
cpu/x86/pc/olpc/via/mfgtest.fth
r2890 r2893 156 156 157 157 : init-menu ( -- ) 158 ?open-screen ?open-mouse 158 ?open-screen ?open-mouse ?open-touchscreen 159 159 #mfgrows to rows 160 160 #mfgcols to cols -
ofw/gui/dialog.fth
r2331 r2893 201 201 ['] selected? find-node nip ( node ) 202 202 " next-enum" run-method ( ) 203 ; 204 : get-key-code ( -- c | c 9b ) 205 key case 206 \ Distinguish between a bare ESC and an ESC-[ sequence 207 esc of 208 d# 10 ms key? if 209 key [char] [ = if key csi else esc then 210 else 211 esc 212 then 213 endof 214 215 csi of key csi endof 216 dup 217 endcase 203 218 ; 204 219 : controls-key ( list -- done? ) -
ofw/gui/graphics.fth
r2755 r2893 23 23 24 24 \needs screen-ih 0 value screen-ih 25 0 value mouse-ih26 25 27 26 : $call-screen ( ??? adr len -- ??? ) screen-ih $call-method ; … … 59 58 ; 60 59 61 : get-event ( #msecs -- false | x y buttons true )62 " get-event" mouse-ih $call-method63 ;64 65 60 : screen-color! ( r g b color# -- ) " color!" $call-screen ; 66 61 : screen-color@ ( color# -- r g b ) " color@" $call-screen ; -
ofw/gui/iconmenu.fth
r2876 r2893 20 20 \ keyboard input removes mouse cursor and moves mouse to selected square 21 21 \ keyboard input (arrows) always moves to an occupied square 22 23 \ need:24 \ put text into square25 26 \ have:27 \ fill-rectangle ( color x y w h - ) color is 0..25528 \ draw-rectangle ( address x y w h - ) address of 128x128 pixmap29 \ read-rectangle ( address x y w h - )30 \ move-mouse-cursor ( x y - )31 \ remove-mouse-cursor ( - )32 \ poll-mouse ( -- x y buttons )33 \ get-event ( #msecs -- false | x y buttons true )34 22 35 23 hex … … 425 413 ; 426 414 427 : do-mouse ( - )415 : do-mouse ( -- ) 428 416 mouse-ih 0= if exit then 429 417 begin mouse-event? while ( x y buttons ) 430 remove-mouse-cursor 418 remove-mouse-cursor ( x y buttons ) 431 419 -rot update-position ( buttons ) 420 new-sq? 421 draw-mouse-cursor 422 repeat 423 ; 424 : do-touchscreen ( -- ) 425 touchscreen-ih 0= if exit then 426 begin touchscreen-event? while ( x y buttons ) 427 remove-mouse-cursor ( x y buttons ) 428 -rot set-xy ( buttons ) 432 429 new-sq? 433 430 draw-mouse-cursor … … 497 494 498 495 false to done? 499 begin do- mouse do-key done? until496 begin do-touchscreen do-mouse do-key done? until 500 497 false to done? 501 498 … … 567 564 \ when a root menu is defined. 568 565 headers 566 569 567 \ LICENSE_BEGIN 570 568 \ Copyright (c) 2006 FirmWorks -
ofw/gui/mouse.fth
r2754 r2893 3 3 4 4 headerless 5 6 0 value mouse-ih 5 7 6 8 false value mouse-absolute? \ True if coordinates are absolute … … 156 158 : clamp ( n min max - m ) rot min max ; 157 159 160 : set-xy ( x y -- ) to ypos to xpos ; 158 161 : update-position ( x y -- ) 159 mouse-absolute? if to ypos to xposexit then162 mouse-absolute? if set-xy exit then 160 163 2dup or 0= if 2drop exit then \ Avoid flicker if there is no movement 161 164 … … 165 168 negate ypos + 0 max-y cursor-h - clamp ( x y' ) 166 169 swap xpos + 0 max-x cursor-w - clamp ( y' x') 167 to xpos to ypos 168 ; 169 170 : get-key-code ( -- c | c 9b ) 171 key case 172 \ Distinguish between a bare ESC and an ESC-[ sequence 173 esc of 174 d# 10 ms key? if 175 key [char] [ = if key csi else esc then 176 else 177 esc 178 then 179 endof 180 181 csi of key csi endof 182 dup 183 endcase 184 ; 170 swap set-xy 171 ; 172 185 173 headers 186 174 … … 214 202 : mouse-event? ( -- false | x y buttons true ) 215 203 " stream-poll?" mouse-ih $call-method 204 ; 205 206 0 value touchscreen-ih 207 208 0 value close-touchscreen? 209 210 : ?close-touchscreen ( -- ) 211 close-touchscreen? if 212 touchscreen-ih close-dev 213 0 to touchscreen-ih 214 hardware-cursor? if 215 false to hardware-cursor? 216 " cursor-off" $call-screen 217 then 218 then 219 ; 220 : ?open-touchscreen ( -- ) 221 touchscreen-ih 0= dup to close-touchscreen? if 222 " touchscreen" open-dev is touchscreen-ih 223 touchscreen-ih 0= if 224 " /touchscreen" open-dev to touchscreen-ih 225 then 226 then 227 ; 228 : touchscreen-event? ( -- false | x y buttons true ) 229 " stream-poll?" touchscreen-ih $call-method 216 230 ; 217 231 -
ofw/gui/textfld.fth
r1 r2893 116 116 then 117 117 mouse-ih if 118 begin 10 get-eventwhile118 begin mouse-event? while 119 119 remove-mouse-cursor 120 120 -rot update-position
Note: See TracChangeset
for help on using the changeset viewer.
