@@ -69,8 +69,99 @@ public override void write(string str)
6969 }
7070 }
7171
72+ /// <summary><see cref="iio.Channel.ChannelModifier"/> class:
73+ /// Contains the available channel modifiers.</summary>
74+ public enum ChannelModifier
75+ {
76+ IIO_NO_MOD ,
77+ IIO_MOD_X ,
78+ IIO_MOD_Y ,
79+ IIO_MOD_Z ,
80+ IIO_MOD_X_AND_Y ,
81+ IIO_MOD_X_AND_Z ,
82+ IIO_MOD_Y_AND_Z ,
83+ IIO_MOD_X_AND_Y_AND_Z ,
84+ IIO_MOD_X_OR_Y ,
85+ IIO_MOD_X_OR_Z ,
86+ IIO_MOD_Y_OR_Z ,
87+ IIO_MOD_X_OR_Y_OR_Z ,
88+ IIO_MOD_LIGHT_BOTH ,
89+ IIO_MOD_LIGHT_IR ,
90+ IIO_MOD_ROOT_SUM_SQUARED_X_Y ,
91+ IIO_MOD_SUM_SQUARED_X_Y_Z ,
92+ IIO_MOD_LIGHT_CLEAR ,
93+ IIO_MOD_LIGHT_RED ,
94+ IIO_MOD_LIGHT_GREEN ,
95+ IIO_MOD_LIGHT_BLUE ,
96+ IIO_MOD_QUATERNION ,
97+ IIO_MOD_TEMP_AMBIENT ,
98+ IIO_MOD_TEMP_OBJECT ,
99+ IIO_MOD_NORTH_MAGN ,
100+ IIO_MOD_NORTH_TRUE ,
101+ IIO_MOD_NORTH_MAGN_TILT_COMP ,
102+ IIO_MOD_NORTH_TRUE_TILT_COMP ,
103+ IIO_MOD_RUNNING ,
104+ IIO_MOD_JOGGING ,
105+ IIO_MOD_WALKING ,
106+ IIO_MOD_STILL ,
107+ IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z ,
108+ IIO_MOD_I ,
109+ IIO_MOD_Q ,
110+ IIO_MOD_CO2 ,
111+ IIO_MOD_VOC ,
112+ IIO_MOD_LIGHT_UV ,
113+ IIO_MOD_LIGHT_DUV ,
114+ IIO_MOD_PM1 ,
115+ IIO_MOD_PM2P5 ,
116+ IIO_MOD_PM4 ,
117+ IIO_MOD_PM10 ,
118+ IIO_MOD_ETHANOL ,
119+ IIO_MOD_H2
120+ }
121+
122+ /// <summary><see cref="iio.Channel.ChannelType"/> class:
123+ /// Contains the available channel types.</summary>
124+ public enum ChannelType
125+ {
126+ IIO_VOLTAGE ,
127+ IIO_CURRENT ,
128+ IIO_POWER ,
129+ IIO_ACCEL ,
130+ IIO_ANGL_VEL ,
131+ IIO_MAGN ,
132+ IIO_LIGHT ,
133+ IIO_INTENSITY ,
134+ IIO_PROXIMITY ,
135+ IIO_TEMP ,
136+ IIO_INCLI ,
137+ IIO_ROT ,
138+ IIO_ANGL ,
139+ IIO_TIMESTAMP ,
140+ IIO_CAPACITANCE ,
141+ IIO_ALTVOLTAGE ,
142+ IIO_CCT ,
143+ IIO_PRESSURE ,
144+ IIO_HUMIDITYRELATIVE ,
145+ IIO_ACTIVITY ,
146+ IIO_STEPS ,
147+ IIO_ENERGY ,
148+ IIO_DISTANCE ,
149+ IIO_VELOCITY ,
150+ IIO_CONCENTRATION ,
151+ IIO_RESISTANCE ,
152+ IIO_PH ,
153+ IIO_UVINDEX ,
154+ IIO_ELECTRICALCONDUCTIVITY ,
155+ IIO_COUNT ,
156+ IIO_INDEX ,
157+ IIO_GRAVITY ,
158+ IIO_POSITIONRELATIVE ,
159+ IIO_PHASE ,
160+ IIO_MASSCONCENTRATION ,
161+ IIO_CHAN_TYPE_UNKNOWN = Int32 . MaxValue
162+ }
72163
73- private IntPtr chn ;
164+ internal IntPtr chn ;
74165 private uint sample_size ;
75166
76167 [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
@@ -118,6 +209,30 @@ public override void write(string str)
118209 [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
119210 private static extern IntPtr iio_channel_get_data_format ( IntPtr chn ) ;
120211
212+ [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
213+ private static extern int iio_channel_get_index ( IntPtr chn ) ;
214+
215+ [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
216+ private static extern IntPtr iio_channel_get_device ( IntPtr chn ) ;
217+
218+ [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
219+ private static extern IntPtr iio_device_get_context ( IntPtr dev ) ;
220+
221+ [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
222+ private static extern int iio_channel_get_modifier ( IntPtr chn ) ;
223+
224+ [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
225+ private static extern int iio_channel_get_type ( IntPtr chn ) ;
226+
227+ [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
228+ private static extern IntPtr iio_channel_find_attr ( IntPtr chn , [ In ] string name ) ;
229+
230+ [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
231+ private static extern void iio_channel_convert ( IntPtr chn , IntPtr dst , IntPtr src ) ;
232+
233+ [ DllImport ( "libiio.dll" , CallingConvention = CallingConvention . Cdecl ) ]
234+ private static extern void iio_channel_convert_inverse ( IntPtr chn , IntPtr dst , IntPtr src ) ;
235+
121236 /// <summary>The name of this channel.</summary>
122237 public readonly string name ;
123238
@@ -139,11 +254,19 @@ public override void write(string str)
139254 /// <summary>A <c>list</c> of all the attributes that this channel has.</summary>
140255 public readonly List < Attr > attrs ;
141256
257+ /// <summary>The modifier of this channel.</summary>
258+ public ChannelModifier modifier { get ; private set ; }
259+
260+ /// <summary>The type of this channel.</summary>
261+ public ChannelType type { get ; private set ; }
262+
142263 internal Channel ( IntPtr chn )
143264 {
144265 this . chn = chn ;
145266 attrs = new List < Attr > ( ) ;
146267 sample_size = ( uint ) Marshal . ReadInt32 ( iio_channel_get_data_format ( this . chn ) ) / 8 ;
268+ modifier = ( ChannelModifier ) iio_channel_get_modifier ( chn ) ;
269+ type = ( ChannelType ) iio_channel_get_type ( chn ) ;
147270 uint nb_attrs = iio_channel_get_attrs_count ( chn ) ;
148271
149272 for ( uint i = 0 ; i < nb_attrs ; i ++ )
@@ -258,5 +381,46 @@ public uint write(IOBuffer buffer, byte[] array, bool raw = false)
258381
259382 return count ;
260383 }
384+
385+ /// <summary>Get the index of this channel.</summary>
386+ public long get_index ( )
387+ {
388+ return iio_channel_get_index ( chn ) ;
389+ }
390+
391+ /// <summary>Finds the attribute of the current channel with the given name.</summary>
392+ /// <returns><see cref="iio.Channel.ChannelAttr"/></returns>
393+ /// <exception cref="System.Exception">There is no attribute with the given name.</exception>
394+ public Attr find_attribute ( string attribute )
395+ {
396+ IntPtr attr = iio_channel_find_attr ( chn , attribute ) ;
397+
398+ if ( attr == IntPtr . Zero )
399+ {
400+ throw new Exception ( "There is no attribute with the given name!" ) ;
401+ }
402+
403+ return new ChannelAttr ( chn , Marshal . PtrToStringAnsi ( attr ) ) ;
404+ }
405+
406+ /// <summary>Finds the device of the current channel.</summary>
407+ /// <returns><see cref="iio.Device"/></returns>
408+ public Device get_device ( )
409+ {
410+ IntPtr dev_ptr = iio_channel_get_device ( chn ) ;
411+ return new Device ( new Context ( dev_ptr ) , dev_ptr ) ;
412+ }
413+
414+ /// <summary>Converts the data from the hardware format to the format of the arhitecture on which libiio is running.</summary>
415+ public void convert ( IntPtr dst , IntPtr src )
416+ {
417+ iio_channel_convert ( chn , dst , src ) ;
418+ }
419+
420+ /// <summary>Converts the data from the arhitecture on which libiio is running to the hardware format.</summary>
421+ public void convert_inverse ( IntPtr dst , IntPtr src )
422+ {
423+ iio_channel_convert_inverse ( chn , dst , src ) ;
424+ }
261425 }
262426}
0 commit comments