Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- * Structures and functions to receive and process sensor events in
- * native code.
- *
- }
- Unit sensor;
- Interface
- Uses ctypes, looper;
- {
- * Sensor types
- * (keep in sync with hardware/sensor.h)
- }
- Const
- ASENSOR_TYPE_ACCELEROMETER = 1;
- ASENSOR_TYPE_MAGNETIC_FIELD = 2;
- ASENSOR_TYPE_GYROSCOPE = 4;
- ASENSOR_TYPE_LIGHT = 5;
- ASENSOR_TYPE_PROXIMITY = 8;
- // * Sensor accuracy measure
- ASENSOR_STATUS_UNRELIABLE = 0;
- ASENSOR_STATUS_ACCURACY_LOW = 1;
- ASENSOR_STATUS_ACCURACY_MEDIUM = 2;
- ASENSOR_STATUS_ACCURACY_HIGH = 3;
- // * A few useful constants
- // Earth's gravity in m/s^2
- ASENSOR_STANDARD_GRAVITY = 9.80665;
- // Maximum magnetic field on Earth's surface in uT
- ASENSOR_MAGNETIC_FIELD_EARTH_MAX = 60.0;
- // Minimum magnetic field on Earth's surface in uT
- ASENSOR_MAGNETIC_FIELD_EARTH_MIN = 30.0;
- // A sensor event.
- Type
- ASensorVector = Packed Record
- x:Single;
- y:Single;
- z:Single;
- status:Shortint;
- reserved:Array[0..2] Of Byte;
- End;
- PASensorEvent = ^ASensorEvent;
- ASensorEvent = Packed Record
- version:Integer; // sizeof(struct ASensorEvent)
- sensor:Integer;
- _type:Integer;
- reserved0:Integer;
- timestamp:Int64;
- vector:ASensorVector;
- (* float data[16];
- ASensorVector vector;
- ASensorVector acceleration;
- ASensorVector magnetic;
- float temperature;
- float distance;
- float light;
- float pressure;
- };*)
- reserved1:Array[0..3]Of Integer;
- End;
- PASensorManager = ^ASensorManager;
- ASensorManager = Record End;
- PASensorEventQueue = ^ASensorEventQueue;
- ASensorEventQueue = Record End;
- PASensor = ^ASensor;
- ASensor = Record End;
- //typedef ASensor const* ASensorRef;
- //typedef ASensorRef const* ASensorList;
- // Get a reference to the sensor manager. ASensorManager is a singleton.
- Function ASensorManager_getInstance():PASensorManager; cdecl; external;
- // Returns the list of available sensors.
- //Function ASensorManager_getSensorList(manager:PASensorManager; Var ASensorList* list);
- // Returns the default sensor for the given type, or NULL if no sensor of that type exist.
- Function ASensorManager_getDefaultSensor(manager:PASensorManager; _type:Integer):PASensor; cdecl; external;
- // Creates a new sensor event queue and associate it with a looper.
- Function ASensorManager_createEventQueue(manager:PASensorManager; looper:PALooper; ident:Integer; callback:ALooper_callbackFunc; data:Pointer):PASensorEventQueue; cdecl; external;
- // Destroys the event queue and free all resources associated to it.
- Function ASensorManager_destroyEventQueue(manager:PASensorManager; queue:ASensorEventQueue):Integer; cdecl; external;
- // Enable the selected sensor. Returns a negative error code on failure.
- Function ASensorEventQueue_enableSensor(queue:PASensorEventQueue; sensor:PASensor):Integer; cdecl; external;
- // Disable the selected sensor. Returns a negative error code on failure.
- Function ASensorEventQueue_disableSensor(queue:PASensorEventQueue; sensor:PASensor):Integer; cdecl; external;
- (*
- * Sets the delivery rate of events in microseconds for the given sensor.
- * Note that this is a hint only, generally event will arrive at a higher
- * rate. It is an error to set a rate inferior to the value returned by
- * ASensor_getMinDelay().
- * Returns a negative error code on failure.
- *)
- Function ASensorEventQueue_setEventRate(queue:PASensorEventQueue; sensor:PASensor; usec:Integer):Integer; cdecl; external;
- (*
- * Returns true if there are one or more events available in the
- * sensor queue. Returns 1 if the queue has events; 0 if
- * it does not have events; and a negative value if there is an error.
- *)
- Function ASensorEventQueue_hasEvents(queue:ASensorEventQueue):Integer; cdecl; external;
- (*
- * Returns the next available events from the queue. Returns a negative
- * value if no events are available or an error has occurred, otherwise
- * the number of events returned.
- *
- * Examples:
- * ASensorEvent event;
- * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
- *
- * ASensorEvent eventBuffer[8];
- * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);
- *
- *)
- Function ASensorEventQueue_getEvents(queue:PASensorEventQueue; events:PASensorEvent; count:csize_t):csize_t; cdecl; external;
- // Returns this sensor's name (non localized)
- Function ASensor_getName(sensor:PASensor):PChar; cdecl; external;
- // Returns this sensor's vendor's name (non localized)
- Function ASensor_getVendor(sensor:PASensor):PChar; cdecl; external;
- // Return this sensor's type
- Function ASensor_getType(sensor:PASensor):Integer; cdecl; external;
- // Returns this sensors's resolution
- Function ASensor_getResolution(sensor:PASensor):Single; cdecl; external;
- (*
- * Returns the minimum delay allowed between events in microseconds.
- * A value of zero means that this sensor doesn't report events at a
- * constant rate, but rather only when a new data is available.
- *)
- Function ASensor_getMinDelay(sensor:PASensor):Integer; cdecl; external;
- Implementation
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement