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
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

Changes to gles2/jni-helper.fs.

    12     12   gforth-class:
    13     13   
    14     14   \ jni-sfield: INPUT_METHOD_SERVICE INPUT_METHOD_SERVICE Ljava/lang/String;
    15     15   \ jni-sfield: POWER_SERVICE POWER_SERVICE Ljava/lang/String;
    16     16   : INPUT_METHOD_SERVICE js" input_method" ;
    17     17   : POWER_SERVICE        js" power" ;
    18     18   : LOCATION_SERVICE     js" location" ;
           19  +: SENSOR_SERVICE       js" sensor" ;
    19     20   
    20     21   jni-method: getSystemService getSystemService (Ljava/lang/String;)Ljava/lang/Object;
    21     22   jni-method: getWindow getWindow ()Landroid/view/Window;
    22     23   
    23     24   jni-class: android/app/Activity
    24     25   jni-method: getWindowManager getWindowManager ()Landroid/view/WindowManager;
    25     26   

Changes to gles2/jni-location.fs.

    18     18   jni-class: android/location/LocationManager
    19     19   
    20     20   jni-method: getAllProviders getAllProviders ()Ljava/util/List;
    21     21   jni-method: getProviders getProviders (Z)Ljava/util/List;
    22     22   jni-method: lm-getProvider getProvider (Ljava/lang/String;)Landroid/location/LocationProvider;
    23     23   jni-method: getLastKnownLocation getLastKnownLocation (Ljava/lang/String;)Landroid/location/Location;
    24     24   
           25  +jni-class: android/hardware/Sensor
           26  +
           27  +-1 Constant TYPE_ALL
           28  +$01 Constant TYPE_ACCELEROMETER
           29  +$02 Constant TYPE_MAGNETIC_FIELD
           30  +$03 Constant TYPE_ORIENTATION \ deprecated API-8
           31  +$04 Constant TYPE_GYROSCOPE
           32  +$05 Constant TYPE_LIGHT
           33  +$06 Constant TYPE_PRESSURE
           34  +$07 Constant TYPE_TEMPERATURE \ deprecated API-14
           35  +$08 Constant TYPE_PROXIMITY
           36  +$09 Constant TYPE_GRAVITY
           37  +$0A Constant TYPE_LINEAR_ACCELERATION
           38  +$0B Constant TYPE_ROTATION_VECTOR
           39  +$0C Constant TYPE_RELATIVE_HUMIDITY
           40  +$0D Constant TYPE_AMBIENT_TEMPERATURE
           41  +$0E Constant TYPE_MAGNETIC_FIELD_UNCALIBRATED
           42  +$0F Constant TYPE_GAME_ROTATION_VECTOR
           43  +$10 Constant TYPE_GYROSCOPE_UNCALIBRATED
           44  +$11 Constant TYPE_SIGNIFICANT_MOTION
           45  +$12 Constant TYPE_STEP_DETECTOR
           46  +$13 Constant TYPE_STEP_COUNTER
           47  +$14 Constant TYPE_GEOMAGNETIC_ROTATION_VECTOR
           48  +
           49  +jni-method: getName getName ()Ljava/lang/String;
           50  +jni-method: getResolution getResolution ()F
           51  +jni-method: getType getType ()I
           52  +jni-method: getPower getPower ()F
           53  +jni-method: toString toString ()Ljava/lang/String;
           54  +
    25     55   jni-class: android/hardware/SensorManager
           56  +
           57  +jni-method: getSensorList getSensorList (I)Ljava/util/List;
           58  +jni-method: getDefaultSensor getDefaultSensor (I)Landroid/hardware/Sensor;
           59  +
           60  +jni-class: android/hardware/SensorEvent
           61  +
           62  +jni-field: se-accuracy accuracy I
           63  +jni-field: se-sensor sensor Landroid/hardware/Sensor;
           64  +jni-field: se-timestamp timestamp J
           65  +jni-field: se-values values [F
    26     66   
    27     67   jni-class: android/os/Handler
    28     68   
    29     69   jni-method: post post (Ljava/lang/Runnable;)Z
    30     70   
    31     71   gforth-class:
    32     72   
................................................................................
    35     75   jni-field: stopgps stopgps Ljava/lang/Runnable;
    36     76   jni-field: startsensor startsensor Ljava/lang/Runnable;
    37     77   jni-field: stopsensor stopsensor Ljava/lang/Runnable;
    38     78   jni-field: args0 args0 Ljava/lang/String;
    39     79   jni-field: argf0 argf0 D
    40     80   jni-field: argj0 argj0 J
    41     81   jni-field: argsensor argsensor Landroid/hardware/Sensor;
           82  +jni-field: locationManager locationManager Landroid/location/LocationManager;
           83  +jni-field: sensorManager sensorManager Landroid/hardware/SensorManager;
    42     84   
    43     85   also android
    44     86   
    45     87   : start-gps ( -- )
    46         -    clazz >o gforth-handler o> >o
    47         -    clazz >o startgps o> post o> drop ;
           88  +    clazz >o startgps gforth-handler >o post o> drop o> ;
    48     89   
    49     90   : stop-gps ( -- )
    50         -    clazz >o gforth-handler o> >o
    51         -    clazz >o stopgps o> post o> drop ;
           91  +    clazz >o stopgps  gforth-handler >o post o> drop o> ;
           92  +
           93  +: start-sensor ( type -- )
           94  +    clazz >o sensorManager >o getDefaultSensor o> to argsensor
           95  +    startsensor gforth-handler >o post o> drop o> ;
           96  +
           97  +: stop-sensor ( -- )
           98  +    clazz >o stopsensor gforth-handler >o post o> drop o> ;
    52     99   
    53    100   : .deg ( degree -- )
    54    101       fdup f0< IF ." -" fnegate THEN
    55    102       fdup floor fdup f>s 0 .r '°' xemit f-  60e f*
    56    103       fdup floor fdup f>s 0 .r ''' xemit f-  60e f*
    57    104       f. ;
    58    105   
................................................................................
    64    111   	." Alt: " getAltitude f. cr
    65    112   	." Spd: " getSpeed f. cr
    66    113   	." Dir: " getBearing f. cr
    67    114   	." Tme: " getTime d. cr
    68    115   	." Acc: " getAccuracy f. cr
    69    116       THEN
    70    117       o> ;
          118  +
          119  +: .sensor ( -- )  sensor >o
          120  +    o 0= IF  ." unknown"
          121  +    ELSE  se-values
          122  +	[f@ bounds DO  I sf@ f. 1 sfloats +LOOP
          123  +    THEN cr o> ;
    71    124   
    72    125   previous previous

Changes to gles2/jni-tools.fs.

   108    108   : c@f ( jobject jfid -- utf16 )  fieldenv JNIEnv-GetCharField() ;
   109    109   : s@f ( jobject jfid -- n )  fieldenv JNIEnv-GetShortField() ;
   110    110   : i@f ( jobject jfid -- n )  fieldenv JNIEnv-GetIntField() ;
   111    111   : j@f ( jobject jfid -- d )  fieldenv JNIEnv-GetLongField() ;
   112    112   : f@f ( jobject jfid -- r )  fieldenv JNIEnv-GetFloatField() ;
   113    113   : d@f ( jobject jfid -- r )  fieldenv JNIEnv-GetDoubleField() ;
   114    114   : l@f ( jobject jfid -- object )  fieldenv JNIEnv-GetObjectField() ;
          115  +' l@f alias [@f
   115    116   
   116    117   : z!f ( c jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetBooleanField() ;
   117    118   : b!f ( c jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetByteField() ;
   118    119   : c!f ( utf16 jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetCharField() ;
   119    120   : s!f ( n jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetShortField() ;
   120    121   : i!f ( n jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetIntField() ;
   121    122   : j!f ( d jobject jfid -- )  2swap 2>r fieldenv 2r> rot JNIEnv-SetLongField() ;
   122    123   : f!f ( r jobject jfid -- )  fieldenv JNIEnv-SetFloatField() ;
   123    124   : d!f ( r jobject jfid -- )  fieldenv JNIEnv-SetDoubleField() ;
   124    125   : l!f ( object jobject jfid -- )  rot >r fieldenv r> swap JNIEnv-SetObjectField() ;
          126  +' l!f alias [!f
   125    127   
   126    128   Create 'field@ '[' 1+ 'A'
   127    129   [DO] "x@f" over [i] swap c! current @ search-wordlist 0= [IF] ' 2drop [THEN] , [LOOP]
   128    130   
   129    131   Create 'field! '[' 1+ 'A'
   130    132   [DO] "x!f" over [i] swap c! current @ search-wordlist 0= [IF] ' 2drop [THEN] , [LOOP]
   131    133   
................................................................................
   222    224       cstring@1 'field@ + @ compile, postpone ;
   223    225       r> set-to  new-in >in ! ;
   224    226   
   225    227   : jni-sfield: ( "forth-name" "name" "signature" -- )
   226    228       : ( o:jobject -- retval )
   227    229       postpone o jni-sfid postpone Literal
   228    230       cstring@1 'sfield@ + @ compile, postpone ; ;
          231  +
          232  +\ array access: you can access one array at a time
          233  +
          234  +Variable jnibuffer
          235  +
          236  +: [len ( array -- n )  env tuck JNIEnv-GetArrayLength() ;
          237  +
          238  +: >buffer ( size -- buffer )  jnibuffer $!len jnibuffer $@ drop ;
          239  +: buffer@ ( -- addr u )  jnibuffer $@ ;
          240  +
          241  +: [z@ ( array -- addr n )  env swap 0 over [len dup >buffer
          242  +    env JNIEnv-GetBooleanArrayRegion() buffer@ ;
          243  +: [b@ ( array -- addr n )  env swap 0 over [len dup >buffer
          244  +    env JNIEnv-GetByteArrayRegion() buffer@ ;
          245  +: [c@ ( array -- addr n )  env swap 0 over [len dup 2* >buffer
          246  +    env JNIEnv-GetCharArrayRegion() buffer@ ;
          247  +: [s@ ( array -- addr n )  env swap 0 over [len dup 2* >buffer
          248  +    env JNIEnv-GetShortArrayRegion() buffer@ ;
          249  +: [i@ ( array -- addr n )  env swap 0 over [len dup sfloats >buffer
          250  +    env JNIEnv-GetIntArrayRegion() buffer@ ;
          251  +: [j@ ( array -- addr n )  env swap 0 over [len dup dfloats >buffer
          252  +    env JNIEnv-GetLongArrayRegion() buffer@ ;
          253  +: [f@ ( array -- addr n )  env swap 0 over [len dup sfloats >buffer
          254  +    env JNIEnv-GetFloatArrayRegion() buffer@ ;
          255  +: [d@ ( array -- addr n )  env swap 0 over [len dup dfloats >buffer
          256  +    env JNIEnv-GetDoubleArrayRegion() buffer@ ;
   229    257   
   230    258   previous previous set-current

Changes to jni-location.fs.

    18     18   jni-class: android/location/LocationManager
    19     19   
    20     20   jni-method: getAllProviders getAllProviders ()Ljava/util/List;
    21     21   jni-method: getProviders getProviders (Z)Ljava/util/List;
    22     22   jni-method: lm-getProvider getProvider (Ljava/lang/String;)Landroid/location/LocationProvider;
    23     23   jni-method: getLastKnownLocation getLastKnownLocation (Ljava/lang/String;)Landroid/location/Location;
    24     24   
           25  +jni-class: android/hardware/Sensor
           26  +
           27  +-1 Constant TYPE_ALL
           28  +$01 Constant TYPE_ACCELEROMETER
           29  +$02 Constant TYPE_MAGNETIC_FIELD
           30  +$03 Constant TYPE_ORIENTATION \ deprecated API-8
           31  +$04 Constant TYPE_GYROSCOPE
           32  +$05 Constant TYPE_LIGHT
           33  +$06 Constant TYPE_PRESSURE
           34  +$07 Constant TYPE_TEMPERATURE \ deprecated API-14
           35  +$08 Constant TYPE_PROXIMITY
           36  +$09 Constant TYPE_GRAVITY
           37  +$0A Constant TYPE_LINEAR_ACCELERATION
           38  +$0B Constant TYPE_ROTATION_VECTOR
           39  +$0C Constant TYPE_RELATIVE_HUMIDITY
           40  +$0D Constant TYPE_AMBIENT_TEMPERATURE
           41  +$0E Constant TYPE_MAGNETIC_FIELD_UNCALIBRATED
           42  +$0F Constant TYPE_GAME_ROTATION_VECTOR
           43  +$10 Constant TYPE_GYROSCOPE_UNCALIBRATED
           44  +$11 Constant TYPE_SIGNIFICANT_MOTION
           45  +$12 Constant TYPE_STEP_DETECTOR
           46  +$13 Constant TYPE_STEP_COUNTER
           47  +$14 Constant TYPE_GEOMAGNETIC_ROTATION_VECTOR
           48  +
           49  +jni-method: getName getName ()Ljava/lang/String;
           50  +jni-method: getResolution getResolution ()F
           51  +jni-method: getType getType ()I
           52  +jni-method: getPower getPower ()F
           53  +jni-method: toString toString ()Ljava/lang/String;
           54  +
    25     55   jni-class: android/hardware/SensorManager
           56  +
           57  +jni-method: getSensorList getSensorList (I)Ljava/util/List;
           58  +jni-method: getDefaultSensor getDefaultSensor (I)Landroid/hardware/Sensor;
           59  +
           60  +jni-class: android/hardware/SensorEvent
           61  +
           62  +jni-field: se-accuracy accuracy I
           63  +jni-field: se-sensor sensor Landroid/hardware/Sensor;
           64  +jni-field: se-timestamp timestamp J
           65  +jni-field: se-values values [F
    26     66   
    27     67   jni-class: android/os/Handler
    28     68   
    29     69   jni-method: post post (Ljava/lang/Runnable;)Z
    30     70   
    31     71   gforth-class:
    32     72   
................................................................................
    35     75   jni-field: stopgps stopgps Ljava/lang/Runnable;
    36     76   jni-field: startsensor startsensor Ljava/lang/Runnable;
    37     77   jni-field: stopsensor stopsensor Ljava/lang/Runnable;
    38     78   jni-field: args0 args0 Ljava/lang/String;
    39     79   jni-field: argf0 argf0 D
    40     80   jni-field: argj0 argj0 J
    41     81   jni-field: argsensor argsensor Landroid/hardware/Sensor;
           82  +jni-field: locationManager locationManager Landroid/location/LocationManager;
           83  +jni-field: sensorManager sensorManager Landroid/hardware/SensorManager;
    42     84   
    43     85   also android
    44     86   
    45     87   : start-gps ( -- )
    46         -    clazz >o gforth-handler o> >o
    47         -    clazz >o startgps o> post o> drop ;
           88  +    clazz >o startgps gforth-handler >o post o> drop o> ;
    48     89   
    49     90   : stop-gps ( -- )
    50         -    clazz >o gforth-handler o> >o
    51         -    clazz >o stopgps o> post o> drop ;
           91  +    clazz >o stopgps  gforth-handler >o post o> drop o> ;
           92  +
           93  +: start-sensor ( type -- )
           94  +    clazz >o sensorManager >o getDefaultSensor o> to argsensor
           95  +    startsensor gforth-handler >o post o> drop o> ;
           96  +
           97  +: stop-sensor ( -- )
           98  +    clazz >o stopsensor gforth-handler >o post o> drop o> ;
    52     99   
    53    100   : .deg ( degree -- )
    54    101       fdup f0< IF ." -" fnegate THEN
    55    102       fdup floor fdup f>s 0 .r '°' xemit f-  60e f*
    56    103       fdup floor fdup f>s 0 .r ''' xemit f-  60e f*
    57    104       f. ;
    58    105   
................................................................................
    64    111   	." Alt: " getAltitude f. cr
    65    112   	." Spd: " getSpeed f. cr
    66    113   	." Dir: " getBearing f. cr
    67    114   	." Tme: " getTime d. cr
    68    115   	." Acc: " getAccuracy f. cr
    69    116       THEN
    70    117       o> ;
          118  +
          119  +: .sensor ( -- )  sensor >o
          120  +    o 0= IF  ." unknown"
          121  +    ELSE  se-values
          122  +	[f@ bounds DO  I sf@ f. 1 sfloats +LOOP
          123  +    THEN cr o> ;
    71    124   
    72    125   previous previous