Mob.Motion (mob v0.3.5)

Copy Markdown View Source

Accelerometer and gyroscope sensor data.

No permission required.

Updates arrive at handle_info at the requested interval:

handle_info({:motion, %{
  accel:     {ax, ay, az},   # m/s² (gravity included)
  gyro:      {gx, gy, gz},   # rad/s
  timestamp: unix_ms
}}, socket)

If you only request one sensor, the other tuple will be {0.0, 0.0, 0.0}.

iOS: CMMotionManager. Android: SensorManager.

Summary

Functions

Start sensor updates.

Stop sensor updates.

Types

sensor()

@type sensor() :: :accelerometer | :gyro

Functions

start(socket, opts \\ [])

@spec start(
  Mob.Socket.t(),
  keyword()
) :: Mob.Socket.t()

Start sensor updates.

Options:

  • sensors: [:accelerometer] | [:gyro] | [:accelerometer, :gyro] (default both)

  • interval_ms: integer — update interval in milliseconds (default 100)

stop(socket)

@spec stop(Mob.Socket.t()) :: Mob.Socket.t()

Stop sensor updates.