Check-in [f4dd8495bc]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Sensor stuff
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f4dd8495bcd0ccc60910e02c58eb8bd852ca0ce2
User & Date: bernd 2014-01-16 16:23:29
Context
2014-01-17
00:13
Rewrite for Gforth\NativeActivity check-in: af01051ada user: bernd tags: trunk
2014-01-16
16:23
Sensor stuff check-in: f4dd8495bc user: bernd tags: trunk
2014-01-13
15:34
Delete references check-in: 3874dedc13 user: bernd tags: trunk
Changes

Changes to gles2/android.fs.

307
308
309
310
311
312
313




314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330













331
332
333
334
335
336
337
338
339
340
341
342
343
344
345




346
347
348
	APP_CMD_START of [: ." app start" cr ;] $err endof
	APP_CMD_STOP of [: ." app stop" cr ;] $err endof
	dup [: ." app cmd " . cr ;] $err
    endcase ; is acmd

also jni





: android-key ( event -- )
    >o getAction dup 2 = IF  drop ."
	getKeyCode dup 0= IF
	    drop getCharacters jstring>sstring unkeys jfree
	ELSE
	    keycode>keys unkeys
	THEN
    ELSE
	0= IF  getUnicodeChar dup 0>
	    IF    >xstring unkeys
	    ELSE  drop  getKeyCode  keycode>keys  unkeys
	    THEN
	THEN
    THEN o> ;

Defer android-touch ( event -- )
' drop IS android-touch














0 Value location
0 Value sensor

Defer android-location ( location -- )
:noname ." new location" cr to location ; IS android-location
Defer android-sensor ( sensor -- )
:noname ." new sensor" cr to sensor ; IS android-sensor

:noname ( event type -- )
    CASE
	0 OF  android-key       ENDOF
	1 OF  android-touch     ENDOF
	2 OF  android-location  ENDOF
	3 OF  android-sensor    ENDOF




    nip ENDCASE ; is akey

previous previous set-current







>
>
>
>

|

|

|



|
|


|

|
|
>
>
>
>
>
>
>
>
>
>
>
>
>

|
|


|

|







>
>
>
>



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
	APP_CMD_START of [: ." app start" cr ;] $err endof
	APP_CMD_STOP of [: ." app stop" cr ;] $err endof
	dup [: ." app cmd " . cr ;] $err
    endcase ; is acmd

also jni

: android-characters ( string -- )  jstring>sstring unkeys jfree ;
: android-unicode    ( uchar -- )   >xstring unkeys ;
: android-keycode    ( keycode -- ) keycode>keys unkeys ;

: android-key ( event -- )
    >o getAction dup 2 = IF  drop
	getKeyCode dup 0= IF
	    drop getCharacters android-characters
	ELSE
	    android-keycode
	THEN
    ELSE
	0= IF  getUnicodeChar dup 0>
	    IF    android-unicode
	    ELSE  drop  getKeyCode  android-keycode
	    THEN
	THEN
    THEN o ]gref o> ;

: android-touch ( event -- ) >o
    me-getAction *input action !
    getFlags *input flags !
    getMetaState *input metastate !
    getEdgeFlags *input edgeflags !
    getPressure f>s *input pressure !
    getSize f>s *input size !
    getPointerCount dup *input tcount !
    *input x0
    0 ?DO
	I getY f>s
	I getX f>s
	rot dup >r 2! r> 2 cells +
    LOOP  drop
    o ]gref o> ;

JValue location
JValue sensor

Defer android-location ( location -- )
:noname to location ; IS android-location
Defer android-sensor ( sensor -- )
:noname to sensor ; IS android-sensor

:noname ( event type -- )
    CASE
	0 OF  android-key         ENDOF
	1 OF  android-touch       ENDOF
	2 OF  android-location    ENDOF
	3 OF  android-sensor      ENDOF
	4 OF  android-characters  ENDOF
	5 OF  android-unicode     ENDOF
	6 OF  android-keycode     ENDOF
	7 Of  android-touch       ENDOF
    nip ENDCASE ; is akey

previous previous set-current

