-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCamBot6D.py
1962 lines (1563 loc) · 79.7 KB
/
CamBot6D.py
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
################################################################################
##
## BY: WANDERSON M.PIMENTA
## PROJECT MADE WITH: Qt Designer and PySide2
## V: 1.0.0
##
## This project can be used freely for all uses, as long as they maintain the
## respective credits only in the Python scripts, any information in the visual
## interface (GUI) can be modified without any implication.
##
## There are limitations on Qt licenses if you want to use your products
## commercially, I recommend reading them on the official website:
## https://doc.qt.io/qtforpython/licenses.html
##
################################################################################
import multiprocessing
from multiprocessing import Process, Queue
from configparser import ConfigParser
import paho.mqtt.client as mqtt
import os
import pyttsx3
# GUI FILE
if __name__ != "__mp_main__":
import sys
import platform
from scipy import interpolate
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import (QCoreApplication, QPropertyAnimation, QDate, QDateTime, QMetaObject, QObject, QPoint, QRect, QSize, QTime, QUrl, Qt, QEvent)
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QIcon, QKeySequence, QLinearGradient, QPalette, QPainter, QPixmap, QRadialGradient)
from PySide2.QtWidgets import *
import time
from threading import Thread
from app_modules import *
import numpy as np
import win32api
import win32con
import win32gui
import win32com.client
import mmap
from dataclasses import dataclass
import struct
import math
try:
import pyi_splash
except:
print ('dev mode')
try:
# Update the text on the splash screen
pyi_splash.update_text("Opening GUI")
# Close the splash screen. It does not matter when the call
# to this function is made, the splash screen remains open until
# this function is called or the Python program is terminated.
except:
print ('dev mode')
###
mqtt_thread = None
engine = pyttsx3.init() # object creation
#DEFAULTS
voice = ''
voice_id = ''
rate = 200
volume = 0.75
hotkey_enable = False
voice_enable = False
mqtt_enable = False
mqtt_ip = ''
mqtt_ip_default = '127.0.0.1'
mqtt_port = ''
mqtt_port_default = '1883'
mqtt_user = ''
mqtt_pass = ''
opentrack_ip = ''
opentrack_port = ''
#
path_time = 3.0
path_ease_selection = 1
spatial_selection = 1
temporal_selection = 0
point_time = 1.0
point_ease_selection = 0
#
joystick_value = None
joystickNames = []
joystickIds = []
joystickUids = []
controller_id = False
controller_name = False
controllers_count = 0
#
tts = ''
ttsQ = ''
all_processes = []
q = Queue()
###
#config file
config = ConfigParser()
controllerTest = False
controller_test = ''
voices = []
#opentrack
x = 0
y = 0
z = 0
yaw = 0
pitch = 0
roll = 0
#camera bot
start_points = 100 #todo: option!
points = 2000
path_x = [] #[left .. right]
path_y = [] #[down .. up]
path_z = [] #[backwards .. forwards]
path_yaw = [] #[-180 .. 180]
path_pitch = [] #[-180 .. 180]
path_roll = [] #[-180 .. 180]
joystickIds = ()
joystickUids = ()
joystickNames = ()
controller = "keyboardandmouse"
joystick_loop = True
#keyboard
keyboard_motion = 1
keyboard_wrap_rotation = True
keyboard_invert_pitch = False
keyboard_invert_yaw = False
keyboard_invert_roll = False
#spacemouse
joystick = None
spacemouse_motion = 1
spacemouse_wrap_rotation = True
spacemouse_invert_pitch = True
spacemouse_invert_yaw = False
spacemouse_invert_roll = False
#xboxone
gamepad = None
xboxone_motion = 1
xboxone_wrap_rotation = True
xboxone_invert_pitch = True
xboxone_invert_yaw = False
xboxone_invert_roll = False
#mqtt
broker_address="192.168.1.10" #todo: option!
client = mqtt.Client("P1") #create new instance
os.chdir(os.path.dirname(os.path.abspath(__file__)))
display = 0 #display for camera control window
os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0"
#pygame.display.set_mode((400, 400), flags=pygame.HIDDEN | pygame.NOFRAME, display=display)
#to change the display, call quit first and set again
#pygame.display.quit()
#pygame.display.set_mode((640, 640), flags=pygame.HIDDEN, display=0)
def CSS_buttonActive(icon):
return(u"QPushButton {\n"
" border: 2px solid rgb(255, 255, 255);\n"
" border-radius: 5px; \n"
" background-color: rgb(85, 170, 255);\n"
" background-image: url("+icon+");\n"
"}")
def CSS_button(icon):
return(u"QPushButton {\n"
" border: 2px solid rgb(52, 59, 72);\n"
" border-radius: 5px; \n"
" background-color: rgb(52, 59, 72);\n"
" background-image: url("+icon+");\n"
"}\n"
"QPushButton:hover {\n"
" background-color: rgb(57, 65, 80);\n"
" border: 2px solid rgb(61, 70, 86);\n"
"}\n"
"QPushButton:pressed { \n"
" background-color: rgb(35, 40, 49);\n"
" border: 2px solid rgb(43, 50, 61);\n"
"}")
def wraparound(old, new):
old_btm = round(old/2-0.25) #required for wrap around of nipple (with negative buffer)
old_top = round(old/2+0.25) #required for wrap around of nipple (with positive buffer)
if (old > 0 and new * old < 0) or (old < 0 and new * old >= 0): #if different signs (and not zero) for positive, or same signe (or zero) if negative
return new + old_top * 2 #add the floor * 2
else:
return new + old_btm * 2 #add the floor * 2
def increment(old, new):
return old + new
if __name__ != "__mp_main__":
class MainWindow(QMainWindow):
def __init__(self):
global mqtt_ip
global mqtt_port
global mqtt_user
global mqtt_pass
global path_time
global path_ease_selection
global spatial_selection
global temporal_selection
global point_ease_selection
global point_time
global opentrack_ip
global opentrack_port
global voice_enable
global joystick_value
global keyboard_motion
global keyboard_wrap_rotation
global keyboard_invert_pitch
global keyboard_invert_yaw
global keyboard_invert_roll
global spacemouse_motion
global spacemouse_wrap_rotation
global spacemouse_invert_pitch
global spacemouse_invert_yaw
global spacemouse_invert_roll
global xboxone_motion
global xboxone_wrap_rotation
global xboxone_invert_pitch
global xboxone_invert_yaw
global xboxone_invert_roll
# Close the splash screen. It does not matter when the call
# to this function is made, the splash screen remains open until
# this function is called or the Python program is terminated.
try:
pyi_splash.close()
except:
print ('dev mode')
#global send_to_opentrack
#send_to_opentrack = Thread(target=self.send_to_opentrack_thread, args=("Thread",))
#send_to_opentrack.start()
QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
F = Functions(self, UIFunctions, self.ui, pygame)
self.F = F
joystick_value = Thread(target=self.joystick_thread)
joystick_value.start()
self.mqtt_flag = None
self.mqtt_connected = False
self.ui.controllerSelection.addItem("")
self.ui.controllerSelection.setItemText(0, QCoreApplication.translate("MainWindow", u"(please select a device)", None))
self.ui.controllerSelection.addItem("")
self.ui.controllerSelection.setItemText(1, QCoreApplication.translate("MainWindow", u"Standard Keyboard and mouse HID", None))
self.ui.controllerSelection.setCurrentIndex(1)
self.ui.controllerSelection.currentIndexChanged.connect(self.on_controllerSelection_changed)
self.ui.controllerUpdateButton.clicked.connect(self.on_controllerUpdate_clicked)
#self.ui.pushButton.setText(QCoreApplication.translate("MainWindow", u"test", None))
self.ui.controllerTestButton.clicked.connect(self.on_test_clicked)
##
n = 0
for voiceChoice in voices:
self.ui.voiceSelection.addItem("")
print(voiceChoice)
self.ui.voiceSelection.setItemText(n, QCoreApplication.translate("MainWindow", voiceChoice.name, None))
n = n+1
if voice:
n = 0
for thisvoice in voices:
if thisvoice.id == voice:
self.ui.voiceSelection.setCurrentIndex(n)
n = n+1
self.ui.voiceSelection.currentIndexChanged.connect(self.on_voiceSelection_changed)
##
self.ui.hotkeyCheckBox.stateChanged.connect(self.on_hotkeyEnable_changed)
self.ui.hotkeyCheckBox.setChecked(hotkey_enable)
self.ui.voiceCheckBox.stateChanged.connect(self.on_voiceEnable_changed)
self.ui.voiceCheckBox.setChecked(voice_enable)
self.ui.MQTTCheckBox.stateChanged.connect(self.on_mqttEnable_changed)
self.ui.MQTTCheckBox.setChecked(mqtt_enable)
self.ui.xBoxButton.clicked.connect(self.on_xBoxButton_clicked)
self.ui.spaceMouseButton.clicked.connect(self.on_spaceMouseButton_clicked)
self.ui.keyboardAndMouseButton.clicked.connect(self.on_keyboardAndMouseButton_clicked)
self.ui.motionSelection.currentIndexChanged.connect(self.on_motionSelection_changed)
self.ui.wrapRotationCheckBox.stateChanged.connect(self.on_wrapRotationCheckBox_changed)
self.ui.invertRollCheckBox.stateChanged.connect(self.on_invertRollCheckBox_changed)
self.ui.invertPitchCheckBox.stateChanged.connect(self.on_invertPitchCheckBox_changed)
self.ui.invertYawCheckBox.stateChanged.connect(self.on_invertYawCheckBox_changed)
match controller:
case "xboxone":
self.ui.xBoxButton.click()
case "spacemouse":
self.ui.spaceMouseButton.click()
case "keyboardandmouse":
self.ui.keyboardAndMouseButton.click()
#camera dropdowns
self.ui.easeSelection.setCurrentIndex(path_ease_selection)
self.ui.easeSelection.currentIndexChanged.connect(self.on_easeSelection_changed)
self.ui.skipEaseSelection.setCurrentIndex(point_ease_selection)
self.ui.skipEaseSelection.currentIndexChanged.connect(self.on_skipEaseSelection_changed)
self.ui.spatialInterpolationSelection.setCurrentIndex(spatial_selection)
self.ui.spatialInterpolationSelection.currentIndexChanged.connect(self.on_spatialInterpolationSelection_changed)
self.ui.temporalInterpolationSelection.setCurrentIndex(temporal_selection)
self.ui.temporalInterpolationSelection.currentIndexChanged.connect(self.on_temporalInterpolationSelection_changed)
## PRINT ==> SYSTEM
print('System: ' + platform.system())
print('Version: ' + platform.release())
########################################################################
## START - WINDOW ATTRIBUTES
########################################################################
## REMOVE ==> STANDARD TITLE BAR
UIFunctions.removeTitleBar(True)
## ==> END ##
## SET ==> WINDOW TITLE
self.setWindowTitle('CamBot 6D')
self.setWindowIcon(QIcon('images/icon.png'))
UIFunctions.labelTitle(self, 'CamBot 6D')
UIFunctions.labelDescription(self, 'six degrees of freedom spline interpolation with opentrack UDP-over-network output')
## ==> END ##
## WINDOW SIZE ==> DEFAULT SIZE
startSize = QSize(800, 600)
self.resize(startSize)
self.setMinimumSize(startSize)
UIFunctions.enableMaximumSize(self, 800, 600)
## ==> END ##
## ==> CREATE MENUS
########################################################################
## ==> TOGGLE MENU SIZE
self.ui.btn_toggle_menu.clicked.connect(lambda: UIFunctions.toggleMenu(self, 220, True))
## ==> END ##
## ==> ADD CUSTOM MENUS
self.ui.stackedWidget.setMinimumWidth(20)
UIFunctions.addNewMenu(self, "CAMERA", "btn_main", "url(:/20x20/icons/20x20/cil-video.png)", True)
UIFunctions.addNewMenu(self, "CONTROLLERS", "btn_controllers", "url(:/20x20/icons/20x20/cil-gamepad.png)", True)
UIFunctions.addNewMenu(self, "INFO", "btn_info", "url(:/20x20/icons/20x20/cil-description.png)", True)
UIFunctions.addNewMenu(self, "SETTINGS", "btn_settings", "url(:/20x20/icons/20x20/cil-equalizer.png)", False)
## ==> END ##
# START MENU => SELECTION
UIFunctions.selectStandardMenu(self, "btn_main")
## ==> END ##
## ==> START PAGE
self.ui.stackedWidget.setCurrentWidget(self.ui.page_main)
## ==> END ##
## USER ICON ==> SHOW HIDE
UIFunctions.userIcon(self, "WM", "", False)
## ==> END ##
## ==> MOVE WINDOW / MAXIMIZE / RESTORE
########################################################################
def moveWindow(event):
# IF MAXIMIZED CHANGE TO NORMAL
if UIFunctions.returStatus() == 1:
UIFunctions.maximize_restore(self)
# MOVE WINDOW
if event.buttons() == Qt.LeftButton:
self.move(self.pos() + event.globalPos() - self.dragPos)
self.dragPos = event.globalPos()
event.accept()
# WIDGET TO MOVE
self.ui.frame_label_top_btns.mouseMoveEvent = moveWindow
## ==> END ##
## ==> LOAD DEFINITIONS
########################################################################
UIFunctions.uiDefinitions(self)
## ==> END ##
########################################################################
## END - WINDOW ATTRIBUTES
############################## ---/--/--- ##############################
########################################################################
# #
## START -------------- WIDGETS FUNCTIONS/PARAMETERS ---------------- ##
# #
## ==> USER CODES BELLOW ##
########################################################################
## ==> QTableWidget RARAMETERS
########################################################################
self.ui.tableWidget_waypoints.hide()
self.ui.frame_div_table_widget_M1.setMaximumSize(16777215, 50)
self.ui.tableWidget_waypoints.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
self.ui.tableWidget_waypoints.horizontalHeader().setSectionResizeMode(1, QtWidgets.QHeaderView.Fixed)
self.ui.tableWidget_waypoints.horizontalHeader().setSectionResizeMode(2, QtWidgets.QHeaderView.Fixed)
self.ui.tableWidget_waypoints.setColumnWidth(0, QtWidgets.QHeaderView.Stretch)
self.ui.tableWidget_waypoints.setColumnWidth(1, 120)
self.ui.tableWidget_waypoints.setColumnWidth(2, 50)
delegate = AlignDelegate(self.ui.tableWidget_waypoints)
self.ui.tableWidget_waypoints.setItemDelegateForColumn(1, delegate)
self.ui.tableWidget_waypoints.setItemDelegateForColumn(2, delegate)
## ==> END ##
## ==> DELETE ALL WAYPOINTS
self.ui.pushButton_delete_all.clicked.connect(lambda: F.deleteAll(q, config))
## ==> play sample voice line
self.ui.voiceTestButton.clicked.connect(lambda: q.put('This is a test of the CamBot 6D audio feedback system.'))
self.ui.remoteIPEdit.setText(QCoreApplication.translate("MainWindow", str(opentrack_ip), None))
self.ui.remoteIPEdit.textChanged.connect(self.opentrack_ip_changed)
#self.ui.opentrackPortEdit.setText(QCoreApplication.translate("MainWindow", str(opentrack_port), None))
#self.ui.opentrackPortEdit.textChanged.connect(self.opentrack_port_changed)
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
self.ui.label_ip_info.setText(QCoreApplication.translate("MainWindow", str(local_ip), None))
self.ui.MQTTIPEdit.setText(QCoreApplication.translate("MainWindow", str(mqtt_ip), None))
self.ui.MQTTIPEdit.textChanged.connect(self.mqtt_ip_changed)
self.ui.MQTTPortEdit.setText(QCoreApplication.translate("MainWindow", str(mqtt_port), None))
self.ui.MQTTPortEdit.textChanged.connect(self.mqtt_port_changed)
self.ui.MQTTUserEdit.setText(QCoreApplication.translate("MainWindow", str(mqtt_user), None))
self.ui.MQTTUserEdit.textChanged.connect(self.mqtt_user_changed)
self.ui.MQTTPassEdit.setText(QCoreApplication.translate("MainWindow", str(mqtt_pass), None))
self.ui.MQTTPassEdit.textChanged.connect(self.mqtt_pass_changed)
self.ui.MQTTTestButton.clicked.connect(self.start_mqtt)
self.ui.pathtimeEdit.setValue(path_time)
self.ui.pathtimeEdit.valueChanged.connect(self.path_time_changed)
self.ui.skiptimeEdit.setValue(point_time)
self.ui.skiptimeEdit.valueChanged.connect(self.skip_time_changed)
self.ui.pushButton_forward.clicked.connect(lambda: self.goForward(q, config))
self.ui.pushButton_backward.clicked.connect(lambda: F.pathBackward(q, config))
## ==> ADD NEW WAYPOINT
self.ui.pushButton_add_waypoint.clicked.connect(lambda: F.newWaypoint(q, config))
## ==> GO HOME
self.ui.pushButton_home.clicked.connect(lambda: F.goHome(q, config))
## ==> QTableWidget RARAMETERS
########################################################################
self.ui.tableWidget.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
## ==> END ##
########################################################################
# #
## END --------------- WIDGETS FUNCTIONS/PARAMETERS ----------------- ##
# #
############################## ---/--/--- ##############################
self.show()
def showForeground(self):
self.F.showForeground()
def goForward(self, q, config):
self.F.pathForward(q, config)
def goBackward(self, q, config):
self.F.pathBackward(q, config)
def opentrack_ip_changed(self, text):
global opentrack_ip
config.set('dualpc', 'ip', str(text))
self.write_config()
opentrack_ip = text
def opentrack_port_changed(self, text):
global opentrack_port
config.set('dualpc', 'port', str(text))
self.write_config()
opentrack_port = text
def mqtt_ip_changed(self, text):
global mqtt_ip
config.set('mqtt', 'ip', str(text))
self.write_config()
mqtt_ip = text
def mqtt_port_changed(self, text):
global mqtt_port
config.set('mqtt', 'port', str(text))
self.write_config()
mqtt_port = text
def mqtt_user_changed(self, text):
global mqtt_user
config.set('mqtt', 'user', str(text))
self.write_config()
mqtt_user = text
def mqtt_pass_changed(self, text):
global mqtt_pass
config.set('mqtt', 'pass', str(text))
self.write_config()
mqtt_pass = text
def path_time_changed(self, double):
global path_time
config.set('speed', 'path', str(double))
self.write_config()
path_time = double
def skip_time_changed(self, double):
global point_time
config.set('speed', 'point', str(double))
self.write_config()
point_time = double
def write_config(self):
try:
with open(configIni, 'w') as f:
config.write(f)
except OSError as error:
print(sys.exc_info()[0])
def stop_controller_test(self):
global controller_test
global controllerTest
controllerTest = False
if controller_test and controller_test.is_alive():
controller_test.join()
x_test = self.ui.tableWidget.item(0, 0)
x_test.setText(QCoreApplication.translate("MainWindow", "", None))
y_test = self.ui.tableWidget.item(0, 1)
y_test.setText(QCoreApplication.translate("MainWindow", "", None))
z_test = self.ui.tableWidget.item(0, 2)
z_test.setText(QCoreApplication.translate("MainWindow", "", None))
yaw_test = self.ui.tableWidget.item(0, 3)
yaw_test.setText(QCoreApplication.translate("MainWindow", "", None))
pitch_test = self.ui.tableWidget.item(0, 4)
pitch_test.setText(QCoreApplication.translate("MainWindow", "", None))
roll_test = self.ui.tableWidget.item(0, 5)
roll_test.setText(QCoreApplication.translate("MainWindow", "", None))
stop_icon = QIcon()
stop_icon.addFile(u":/16x16/icons/16x16/cil-media-play.png", QSize(), QIcon.Normal, QIcon.Off)
self.ui.controllerTestButton.setIcon(stop_icon)
self.ui.controllerTestButton.setText(QCoreApplication.translate("MainWindow", u" TEST", None))
self.ui.controllerTestButton.setStyleSheet(u"QPushButton {\n"
" margin-left: 5px;\n"
" border: 2px solid rgb(52, 59, 72);\n"
" border-radius: 5px; \n"
" background-color: rgb(52, 59, 72);\n"
"}\n"
"QPushButton:hover {\n"
" background-color: rgb(57, 65, 80);\n"
" border: 2px solid rgb(61, 70, 86);\n"
"}\n"
"QPushButton:pressed { \n"
" background-color: rgb(35, 40, 49);\n"
" border: 2px solid rgb(43, 50, 61);\n"
"}")
def controller_test_thread(self, threadname):
global x
global y
global z
global yaw
global pitch
global roll
global controllerTest
x_snap = x
y_snap = y
z_snap = z
yaw_snap = yaw
pitch_snap = pitch
roll_snap = roll
while controllerTest:
print(x,y,z)
time.sleep(0.02) #50 fps (ish)
x_test = self.ui.tableWidget.item(0, 0)
x_test.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
x_test.setText(QCoreApplication.translate("MainWindow", str(round((x-x_snap)*-1000)), None))
y_test = self.ui.tableWidget.item(0, 1)
y_test.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
y_test.setText(QCoreApplication.translate("MainWindow", str(round((y-y_snap)*1000)), None))
z_test = self.ui.tableWidget.item(0, 2)
z_test.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
z_test.setText(QCoreApplication.translate("MainWindow", str(round((z-z_snap)*-1000)), None))
yaw_test = self.ui.tableWidget.item(0, 3)
yaw_test.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
yaw_test.setText(QCoreApplication.translate("MainWindow", str(round((yaw-yaw_snap)*1000)), None))
pitch_test = self.ui.tableWidget.item(0, 4)
pitch_test.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
pitch_test.setText(QCoreApplication.translate("MainWindow", str(round((pitch-pitch_snap)*-1000)), None))
roll_test = self.ui.tableWidget.item(0, 5)
roll_test.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
roll_test.setText(QCoreApplication.translate("MainWindow", str(round((roll-roll_snap)*-1000)), None))
def on_test_clicked(self):
global controllerTest
global controller_test
if not controllerTest:
controllerTest = True
controller_test = Thread(target=self.controller_test_thread, args=("Thread",))
controller_test.start()
stop_icon = QIcon()
stop_icon.addFile(u":/16x16/icons/16x16/cil-media-stop.png", QSize(), QIcon.Normal, QIcon.Off)
self.ui.controllerTestButton.setIcon(stop_icon)
self.ui.controllerTestButton.setText(QCoreApplication.translate("MainWindow", u" Stop", None))
self.ui.controllerTestButton.setStyleSheet(u"QPushButton {\n"
" margin-left: 5px;\n"
" border: 2px solid rgb(124, 29, 0);\n"
" border-radius: 5px; \n"
" background-color: rgb(124, 29, 0);\n"
"}\n"
"QPushButton:hover {\n"
" background-color: rgb(137, 32, 0);\n"
" border: 2px solid rgb(147, 33, 0);\n"
"}\n"
"QPushButton:pressed { \n"
" background-color: rgb(84, 19, 0);\n"
" border: 2px solid rgb(104, 20, 0);\n"
"}")
else:
self.stop_controller_test()
def repopulate_controllers_dropdown(self):
global controller
global joystickNames
global joystickUids
global controller_id
global controller_name
global joystickNames
global joystickUids
global joystickIds
joystickNames = [pygame.joystick.Joystick(x).get_name() for x in range(pygame.joystick.get_count())]
joystickIds = [pygame.joystick.Joystick(x).get_instance_id() for x in range(pygame.joystick.get_count())]
joystickUids = [pygame.joystick.Joystick(x).get_guid() for x in range(pygame.joystick.get_count())]
print(joystickIds, pygame.joystick.get_count())
controller_id = False
controller_name = False
controller_found = -1
if controller == "xboxone":
if config.has_option('controllers', 'xboxone_id'):
controller_id = config.get('controllers', 'xboxone_id')
if config.has_option('controllers', 'xboxone_name'):
controller_name = config.get('controllers', 'xboxone_name')
self.ui.controllerSelection.clear()
self.ui.controllerSelection.addItem("")
self.ui.controllerSelection.setItemText(0, QCoreApplication.translate("MainWindow", u"(please select your Xbox gamepad)", None))
elif controller == "spacemouse":
if config.has_option('controllers', 'spacemouse_id'):
controller_id = config.get('controllers', 'spacemouse_id')
if config.has_option('controllers', 'spacemouse_name'):
controller_name = config.get('controllers', 'spacemouse_name')
self.ui.controllerSelection.clear()
self.ui.controllerSelection.addItem("")
self.ui.controllerSelection.setItemText(0, QCoreApplication.translate("MainWindow", u"(please select your SpaceMouse)", None))
else:
self.ui.controllerSelection.clear()
self.ui.controllerSelection.addItem("")
self.ui.controllerSelection.setItemText(0, QCoreApplication.translate("MainWindow", u"(please select a device)", None))
self.ui.controllerSelection.addItem("")
self.ui.controllerSelection.setItemText(1, QCoreApplication.translate("MainWindow", u"Standard Keyboard and mouse HID", None))
self.ui.controllerSelection.setCurrentIndex(1)
print("ID", controller_id)
if controller == "xboxone" or controller == "spacemouse":
n = 0
for x in joystickIds:
self.ui.controllerSelection.addItem("")
self.ui.controllerSelection.setItemText(n+1, QCoreApplication.translate("MainWindow", joystickNames[n], None))
print(joystickUids[n])
if controller_id == joystickUids[n]:
controller_found = n
n = n+1
print("FOUND", controller_found)
if controller_found >= 0:
print("SETTING TO", controller_found+1)
self.ui.controllerSelection.setCurrentIndex(controller_found+1)
elif controller_id:
self.ui.controllerSelection.addItem("")
if controller_name:
self.ui.controllerSelection.setItemText(n+1, QCoreApplication.translate("MainWindow", controller_name + u" [disconnected]", None))
else:
self.ui.controllerSelection.setItemText(n+1, QCoreApplication.translate("MainWindow", u"UNKNOWN [disconnected]", None))
self.ui.controllerSelection.setCurrentIndex(n+1)
else:
self.ui.controllerSelection.setCurrentIndex(0)
def on_xBoxButton_clicked(self):
global controller
self.stop_controller_test()
#self.joystick_reinit()
controller = "xboxone"
config.set('controllers', 'type', 'xboxone')
self.ui.motionSelection.setCurrentIndex(xboxone_motion)
self.on_motionSelection_changed(xboxone_motion)
self.ui.wrapRotationCheckBox.setChecked(xboxone_wrap_rotation)
self.ui.invertRollCheckBox.setChecked(xboxone_invert_roll)
self.ui.invertPitchCheckBox.setChecked(xboxone_invert_pitch)
self.ui.invertYawCheckBox.setChecked(xboxone_invert_yaw)
self.on_wrapRotationCheckBox_changed(xboxone_wrap_rotation)
self.on_invertRollCheckBox_changed(xboxone_invert_roll)
self.on_invertPitchCheckBox_changed(xboxone_invert_pitch)
self.on_invertYawCheckBox_changed(xboxone_invert_yaw)
self.repopulate_controllers_dropdown()
self.ui.labelStreamDeck.setVisible(False)
self.ui.tableWidget.setVisible(True)
self.ui.controllerTestButton.setVisible(True)
self.ui.controllerTestButton.setEnabled(True)
self.ui.keyMapImage.setStyleSheet(u"QPushButton {\n"
" background-color: rgb(41, 46, 57);\n"
" border-radius: 0px; \n"
" background-image: url(images/xbox-map.png);\n"
"}")
self.ui.xBoxButton.setStyleSheet(CSS_buttonActive("images/controllers-02.png"))
self.ui.keyboardAndMouseButton.setStyleSheet(CSS_button("images/controllers-04.png"))
self.ui.spaceMouseButton.setStyleSheet(CSS_button("images/controllers-01.png"))
self.ui.label_controller_info.setText(QCoreApplication.translate("MainWindow", u"CamBot 6D is compatible with Microsoft Xbox Series X, Xbox Series S, and Xbox One gamepads.\n\nNote: Works in fullscreen mode. Can only support 5 analog axis, roll is controlled digitally. Make sure the particular controller has no keybindings set in Star Citizen.", None))
try:
with open(configIni, 'w') as f:
config.write(f)
except OSError as error:
print(sys.exc_info()[0])
def on_keyboardAndMouseButton_clicked(self):
global controller
self.stop_controller_test()
controller = "keyboardandmouse"
config.set('controllers', 'type', 'keyboardandmouse')
self.ui.motionSelection.setCurrentIndex(keyboard_motion)
self.on_motionSelection_changed(keyboard_motion)
self.ui.wrapRotationCheckBox.setChecked(keyboard_wrap_rotation)
self.ui.invertRollCheckBox.setChecked(keyboard_invert_roll)
self.ui.invertPitchCheckBox.setChecked(keyboard_invert_pitch)
self.ui.invertYawCheckBox.setChecked(keyboard_invert_yaw)
self.on_wrapRotationCheckBox_changed(keyboard_wrap_rotation)
self.on_invertRollCheckBox_changed(keyboard_invert_roll)
self.on_invertPitchCheckBox_changed(keyboard_invert_pitch)
self.on_invertYawCheckBox_changed(keyboard_invert_yaw)
self.repopulate_controllers_dropdown()
self.ui.labelStreamDeck.setVisible(True)
self.ui.tableWidget.setVisible(False)
self.ui.controllerTestButton.setVisible(False)
self.ui.controllerTestButton.setEnabled(False)
self.ui.keyMapImage.setStyleSheet(u"QPushButton {\n"
" background-color: rgb(41, 46, 57);\n"
" border-radius: 0px; \n"
" background-image: url(images/keyboard-map.png);\n"
"}")
self.ui.controllerSelection.setItemText(0, QCoreApplication.translate("MainWindow", u"(please select your controller)", None))
self.ui.xBoxButton.setStyleSheet(CSS_button("images/controllers-02.png"))
self.ui.keyboardAndMouseButton.setStyleSheet(CSS_buttonActive("images/controllers-04.png"))
self.ui.spaceMouseButton.setStyleSheet(CSS_button("images/controllers-01.png"))
self.ui.label_controller_info.setText(QCoreApplication.translate("MainWindow", u"CamBot 6D is compatible with any regular keyboard and mouse.\n\nNote: Does not work in fullscreen mode. Will display an overlay window that captures all mouse and keyboard input while setting waypoints. Can be activated via graphical user interface or Stream Deck MQTT remote.", None))
try:
with open(configIni, 'w') as f:
config.write(f)
except OSError as error:
print(sys.exc_info()[0])
def on_spaceMouseButton_clicked(self):
global controller
self.stop_controller_test()
#self.joystick_reinit()
controller = "spacemouse"
config.set('controllers', 'type', 'spacemouse')
self.ui.motionSelection.setCurrentIndex(spacemouse_motion)
self.on_motionSelection_changed(spacemouse_motion)
self.ui.wrapRotationCheckBox.setChecked(spacemouse_wrap_rotation)
self.ui.invertRollCheckBox.setChecked(spacemouse_invert_roll)
self.ui.invertPitchCheckBox.setChecked(spacemouse_invert_pitch)
self.ui.invertYawCheckBox.setChecked(spacemouse_invert_yaw)
self.on_wrapRotationCheckBox_changed(spacemouse_wrap_rotation)
self.on_invertRollCheckBox_changed(spacemouse_invert_roll)
self.on_invertPitchCheckBox_changed(spacemouse_invert_pitch)
self.on_invertYawCheckBox_changed(spacemouse_invert_yaw)
self.repopulate_controllers_dropdown()
self.ui.labelStreamDeck.setVisible(False)
self.ui.tableWidget.setVisible(True)
self.ui.controllerTestButton.setVisible(True)
self.ui.controllerTestButton.setEnabled(True)
self.ui.keyMapImage.setStyleSheet(u"QPushButton {\n"
" background-color: rgb(41, 46, 57);\n"
" border-radius: 0px; \n"
" background-image: url(images/spacemouse-map.png);\n"
"}")
self.ui.xBoxButton.setStyleSheet(CSS_button("images/controllers-02.png"))
self.ui.keyboardAndMouseButton.setStyleSheet(CSS_button("images/controllers-04.png"))
self.ui.spaceMouseButton.setStyleSheet(CSS_buttonActive("images/controllers-01.png"))
self.ui.label_controller_info.setText(QCoreApplication.translate("MainWindow", u"CamBot 6D is compatible with 3Dconnexion SpaceMouse Enterprise, Pro, and Compact 3D mice.\n\nNote: Works in fullscreen mode if combined with Stream Deck MQTT remote. Allows for analog control of all 6 axis, but has no decoupled control of individual axis.", None))
try:
with open(configIni, 'w') as f:
config.write(f)
except OSError as error:
print(sys.exc_info()[0])
def on_controllerUpdate_clicked(self):
self.repopulate_controllers_dropdown()
def on_controllerSelection_changed(self, i):
global controller_id
global controller_name
global joystick
global gamepad
print ("Current index",i,"selection changed ",self.ui.controllerSelection.currentText())
print("Count", pygame.joystick.get_count())
match controller:
case "xboxone": # We test for different values and print different messages
if i > 0 and i <= pygame.joystick.get_count():
config.set('controllers', 'xboxone_id', joystickUids[i-1])
config.set('controllers', 'xboxone_name', joystickNames[i-1])
gamepad = joystickUids[i-1]
elif i == 0:
config.set('controllers', 'xboxone_id', '')
config.set('controllers', 'xboxone_name', '')
gamepad = None
else:
config.set('controllers', 'xboxone_id', str(controller_id))
config.set('controllers', 'xboxone_name', str(controller_name))
gamepad = controller_id
case "spacemouse": # We test for different values and print different messages
if i > 0 and i <= pygame.joystick.get_count():
config.set('controllers', 'spacemouse_id', joystickUids[i-1])
config.set('controllers', 'spacemouse_name', joystickNames[i-1])
joystick = joystickUids[i-1]
elif i == 0:
config.set('controllers', 'spacemouse_id', '')
config.set('controllers', 'spacemouse_name', '')
joystick = None
else:
config.set('controllers', 'spacemouse_id', str(controller_id))
config.set('controllers', 'spacemouse_name', str(controller_name))
joystick = controller_id
case "keyboardandmouse":
self.ui.controllerSelection.setCurrentIndex(1)
try:
with open(configIni, 'w') as f:
config.write(f)
except OSError as error:
print(sys.exc_info()[0])
print('gamepad', gamepad)
print('joystick', joystick)
def on_hotkeyEnable_changed(self, i):
value = 'true'
if i == 0:
value = 'false'
self.F.stop_hotkey()
else:
self.F.start_hotkey()
config.set('main', 'hotkey', value )
try:
with open(configIni, 'w') as f:
config.write(f)
except OSError as error:
print(sys.exc_info()[0])
def on_wrapRotationCheckBox_changed(self, i):
global xboxone_wrap_rotation
global spacemouse_wrap_rotation
global keyboard_wrap_rotation
value = 'true'
valueBol = True
if i == 0:
value = 'false'
valueBol = False
match controller:
case "xboxone":
config.set('controllers', 'xboxone_wrap_rotation', value)
xboxone_wrap_rotation = valueBol
case "spacemouse":
config.set('controllers', 'spacemouse_wrap_rotation', value)
spacemouse_wrap_rotation = valueBol
case "keyboardandmouse":