sensors

module sensors

Access Android sensors

Sensors are to be enabled when App is created. The following example enables all sensors. The events (SensorEvent, ASensorAccelerometer, ASensorMagneticField...) are sent to the input callback of App

redef class App
    init
    do
        sensors_support_enabled = true
        accelerometer.enabled = true
        accelerometer.eventrate = 10000
        magnetic_field.enabled = true
        gyroscope.enabled = true
        light.enabled = true
        proximity.enabled = true
    end
end

Dependencies

dep_module_android__sensorsgamegamemnitmnitsensorssensorssensors->gamesensors->mnit

Imports

  • game: Android services and implementation of app.nit for gamnit and mnit
  • mnit: Multiplatform game framework for Nit

Concerns

  • android: Android platform support and APIs
  • app: app.nit, a framework for portable applications
    • app_base: Base of the app.nit framework, defines App

in android::sensors

ASensorEventQueue

extern class ASensorEventQueue

Manages the sensors events

Introduces
  • enable_sensor: Enable the selected sensor, returns a negative value on error
  • disable_sensor: Disable the selected sensor, returns a negative value on error
  • set_event_rate: Set the delivery rate of events in microseconds for the given sensor
  • has_events: Returns 1 if the queue has events, 0 if it does not have events,
  • get_events: Returns the next available events from the queue.
Redefines
  • SELF: Type of this instance, automatically specialized in every class

ASensorManager

from app::app_base

App

app::App

redef class App

App subclasses are cross-platform applications

This class is refined by platform modules and so App can be specialized directly in the user application code.

Redefines
  • run: Main entry point of your application
  • handle_looper_event: Handle an event retrieved by the ALooper and poll_looper without a callback