Changes to gles2/jni-helper.fs.

45
46
47
48
49
50
51












52
53
54
55
56






57
58
59
60
61
62
63
jni-method: getUnicodeChar(I) getUnicodeChar (I)I
jni-method: getUnicodeChar getUnicodeChar ()I
jni-method: getKeyCode getKeyCode ()I
jni-method: getCharacters getCharacters ()Ljava/lang/String;
jni-method: getAction getAction ()I
jni-method: isLongPress isLongPress ()Z













jni-class: java/util/List

jni-method: l-get get (I)Ljava/lang/Object;
jni-method: l-size size ()I







: getUnicodeKey { event -- key }
    event AKeyEvent_getAction event AKeyEvent_getKeyCode newKeyEvent >o
    event AKeyEvent_getMetaState getUnicodeChar(I) o> ;

Variable kbflag

: togglekb ( -- )







>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
>
>
>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
jni-method: getUnicodeChar(I) getUnicodeChar (I)I
jni-method: getUnicodeChar getUnicodeChar ()I
jni-method: getKeyCode getKeyCode ()I
jni-method: getCharacters getCharacters ()Ljava/lang/String;
jni-method: getAction getAction ()I
jni-method: isLongPress isLongPress ()Z

jni-class: android/view/MotionEvent
jni-method: getPointerCount getPointerCount ()I
jni-method: getX getX (I)F
jni-method: getY getY (I)F
jni-method: me-getAction getAction ()I
jni-method: getFlags getFlags ()I
jni-method: getEdgeFlags getEdgeFlags ()I
jni-method: getEventTime getEventTime ()J
jni-method: getMetaState getMetaState ()I
jni-method: getSize getSize (I)F
jni-method: getPressure getPressure (I)F

jni-class: java/util/List

jni-method: l-get get (I)Ljava/lang/Object;
jni-method: l-size size ()I

: l[] ( n list -- object )  >o l-get o> ;
: l# ( list -- n )  >o l-size o> ;

: l-map ( xt list -- )  >o { xt } ( -- )
    l-size 0 ?DO  I l-get >o xt execute ref>  LOOP o> ;

: getUnicodeKey { event -- key }
    event AKeyEvent_getAction event AKeyEvent_getKeyCode newKeyEvent >o
    event AKeyEvent_getMetaState getUnicodeChar(I) o> ;

Variable kbflag

: togglekb ( -- )

Changes to gles2/jni-location.fs.

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134



135
jni-field: argsensor argsensor Landroid/hardware/Sensor;
jni-field: locationManager locationManager Landroid/location/LocationManager;
jni-field: sensorManager sensorManager Landroid/hardware/SensorManager;

also android

: start-gps ( -- )
    clazz >o startgps gforth-handler >o post o> drop o> ;

: stop-gps ( -- )
    clazz >o stopgps  gforth-handler >o post o> drop o> ;

: start-sensor ( type delayus -- )
    clazz >o
    argj0 2>r
    0 to argj0
    sensorManager >o getDefaultSensor o> to argsensor
    startsensor gforth-handler >o post o> drop
    2r> to argj0
    o> ;

: stop-sensor ( -- )


    clazz >o stopsensor gforth-handler >o post o> drop o> ;

: .deg ( degree -- )
    fdup f0< IF ." -" fnegate THEN
    fdup floor fdup f>s 0 .r '°' xemit f-  60e f*
    fdup floor fdup f>s 0 .r ''' xemit f-  60e f*
    f. ;

: .location ( -- )  location >o
    o 0= IF  ." unknown" cr
    ELSE

	." Lat: " getLatitude .deg cr
	." Lon: " getLongitude .deg cr
	." Alt: " getAltitude f. cr
	." Spd: " getSpeed f. cr
	." Dir: " getBearing f. cr
	." Tme: " getTime d. cr
	." Acc: " getAccuracy f. cr
    THEN
    o> ;

: .sensor ( -- )  sensor >o
    o 0= IF  ." unknown"
    ELSE

	se-values [f@ bounds DO  I sf@ f. 1 sfloats +LOOP
    THEN cr o> ;




previous previous







|


|





|
|



|
>
>
|










>













>



>
>
>

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
jni-field: argsensor argsensor Landroid/hardware/Sensor;
jni-field: locationManager locationManager Landroid/location/LocationManager;
jni-field: sensorManager sensorManager Landroid/hardware/SensorManager;

also android

: start-gps ( -- )
    clazz >o startgps gforth-handler >o post ref> drop o> ;

: stop-gps ( -- )
    clazz >o stopgps  gforth-handler >o post ref> drop o> ;

: start-sensor ( type delayus -- )
    clazz >o
    argj0 2>r
    0 to argj0
    sensorManager >o getDefaultSensor dup ref> to argsensor ]ref
    startsensor gforth-handler >o post ref> drop
    2r> to argj0
    o> ;

: stop-sensor ( type -- )
    clazz >o
    sensorManager >o getDefaultSensor dup ref> to argsensor ]ref
    stopsensor gforth-handler >o post ref> drop o> ;

: .deg ( degree -- )
    fdup f0< IF ." -" fnegate THEN
    fdup floor fdup f>s 0 .r '°' xemit f-  60e f*
    fdup floor fdup f>s 0 .r ''' xemit f-  60e f*
    f. ;

: .location ( -- )  location >o
    o 0= IF  ." unknown" cr
    ELSE
	getProvider dup .jstring ]ref
	." Lat: " getLatitude .deg cr
	." Lon: " getLongitude .deg cr
	." Alt: " getAltitude f. cr
	." Spd: " getSpeed f. cr
	." Dir: " getBearing f. cr
	." Tme: " getTime d. cr
	." Acc: " getAccuracy f. cr
    THEN
    o> ;

