Skip to content

sensorlib.get_magnetic_field and .get_acceleration fail with SensorException` #9

@aaaaalbert

Description

@aaaaalbert

Test program, tested on a Google Nexus 6 with Android 5.1.1:

getsensor = dy_import_module("getsensor.r2py")

# Try the sensor calls that require that `start_sensing` 
# has already been called
for sensor_function in [getsensor.get_magnetic_field,
    getsensor.get_acceleration, getsensor.get_light]:
  try:
    log(sensor_function(), "\n")
  except Exception, e:
    log(repr(sensor_function), "failed with", repr(e), "\n")

Problem: get_magnetic_field and get_acceleration request a sensor value before starting the sensor.

(get_light does too, but this doesn't seem to be a problem.)

Log:

========================================
Running program: dylink.r2py
Arguments: ['sensorfails.r2py']
========================================
Using port 63104 to get sensor data.
Something went wrong!
<function get_magnetic_field at 0xb5daecb0> failed with SensorException(u"java.lang.NullPointerException: Null pointer exception during instruction 'monitor-enter v1'",) 
Something went wrong!
<function get_acceleration at 0xb5daec70> failed with SensorException(u"java.lang.NullPointerException: Null pointer exception during instruction 'monitor-enter v1'",) 
None 

Possible solution: Implement a state machine around start_sensing, stop_sensing that ensures that the sensors queried are already set up to return data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions