Check-in [6c22b329d1]
Not logged in

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

Overview
Comment:Sensor stuff (getting sensor data crashes after a while)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6c22b329d17f6ba20e5c69f42b5bdbbb9b4c5ea6
User & Date: bernd 2014-01-13 01:12:08.346
Context
2014-01-13
02:46
Set delay accordingly check-in: a87d6756b0 user: bernd tags: trunk
01:12
Sensor stuff (getting sensor data crashes after a while) check-in: 6c22b329d1 user: bernd tags: trunk
2014-01-12
00:36
Fix to field operations check-in: 5d978cd2dc user: bernd tags: trunk
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to gles2/jni-helper.fs.
12
13
14
15
16
17
18

19
20
21
22
23
24
25
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26







+







gforth-class:

\ jni-sfield: INPUT_METHOD_SERVICE INPUT_METHOD_SERVICE Ljava/lang/String;
\ jni-sfield: POWER_SERVICE POWER_SERVICE Ljava/lang/String;
: INPUT_METHOD_SERVICE js" input_method" ;
: POWER_SERVICE        js" power" ;
: LOCATION_SERVICE     js" location" ;
: SENSOR_SERVICE       js" sensor" ;

jni-method: getSystemService getSystemService (Ljava/lang/String;)Ljava/lang/Object;
jni-method: getWindow getWindow ()Landroid/view/Window;

jni-class: android/app/Activity
jni-method: getWindowManager getWindowManager ()Landroid/view/WindowManager;

Changes to gles2/jni-location.fs.
18
19
20
21
22
23
24






























25










26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41


42
43
44
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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
82
83
84
85
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
















+
+




-
-
+


+
+
+
+
-
-
+
+
+
+




















+
+
+
+
+
+

jni-class: android/location/LocationManager

jni-method: getAllProviders getAllProviders ()Ljava/util/List;
jni-method: getProviders getProviders (Z)Ljava/util/List;
jni-method: lm-getProvider getProvider (Ljava/lang/String;)Landroid/location/LocationProvider;
jni-method: getLastKnownLocation getLastKnownLocation (Ljava/lang/String;)Landroid/location/Location;

jni-class: android/hardware/Sensor

-1 Constant TYPE_ALL
$01 Constant TYPE_ACCELEROMETER
$02 Constant TYPE_MAGNETIC_FIELD
$03 Constant TYPE_ORIENTATION \ deprecated API-8
$04 Constant TYPE_GYROSCOPE
$05 Constant TYPE_LIGHT
$06 Constant TYPE_PRESSURE
$07 Constant TYPE_TEMPERATURE \ deprecated API-14
$08 Constant TYPE_PROXIMITY
$09 Constant TYPE_GRAVITY
$0A Constant TYPE_LINEAR_ACCELERATION
$0B Constant TYPE_ROTATION_VECTOR
$0C Constant TYPE_RELATIVE_HUMIDITY
$0D Constant TYPE_AMBIENT_TEMPERATURE
$0E Constant TYPE_MAGNETIC_FIELD_UNCALIBRATED
$0F Constant TYPE_GAME_ROTATION_VECTOR
$10 Constant TYPE_GYROSCOPE_UNCALIBRATED
$11 Constant TYPE_SIGNIFICANT_MOTION
$12 Constant TYPE_STEP_DETECTOR
$13 Constant TYPE_STEP_COUNTER
$14 Constant TYPE_GEOMAGNETIC_ROTATION_VECTOR

jni-method: getName getName ()Ljava/lang/String;
jni-method: getResolution getResolution ()F
jni-method: getType getType ()I
jni-method: getPower getPower ()F
jni-method: toString toString ()Ljava/lang/String;

jni-class: android/hardware/SensorManager

jni-method: getSensorList getSensorList (I)Ljava/util/List;
jni-method: getDefaultSensor getDefaultSensor (I)Landroid/hardware/Sensor;

jni-class: android/hardware/SensorEvent

jni-field: se-accuracy accuracy I
jni-field: se-sensor sensor Landroid/hardware/Sensor;
jni-field: se-timestamp timestamp J
jni-field: se-values values [F

jni-class: android/os/Handler

jni-method: post post (Ljava/lang/Runnable;)Z

gforth-class:

jni-field: gforth-handler handler Landroid/os/Handler;
jni-field: startgps startgps Ljava/lang/Runnable;
jni-field: stopgps stopgps Ljava/lang/Runnable;
jni-field: startsensor startsensor Ljava/lang/Runnable;
jni-field: stopsensor stopsensor Ljava/lang/Runnable;
jni-field: args0 args0 Ljava/lang/String;
jni-field: argf0 argf0 D
jni-field: argj0 argj0 J
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 gforth-handler o> >o
    clazz >o startgps o> post o> drop ;
    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 -- )
    clazz >o sensorManager >o getDefaultSensor o> to argsensor
    clazz >o gforth-handler o> >o
    clazz >o stopgps o> post o> drop ;
    startsensor gforth-handler >o post o> drop 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
Changes to gles2/jni-tools.fs.
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
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







+










+







: c@f ( jobject jfid -- utf16 )  fieldenv JNIEnv-GetCharField() ;
: s@f ( jobject jfid -- n )  fieldenv JNIEnv-GetShortField() ;
: i@f ( jobject jfid -- n )  fieldenv JNIEnv-GetIntField() ;
: j@f ( jobject jfid -- d )  fieldenv JNIEnv-GetLongField() ;
: f@f ( jobject jfid -- r )  fieldenv JNIEnv-GetFloatField() ;
: d@f ( jobject jfid -- r )  fieldenv JNIEnv-GetDoubleField() ;
: l@f ( jobject jfid -- object )  fieldenv JNIEnv-GetObjectField() ;
' l@f alias [@f

: z!f ( c jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetBooleanField() ;
: b!f ( c jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetByteField() ;
: c!f ( utf16 jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetCharField() ;
: s!f ( n jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetShortField() ;
: i!f ( n jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetIntField() ;
: j!f ( d jobject jfid -- )  2swap 2>r fieldenv 2r> rot JNIEnv-SetLongField() ;
: f!f ( r jobject jfid -- )  fieldenv JNIEnv-SetFloatField() ;
: d!f ( r jobject jfid -- )  fieldenv JNIEnv-SetDoubleField() ;
: l!f ( object jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetObjectField() ;
' l!f alias [!f

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

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

222
223
224
225
226
227
228
229


























230
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

    cstring@1 'field@ + @ compile, postpone ;
    r> set-to  new-in >in ! ;

: jni-sfield: ( "forth-name" "name" "signature" -- )
    : ( o:jobject -- retval )
    postpone o jni-sfid postpone Literal
    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 )  env swap 0 over [len dup >buffer
    env JNIEnv-GetBooleanArrayRegion() buffer@ ;
: [b@ ( array -- addr n )  env swap 0 over [len dup >buffer
    env JNIEnv-GetByteArrayRegion() buffer@ ;
: [c@ ( array -- addr n )  env swap 0 over [len dup 2* >buffer
    env JNIEnv-GetCharArrayRegion() buffer@ ;
: [s@ ( array -- addr n )  env swap 0 over [len dup 2* >buffer
    env JNIEnv-GetShortArrayRegion() buffer@ ;
: [i@ ( array -- addr n )  env swap 0 over [len dup sfloats >buffer
    env JNIEnv-GetIntArrayRegion() buffer@ ;
: [j@ ( array -- addr n )  env swap 0 over [len dup dfloats >buffer
    env JNIEnv-GetLongArrayRegion() buffer@ ;
: [f@ ( array -- addr n )  env swap 0 over [len dup sfloats >buffer
    env JNIEnv-GetFloatArrayRegion() buffer@ ;
: [d@ ( array -- addr n )  env swap 0 over [len dup dfloats >buffer
    env JNIEnv-GetDoubleArrayRegion() buffer@ ;

previous previous set-current
Changes to jni-location.fs.
18
19
20
21
22
23
24






























25










26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41


42
43
44
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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
82
83
84
85
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
















+
+




-
-
+


+
+
+
+
-
-
+
+
+
+




















+
+
+
+
+
+

jni-class: android/location/LocationManager

jni-method: getAllProviders getAllProviders ()Ljava/util/List;
jni-method: getProviders getProviders (Z)Ljava/util/List;
jni-method: lm-getProvider getProvider (Ljava/lang/String;)Landroid/location/LocationProvider;
jni-method: getLastKnownLocation getLastKnownLocation (Ljava/lang/String;)Landroid/location/Location;

jni-class: android/hardware/Sensor

-1 Constant TYPE_ALL
$01 Constant TYPE_ACCELEROMETER
$02 Constant TYPE_MAGNETIC_FIELD
$03 Constant TYPE_ORIENTATION \ deprecated API-8
$04 Constant TYPE_GYROSCOPE
$05 Constant TYPE_LIGHT
$06 Constant TYPE_PRESSURE
$07 Constant TYPE_TEMPERATURE \ deprecated API-14
$08 Constant TYPE_PROXIMITY
$09 Constant TYPE_GRAVITY
$0A Constant TYPE_LINEAR_ACCELERATION
$0B Constant TYPE_ROTATION_VECTOR
$0C Constant TYPE_RELATIVE_HUMIDITY
$0D Constant TYPE_AMBIENT_TEMPERATURE
$0E Constant TYPE_MAGNETIC_FIELD_UNCALIBRATED
$0F Constant TYPE_GAME_ROTATION_VECTOR
$10 Constant TYPE_GYROSCOPE_UNCALIBRATED
$11 Constant TYPE_SIGNIFICANT_MOTION
$12 Constant TYPE_STEP_DETECTOR
$13 Constant TYPE_STEP_COUNTER
$14 Constant TYPE_GEOMAGNETIC_ROTATION_VECTOR

jni-method: getName getName ()Ljava/lang/String;
jni-method: getResolution getResolution ()F
jni-method: getType getType ()I
jni-method: getPower getPower ()F
jni-method: toString toString ()Ljava/lang/String;

jni-class: android/hardware/SensorManager

jni-method: getSensorList getSensorList (I)Ljava/util/List;
jni-method: getDefaultSensor getDefaultSensor (I)Landroid/hardware/Sensor;

jni-class: android/hardware/SensorEvent

jni-field: se-accuracy accuracy I
jni-field: se-sensor sensor Landroid/hardware/Sensor;
jni-field: se-timestamp timestamp J
jni-field: se-values values [F

jni-class: android/os/Handler

jni-method: post post (Ljava/lang/Runnable;)Z

gforth-class:

jni-field: gforth-handler handler Landroid/os/Handler;
jni-field: startgps startgps Ljava/lang/Runnable;
jni-field: stopgps stopgps Ljava/lang/Runnable;
jni-field: startsensor startsensor Ljava/lang/Runnable;
jni-field: stopsensor stopsensor Ljava/lang/Runnable;
jni-field: args0 args0 Ljava/lang/String;
jni-field: argf0 argf0 D
jni-field: argj0 argj0 J
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 gforth-handler o> >o
    clazz >o startgps o> post o> drop ;
    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 -- )
    clazz >o sensorManager >o getDefaultSensor o> to argsensor
    clazz >o gforth-handler o> >o
    clazz >o stopgps o> post o> drop ;
    startsensor gforth-handler >o post o> drop 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