: .sensor ( -- )  sensor >o
    o 0= IF  ." unknown"
    ELSE
	se-sensor >o getName .jstring space ref>
	se-values [f@ bounds DO  I sf@ f. 1 sfloats +LOOP
    THEN cr o> ;

: .sensors ( -- )  clazz >o sensorManager >o TYPE_ALL getSensorList >o
    [: cr getType . getName .jstring ;] o l-map ref> ref> o> ;

previous previous

Changes to gles2/jni-tools.fs.

140
141
142
143
144
145
146













147
148















149
150
151
152
153
154

155
156
157
158
159
160



161
162
163
164

165
166
167
168
169
170
171
...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
: f@' ( jclass jfid -- r )  fieldenv JNIEnv-GetStaticFloatField() ;
: d@' ( jclass jfid -- r )  fieldenv JNIEnv-GetStaticDoubleField() ;
: l@' ( jclass jfid -- object )  fieldenv JNIEnv-GetStaticObjectField() ;

Create 'sfield@ '[' 1+ 'A'
[DO] "x@'" over [i] swap c! current @ search-wordlist 0= [IF] ' 2drop [THEN] , [LOOP]














Variable cstring
Variable cstring1
















: $0! ( addr u string -- addr' ) >r
    r@ $! 0 r@ $@ + c! r> $@ drop ;
: cstr" ( -- addr )  parse-name cstring  $0! ;
: cstr1" ( -- addr ) parse-name cstring1 $0! ;
: make-jstring ( c-addr -- jstring-addr ) env tuck JNIEnv-NewStringUTF() ;

: js" ( -- addr )  '"' parse cstring $0! make-jstring ;
comp: drop '"' parse cstring $0!
    cstring>sstring 1+ ]] SLiteral drop make-jstring [[ ;

Variable iscopy
2Variable to-release



: jstring>sstring ( string -- addr u )
    dup >r iscopy fieldenv JNIEnv-GetStringUTFChars()
    r> over to-release 2! cstring>sstring ;
: jfree ( -- ) to-release 2@ fieldenv JNIEnv-ReleaseStringUTFChars() ;


0 Value jniclass

"Java identifier not found" exception Constant !!javanf!!

: ?javanf ( id -- id )  dup 0= !!javanf!! and throw ;

................................................................................
    cstring@1 'sfield@ + @ compile, postpone ; ;

\ array access: you can access one array at a time

Variable jnibuffer

: [len ( array -- n )  env tuck JNIEnv-GetArrayLength() ;
: ]ref ( array -- )  env tuck JNIEnv-DeleteLocalRef() ;

: >buffer ( size -- buffer )  jnibuffer $!len jnibuffer $@ drop ;
: buffer@ ( -- addr u )  jnibuffer $@ ;

: [z@ ( array -- addr n )  >r env r@ 0 r@ [len dup >buffer
    env JNIEnv-GetBooleanArrayRegion() buffer@ r> ]ref ;
: [b@ ( array -- addr n )  >r env r@ 0 r@ [len dup >buffer







>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





|
>






>
>
>
|


<
>







 







<







140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
...
262
263
264
265
266
267
268

269
270
271
272
273
274
275
: f@' ( jclass jfid -- r )  fieldenv JNIEnv-GetStaticFloatField() ;
: d@' ( jclass jfid -- r )  fieldenv JNIEnv-GetStaticDoubleField() ;
: l@' ( jclass jfid -- object )  fieldenv JNIEnv-GetStaticObjectField() ;

Create 'sfield@ '[' 1+ 'A'
[DO] "x@'" over [i] swap c! current @ search-wordlist 0= [IF] ' 2drop [THEN] , [LOOP]

\ global ref handling - you should ]gref every global ref after usage

: ]ref ( object -- )  env tuck JNIEnv-DeleteLocalRef() ;
: ]gref ( object -- )  env tuck JNIEnv-DeleteGlobalRef() ;
: ref> ( object -- ) o ]ref r> o> >r ;
comp: drop ]] o ]ref o> [[ ;

: gref! ( gref addr -- )  dup @ ?dup-IF  ]gref  THEN ! ;
: jvalue! ( gref xt -- )  >body gref! ;
comp: drop >body postpone ALiteral postpone gref! ;

: JValue ( "name" -- ) 0 Value ['] jvalue! set-to ;

Variable cstring
Variable cstring1

\ round robin store for four active jstrings

JValue jstring0
JValue jstring1
JValue jstring2
JValue jstring3
Variable jstring#
: to-jstring ( value -- )
    1 jstring# +!  jstring# 3 and case
	0 of  to jstring0  endof
	1 of  to jstring1  endof
	2 of  to jstring2  endof
	3 of  to jstring3  endof
    endcase ;

: $0! ( addr u string -- addr' ) >r
    r@ $! 0 r@ $@ + c! r> $@ drop ;
: cstr" ( -- addr )  parse-name cstring  $0! ;
: cstr1" ( -- addr ) parse-name cstring1 $0! ;
: make-jstring ( c-addr -- jstring-addr )
    env tuck JNIEnv-NewStringUTF() dup to-jstring ;
: js" ( -- addr )  '"' parse cstring $0! make-jstring ;
comp: drop '"' parse cstring $0!
    cstring>sstring 1+ ]] SLiteral drop make-jstring [[ ;

Variable iscopy
2Variable to-release
: jfree ( -- )
    to-release 2@ 2dup d0= IF  2drop  EXIT  THEN  0. to-release 2!
    fieldenv JNIEnv-ReleaseStringUTFChars() ;
: jstring>sstring ( string -- addr u )  jfree
    dup >r iscopy fieldenv JNIEnv-GetStringUTFChars()
    r> over to-release 2! cstring>sstring ;

: .jstring ( string -- ) jstring>sstring type jfree ;

0 Value jniclass

"Java identifier not found" exception Constant !!javanf!!

: ?javanf ( id -- id )  dup 0= !!javanf!! and throw ;

................................................................................
    cstring@1 'sfield@ + @ compile, postpone ; ;

\ array access: you can access one array at a time

Variable jnibuffer

: [len ( array -- n )  env tuck JNIEnv-GetArrayLength() ;


: >buffer ( size -- buffer )  jnibuffer $!len jnibuffer $@ drop ;
: buffer@ ( -- addr u )  jnibuffer $@ ;

: [z@ ( array -- addr n )  >r env r@ 0 r@ [len dup >buffer
    env JNIEnv-GetBooleanArrayRegion() buffer@ r> ]ref ;
: [b@ ( array -- addr n )  >r env r@ 0 r@ [len dup >buffer

Changes to jni-location.fs.

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134



135
jni-field: argsensor argsensor Landroid/hardware/Sensor;
jni-field: locationManager locationManager Landroid/location/LocationManager;
jni-field: sensorManager sensorManager Landroid/hardware/SensorManager;

also android

: start-gps ( -- )
    clazz >o startgps gforth-handler >o post o> drop o> ;

: stop-gps ( -- )
    clazz >o stopgps  gforth-handler >o post o> drop o> ;

: start-sensor ( type delayus -- )
    clazz >o
    argj0 2>r
    0 to argj0
    sensorManager >o getDefaultSensor o> to argsensor
    startsensor gforth-handler >o post o> drop
    2r> to argj0
    o> ;

: stop-sensor ( -- )


    clazz >o stopsensor gforth-handler >o post o> drop o> ;

: .deg ( degree -- )
    fdup f0< IF ." -" fnegate THEN
    fdup floor fdup f>s 0 .r '°' xemit f-  60e f*
    fdup floor fdup f>s 0 .r ''' xemit f-  60e f*
    f. ;

: .location ( -- )  location >o
    o 0= IF  ." unknown" cr
    ELSE

	." Lat: " getLatitude .deg cr
	." Lon: " getLongitude .deg cr
	." Alt: " getAltitude f. cr
	." Spd: " getSpeed f. cr
	." Dir: " getBearing f. cr
	." Tme: " getTime d. cr
	." Acc: " getAccuracy f. cr
    THEN
    o> ;

: .sensor ( -- )  sensor >o
    o 0= IF  ." unknown"
    ELSE

	se-values [f@ bounds DO  I sf@ f. 1 sfloats +LOOP
    THEN cr o> ;




previous previous







|


|





|
|



|
>
>
|










>













>



>
>
>

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
jni-field: argsensor argsensor Landroid/hardware/Sensor;
jni-field: locationManager locationManager Landroid/location/LocationManager;
jni-field: sensorManager sensorManager Landroid/hardware/SensorManager;

also android

: start-gps ( -- )
    clazz >o startgps gforth-handler >o post ref> drop o> ;

: stop-gps ( -- )
    clazz >o stopgps  gforth-handler >o post ref> drop o> ;

: start-sensor ( type delayus -- )
    clazz >o
    argj0 2>r
    0 to argj0
    sensorManager >o getDefaultSensor dup ref> to argsensor ]ref
    startsensor gforth-handler >o post ref> drop
    2r> to argj0
    o> ;

: stop-sensor ( type -- )
    clazz >o
    sensorManager >o getDefaultSensor dup ref> to argsensor ]ref
    stopsensor gforth-handler >o post ref> drop o> ;

: .deg ( degree -- )
    fdup f0< IF ." -" fnegate THEN
    fdup floor fdup f>s 0 .r '°' xemit f-  60e f*
    fdup floor fdup f>s 0 .r ''' xemit f-  60e f*
    f. ;

: .location ( -- )  location >o
    o 0= IF  ." unknown" cr
    ELSE
	getProvider dup .jstring ]ref
	." Lat: " getLatitude .deg cr
	." Lon: " getLongitude .deg cr
	." Alt: " getAltitude f. cr
	." Spd: " getSpeed f. cr
	." Dir: " getBearing f. cr
	." Tme: " getTime d. cr
	." Acc: " getAccuracy f. cr
    THEN
    o> ;

: .sensor ( -- )  sensor >o
    o 0= IF  ." unknown"
    ELSE
	se-sensor >o getName .jstring space ref>
	se-values [f@ bounds DO  I sf@ f. 1 sfloats +LOOP
    THEN cr o> ;

: .sensors ( -- )  clazz >o sensorManager >o TYPE_ALL getSensorList >o
    [: cr getType . getName .jstring ;] o l-map ref> ref> o> ;

previous previous