forked from in4lio/ev3dev-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ev3.i
4369 lines (3679 loc) · 118 KB
/
ev3.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ev3.i was generated by yup.py (yupp) 1.0c3
out of ev3.yu-i
*//**
* \file ev3.i (ev3.yu-i)
* \brief SWIG interface file.
* \author Vitaly Kravtsov ([email protected])
* \copyright See the LICENSE file.
*/
%module ev3
%include "cstring.i"
%include "stdint.i"
%include "typemaps.i"
%{
#include "../source/ev3/ev3.h"
#include "../source/ev3/ev3_led.h"
#include "../source/ev3/ev3_light.h"
#include "../source/ev3/ev3_port.h"
#include "../source/ev3/ev3_sensor.h"
#include "../source/ev3/ev3_tacho.h"
#include "../source/ev3/ev3_dc.h"
#include "../source/ev3/ev3_servo.h"
#include "../source/ev3/brick.h"
%}
%define ALLOC_OUTPUT_BUFFER(TYPEMAP,MAX)
%typemap(in,noblock=1,numinputs=0) TYPEMAP (char temp[MAX+1]) {
$1 = temp;
}
%enddef
/* String buffer without size is passed only for getting a port name */
ALLOC_OUTPUT_BUFFER( char *buf, 64 );
/* Unfortunately incompatible with %typemap( default ) size_t sz { $1 = DEFAULT_BUF_SIZE; } */
%cstring_output_maxsize( char *buf, size_t sz );
%include "./platform.h"
#ifdef SWIGPERL
/* because of the problem with SWIG_From_bool on the brick... */
#define bool int
#endif
%apply uint8_t *OUTPUT { uint8_t *sn };
%apply bool *OUTPUT { bool *buf };
%apply int *OUTPUT { int *buf };
%apply uint8_t *OUTPUT { uint8_t *buf };
%apply uint8_t *OUTPUT { byte *buf };
%apply uint32_t *OUTPUT { uint32_t *buf };
%apply uint32_t *OUTPUT { dword *buf };
%apply float *OUTPUT { float *buf };
%apply uint8_t *OUTPUT { FLAGS_T *flags };
%apply uint32_t { dword };
%apply uint8_t { byte };
%apply uint8_t { INX_T };
%apply uint8_t { FLAGS_T };
%apply uint8_t { POOL_T };
#ifdef SWIGRUBY
%typemap( out ) size_t, bool { $result = $1 ? Qtrue : Qfalse; };
%typemap( in ) bool { $1 = $input == Qtrue ? 1 : 0; };
#endif
%typemap( default ) uint8_t from { $1 = 0; };
%typemap( default ) dword defval { $1 = 0; };
%typemap( default ) float defval { $1 = 0.0; };
%typemap( default ) int defval { $1 = 0; };
/*
* ev3
*/
// CLIENT ////////////////////////////////////////
#if EV3_BRICK == 0
%rename( brick_addr ) ev3_brick_addr;
extern char *ev3_brick_addr;
%rename( brick_port ) ev3_brick_port;
extern uint16_t ev3_brick_port;
//////////////////////////////////////////////////
#endif
extern int ev3_init( void );
extern void ev3_uninit( void );
extern size_t ev3_write_binary( const char *fn, char *STRING, size_t LENGTH );
extern size_t ev3_write( const char *fn, char *value );
extern size_t ev3_write_bool( const char *fn, bool value );
extern size_t ev3_write_int( const char *fn, int value );
extern size_t ev3_write_dword( const char *fn, uint32_t value );
extern size_t ev3_write_byte( const char *fn, uint8_t value );
extern size_t ev3_write_float( const char *fn, float value );
extern size_t ev3_multi_write_binary( uint8_t *sn, uint16_t pos, const char *fn, char *STRING, size_t LENGTH );
extern size_t ev3_multi_write( uint8_t *sn, uint16_t pos, const char *fn, char *value );
extern size_t ev3_multi_write_bool( uint8_t *sn, uint16_t pos, const char *fn, bool value );
extern size_t ev3_multi_write_int( uint8_t *sn, uint16_t pos, const char *fn, int value );
extern size_t ev3_multi_write_dword( uint8_t *sn, uint16_t pos, const char *fn, uint32_t value );
extern size_t ev3_multi_write_byte( uint8_t *sn, uint16_t pos, const char *fn, uint8_t value );
extern size_t ev3_multi_write_float( uint8_t *sn, uint16_t pos, const char *fn, float value );
extern size_t ev3_read_binary( const char *fn, char *buf, size_t sz );
extern size_t ev3_read( const char *fn, char *buf, size_t sz );
#ifndef SWIGRUBY
extern size_t ev3_read_bool( const char *fn, bool *buf );
#endif
extern size_t ev3_read_int( const char *fn, int *buf );
extern size_t ev3_read_dword( const char *fn, uint32_t *buf );
extern size_t ev3_read_byte( const char *fn, uint8_t *buf );
extern size_t ev3_read_float( const char *fn, float *buf );
extern size_t ev3_listdir( const char *fn, char *buf, size_t sz );
extern size_t ev3_read_keys( uint8_t *buf );
extern bool ev3_poweroff( void );
enum {
EV3_KEY__NONE_ = 0,
EV3_KEY_UP = 0x01L,
EV3_KEY_DOWN = 0x02L,
EV3_KEY_LEFT = 0x04L,
EV3_KEY_RIGHT = 0x08L,
EV3_KEY_CENTER = 0x10L,
EV3_KEY_BACK = 0x20L,
};
#define DESC_LIMIT 64
#define DESC_VEC_LEN 4
/**
* \brief Identifiers of LEDs.
*/
enum {
EV3_LEFT_GREEN,
EV3_RIGHT_GREEN,
EV3_LEFT_RED,
EV3_RIGHT_RED,
LED_OUTA,
LED_OUTB,
LED_OUTC,
LED_OUTD,
LED__COUNT_ /**< Count of EV3 LEDs. */
};
/**
* \brief Triggers identifiers of LEDs.
*/
enum {
TRIGGER_NONE,
TRIGGER_MMC0,
TRIGGER_TIMER,
TRIGGER_HEARTBEAT,
TRIGGER_DEFAULT_ON,
TRIGGER_TRANSIENT,
TRIGGER_LEGOEV3_BATTERY_CHARGING_OR_FULL,
TRIGGER_LEGOEV3_BATTERY_CHARGING,
TRIGGER_LEGOEV3_BATTERY_FULL,
TRIGGER_LEGOEV3_BATTERY_CHARGING_BLINK_FULL_SOLID,
TRIGGER_RFKILL0,
TRIGGER_PHY0RX,
TRIGGER_PHY0TX,
TRIGGER_PHY0ASSOC,
TRIGGER_PHY0RADIO,
TRIGGER_RFKILL1,
TRIGGER__COUNT_ /**< Count of EV3 triggers. */
};
#define LED_ATTR__COUNT_ 5
/**
* \brief Read "brightness" attribute of the LED.
* \param inx Index of the LED.
* \param[out] buf Buffer for result.
* \return Count of read bytes.
*/
extern size_t get_led_brightness( uint8_t inx, byte *buf );
/**
* \brief Write "brightness" attribute of the LED.
* \param inx Index of the LED.
* \param value Attribute value.
* \return Count of written bytes.
*/
extern size_t set_led_brightness( uint8_t inx, byte value );
/**
* \brief Read "delay_off" attribute of the LED.
* \param inx Index of the LED.
* \param[out] buf Buffer for result.
* \return Count of read bytes.
*/
extern size_t get_led_delay_off( uint8_t inx, int *buf );
/**
* \brief Write "delay_off" attribute of the LED.
* \param inx Index of the LED.
* \param value Attribute value.
* \return Count of written bytes.
*/
extern size_t set_led_delay_off( uint8_t inx, int value );
/**
* \brief Read "delay_on" attribute of the LED.
* \param inx Index of the LED.
* \param[out] buf Buffer for result.
* \return Count of read bytes.
*/
extern size_t get_led_delay_on( uint8_t inx, int *buf );
/**
* \brief Write "delay_on" attribute of the LED.
* \param inx Index of the LED.
* \param value Attribute value.
* \return Count of written bytes.
*/
extern size_t set_led_delay_on( uint8_t inx, int value );
/**
* \brief Read "max_brightness" attribute of the LED.
* \param inx Index of the LED.
* \param[out] buf Buffer for result.
* \return Count of read bytes.
*/
extern size_t get_led_max_brightness( uint8_t inx, byte *buf );
/**
* \brief Read "trigger" attribute of the LED.
* \param inx Index of the LED.
* \param[out] buf Buffer for result.
* \param sz Buffer size.
* \return Count of read bytes.
*/
extern size_t get_led_trigger( uint8_t inx, char *buf, size_t sz );
/**
* \brief Write "trigger" attribute of the LED.
* \param inx Index of the LED.
* \param value Attribute value.
* \return Count of written bytes.
*/
extern size_t set_led_trigger( uint8_t inx, char *value );
/**
* \brief Read "trigger" attribute of the LED and get the index.
* \param inx Index of the LED.
* \return Index of trigger or TRIGGER__COUNT_ - error has occurred.
*/
extern INX_T get_led_trigger_inx( uint8_t inx );
/**
* \brief Write "trigger" attribute of the LED by the index.
* \param inx Index of the LED.
* \param trigger_inx Index of the trigger.
* \return Count of written bytes.
*/
extern size_t set_led_trigger_inx( uint8_t inx, INX_T trigger_inx );
/**
* \brief Get name of the specified LED trigger.
* \param trigger_inx Index of the trigger.
* \return Requested value.
*/
extern const char *ev3_led_trigger( INX_T trigger_inx );
/**
* \brief Identifiers of light locations.
*/
enum {
LIT_LEFT,
LIT_RIGHT,
LIT__LOC__
};
/**
* \brief Identifiers of light colors.
*/
enum {
LIT_OFF,
LIT_GREEN,
LIT_RED,
LIT_AMBER,
LIT__COL__
};
/**
* \brief Light colors.
*/
extern const char *const LIT_COLOR[];
/**
* \brief Get the light color name.
* \param col Color.
* \return Color name.
*/
extern const char *light_color( uint8_t col );
/**
* \brief Set the light color.
* \param loc Location.
* \param col Color.
*/
extern void set_light( uint8_t loc, uint8_t col );
/**
* \brief Get the light color.
* \param loc Location.
* \return Color.
*/
extern uint8_t get_light( uint8_t loc );
/**
* \brief Set the light trigger.
* \param loc Location.
* \param col Color.
* \param trigger Index of trigger.
*/
extern void set_light_trigger( uint8_t loc, uint8_t col, uint8_t trigger );
/**
* \brief Get the light trigger.
* \param loc Location.
* \param col Color.
* \return Index of trigger or TRIGGER__COUNT_ - error has occurred.
*/
extern uint8_t get_light_trigger( uint8_t loc, uint8_t col );
/**
* \brief Set the light blink.
* \param loc Location.
* \param col Color.
* \param delay_on Time of "on" state in ms.
* \param delay_off Time of "off" state in ms.
*/
extern void set_light_blink( uint8_t loc, uint8_t col, int delay_on, int delay_off );
/**
* \brief Check the light is blinking.
* \param loc Location.
* \param col Color.
* \return Flag - the light is blinking.
*/
extern bool get_light_blink( uint8_t loc, uint8_t col );
#define PORT_DIR "/sys/class/lego-port" /**< Directory of EV3 ports. */
/**
* \brief Structure of a EV3 port descriptor.
*/
typedef struct {
INX_T type_inx; /**< EV3 port type. */
uint8_t port; /**< EV3 port EV3 port. */
uint8_t extport; /**< EV3 port extended port. */
uint8_t addr; /**< EV3 port I2C address. */
} EV3_PORT;
#define PORT_DESC__LIMIT_ DESC_LIMIT /**< Limit of EV3 port descriptors. */
#define PORT__NONE_ PORT_DESC__LIMIT_ /**< EV3 port is not found. */
/**
* \brief Vector of EV3 port descriptors (filled by \ref ev3_port_init).
*/
extern EV3_PORT ev3_port[ PORT_DESC__LIMIT_ ];
/**
* \brief Identifiers of EV3 port types.
*/
enum {
PORT_TYPE__NONE_ = 0, /* XXX: memset( 0 ) is used */
HT_NXT_SMUX_PORT,
LEGOEV3_INPUT_PORT,
LEGOEV3_OUTPUT_PORT,
MS_EV3_SMUX_PORT,
MS_NXTMMX_OUT_PORT,
WEDO_PORT,
PORT_TYPE__COUNT_, /**< Count of EV3 port types. */
PORT_TYPE__UNKNOWN_ = PORT_TYPE__COUNT_
};
/**
* \brief Identifiers of EV3 port "mode" attribute.
*/
enum {
PORT_MODE__NONE_ = 0,
HT_NXT_SMUX_PORT_ANALOG, HT_NXT_SMUX_ANALOG = HT_NXT_SMUX_PORT_ANALOG,
HT_NXT_SMUX_PORT_I2C, HT_NXT_SMUX_I2C = HT_NXT_SMUX_PORT_I2C,
LEGOEV3_INPUT_PORT_AUTO, INPUT_AUTO = LEGOEV3_INPUT_PORT_AUTO,
LEGOEV3_INPUT_PORT_NXT_ANALOG, INPUT_NXT_ANALOG = LEGOEV3_INPUT_PORT_NXT_ANALOG,
LEGOEV3_INPUT_PORT_NXT_COLOR, INPUT_NXT_COLOR = LEGOEV3_INPUT_PORT_NXT_COLOR,
LEGOEV3_INPUT_PORT_NXT_I2C, INPUT_NXT_I2C = LEGOEV3_INPUT_PORT_NXT_I2C,
LEGOEV3_INPUT_PORT_OTHER_I2C, INPUT_OTHER_I2C = LEGOEV3_INPUT_PORT_OTHER_I2C,
LEGOEV3_INPUT_PORT_EV3_ANALOG, INPUT_EV3_ANALOG = LEGOEV3_INPUT_PORT_EV3_ANALOG,
LEGOEV3_INPUT_PORT_EV3_UART, INPUT_EV3_UART = LEGOEV3_INPUT_PORT_EV3_UART,
LEGOEV3_INPUT_PORT_OTHER_UART, INPUT_OTHER_UART = LEGOEV3_INPUT_PORT_OTHER_UART,
LEGOEV3_INPUT_PORT_RAW, INPUT_RAW = LEGOEV3_INPUT_PORT_RAW,
LEGOEV3_OUTPUT_PORT_AUTO, OUTPUT_AUTO = LEGOEV3_OUTPUT_PORT_AUTO,
LEGOEV3_OUTPUT_PORT_TACHO_MOTOR, OUTPUT_TACHO_MOTOR = LEGOEV3_OUTPUT_PORT_TACHO_MOTOR,
LEGOEV3_OUTPUT_PORT_DC_MOTOR, OUTPUT_DC_MOTOR = LEGOEV3_OUTPUT_PORT_DC_MOTOR,
LEGOEV3_OUTPUT_PORT_LED, OUTPUT_LED = LEGOEV3_OUTPUT_PORT_LED,
LEGOEV3_OUTPUT_PORT_RAW, OUTPUT_RAW = LEGOEV3_OUTPUT_PORT_RAW,
MS_EV3_SMUX_PORT_UART, MS_EV3_SMUX_UART = MS_EV3_SMUX_PORT_UART,
MS_EV3_SMUX_PORT_ANALOG, MS_EV3_SMUX_ANALOG = MS_EV3_SMUX_PORT_ANALOG,
MS_NXTMMX_OUT_PORT_TACHO_MOTOR, MS_NXTMMX_TACHO_MOTOR = MS_NXTMMX_OUT_PORT_TACHO_MOTOR,
WEDO_PORT_AUTO, WEDO_AUTO = WEDO_PORT_AUTO,
PORT_MODE__COUNT_, /**< Count of EV3 port "mode" attribute. */
PORT_MODE__UNKNOWN_ = PORT_MODE__COUNT_
};
/**
* \brief Read "address" attribute of the EV3 port.
* \param sn Sequence number.
* \param[out] buf Buffer for result.
* \param sz Buffer size.
* \return Count of read bytes.
*/
extern size_t get_port_address( uint8_t sn, char *buf, size_t sz );
/**
* \brief Read "driver_name" attribute of the EV3 port.
* \param sn Sequence number.
* \param[out] buf Buffer for result.
* \param sz Buffer size.
* \return Count of read bytes.
*/
extern size_t get_port_driver_name( uint8_t sn, char *buf, size_t sz );
/**
* \brief Read "mode" attribute of the EV3 port.
* \param sn Sequence number.
* \param[out] buf Buffer for result.
* \param sz Buffer size.
* \return Count of read bytes.
*/
extern size_t get_port_mode( uint8_t sn, char *buf, size_t sz );
/**
* \brief Write "mode" attribute of the EV3 port.
* \param sn Sequence number.
* \param value Attribute value.
* \return Count of written bytes.
*/
extern size_t set_port_mode( uint8_t sn, char *value );
/**
* \brief Write "mode" attribute of several EV3 ports.
* \param sn Vector of sequence numbers ending with DESC_LIMIT.
* \param value Attribute value.
* \return Count of written bytes.
*/
extern size_t multi_set_port_mode( uint8_t *sn, char *value );
/**
* \brief Read "modes" attribute of the EV3 port.
* \param sn Sequence number.
* \param[out] buf Buffer for result.
* \param sz Buffer size.
* \return Count of read bytes.
*/
extern size_t get_port_modes( uint8_t sn, char *buf, size_t sz );
/**
* \brief Write "set_device" attribute of the EV3 port.
* \param sn Sequence number.
* \param value Attribute value.
* \return Count of written bytes.
*/
extern size_t set_port_set_device( uint8_t sn, char *value );
/**
* \brief Write "set_device" attribute of several EV3 ports.
* \param sn Vector of sequence numbers ending with DESC_LIMIT.
* \param value Attribute value.
* \return Count of written bytes.
*/
extern size_t multi_set_port_set_device( uint8_t *sn, char *value );
/**
* \brief Read "status" attribute of the EV3 port.
* \param sn Sequence number.
* \param[out] buf Buffer for result.
* \param sz Buffer size.
* \return Count of read bytes.
*/
extern size_t get_port_status( uint8_t sn, char *buf, size_t sz );
/**
* \brief Get name of the specified EV3 port type.
* \param type_inx Index of the EV3 port type.
* \return Requested value.
*/
extern const char *ev3_port_type( INX_T type_inx );
/**
* \brief Read "driver_name" attribute and get index of the EV3 port type.
* \param sn Sequence number.
* \return Requested value.
*/
extern INX_T get_port_type_inx( uint8_t sn );
/**
* \brief Read EV3 port attributes that are required for filling the descriptor.
* \param sn Sequence number.
* \param desc Buffer for the descriptor.
* \return Count of read bytes.
*/
extern size_t get_port_desc( uint8_t sn, EV3_PORT *desc );
/**
* \brief Get descriptor of the EV3 port.
* \param sn Sequence number.
* \return Pointer to the EV3 port descriptor.
*/
extern EV3_PORT *ev3_port_desc( uint8_t sn );
/**
* \brief Get type from the EV3 port descriptor.
* \param sn Sequence number.
* \return Requested value.
*/
extern INX_T ev3_port_desc_type_inx( uint8_t sn );
/**
* \brief Get EV3 port from the EV3 port descriptor.
* \param sn Sequence number.
* \return Requested value.
*/
extern uint8_t ev3_port_desc_port( uint8_t sn );
/**
* \brief Get extended port from the EV3 port descriptor.
* \param sn Sequence number.
* \return Requested value.
*/
extern uint8_t ev3_port_desc_extport( uint8_t sn );
/**
* \brief Get I2C address from the EV3 port descriptor.
* \param sn Sequence number.
* \return Requested value.
*/
extern uint8_t ev3_port_desc_addr( uint8_t sn );
/**
* \brief Assemble EV3 port name from the EV3 port descriptor.
* \param sn Sequence number.
* \param[out] buf Buffer for result.
* \return Requested value.
*/
extern char *ev3_port_port_name( uint8_t sn, char *buf );
/**
* \brief Search of a sequence number of the specified EV3 port type.
* \param type_inx EV3 port type.
* \param[out] sn Buffer for the sequence number.
* \param from Search initial value.
* \return Flag - the EV3 port is found.
*/
extern bool ev3_search_port_type( INX_T type_inx, uint8_t *sn, uint8_t from );
/**
* \brief Search of a sequence number the EV3 port by plug-in attributes.
* \param port EV3 port.
* \param extport Extended port.
* \param[out] sn Buffer for the sequence number.
* \param from Search initial value.
* \return Flag - the EV3 port is found.
*/
extern bool ev3_search_port_plugged_in( uint8_t port, uint8_t extport, uint8_t *sn, uint8_t from );
/**
* \brief Get name of the specified EV3 port mode.
* \param mode_inx Index of the EV3 port mode.
* \return Requested value.
*/
extern const char *ev3_port_mode( INX_T mode_inx );
/**
* \brief Read "mode" attribute of the specified EV3 port type and get the index.
* \param sn Sequence number.
* \param type_inx Index of the EV3 port type.
* \return Requested value.
*/
extern INX_T get_port_mode_inx_of_type( uint8_t sn, INX_T type_inx );
/**
* \brief Read "mode" attribute of the EV3 port and get the index.
* \param sn Sequence number.
* \return Requested value.
*
* This function gets type of the EV3 port from the descriptor.
*/
extern INX_T get_port_mode_inx( uint8_t sn );
/**
* \brief Write "mode" attribute of the EV3 port by the index.
* \param sn Sequence number.
* \param mode_inx Index of the EV3 port mode.
* \return Count of written bytes.
*/
extern size_t set_port_mode_inx( uint8_t sn, INX_T mode_inx );
/**
* \brief Write "mode" attribute of several EV3 ports by the index.
* \param sn Vector of sequence numbers ending with DESC_LIMIT.
* \param mode_inx Index of the EV3 port mode.
* \return Count of written bytes.
*/
extern size_t multi_set_port_mode_inx( uint8_t *sn, INX_T mode_inx );
/**
* \brief Detect connected EV3 ports.
* \return Number of found EV3 ports or -1 in case of an error.
*/
extern int ev3_port_init( void );
/**
* \brief Identifiers of EV3 ports and extended ports.
*/
#define EV3_PORT__NONE_ 0 /* XXX: 0 is used */
#define EXT_PORT__NONE_ EV3_PORT__NONE_
#define INPUT_1 49 // '1'
#define INPUT_2 50 // '2'
#define INPUT_3 51 // '3'
#define INPUT_4 52 // '4'
#define OUTPUT_A 65 // 'A'
#define OUTPUT_B 66 // 'B'
#define OUTPUT_C 67 // 'C'
#define OUTPUT_D 68 // 'D'
#define MUX_1 49 // '1'
#define MUX_2 50 // '2'
#define MUX_3 51 // '3'
#define MUX_4 52 // '4'
#define SERVO__OFFSET_ 16
#define SERVO_1 65 // 'A'
#define SERVO_2 66 // 'B'
#define SERVO_3 67 // 'C'
#define SERVO_4 68 // 'D'
#define SERVO_5 69 // 'E'
#define SERVO_6 70 // 'F'
#define SERVO_7 71 // 'G'
#define SERVO_8 72 // 'H'
#define NXTMMX__OFFSET_ 28
#define NXTMMX_1 77 // 'M'
#define NXTMMX_2 78 // 'N'
#define WEDO__OFFSET_ 48
#define WEDO_1 97 // 'a'
#define WEDO_2 98 // 'b'
#define WEDO_3 99 // 'c'
#define WEDO_4 100 // 'd'
/**
* \brief Search of a port sequence number by the EV3 port and the extended port.
* \param port EV3 port index.
* \param extport Extended port index.
* \return Port sequence number.
*/
extern uint8_t ev3_search_port( uint8_t port, uint8_t extport );
/**
* \brief Parse name of the EV3 port.
* \param name Port name.
* \param port Buffer for the EV3 port index.
* \param extport Buffer for the extended port index.
* \param addr Buffer for the address.
*/
extern void ev3_parse_port_name( char *name, uint8_t *port, uint8_t *extport, uint8_t *addr );
/**
* \brief Assemble name of the EV3 port.
* \param port EV3 port index.
* \param extport Extended port index.
* \param addr Address.
* \param[out] buf Buffer for result.
* \return Requested value.
*/
extern char *ev3_port_name( uint8_t port, uint8_t extport, uint8_t addr, char *buf );
#define SENSOR_DIR "/sys/class/lego-sensor" /**< Directory of sensors. */
/**
* \brief Structure of a sensor descriptor.
*/
typedef struct {
INX_T type_inx; /**< Sensor type. */
uint8_t port; /**< Sensor EV3 port. */
uint8_t extport; /**< Sensor extended port. */
uint8_t addr; /**< Sensor I2C address. */
} EV3_SENSOR;
#define SENSOR_DESC__LIMIT_ DESC_LIMIT /**< Limit of sensor descriptors. */
#define SENSOR__NONE_ SENSOR_DESC__LIMIT_ /**< Sensor is not found. */
/**
* \brief Vector of sensor descriptors (filled by \ref ev3_sensor_init).
*/
extern EV3_SENSOR ev3_sensor[ SENSOR_DESC__LIMIT_ ];
/**
* \brief Identifiers of sensor types.
*/
enum {
SENSOR_TYPE__NONE_ = 0, /* XXX: memset( 0 ) is used */
EV3_ANALOG_XX,
NXT_ANALOG,
PIXY_LEGO,
DI_DFLEX,
FCL_9DOF,
FCL_ADC,
FCL_ALTITUDE,
FCL_GESTURE,
FCL_HUMIDITY,
FCL_IR,
FCL_LIGHT,
HT_NXT_COLOR,
HT_NXT_ANGLE,
HT_NXT_ACCEL,
HT_NXT_BAROMETRIC,
HT_NXT_COLOR_V2,
HT_NXT_EOPD,
HT_NXT_FORCE,
HT_NXT_GYRO,
HT_NXT_IR_LINK,
HT_NXT_IR_RECEIVER,
HT_NXT_PIR,
HT_NXT_COMPASS,
HT_NXT_MAG,
HT_NXT_IR_SEEK_V2,
HT_NXT_SMUX,
HT_SUPER_PRO,
LEGO_EV3_US,
LEGO_EV3_GYRO,
LEGO_EV3_COLOR,
LEGO_EV3_TOUCH,
LEGO_EV3_IR,
WEDO_HUB,
WEDO_MOTION,
WEDO_TILT,
LEGO_POWER_STORAGE,
LEGO_NXT_TEMP,
LEGO_NXT_TOUCH,
LEGO_NXT_LIGHT,
LEGO_NXT_SOUND,
LEGO_NXT_US,
MI_XG1300L,
MS_ABSOLUTE_IMU,
MS_ANGLE,
MS_EV3_SMUX,
MS_LIGHT_ARRAY,
MS_LINE_LEADER,
MS_NXTCAM,
MS_NXTMMX,
MS_8CH_SERVO,
MS_PPS58_NX,
MS_PIXY_ADAPTER,
MS_NXT_TOUCH_MUX,
SENSOR_TYPE__COUNT_, /**< Count of sensor types. */
SENSOR_TYPE__UNKNOWN_ = SENSOR_TYPE__COUNT_
};
/**
* \brief Identifiers of sensor "mode" attribute.
*/
enum {
SENSOR_MODE__NONE_ = 0,
EV3_ANALOG_XX_ANALOG,
NXT_ANALOG_ANALOG_0,
NXT_ANALOG_ANALOG_1,
PIXY_LEGO_ALL,
PIXY_LEGO_SIG1,
PIXY_LEGO_SIG2,
PIXY_LEGO_SIG3,
PIXY_LEGO_SIG4,
PIXY_LEGO_SIG5,
PIXY_LEGO_SIG6,
PIXY_LEGO_SIG7,
DI_DFLEX_FLEX,
FCL_9DOF_GYRO,
FCL_9DOF_ACC,
FCL_9DOF_MAGNET,
FCL_ADC_CH1_VOLTAGE,
FCL_ADC_CH2_VOLTAGE,
FCL_ADC_VOLTAGE,
FCL_ALTITUDE_PRESSURE,
FCL_ALTITUDE_ALTITUDE,
FCL_GESTURE_GESTURE,
FCL_GESTURE_PROXIMITY,
FCL_GESTURE_RGB_RAW,
FCL_GESTURE_CLEAR,
FCL_HUMIDITY_CENTIGRADE,
FCL_HUMIDITY_FAHRENHEIT,
FCL_HUMIDITY_HUMIDITY,
FCL_IR_IR_DATA,
FCL_LIGHT_ILLUMINANCE,
HT_NXT_COLOR_COLOR,
HT_NXT_COLOR_RED,
HT_NXT_COLOR_GREEN,
HT_NXT_COLOR_BLUE,
HT_NXT_COLOR_RAW,
HT_NXT_COLOR_NORM,
HT_NXT_COLOR_ALL,
HT_NXT_ANGLE_ANGLE,
HT_NXT_ANGLE_ANGLE_ACC,
HT_NXT_ANGLE_SPEED,
HT_NXT_ACCEL_ACCEL,
HT_NXT_ACCEL_ALL,
HT_NXT_BAROMETRIC_PRESS,
HT_NXT_BAROMETRIC_TEMP,
HT_NXT_COLOR_V2_COLOR,
HT_NXT_COLOR_V2_RED,
HT_NXT_COLOR_V2_GREEN,
HT_NXT_COLOR_V2_BLUE,
HT_NXT_COLOR_V2_WHITE,
HT_NXT_COLOR_V2_NORM,
HT_NXT_COLOR_V2_ALL,
HT_NXT_COLOR_V2_RAW,
HT_NXT_EOPD_LONG,
HT_NXT_EOPD_SHORT,
HT_NXT_FORCE_FORCE,
HT_NXT_GYRO_GYRO,
HT_NXT_IR_LINK_IRLINK,
HT_NXT_IR_RECEIVER_1_MOTOR,
HT_NXT_IR_RECEIVER_8_MOTOR,
HT_NXT_PIR_PROX,
HT_NXT_COMPASS_COMPASS,
HT_NXT_MAG_MAG,
HT_NXT_IR_SEEK_V2_DC,
HT_NXT_IR_SEEK_V2_AC,
HT_NXT_IR_SEEK_V2_DC_ALL,
HT_NXT_IR_SEEK_V2_AC_ALL,
HT_NXT_SMUX_MUX,
HT_SUPER_PRO_AIN,
HT_SUPER_PRO_DIN,
HT_SUPER_PRO_DOUT,
HT_SUPER_PRO_DCTRL,
HT_SUPER_PRO_STROBE,
HT_SUPER_PRO_LED,
HT_SUPER_PRO_AOUT_0,
HT_SUPER_PRO_AOUT_1,
LEGO_EV3_US_US_DIST_CM, US_US_DIST_CM = LEGO_EV3_US_US_DIST_CM,
LEGO_EV3_US_US_DIST_IN, US_US_DIST_IN = LEGO_EV3_US_US_DIST_IN,
LEGO_EV3_US_US_LISTEN, US_US_LISTEN = LEGO_EV3_US_US_LISTEN,
LEGO_EV3_US_US_SI_CM, US_US_SI_CM = LEGO_EV3_US_US_SI_CM,
LEGO_EV3_US_US_SI_IN, US_US_SI_IN = LEGO_EV3_US_US_SI_IN,
LEGO_EV3_US_US_DC_CM, US_US_DC_CM = LEGO_EV3_US_US_DC_CM,
LEGO_EV3_US_US_DC_IN, US_US_DC_IN = LEGO_EV3_US_US_DC_IN,
LEGO_EV3_GYRO_GYRO_ANG, GYRO_GYRO_ANG = LEGO_EV3_GYRO_GYRO_ANG,
LEGO_EV3_GYRO_GYRO_RATE, GYRO_GYRO_RATE = LEGO_EV3_GYRO_GYRO_RATE,
LEGO_EV3_GYRO_GYRO_FAS, GYRO_GYRO_FAS = LEGO_EV3_GYRO_GYRO_FAS,
LEGO_EV3_GYRO_GYRO_G_AND_A, GYRO_GYRO_G_AND_A = LEGO_EV3_GYRO_GYRO_G_AND_A,
LEGO_EV3_GYRO_GYRO_CAL, GYRO_GYRO_CAL = LEGO_EV3_GYRO_GYRO_CAL,
LEGO_EV3_COLOR_COL_REFLECT, COLOR_COL_REFLECT = LEGO_EV3_COLOR_COL_REFLECT,
LEGO_EV3_COLOR_COL_AMBIENT, COLOR_COL_AMBIENT = LEGO_EV3_COLOR_COL_AMBIENT,
LEGO_EV3_COLOR_COL_COLOR, COLOR_COL_COLOR = LEGO_EV3_COLOR_COL_COLOR,
LEGO_EV3_COLOR_REF_RAW, COLOR_REF_RAW = LEGO_EV3_COLOR_REF_RAW,
LEGO_EV3_COLOR_RGB_RAW, COLOR_RGB_RAW = LEGO_EV3_COLOR_RGB_RAW,
LEGO_EV3_COLOR_COL_CAL, COLOR_COL_CAL = LEGO_EV3_COLOR_COL_CAL,
LEGO_EV3_TOUCH_TOUCH, TOUCH_TOUCH = LEGO_EV3_TOUCH_TOUCH,
LEGO_EV3_IR_IR_PROX, IR_IR_PROX = LEGO_EV3_IR_IR_PROX,
LEGO_EV3_IR_IR_SEEK, IR_IR_SEEK = LEGO_EV3_IR_IR_SEEK,
LEGO_EV3_IR_IR_REMOTE, IR_IR_REMOTE = LEGO_EV3_IR_IR_REMOTE,
LEGO_EV3_IR_IR_REM_A, IR_IR_REM_A = LEGO_EV3_IR_IR_REM_A,
LEGO_EV3_IR_IR_S_ALT, IR_IR_S_ALT = LEGO_EV3_IR_IR_S_ALT,
LEGO_EV3_IR_IR_CAL, IR_IR_CAL = LEGO_EV3_IR_IR_CAL,
WEDO_HUB_HUB,
WEDO_MOTION_PROX,
WEDO_MOTION_RAW,
WEDO_TILT_TILT,
WEDO_TILT_TILT_AXIS,
WEDO_TILT_RAW,
LEGO_POWER_STORAGE_IN_VOLT,
LEGO_POWER_STORAGE_IN_AMP,
LEGO_POWER_STORAGE_OUT_VOLT,
LEGO_POWER_STORAGE_OUT_AMP,
LEGO_POWER_STORAGE_JOULE,
LEGO_POWER_STORAGE_IN_WATT,
LEGO_POWER_STORAGE_OUT_WATT,
LEGO_POWER_STORAGE_ALL,
LEGO_NXT_TEMP_NXT_TEMP_C,
LEGO_NXT_TEMP_NXT_TEMP_F,
LEGO_NXT_TOUCH_TOUCH,
LEGO_NXT_LIGHT_REFLECT,
LEGO_NXT_LIGHT_AMBIENT,
LEGO_NXT_SOUND_DB,
LEGO_NXT_SOUND_DBA,
LEGO_NXT_US_US_DIST_CM,
LEGO_NXT_US_US_DIST_IN,
LEGO_NXT_US_US_SI_CM,
LEGO_NXT_US_US_SI_IN,
LEGO_NXT_US_US_LISTEN,
MI_XG1300L_ANGLE,
MI_XG1300L_SPEED,
MI_XG1300L_ACCEL,
MI_XG1300L_ALL,
MS_ABSOLUTE_IMU_TILT,
MS_ABSOLUTE_IMU_ACCEL,
MS_ABSOLUTE_IMU_COMPASS,
MS_ABSOLUTE_IMU_MAG,
MS_ABSOLUTE_IMU_GYRO,
MS_ABSOLUTE_IMU_ALL,
MS_ANGLE_ANGLE,
MS_ANGLE_ANGLE2,
MS_ANGLE_SPEED,
MS_ANGLE_ALL,
MS_EV3_SMUX_MUX,
MS_LIGHT_ARRAY_CAL,
MS_LIGHT_ARRAY_RAW,
MS_LINE_LEADER_PID,
MS_LINE_LEADER_PID_ALL,
MS_LINE_LEADER_CAL,
MS_LINE_LEADER_RAW,
MS_NXTCAM_TRACK,
MS_NXTMMX_STATUS,
MS_NXTMMX_STATUS_OLD,
MS_8CH_SERVO_V3,
MS_8CH_SERVO_OLD,
MS_PPS58_NX_RAW,
MS_PPS58_NX_ABS_PSI,
MS_PPS58_NX_ABS_MBAR,
MS_PPS58_NX_ABS_KPA,
MS_PPS58_NX_REL_PSI,
MS_PPS58_NX_REL_MBAR,
MS_PPS58_NX_REL_KPA,
MS_PIXY_ADAPTER_TRACK,
MS_NXT_TOUCH_MUX_TOUCH_MUX,
SENSOR_MODE__COUNT_, /**< Count of sensor "mode" attribute. */
SENSOR_MODE__UNKNOWN_ = SENSOR_MODE__COUNT_
};
/**
* \brief Identifiers of sensor "command" attribute.
*/
enum {
SENSOR_COMMAND__NONE_ = 0,
HT_NXT_ANGLE_RESET,
HT_NXT_ANGLE_CAL,
HT_NXT_SMUX_HALT,
HT_NXT_SMUX_DETECT,
HT_NXT_SMUX_RUN,
WEDO_HUB_OUT_OFF,
WEDO_HUB_OUT_ON,
WEDO_HUB_CLEAR_ERR,
MI_XG1300L_RESET,
MI_XG1300L_ACCEL_2G,
MI_XG1300L_ACCEL_4G,
MI_XG1300L_ACCEL_8G,
MS_ABSOLUTE_IMU_BEGIN_COMP_CAL,
MS_ABSOLUTE_IMU_END_COMP_CAL,
MS_ABSOLUTE_IMU_ACCEL_2G,
MS_ABSOLUTE_IMU_ACCEL_4G,
MS_ABSOLUTE_IMU_ACCEL_8G,
MS_ABSOLUTE_IMU_ACCEL_16G,
MS_ANGLE_RESET,
MS_LIGHT_ARRAY_CAL_WHITE,
MS_LIGHT_ARRAY_CAL_BLACK,
MS_LIGHT_ARRAY_SLEEP,
MS_LIGHT_ARRAY_WAKE,
MS_LIGHT_ARRAY_60HZ,
MS_LIGHT_ARRAY_50HZ,
MS_LIGHT_ARRAY_UNIVERSAL,
MS_LINE_LEADER_CAL_WHITE,
MS_LINE_LEADER_CAL_BLACK,
MS_LINE_LEADER_SLEEP,
MS_LINE_LEADER_WAKE,
MS_LINE_LEADER_INV_COL,
MS_LINE_LEADER_RST_COL,
MS_LINE_LEADER_SNAP,