Advertisement
Guest User

Untitled

a guest
Jun 26th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.20 KB | None | 0 0
  1. {
  2.  * Structures and functions to receive and process sensor events in
  3.  * native code.
  4.  *
  5. }
  6.  
  7. Unit sensor;
  8.  
  9. Interface
  10. Uses ctypes, looper;
  11.  
  12. {
  13.  * Sensor types
  14.  * (keep in sync with hardware/sensor.h)
  15.  }
  16. Const
  17.  
  18.   ASENSOR_TYPE_ACCELEROMETER      = 1;
  19.   ASENSOR_TYPE_MAGNETIC_FIELD     = 2;
  20.   ASENSOR_TYPE_GYROSCOPE          = 4;
  21.   ASENSOR_TYPE_LIGHT              = 5;
  22.   ASENSOR_TYPE_PROXIMITY          = 8;
  23.  
  24. // * Sensor accuracy measure
  25.   ASENSOR_STATUS_UNRELIABLE       = 0;
  26.   ASENSOR_STATUS_ACCURACY_LOW     = 1;
  27.   ASENSOR_STATUS_ACCURACY_MEDIUM  = 2;
  28.   ASENSOR_STATUS_ACCURACY_HIGH    = 3;
  29.  
  30. // * A few useful constants
  31.  
  32. // Earth's gravity in m/s^2
  33.   ASENSOR_STANDARD_GRAVITY           = 9.80665;
  34. // Maximum magnetic field on Earth's surface in uT
  35.   ASENSOR_MAGNETIC_FIELD_EARTH_MAX   = 60.0;
  36. // Minimum magnetic field on Earth's surface in uT
  37.   ASENSOR_MAGNETIC_FIELD_EARTH_MIN   = 30.0;
  38.  
  39. // A sensor event.
  40.  
  41. Type
  42.   ASensorVector = Packed Record
  43.     x:Single;
  44.     y:Single;
  45.     z:Single;
  46.     status:Shortint;
  47.     reserved:Array[0..2] Of Byte;
  48.   End;
  49.  
  50.   PASensorEvent = ^ASensorEvent;
  51.   ASensorEvent = Packed Record
  52.     version:Integer; // sizeof(struct ASensorEvent)
  53.     sensor:Integer;
  54.     _type:Integer;
  55.     reserved0:Integer;
  56.     timestamp:Int64;
  57.     vector:ASensorVector;
  58. (*        float           data[16];
  59.         ASensorVector   vector;
  60.         ASensorVector   acceleration;
  61.         ASensorVector   magnetic;
  62.         float           temperature;
  63.         float           distance;
  64.         float           light;
  65.         float           pressure;
  66.     };*)
  67.     reserved1:Array[0..3]Of Integer;
  68.   End;
  69.  
  70.   PASensorManager = ^ASensorManager;
  71.   ASensorManager = Record End;
  72.  
  73.   PASensorEventQueue = ^ASensorEventQueue;
  74.   ASensorEventQueue = Record End;
  75.  
  76.   PASensor =  ^ASensor;
  77.   ASensor = Record End;
  78.  
  79. //typedef ASensor const* ASensorRef;
  80. //typedef ASensorRef const* ASensorList;
  81.  
  82.  
  83. // Get a reference to the sensor manager. ASensorManager is a singleton.
  84. Function ASensorManager_getInstance():PASensorManager; cdecl; external;
  85.  
  86.  
  87. // Returns the list of available sensors.
  88. //Function ASensorManager_getSensorList(manager:PASensorManager; Var ASensorList* list);
  89.  
  90. // Returns the default sensor for the given type, or NULL if no sensor of that type exist.
  91. Function ASensorManager_getDefaultSensor(manager:PASensorManager; _type:Integer):PASensor; cdecl; external;
  92.  
  93. // Creates a new sensor event queue and associate it with a looper.
  94. Function ASensorManager_createEventQueue(manager:PASensorManager; looper:PALooper; ident:Integer; callback:ALooper_callbackFunc; data:Pointer):PASensorEventQueue; cdecl; external;
  95.  
  96. // Destroys the event queue and free all resources associated to it.
  97. Function ASensorManager_destroyEventQueue(manager:PASensorManager; queue:ASensorEventQueue):Integer; cdecl; external;
  98.  
  99.  
  100. // Enable the selected sensor. Returns a negative error code on failure.
  101. Function ASensorEventQueue_enableSensor(queue:PASensorEventQueue; sensor:PASensor):Integer; cdecl; external;
  102.  
  103. // Disable the selected sensor. Returns a negative error code on failure.
  104. Function ASensorEventQueue_disableSensor(queue:PASensorEventQueue; sensor:PASensor):Integer; cdecl; external;
  105.  
  106. (*
  107.  * Sets the delivery rate of events in microseconds for the given sensor.
  108.  * Note that this is a hint only, generally event will arrive at a higher
  109.  * rate. It is an error to set a rate inferior to the value returned by
  110.  * ASensor_getMinDelay().
  111.  * Returns a negative error code on failure.
  112.  *)
  113. Function ASensorEventQueue_setEventRate(queue:PASensorEventQueue; sensor:PASensor; usec:Integer):Integer; cdecl; external;
  114.  
  115. (*
  116.  * Returns true if there are one or more events available in the
  117.  * sensor queue.  Returns 1 if the queue has events; 0 if
  118.  * it does not have events; and a negative value if there is an error.
  119.  *)
  120. Function ASensorEventQueue_hasEvents(queue:ASensorEventQueue):Integer; cdecl; external;
  121.  
  122. (*
  123.  * Returns the next available events from the queue.  Returns a negative
  124.  * value if no events are available or an error has occurred, otherwise
  125.  * the number of events returned.
  126.  *
  127.  * Examples:
  128.  *   ASensorEvent event;
  129.  *   ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
  130.  *
  131.  *   ASensorEvent eventBuffer[8];
  132.  *   ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);
  133.  *
  134.  *)
  135. Function ASensorEventQueue_getEvents(queue:PASensorEventQueue; events:PASensorEvent; count:csize_t):csize_t; cdecl; external;
  136.  
  137. // Returns this sensor's name (non localized)
  138. Function ASensor_getName(sensor:PASensor):PChar; cdecl; external;
  139.  
  140. // Returns this sensor's vendor's name (non localized)
  141. Function ASensor_getVendor(sensor:PASensor):PChar; cdecl; external;
  142.  
  143. // Return this sensor's type
  144. Function ASensor_getType(sensor:PASensor):Integer; cdecl; external;
  145.  
  146. // Returns this sensors's resolution
  147. Function ASensor_getResolution(sensor:PASensor):Single; cdecl; external;
  148.  
  149. (*
  150.  * Returns the minimum delay allowed between events in microseconds.
  151.  * A value of zero means that this sensor doesn't report events at a
  152.  * constant rate, but rather only when a new data is available.
  153.  *)
  154. Function ASensor_getMinDelay(sensor:PASensor):Integer; cdecl; external;
  155.  
  156. Implementation
  157.  
  158. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement