forked from tomasfrajt/PyEpoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyEpoc.py
More file actions
1579 lines (1447 loc) · 69.7 KB
/
PyEpoc.py
File metadata and controls
1579 lines (1447 loc) · 69.7 KB
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
# -*- coding: utf-8 -*-
"""This module communicates with Emotiv's DLL"""
## @package PyEpoc
# This is a Python wrapper for Emotiv's dynamic link libraries.
## @mainpage PyEpoc
# @summary This module enables Python to communicate with the Emotiv Epoc head-set and Emotiv's EmoComposer, using Emotiv's dynamic link libraries. Although some functions return data in a way that differs from the Emotiv SDK, PyEpoc functions should be familiar to those using the Emotiv SDK.\n\n
# \b Classes:\n
# \li EpocHandler
#
# \b Structs:\n
# \li InputSensorDescriptor
#
# \b Dictionaries:\n
# \li #ERRCODE
# \li #EVENT
# \li #SUITE
# \li #SIGNALSTRENGTH
# \li #AFFECTIVALGO
# \li #EXPEVENT
# \li #EXPRESSIVALGO
# \li #EXPRTHRESHOLD
# \li #EXPRTRAININGCONTROL
# \li #EXPRSIGNATURE
# \li #COGACTION
# \li #COGTRAININGCONTROL
# \li #COGEVENT
# \li #INPUTCHANNELS
# \li #CONTACTQUALITY
#
#
# @version \b PyEpoc 1.2
# @copyright Copyright 2009 Morten André Steinsland. \n\n
# @author Morten André Steinsland \n
# @contact morten.a.steinsland@gmail.com \n
# @contact http://www.mortenblog.net \n
#
# @note \li This module requires <a href="http://www.emotiv.com">Emotiv</a>'s SDK - Copyright 2009 , Emotiv Systems, Inc.
# \li This module requires <a href="http://www.python.org/download/releases/2.6.4/">Python 2.6.4</a> (or later) - Copyright 1990-2009 , Python Software Foundation.\n
import ctypes
#import time
#import decimal
## Emotiv Engine's Return Codes.
#
# This dictionary contains the EmoEngine return codes.
#
# EDK_OK : \b 0x0000 \n
# EDK_UNKNOWN_ERROR : \b 0x0001 \n
# EDK_INVALID_PROFILE_ARCHIVE : \b 0x0101 \n
# EDK_NO_USER_FOR_BASEPROFILE : \b 0x0102 \n
# EDK_CANNOT_ACQUIRE_DATA : \b 0x0200 \n
# EDK_BUFFER_TOO_SMALL : \b 0x0300 \n
# EDK_OUT_OF_RANGE : \b 0x0301 \n
# EDK_INVALID_PARAMETER : \b 0x0302 \n
# EDK_PARAMETER_LOCKED : \b 0x0303 \n
# EDK_COG_INVALID_TRAINING_ACTION : \b 0x0304 \n
# EDK_COG_INVALID_TRAINING_CONTROL : \b 0x0305 \n
# EDK_COG_INVALID_ACTIVE_ACTION : \b 0x0306 \n
# EDK_COG_EXCESS_MAX_ACTIONS : \b 0x0307 \n
# EDK_EXP_NO_SIG_AVAILABLE : \b 0x0308 \n
# EDK_FILESYSTEM_ERROR : \b 0x0309 \n
# EDK_INVALID_USER_ID : \b 0x0400 \n
# EDK_EMOENGINE_UNINITIALIZED : \b 0x0500 \n
# EDK_EMOENGINE_DISCONNECTED : \b 0x0501 \n
# EDK_EMOENGINE_PROXY_ERROR : \b 0x0502 \n
# EDK_NO_EVENT : \b 0x0600 \n
# EDK_GYRO_NOT_CALIBRATED : \b 0x0700 \n
# EDK_OPTIMIZATION_IS_ON : \b 0x0800 \n
# EDK_RESERVED1 : \b 0x0900 \n
# @see edkErrorCode.h
ERRCODE = {'EDK_OK' : 0x0000,
'EDK_UNKNOWN_ERROR' : 0x0001,
'EDK_INVALID_PROFILE_ARCHIVE' : 0x0101,
'EDK_NO_USER_FOR_BASEPROFILE' : 0x0102,
'EDK_CANNOT_ACQUIRE_DATA' : 0x0200,
'EDK_BUFFER_TOO_SMALL' : 0x0300,
'EDK_OUT_OF_RANGE' : 0x0301,
'EDK_INVALID_PARAMETER' : 0x0302,
'EDK_PARAMETER_LOCKED' : 0x0303,
'EDK_COG_INVALID_TRAINING_ACTION' : 0x0304,
'EDK_COG_INVALID_TRAINING_CONTROL' : 0x0305,
'EDK_COG_INVALID_ACTIVE_ACTION' : 0x0306,
'EDK_COG_EXCESS_MAX_ACTIONS' : 0x0307,
'EDK_EXP_NO_SIG_AVAILABLE' : 0x0308,
'EDK_FILESYSTEM_ERROR' : 0x0309,
'EDK_INVALID_USER_ID' : 0x0400,
'EDK_EMOENGINE_UNINITIALIZED' : 0x0500,
'EDK_EMOENGINE_DISCONNECTED' : 0x0501,
'EDK_EMOENGINE_PROXY_ERROR' : 0x0502,
'EDK_NO_EVENT' : 0x0600,
'EDK_GYRO_NOT_CALIBRATED' : 0x0700,
'EDK_OPTIMIZATION_IS_ON' : 0x0800,
'EDK_RESERVED1' : 0x0900}
## Emotiv Events.
#
# This dictionary contains EmoEngine event types.
#
# EE_UnknownEvent : \b 0x0000 \n
# EE_EmulatorError : \b 0x0001 \n
# EE_ReservedEvent : \b 0x0002 \n
# EE_UserAdded : \b 0x0010 \n
# EE_UserRemoved : \b 0x0020 \n
# EE_EmoStateUpdated : \b 0x0040 \n
# EE_ProfileEvent : \b 0x0080 \n
# EE_CognitivEvent : \b 0x0100 \n
# EE_ExpressivEvent : \b 0x0200 \n
# EE_InternalStateChanged : \b 0x0400 \n
# @see EE_Event_enum (edk.h)
EVENT = {'EE_UnknownEvent' : 0x0000,
'EE_EmulatorError' : 0x0001,
'EE_ReservedEvent' : 0x0002,
'EE_UserAdded' : 0x0010,
'EE_UserRemoved' : 0x0020,
'EE_EmoStateUpdated' : 0x0040,
'EE_ProfileEvent' : 0x0080,
'EE_CognitivEvent' : 0x0100,
'EE_ExpressivEvent' : 0x0200,
'EE_InternalStateChanged' : 0x0400}
## Emotiv Detection Suites.
#
# This dictionary contains the detection suite types.
#
# EE_EXPRESSIV : \b 0 \n
# EE_AFFECTIV : \b 1 \n
# EE_COGNITIV : \b 2 \n
# @see EE_EmotivSuite_enum (EmoStateDLL.h)
SUITE = {'EE_EXPRESSIV' :0,
'EE_AFFECTIV' :1,
'EE_COGNITIV' :2}
## Wireless Signal Strength.
#
# This dictionary contains the wireless signal strength levels.
#
# NO_SIGNAL : \b 0 \n
# BAD_SIGNAL : \b 1 \n
# GOOD_SIGNAL : \b 2 \n
# @see EE_SignalStrength_enum (EmoStateDLL.h)
SIGNALSTRENGTH = {'NO_SIGNAL' : 0,
'BAD_SIGNAL' : 1,
'GOOD_SIGNAL' : 2}
## Affectiv Algorithms.
#
# This dictionary contains the affectiv emotional types.
#
# AFF_EXCITEMENT : \b 0x0001 \n
# AFF_MEDITATION : \b 0x0002 \n
# AFF_FRUSTRATION : \b 0x0004 \n
# AFF_ENGAGEMENT_BOREDOM : \b 0x0008 \n
# @see EE_AffectivAlgo_enum (EmoStateDLL.h)
AFFECTIVALGO = {'AFF_EXCITEMENT' : 0x0001,
'AFF_MEDITATION' : 0x0002,
'AFF_FRUSTRATION' : 0x0004,
'AFF_ENGAGEMENT_BOREDOM': 0x0008}
## Expressiv Events.
#
# Expressiv specific event types.
#
# EE_ExpressivNoEvent : \b 0 \n
# EE_ExpressivTrainingStarted : \b 1 \n
# EE_ExpressivTrainingSucceeded : \b 2 \n
# EE_ExpressivTrainingFailed : \b 3 \n
# EE_ExpressivTrainingCompleted : \b 4 \n
# EE_ExpressivTrainingDataErased : \b 5 \n
# EE_ExpressivTrainingRejected : \b 6 \n
# EE_ExpressivTrainingReset : \b 7 \n
# @see EE_ExpressivEvent_enum (edk.h)
EXPEVENT = {'EE_ExpressivNoEvent': 0,
'EE_ExpressivTrainingStarted': 1,
'EE_ExpressivTrainingSucceeded' : 2,
'EE_ExpressivTrainingFailed':3,
'EE_ExpressivTrainingCompleted':4,
'EE_ExpressivTrainingDataErased':5,
'EE_ExpressivTrainingRejected': 6,
'EE_ExpressivTrainingReset': 7}
## Expressiv Facial Expression.
#
# This dictionary contains the expressiv facial expression types.
#
# EXP_NEUTRAL : \b 0x0001 \n
# EXP_BLINK : \b 0x0002 \n
# EXP_WINK_LEFT : \b 0x0004 \n
# EXP_WINK_RIGHT : \b 0x0008 \n
# EXP_HORIEYE : \b 0x0010 \n
# EXP_EYEBROW : \b 0x0020 \n
# EXP_FURROW : \b 0x0040 \n
# EXP_SMILE : \b 0x0080 \n
# EXP_CLENCH : \b 0x0100 \n
# EXP_LAUGH : \b 0x0200 \n
# EXP_SMIRK_LEFT : \b 0x0400 \n
# EXP_SMIRK_RIGHT : \b 0x0800 \n
# @see EE_ExpressivAlgo_enum (EmoStateDLL.h)
EXPRESSIVALGO = {'EXP_NEUTRAL' : 0x0001,
'EXP_BLINK' : 0x0002,
'EXP_WINK_LEFT' : 0x0004,
'EXP_WINK_RIGHT' : 0x0008,
'EXP_HORIEYE' : 0x0010,
'EXP_EYEBROW' : 0x0020,
'EXP_FURROW' : 0x0040,
'EXP_SMILE' : 0x0080,
'EXP_CLENCH' : 0x0100,
'EXP_LAUGH' : 0x0200,
'EXP_SMIRK_LEFT' : 0x0400,
'EXP_SMIRK_RIGHT' : 0x0800}
## Expressiv Threshold.
#
# Expressiv Suite sensitivity threshold.
#
# EXP_SENSITIVITY : \b 0 \n
# @see EE_ExpressivThreshold_enum (edk.h)
EXPRTHRESHOLD = {'EXP_SENSITIVITY': 0}
## Expressiv Training Control.
#
# Expressiv Suite training controls.
#
# EXP_NONE : \b 0 \n
# EXP_START : \b 1 \n
# EXP_ACCEPT : \b 2 \n
# EXP_REJECT : \b 3 \n
# EXP_ERASE : \b 4 \n
# EXP_RESET : \b 5 \n
# @see EE_ExpressivTrainingControl_enum (edk.h)
EXPRTRAININGCONTROL = {'EXP_NONE' : 0,
'EXP_START' : 1,
'EXP_ACCEPT': 2,
'EXP_REJECT': 3,
'EXP_ERASE' : 4,
'EXP_RESET' : 5}
## Expressiv Signature.
#
# Expressiv Suite signature types.
#
# EXP_SIG_UNIVERSAL : \b 0 \n
# EXP_SIG_TRAINED : \b 1 \n
# @see EE_ExpressivSignature_enum (edk.h)
EXPRSIGNATURE = {'EXP_SIG_UNIVERSAL': 0,
'EXP_SIG_TRAINED' : 1}
## Cognitiv Actions.
#
# Cognitiv action types.
#
# COG_NEUTRAL : \b 0x0001 \n
# COG_PUSH : \b 0x0002 \n
# COG_PULL : \b 0x0004 \n
# COG_LIFT : \b 0x0008 \n
# COG_DROP : \b 0x0010 \n
# COG_LEFT : \b 0x0020 \n
# COG_RIGHT : \b 0x0040 \n
# COG_ROTATE_LEFT : \b 0x0080 \n
# COG_ROTATE_RIGHT : \b 0x0100 \n
# COG_ROTATE_CLOCKWISE : \b 0x0200 \n
# COG_ROTATE_COUNTER_CLOCKWISE : \b 0x0400 \n
# COG_ROTATE_FORWARDS : \b 0x0800 \n
# COG_ROTATE_REVERSE : \b 0x1000 \n
# COG_DISAPPEAR : \b 0x2000 \n
# @see EE_CognitivAction_enum (EmoStateDLL.h)
COGACTION = {'COG_NEUTRAL' : 0x0001,
'COG_PUSH' : 0x0002,
'COG_PULL' : 0x0004,
'COG_LIFT' : 0x0008,
'COG_DROP' : 0x0010,
'COG_LEFT' : 0x0020,
'COG_RIGHT' : 0x0040,
'COG_ROTATE_LEFT' : 0x0080,
'COG_ROTATE_RIGHT' : 0x0100,
'COG_ROTATE_CLOCKWISE' : 0x0200,
'COG_ROTATE_COUNTER_CLOCKWISE': 0x0400,
'COG_ROTATE_FORWARDS' : 0x0800,
'COG_ROTATE_REVERSE' : 0x1000,
'COG_DISAPPEAR' : 0x2000}
## Cognitiv Training Control.
#
# Cognitiv Suite training controls.
#
# COG_NONE : \b 0 \n
# COG_START : \b 1 \n
# COG_ACCEPT : \b 2 \n
# COG_REJECT : \b 3 \n
# COG_ERASE : \b 4 \n
# COG_RESET : \b 5 \n
## @see EE_CognitivTrainingControl_enum (edk.h)
COGTRAININGCONTROL = {'COG_NONE' : 0,
'COG_START' : 1,
'COG_ACCEPT' : 2,
'COG_REJECT' : 3,
'COG_ERASE' : 4,
'COG_RESET' : 5}
## Cognitiv Events.
#
# Cognitiv-specific event types.
#
# EE_CognitivNoEvent : \b 0 \n
# EE_CognitivTrainingStarted : \b 1 \n
# EE_CognitivTrainingSucceeded : \b 2 \n
# EE_CognitivTrainingFailed : \b 3 \n
# EE_CognitivTrainingCompleted : \b 4 \n
# EE_CognitivTrainingDataErased : \b 5 \n
# EE_CognitivTrainingRejected : \b 6 \n
# EE_CognitivTrainingReset : \b 7 \n
# EE_CognitivAutoSamplingNeutralCompleted : \b 8 \n
# EE_CognitivSignatureUpdated : \b 9 \n
# @see EE_CognitivEvent_enum (edk.h)
COGEVENT = {'EE_CognitivNoEvent' : 0,
'EE_CognitivTrainingStarted' : 1,
'EE_CognitivTrainingSucceeded' : 2,
'EE_CognitivTrainingFailed' : 3,
'EE_CognitivTrainingCompleted' : 4,
'EE_CognitivTrainingDataErased' : 5,
'EE_CognitivTrainingRejected' : 6,
'EE_CognitivTrainingReset' : 7,
'EE_CognitivAutoSamplingNeutralCompleted' : 8,
'EE_CognitivSignatureUpdated' : 9}
## Input Channels.
#
# Headset Input Channels.
#
# EE_CHAN_CMS : \b 0 \n
# EE_CHAN_DRL : \b 1 \n
# EE_CHAN_FP1 : \b 2 \n
# EE_CHAN_AF3 : \b 3 \n
# EE_CHAN_F7 : \b 4 \n
# EE_CHAN_F3 : \b 5 \n
# EE_CHAN_FC5 : \b 6 \n
# EE_CHAN_T7 : \b 7 \n
# EE_CHAN_P7 : \b 8 \n
# EE_CHAN_O1 : \b 9 \n
# EE_CHAN_O2 : \b 10 \n
# EE_CHAN_P8 : \b 11 \n
# EE_CHAN_T8 : \b 12 \n
# EE_CHAN_FC6 : \b 13 \n
# EE_CHAN_F4 : \b 14 \n
# EE_CHAN_F8 : \b 15 \n
# EE_CHAN_AF4 : \b 16 \n
# EE_CHAN_FP2 : \b 17 \n
# @see EE_InputChannels_enum (EmoStateDLL.h)
INPUTCHANNELS = {'EE_CHAN_CMS' : 0,
'EE_CHAN_DRL' : 1,
'EE_CHAN_FP1' : 2,
'EE_CHAN_AF3' : 3,
'EE_CHAN_F7' : 4,
'EE_CHAN_F3' : 5,
'EE_CHAN_FC5' : 6,
'EE_CHAN_T7' : 7,
'EE_CHAN_P7' : 8,
'EE_CHAN_O1' : 9,
'EE_CHAN_O2' : 10,
'EE_CHAN_P8' : 11,
'EE_CHAN_T8' : 12,
'EE_CHAN_FC6' : 13,
'EE_CHAN_F4' : 14,
'EE_CHAN_F8' : 15,
'EE_CHAN_AF4' : 16,
'EE_CHAN_FP2' : 17}
## EEG Sensor Contact Quality.
#
# EEG Electrode Contact Quality enumeration. Used to characterize the EEG signal reception
# or electrode contact for a sensor on the headset.
#
# EEG_CQ_NO_SIGNAL : \b 0 \n
# EEG_CQ_VERY_BAD : \b 1 \n
# EEG_CQ_POOR : \b 3 \n
# EEG_CQ_FAIR : \b 4 \n
# EEG_CQ_GOOD : \b 5 \n
# @note This differs from the wireless signal strength (#SIGNALSTRENGTH), which refers to the radio
# communication between the headset transmitter and USB dongle receiver.
# @see EE_EEG_ContactQuality_enum (EmoStateDLL.h)
CONTACTQUALITY = {'EEG_CQ_NO_SIGNAL' : 0,
'EEG_CQ_VERY_BAD' : 1,
'EEG_CQ_POOR' : 3,
'EEG_CQ_FAIR' : 4,
'EEG_CQ_GOOD' : 5}
## @struct InputSensorDescriptor
# \brief Input sensor description struct.
#
# A struct to hold input sensor descriptions
# @sa #INPUTCHANNELS
class InputSensorDescriptor(ctypes.Structure):
""".ChannelId - logical channel id
.Exist - does this sensor exist
.Label - sensor label
.xLoc - x coordinate from center of head towards nose
.yLoc - y coordinate from center of head towards ears
.zLoc - z coordinate from center of head toward top of skull"""
_fields_ = [("ChannelId", ctypes.c_int), ## logical channel id
("Exist", ctypes.c_int), ## does this sensor exist on this headset model
("Label", ctypes.c_char_p), ## text label identifying this sensor
("xLoc", ctypes.c_double), ## x coordinate from center of head towards nose
("yLoc", ctypes.c_double), ## y coordinate from center of head towards ears
("zLoc", ctypes.c_double)] ## z coordinate from center of head toward top of skull
## @class EpocHandler
# \brief The wrapper class.
#
# This class creates a link to Emotiv's DLL and it's functions.
class EpocHandler:
## \internal
def __init__(self):
self.EmotivEngineDLL = ctypes.cdll.edk # link the edk.dll
## Initializes a connection to EmoEngine.
#
# This function should be called at the beginning of programs.
# @return #ERRCODE
# @sa EpocHandler::EE_EngineRemoteConnect()
# @see edkErrorCode.h
def EE_EngineConnect(self):
return self.EmotivEngineDLL.EE_EngineConnect()
## Initializes a connection to EmoComposer.
#
# This function should be called at the beginning of programs.
# @param ip str, IP address of the host
# @param port int, the port of the host
# @return #ERRCODE
# @sa EpocHandler::EE_EngineConnect()
# @see edkErrorCode.h
# @note For Emotiv Control Panel use port 3008. For EmoComposer use port 1726.
def EE_EngineRemoteConnect(self, ip, port):
return self.EmotivEngineDLL.EE_EngineRemoteConnect(ip, port)
## Ends the connection to EmoEngine.
#
# Closes the connection to EmoEngine. This function should be called at the end of programs.
# @return #ERRCODE
# @see edkErrorCode.h
def EE_EngineDisconnect(self):
return self.EmotivEngineDLL.EE_EngineDisconnect()
## Enables diagnostics logging.
#
# @param emotivlogfile str, filepath
# @param enabled int, 1 enable / 0 disable
# @warning This should only be enabled if instructed to do so by Emotiv developer support for
# the purposes of collecting diagnostic information.
# @return #ERRCODE
# @see edkErrorCode.h
def EE_EnableDiagnostics(self, emotivlogfile, enabled):
if (enabled != 0):
emotivlogfile = """logs\emotiv.log""" # set the default log file
return self.EmotivEngineDLL.EE_EnableDiagnostics(emotivlogfile, 1)
else:
return self.EmotivEngineDLL.EE_EnableDiagnostics(emotivlogfile, 0)
## Create a handle for EmoEngine event.
#
# This handle can be reused by the caller to retrieve events.
# @return handle, EmoEngineEventHandle
def EE_EmoEngineEventCreate(self):
return self.EmotivEngineDLL.EE_EmoEngineEventCreate()
## Create a handle to EmoEngine profile event.
#
# details Returns a handle to memory that can hold a profile byte stream.
# This handle can be reused by the caller to retrieve subsequent profile bytes.
# @return handle, EmoEngineEventHandle
def EE_ProfileEventCreate(self):
return self.EmotivEngineDLL.EE_ProfileEventCreate()
## Free an event handle.
#
# This frees memory referenced by event handle.
# @param emoengineeventhandle handle, created by EE_EmoEngineEventCreate()
def EE_EmoEngineEventFree(self, emoengineeventhandle):
self.EmotivEngineDLL.EE_EmoEngineEventFree(emoengineeventhandle)
## Create a handle to EmoState.
#
# Returns a handle to memory that can store an EmoState.
# This handle can be reused by the caller to retrieve subsequent EmoStates.
# @return handle
def EE_EmoStateCreate(self):
return self.EmotivEngineDLL.EE_EmoStateCreate()
## Free EmoState.
#
# Frees memory referenced by an EmoState handle.
# @param emostatehandle handle, created by EE_EmoStateCreate()
def EE_EmoStateFree(self, emostatehandle):
self.EmotivEngineDLL.EE_EmoStateFree(emostatehandle)
## Get EmoEngine event type.
#
# Returns the event type for an event already retrieved using EE_EngineGetNextEvent.
# @param emoengineeventhandle handle
# @return #EVENT
def EE_EmoEngineEventGetType(self, emoengineeventhandle):
return self.EmotivEngineDLL.EE_EmoEngineEventGetType(emoengineeventhandle)
## Get Cognitiv event type.
#
# Returns the Cognitiv-specific event type for an EE_CognitivEvent event already
# retrieved using EE_EngineGetNextEvent. \n
# @param emoengineeventhandle handle, created by EE_EmoEngineEventCreate()
# @return #COGEVENT
def EE_CognitivEventGetType(self, emoengineeventhandle):
return self.EmotivEngineDLL.EE_CognitivEventGetType(emoengineeventhandle)
## Get Expressiv event type.
#
# Returns the Expressiv-specific event type for an EE_ExpressivEvent event already
# retrieved using EE_EngineGetNextEvent.
# @param emoengineeventhandle handle, created by EE_EmoEngineEventCreate()
# @return #EXPEVENT
def EE_ExpressivEventGetType(self, emoengineeventhandle):
return self.EmotivEngineDLL.EE_ExpressivEventGetType(emoengineeventhandle)
## Get user ID.
#
# Retrieves the user ID for EE_UserAdded and EE_UserRemoved events.
# @param emoengineeventhandle handle
# @return (#ERRCODE, userID)
def EE_EmoEngineEventGetUserId(self, emoengineeventhandle):
userid = ctypes.c_int()
code = self.EmotivEngineDLL.EE_EmoEngineEventGetUserId(emoengineeventhandle, ctypes.byref(userid))
returnid = userid.value
del userid
return (code, returnid)
## Get EmoState.
#
# Copies an EmoState returned with a EE_EmoStateUpdate event to memory referenced by an EmoStateHandle.
# @param emoengineeventhandle handle, returned by EE_EmoEngineEventCreate() and populated with EE_EmoEngineGetNextEvent()
# @param emostatehandle handle, returned by EE_EmoStateCreate()
# @return #ERRCODE
def EE_EmoEngineEventGetEmoState(self, emoengineeventhandle, emostatehandle):
return self.EmotivEngineDLL.EE_EmoEngineEventGetEmoState(emoengineeventhandle, emostatehandle)
## Retrieves the next EmoEngine event.
#
# Non-blocking call.
# @note ERRCODE['EDK_OK'] if a new event has been retrieved.
# ERRCODE['EDK_NO_EVENT'] if no new events have been generated by EmoEngine.
# @param emoengineeventhandle handle created by EE_EmoEngineEventCreate()
# @return #ERRCODE
def EE_EngineGetNextEvent(self, emoengineeventhandle):
return self.EmotivEngineDLL.EE_EngineGetNextEvent(emoengineeventhandle)
## Clear EmoEngine event.
#
# Clear a specific EmoEngine event type or all events currently inside the event queue.
# Event flags can be combined together as one argument except EE_UnknownEvent and EE_EmulatorError.\n
# @note ERRCODE['EDK_OK'] if the events have been cleared from the queue.\n
# ERRCODE['EDK_INVALID_PARAMETER'] if input event types are invalid.\n
# @param eventtypes list, EmoEngine event types (#EVENT)
# @return #ERRCODE
def EE_EngineClearEventQueue(self, eventtypes):
return self.EmotivEngineDLL.EE_EngineClearEventQueue(eventtypes)
## Get number of users.
#
# Retrieves the number of users on the engine.
# @return (#ERRCODE, numberofusers)
def EE_EngineGetNumUser(self):
numusers = ctypes.c_int()
code = self.EmotivEngineDLL.EE_EngineGetNumUser(ctypes.byref(numusers))
returnnum = numusers.value
del numusers
return (code, returnnum)
## Set Player number on display.
#
# Sets the player number displayed on the physical input device (currently the USB Dongle)
# that corresponds to the specified user.
# @param userid int, EmoEngine user ID
# @param playernum int, application assigned player number displayed on input device hardware (must be in the range 1-4)
# @return #ERRCODE
def EE_SetHardwarePlayerDisplay(self, userid, playernum):
return self.EmotivEngineDLL.EE_SetHardwarePlayerDisplay(userid, playernum)
## Set User Profile.
#
# Loads an EmoEngine profile for the specified user.
# @param userid int, User ID
# @param profilebuffer pointer, to buffer containing a serialized user profile previously returned from EmoEngine.
# @param length int, buffer size (number of bytes)
# @todo Make it work!!
def EE_SetUserProfile(self, userid, profilebuffer, length):
buffer = ctypes.create_string_buffer(length)
buffer.value = profilebuffer
code = self.EmotivEngineDLL.EE_SetUserProfile(userid, buffer, length)
return code
## Get User Profile.
#
# Returns user profile data in a synchronous manner. Fills in the event referred to by emoengineeventhandle
# with an EE_ProfileEvent event that contains the profile data for the specified user.
# @param userid int, User ID
# @param emoengineeventhan handle,returned by EE_EmoEngineEventCreate()
# @return #ERRCODE
def EE_GetUserProfile(self, userid, emoengineeventhandle):
return self.EmotivEngineDLL.EE_GetUserProfile(userid, emoengineeventhandle)
## Get Base Profile.
#
# Returns a serialized user profile for a default user in a synchronous manner. Fills in the event referred
# to by emoengineeventhandle with an EE_ProfileEvent event that contains the profile data for the default user
# @param emoengineeventhandle handle, returned by EE_EmoEngineEventCreate()
# @return #ERRCODE
def EE_GetBaseProfile(self, emoengineeventhandle):
return self.EmotivEngineDLL.EE_GetBaseProfile(emoengineeventhandle)
## Get User Profile Size.
#
# Retrieves the number of bytes required to store a serialized version of the requested user profile.
# @param emoengineeventhandle handle, returned by EE_EmoEngineEventCreate()
# @return (#ERRCODE, int sizeinbytes)
# @todo figure out why it gives EDK_INVALID_PARAMETER
def EE_GetUserProfileSize(self, emoengineeventhandle):
profilesizeout = ctypes.c_uint()
code = self.EmotivEngineDLL.EE_GetUserProfileSize(emoengineeventhandle, ctypes.byref(profilesizeout))
sizeinbytes = profilesizeout.value
del profilesizeout
return (code, int(sizeinbytes))
## Get User Profile Bytes.
#
# Returns a serialized version of the requested user profile.
# @param emoengineeventhandle handle, something something
# @param bufferlength int, size of buffer in bytes
# @todo make it work!!
# @sa EpocHandler::EE_GetUserProfileSize()
def EE_GetUserProfileBytes(self, emoengineeventhandle, bufferlength):
buffer = ctypes.create_string_buffer(bufferlength)
code = self.EmotivEngineDLL.EE_GetUserProfileBytes(emoengineeventhandle, ctypes.byref(buffer), bufferlength)
returnbuffer = buffer.raw
del buffer
return (code, returnbuffer)
## Load User Profile.
#
# Loads a user profile from disk and assigns it to the specified user.
# @param userid int, User ID
# @param inputfilename str, filepath
# @return #ERRCODE
# @sa EpocHandler::EE_SaveUserProfile()
def EE_LoadUserProfile(self, userid, inputfilename):
return self.EmotivEngineDLL.EE_LoadUserProfile(userid, inputfilename)
## Save User Profile.
#
# Saves a user profile for specified user to disk.
# @param userid int, User ID
# @param outputfilename str, filepath
# @return #ERRCODE
# @sa EpocHandler::EE_LoadUserProfile()
def EE_SaveUserProfile(self, userid, outputfilename):
return self.EmotivEngineDLL.EE_SaveUserProfile(userid, outputfilename)
## Set Expressiv Alghorithms Threshold.
#
# Set threshold for Expressiv algorithms.
# @param userid int, User ID
# @param expressivalgoname #EXPRESSIVALGO
# @param thresholdname #EXPRTHRESHOLD
# @param value int, threshold value (min: 0 max: 1000)
# @return #ERRCODE
def EE_ExpressivSetThreshold(self, userid, expressivalgoname, thresholdname, value):
return self.EmotivEngineDLL.EE_ExpressivSetThreshold(userid, expressivalgoname, thresholdname, value)
## Get Expressiv Threshold.
#
# Get threshold from Expressiv algorithms.
# @param userid int, User ID
# @param expressivalgoname #EXPRESSIVALGO
# @param thresholdname #EXPRTHRESHOLD
# @return (#ERRCODE , int value)
def EE_ExpressivGetThreshold(self, userid, expressivalgoname, thresholdname):
valueout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_ExpressivGetThreshold(userid, expressivalgoname, thresholdname, ctypes.byref(valueout))
returnvalue = valueout.value
del valueout
return (code, returnvalue)
## Set Expressiv Training Action.
#
# Set the current facial expression for Expressiv training.
# @param userid int, User ID
# @param expressivalgoname #EXPRESSIVALGO
# @return #ERRCODE
def EE_ExpressivSetTrainingAction(self, userid, expressivalgoname):
return self.EmotivEngineDLL.EE_ExpressivSetTrainingAction(userid, expressivalgoname)
## Set Expressiv Training Control.
#
# Set the control flag for Expressiv training. Blocking call.
# @param int, User ID
# @param control #EXPRTRAININGCONTROL
# @return #ERRCODE - current status of EmoEngine. If the query is successful, returns EDK_OK.
def EE_ExpressivSetTrainingControl(self, userid, control):
return self.EmotivEngineDLL.EE_ExpressivSetTrainingControl(userid, control)
## Get Expressiv Training Action.
#
# Gets the facial expression currently selected for Expressiv training. Blocking call.
# @param userid int, User ID
# @return (#ERRCODE, int action)
# @see #EXPRESSIVALGO
# @todo check return value [1]
def EE_ExpressivGetTrainingAction(self, userid):
actionout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_ExpressivGetTrainingAction(userid, ctypes.byref(actionout))
returnaction = actionout.value
del actionout
return (code, returnaction)
## Get Expressiv Training Time.
#
# Return the duration of a Expressiv training session in ms.
# @param userid int, User ID
# @return (#ERRCODE, int time)
def EE_ExpressivGetTrainingTime(self, userid):
timeout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_ExpressivGetTrainingTime(userid, ctypes.byref(timeout))
returntime = timeout.value
del timeout
return (code, returntime)
## Get Expressiv Trained Signature Actions
#
# Gets a list of the actions that have been trained by the user.
# @param userid int, User ID
# @return (#ERRCODE , bitvector trainedactions)
# @todo make it work!! figure out bitvector
def EE_ExpressivGetTrainedSignatureActions(self, userid):
trainedactionsout = ctypes.c_ulong()
code = self.EmotivEngineDLL.EE_ExpressivGetTrainedSignatureActions(userid, ctypes.byref(trainedactionsout))
returntrainedactions = trainedactionsout.value
del trainedactionsout
return (code, returntrainedactions)
## Get Expressiv Trained Signature Available Flag.
#
# Gets a flag indicating if the user has trained sufficient actions to activate a trained
# signature. return[1] will be set to 1 if the user has trained EXP_NEUTRAL and at least
# one other Expressiv action. Otherwise, return[1] = 0.
# @param userid int, User ID
# @return (#ERRCODE , int flag)
# @see #EXPRESSIVALGO
def EE_ExpressivGetTrainedSignatureAvailable(self, userid):
availableout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_ExpressivGetTrainedSignatureAvailable(userid, ctypes.byref(availableout))
returnavailable = availableout.value
del availableout
return (code, returnavailable)
## Set Expressiv Signature Type.
#
# Configures the Expressiv suite to use either the built-in, universal signature or a personal, trained
# signature. Note: Expressiv defaults to use its universal signature. This function will fail if
# EE_ExpressivGetTrainedSignatureAvailable() returns false. Blocking call
# @param userid int, User ID
# @param expsigtype #EXPRSIGNATURE
# @return #ERRCODE
def EE_ExpressivSetSignatureType(self, userid, expsigtype):
return self.EmotivEngineDLL.EE_ExpressivSetSignatureType(userid, expsigtype)
## Get Expressiv Signature Type.
#
# Indicates whether the Expressiv suite is currently using either the built-in, universal signature or
# a trained signature. Blocking call
# @param userid int, User ID
# @return (#ERRCODE , int sigtype)
# @see #ERRCODE
# @see #EXPRSIGNATURE
def EE_ExpressivGetSignatureType(self, userid):
sigtypeout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_ExpressivGetSignatureType(userid, ctypes.byref(sigtypeout))
returnsigtype = sigtypeout.value
del sigtypeout
return (code, returnsigtype)
## Set Cognitiv Active Actions
#
# Set the current Cognitiv active action types.
# @param userid int, User ID
# @param activeactions bitvector, a bit vector composed of #COGACTION contants
# @todo Make it work! Find out what bitvectors are.
def EE_CognitivSetActiveActions(self, userid, activeactions):
#return self.EmotivEngineDLL.EE_CognitivSetActiveActions(userid, activeactions)
pass
## Get Cognitiv Active Actions
#
# Get the current Cognitiv active action types.
# @param userid int, User ID
# @return (#ERRCODE, ulong activeactions)
# @todo Find out what bitvectors are.
# @test Test it!
# @see #COGACTION
def EE_CognitivGetActiveActions(self, userid):
activeactionsout = ctypes.c_ulong()
code = self.EmotivEngineDLL.EE_CognitivGetActiveActions(userid, ctypes.byref(activeactionsout))
returnactions = activeactionsout.value
del activeactionsout
return (code, returnactions)
## Get Cognitiv Training Time
#
# Return the duration of a Cognitiv training session in ms.
# @param userid int, User ID
# @return (#ERRCODE, int trainingms)
# @see #ERRCODE
def EE_CognitivGetTrainingTime(self, userid):
trainingtimeout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_CognitivGetTrainingTime(userid, ctypes.byref(trainingtimeout))
returntrainingtime = trainingtimeout.value
del trainingtimeout
return (code, returntrainingtime)
## Set Cognitiv Training Control
#
# Set the training control flag for Cognitiv training.
# @param userid int, User ID
# @return #ERRCODE
# @see #COGTRAININGCONTROL
def EE_CognitivSetTrainingControl(self, userid, trainingcontrol):
return self.EmotivEngineDLL.EE_CognitivSetTrainingControl(userid, trainingcontrol)
## Set Cognitiv Training Action
#
# Set the type of Cognitiv action to be trained.
# @param userid int, User ID
# @param action int, #COGACTION
# @return #ERRCODE
def EE_CognitivSetTrainingAction(self, userid, action):
return self.EmotivEngineDLL.EE_CognitivSetTrainingAction(userid, action)
## Get Cognitiv Training Action
#
# Get the type of Cognitiv action currently selected for training.
# @param userid int, User ID
# @return (#ERRCODE, #COGACTION)
def EE_CognitivGetTrainingAction(self, userid):
trainingactionout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_CognitivGetTrainingAction(userid, ctypes.byref(trainingactionout))
returntrainingaction = trainingactionout.value
del trainingactionout
return (code, returntrainingaction)
## Get Cognitiv Trained Signature Actions
#
# Gets a list of the Cognitiv actions that have been trained by the user.\nBlocking call
# @param userid int, User ID
# @return (#ERRCODE, ulong trainedactions)
# @see #COGACTION
# @test Test it!
def EE_CognitivGetTrainedSignatureActions(self, userid):
trainedactionsout = ctypes.c_ulong()
code = self.EmotivEngineDLL.EE_CognitivGetTrainedSignatureActions(userid, ctypes.byref(trainedactionsout))
returntrainedactions = trainedactionsout.value
del trainedactionsout
return (code, returntrainedactions)
## Get Overall Cognitiv Skill Rating
#
# Gets the current overall skill rating of the user in Cognitiv.
# @param userid int, User ID
# @return (#ERRCODE, float overallskillrating)
# @note Representation error (0.70 in EmoComposer returned 0.69999998807907104)
def EE_CognitivGetOverallSkillRating(self, userid):
skillratingout = ctypes.c_float()
code = self.EmotivEngineDLL.EE_CognitivGetOverallSkillRating(userid, ctypes.byref(skillratingout))
returnoverallskillrating = skillratingout.value
del skillratingout
return (code, returnoverallskillrating)
## Get Cognitiv Action Skill Rating
#
# Gets the current skill rating for particular Cognitiv actions of the user. Blocking call.
# @param userid int, User ID
# @param action int, #COGACTION
# @return (#ERRCODE, float skillrating)
def EE_CognitivGetActionSkillRating(self, userid, action):
skillratingout = ctypes.c_float()
code = self.EmotivEngineDLL.EE_CognitivGetActionSkillRating(userid, action, ctypes.byref(skillratingout))
returnskillrating = skillratingout.value
del skillratingout
return (code, returnskillrating)
## Set Cognitiv Activation Level
#
# Set the overall sensitivity for all Cognitiv actions (lowest 1 - highest 7)
# @param userid int, User ID
# @param level int, sensitivity level 1-7
# @return #ERRCODE
# @sa EpocHandler::EE_CognitivGetActivationLevel()
def EE_CognitivSetActivationLevel(self, userid, level):
return self.EmotivEngineDLL.EE_CognitivSetActivationLevel(userid, level)
## Set Cognitiv Action Sensitivity
#
# Set the sensitivity of Cognitiv actions (lowest 1 - highest 10)
# @param userid int, User ID
# @param action1sens int, sensitivity of action 1
# @param action2sens int, sensitivity of action 2
# @param action3sens int, sensitivity of action 3
# @param action4sens int, sensitivity of action 4
# @return #ERRCODE
# @test Test it!
# @todo Find out what this does.
# @sa EpocHandler::EE_CognitivGetActionSensitivity()
def EE_CognitivSetActionSensitivity(self, userid, action1sens, action2sens, action3sens, action4sens):
return self.EmotivEngineDLL.EE_CognitivSetActionSensitivity(userid, action1sens, action2sens, action3sens, action4sens)
## Get Cognitiv Activation Level
#
# Get the overall sensitivity for all Cognitiv actions (Min 1 Max 10)
# @param userid int, User ID
# @return (#ERRCODE, int level)
# @sa EpocHandler::EE_CognitivSetActivationLevel()
def EE_CognitivGetActivationLevel(self, userid):
levelout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_CognitivGetActivationLevel(userid, ctypes.byref(levelout))
returnlevel = levelout.value
del levelout
return (code, returnlevel)
## Get Cognitiv Action Sensitivity
#
# Query the sensitivity of Cognitiv actions.
# @param userid int, User ID
# @return (#ERRCODE, action1sens, action2sens, action3sens, action4sens)
# @sa EpocHandler::EE_CognitivSetActionSensitivity()
def EE_CognitivGetActionSensitivity(self, userid):
action1sensout = ctypes.c_int()
action2sensout = ctypes.c_int()
action3sensout = ctypes.c_int()
action4sensout = ctypes.c_int()
code = self.EmotivEngineDLL.EE_CognitivGetActionSensitivity(userid, ctypes.byref(action1sensout), ctypes.byref(action2sensout), ctypes.byref(action3sensout), ctypes.byref(action4sensout))
action1sens = action1sensout.value
action2sens = action2sensout.value
action3sens = action3sensout.value
action4sens = action4sensout.value
del action1sensout, action2sensout, action3sensout, action4sensout
return (code, action1sens, action2sens, action3sens, action4sens)
## Start Sampling Cognitiv Neutral
#
# Start the sampling of Neutral state in Cognitiv.
# @param userid int, User ID
# @return #ERRCODE
# @sa EpocHandler::EE_CognitivStopSamplingNeutral()
def EE_CognitivStartSamplingNeutral(self, userid):
return self.EmotivEngineDLL.EE_CognitivStartSamplingNeutral(userid)
## Stop Sampling Cognitiv Neutral
#
# Stop the sampling of Neutral state in Cognitiv.
# @param userid int, User ID
# @return #ERRCODE
# @sa EpocHandler::EE_CognitivStartSamplingNeutral()
def EE_CognitivStopSamplingNeutral(self, userid):
return self.EmotivEngineDLL.EE_CognitivStopSamplingNeutral(userid)
## Set Cognitiv Signature Caching
#
# Enable or disable signature caching in Cognitiv (1 enable/0 disable)
# @param userid int, User ID
# @param enable int, 1/0
# @return #ERRCODE
# @sa EpocHandler::EE_CognitivGetSignatureCaching()
def EE_CognitivSetSignatureCaching(self, userid, enable):
return self.EmotivEngineDLL.EE_CognitivSetSignatureCaching(userid, enable)
## Get Cognitiv Signature Caching
#
# Get the status of signature caching in Cognitiv
# @param userid int, User ID
# @return (#ERRCODE, int flag)
# @sa EpocHandler::EE_CognitivSetSignatureCaching()
def EE_CognitivGetSignatureCaching(self, userid):
flag = ctypes.c_int()
code = self.EmotivEngineDLL.EE_CognitivGetSignatureCaching(userid, ctypes.byref(flag))
returnflag = flag.value
del flag
return (code, returnflag)
## Set Cognitiv Signature Cache Size
#
# Set the cache size for the signature caching in Cognitiv
# @param userid int, User ID