-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparser_main.py
66 lines (59 loc) · 2.56 KB
/
parser_main.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
############ Logitech F310 Gamepad Controller Main - parser_main.py ##########
# Original Author: John Zeller
# Description: Parser_Main polls the data in a python dictionary to check the
# states of several buttons coming from parser_core.py. Once it
# reads these states, it will display them for reference on the
# terminal it was launched in
### NOTES #####################################################################
# 1) LEAVE MODE 'OFF' there is no support in parser_main.py for MODE ON
# 2) Naturally the gamepad sends the following values:
# LJ/RJ - Down: 0-127
# LJ/RJ - Up: 255-128
# LJ/RJ - Left: 255-128
# LJ/RJ - Right: 0-127
###############################################################################
### Buttons/Joys Represented: #################################################
# A, B, X, Y, RB, LB, LJButton, RJButton, Back, Start, Middle
# RT, LT, LeftJoy, RightJoy, Left, Right, Up, Down
###############################################################################
import sys
sys.path.append("./core")
import threading
from bus import *
from parser_core import *
from gui_main import *
import Tkinter as tk # Native Python GUI Framework
import time
class ParserMain(threading.Thread):
def __init__(self):
# Create bus object
self.bus = Bus()
# Create a dictionary to be used to keep states from joy_core
self.states = { 'A':0, 'B':0, 'X':0, 'Y':0, \
'Back':0, 'Start':0, 'Middle':0, \
'Left':0, 'Right':0, 'Up':0, 'Down':0, \
'LB':0, 'RB':0, 'LT':0, 'RT':0, \
'LJ/Button':0, 'RJ/Button':0, \
'LJ/Left':0, 'LJ/Right':0, 'LJ/Up':0, 'LJ/Down':0, \
'RJ/Left':0, 'RJ/Right':0, 'RJ/Up':0, 'RJ/Down':0, \
'Byte0':0, 'Byte1':0, 'Byte2':0, 'Byte3':0, \
'Byte4':0, 'Byte5':0, 'Byte6':0, 'Byte7':0, \
'Byte0/INT':0, 'Byte1/INT':0, 'Byte2/INT':0, \
'Byte3/INT':0, 'Byte4/INT':0, 'Byte5/INT':0, \
'Byte6/INT':0, 'Byte7/INT':0}
# Launch Parser_Core as a seperate thread to parse the gamepad
self.parsercore = ParserCore(self.bus, self.states)
self.parsercore.start()
def run(self):
# Description: Polls the gamepad states and displays their current
# values on a simple Tkinter GUI
# Launch simple GUI with Tkinter (Native GUI on Python)
gui = GUI(self.states) # Create GUI object
try:
gui.mainloop() # Launch GUI object into the main loop
except AttributeError as ex: # If mainloop is broken then sys.quit
print "Found AttributeError, closing debugger"
# Now Exit
if __name__ == '__main__':
parser = ParserMain()
parser.run()