2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
21 internal static partial class Interop
23 internal static class Sensor
25 //Sensor Hardware CAPI
26 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_name")]
27 internal static extern int GetName(IntPtr sensorhandle, out String name);
29 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_vendor")]
30 internal static extern int GetVendor(IntPtr sensorHandle, out String vendor);
32 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_type")]
33 internal static extern int GetType(IntPtr sensorHandle, out SensorType type);
35 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_min_range")]
36 internal static extern int GetMinRange(IntPtr sensorHandle, out float minRange);
38 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_max_range")]
39 internal static extern int GetMaxRange(IntPtr sensorHandle, out float maxRange);
41 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_resolution")]
42 internal static extern int GetResolution(IntPtr sensorHandle, out float resolution);
44 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_min_interval")]
45 internal static extern int GetMinInterval(IntPtr sensorHandle, out int minInterval);
47 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_fifo_count")]
48 internal static extern int GetFifoCount(IntPtr sensorHandle, out int fifoCount);
50 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_max_batch_count")]
51 internal static extern int GetMaxBatchCount(IntPtr sensorHandle, out int maxBatchCount);
53 internal static class SensorListener
55 //Sensor Listener CAPI
56 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
57 internal delegate void SensorEventCallback(IntPtr sensorHandle, IntPtr eventData, IntPtr data);
58 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
59 internal delegate void SensorAccuracyCallback(IntPtr sensorHandle, ulong timestamp, SensorDataAccuracy accuracy, IntPtr data);
61 [DllImport(Libraries.Sensor, EntryPoint = "sensor_create_listener")]
62 internal static extern int CreateListener(IntPtr sensorHandle, out IntPtr listenerHandle);
64 [DllImport(Libraries.Sensor, EntryPoint = "sensor_destroy_listener")]
65 internal static extern int DestroyListener(IntPtr listenerHandle);
67 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_start")]
68 internal static extern int StartListener(IntPtr listenerHandle);
70 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_stop")]
71 internal static extern int StopListener(IntPtr listenerHandle);
73 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_set_event_cb")]
74 internal static extern int SetEventCallback(IntPtr listenerHandle, uint intervalMs, SensorEventCallback callback, IntPtr data);
76 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_unset_event_cb")]
77 internal static extern int UnsetEventCallback(IntPtr listernerHandle);
79 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_set_accuracy_cb")]
80 internal static extern int SetAccuracyCallback(IntPtr listenerHandle, SensorAccuracyCallback callback, IntPtr data);
82 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_unset_accuracy_cb")]
83 internal static extern int UnsetAccuracyCallback(IntPtr listernerHandle);
85 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_set_interval")]
86 internal static extern int SetInterval(IntPtr listenerHandle, uint intervalMs);
88 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_set_max_batch_latency")]
89 internal static extern int SetMaxBatchLatency(IntPtr listenerHandle, uint maxBatchLatency);
91 [DllImport(Libraries.Sensor, EntryPoint = "sensor_listener_set_attribute_int")]
92 internal static extern int SetAttribute(IntPtr listenerHandle, SensorAttribute sensorAttribute, int option);
95 internal static class SensorManager
98 [DllImport(Libraries.Sensor, EntryPoint = "sensor_is_supported")]
99 internal static extern int SensorIsSupported(SensorType type, out bool supported);
101 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_default_sensor")]
102 internal static extern int GetDefaultSensor(SensorType type, out IntPtr sensor);
104 [DllImport(Libraries.Sensor, EntryPoint = "sensor_get_sensor_list")]
105 internal static extern int GetSensorList(SensorType type, out IntPtr list, out int sensor_count);
108 internal static partial class Libc
110 [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
111 internal static extern int Free(IntPtr ptr);
114 [StructLayout(LayoutKind.Sequential, Pack = 0)]
115 internal struct SensorEventStruct
117 internal SensorDataAccuracy accuracy;
118 internal UInt64 timestamp;
119 internal int value_count;
120 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
121 internal float[] values;
124 internal static IntPtr[] IntPtrToIntPtrArray(IntPtr unmanagedArray, int size)
126 IntPtr[] managedArray = new IntPtr[size];
127 Marshal.Copy(unmanagedArray, managedArray, 0, size);
131 internal static SensorEventStruct IntPtrToEventStruct(IntPtr unmanagedVariable)
133 SensorEventStruct outStruct = (SensorEventStruct)Marshal.PtrToStructure(unmanagedVariable, typeof(SensorEventStruct));