1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | # |
---|
4 | # Puzzlebox - Brainstorms - Configuration |
---|
5 | # |
---|
6 | # Copyright Puzzlebox Productions, LLC (2010) |
---|
7 | # |
---|
8 | # This code is released under the GNU Pulic License (GPL) version 2 |
---|
9 | # For more information please refer to http://www.gnu.org/copyleft/gpl.html |
---|
10 | # |
---|
11 | # Last Update: 2010.06.21 |
---|
12 | # |
---|
13 | ##################################################################### |
---|
14 | |
---|
15 | import os, sys |
---|
16 | import pygame |
---|
17 | |
---|
18 | ##################################################################### |
---|
19 | # General configuration |
---|
20 | ##################################################################### |
---|
21 | |
---|
22 | DEBUG = 1 |
---|
23 | |
---|
24 | CONFIGURATION_FILE_PATH = 'puzzlebox_brainstorms_configuration.ini' |
---|
25 | |
---|
26 | DISCRETE_CONTROL_COMMANDS = True |
---|
27 | |
---|
28 | DEFAULT_WINDOWS_BLUETOOTH_DEVICE = 'COM1' |
---|
29 | DEFAULT_LINUX_BLUETOOTH_DEVICE = '/dev/rfcomm0' |
---|
30 | |
---|
31 | ##################################################################### |
---|
32 | # Logging |
---|
33 | ##################################################################### |
---|
34 | |
---|
35 | LOG_LEVEL_DEBUG = 2 |
---|
36 | LOG_LEVEL_INFO = 1 |
---|
37 | LOG_LEVEL_ERROR = 0 |
---|
38 | LOG_LEVEL_DISABLE = -1 |
---|
39 | |
---|
40 | DEFAULT_LOG_LEVEL = LOG_LEVEL_DEBUG |
---|
41 | DEFAULT_LOGFILE = 'puzzlebox' |
---|
42 | |
---|
43 | LOGFILE_DIR = '/var/log/puzzlebox' |
---|
44 | LOGFILE_SUFFIX = '.log' |
---|
45 | LOGFILE_SUFFIX_DEBUG = '_debug.log' |
---|
46 | LOGFILE_SUFFIX_INFO = '_info.log' |
---|
47 | LOGFILE_SUFFIX_ERROR = '_error.log' |
---|
48 | |
---|
49 | SPLIT_LOGFILES = False |
---|
50 | |
---|
51 | #BRAINSTORMS_LOGFILE = 'brainstorms' |
---|
52 | |
---|
53 | |
---|
54 | ##################################################################### |
---|
55 | # Network addresses |
---|
56 | ##################################################################### |
---|
57 | |
---|
58 | SERVER_INTERFACE = '' # listen on all of server's network interfaces |
---|
59 | #SERVER_HOST = '172.16.1.1' |
---|
60 | SERVER_HOST = '127.0.0.1' # localhost |
---|
61 | SERVER_PORT = 8194 |
---|
62 | |
---|
63 | THINKGEAR_SERVER_HOST = '127.0.0.1' |
---|
64 | THINKGEAR_SERVER_PORT = 13854 |
---|
65 | |
---|
66 | |
---|
67 | ##################################################################### |
---|
68 | # Remote Control configuration |
---|
69 | ##################################################################### |
---|
70 | |
---|
71 | if (sys.platform == 'win32'): |
---|
72 | BLUETOOTH_DEVICE = DEFAULT_WINDOWS_BLUETOOTH_DEVICE |
---|
73 | else: |
---|
74 | BLUETOOTH_DEVICE = DEFAULT_LINUX_BLUETOOTH_DEVICE |
---|
75 | |
---|
76 | MOTORS_MOUNTED_BACKWARDS = True |
---|
77 | MOTOR_PORT_RIGHT = 'a' |
---|
78 | MOTOR_PORT_LEFT = 'b' |
---|
79 | DEFAULT_RC_COMMAND = 'test_drive' |
---|
80 | |
---|
81 | |
---|
82 | ##################################################################### |
---|
83 | # Server configuration |
---|
84 | ##################################################################### |
---|
85 | |
---|
86 | MAX_COMPONENTS = 16 |
---|
87 | |
---|
88 | |
---|
89 | ##################################################################### |
---|
90 | # Client configuration |
---|
91 | ##################################################################### |
---|
92 | |
---|
93 | MAX_CONNECTION_ATTEMPTS = 5 |
---|
94 | HEALTH_CHECK_CONNECTION_ATTEMPTS = 5 |
---|
95 | NO_REPLY_WAIT = 10 # how many seconds before considering a component dead |
---|
96 | |
---|
97 | |
---|
98 | ##################################################################### |
---|
99 | # ThinkGear Connect configuration |
---|
100 | ##################################################################### |
---|
101 | |
---|
102 | THINKGEAR_AUTHORIZATION_REQUEST = { \ |
---|
103 | "appName": "Puzzlebox Brainstorms", \ |
---|
104 | "appKey": "2e285d7bd5565c0ea73e7e265c73f0691d932408" |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | ##################################################################### |
---|
109 | # Client Interface configuration |
---|
110 | ##################################################################### |
---|
111 | |
---|
112 | DISPLAY_WINDOW_X_COORDINATE = 0 |
---|
113 | DISPLAY_WINDOW_Y_COORDINATE = 0 |
---|
114 | DISPLAY_WINDOW_X_DIMENSION = 254 |
---|
115 | DISPLAY_WINDOW_Y_DIMENSION = 424 |
---|
116 | |
---|
117 | #WINDOW_BACKGROUND_COLOR = (255,255,255) # white background |
---|
118 | #WINDOW_BACKGROUND_COLOR = (128,128,128) # grey background |
---|
119 | #WINDOW_BACKGROUND_COLOR = (64,64,64) # dark grek background |
---|
120 | WINDOW_BACKGROUND_COLOR = (0,0,0) # black background |
---|
121 | |
---|
122 | IMAGE_DIRECTORY = os.path.join(os.getcwd(), 'images') |
---|
123 | |
---|
124 | # Keyboard key reference at http://www.pygame.org/docs/ref/key.html#pygame.key |
---|
125 | BUTTON_LAYOUT = { \ |
---|
126 | |
---|
127 | 'left': { \ |
---|
128 | 'command': 'turn_left', \ |
---|
129 | 'active': False, \ |
---|
130 | 'button_image': '1-upper_left-white.png', \ |
---|
131 | 'activated_image': '1-upper_left-orange.png', \ |
---|
132 | 'image_x': 0, \ |
---|
133 | 'image_y': 0, \ |
---|
134 | 'match_keys': [pygame.K_LEFT, pygame.K_a, pygame.K_q] |
---|
135 | }, \ |
---|
136 | |
---|
137 | 'forward': { \ |
---|
138 | 'command': 'drive_forward', \ |
---|
139 | 'active': False, \ |
---|
140 | 'button_image': '2-up-white.png', \ |
---|
141 | 'activated_image': '2-up-orange.png', \ |
---|
142 | 'image_x': 98, \ |
---|
143 | 'image_y': 0, \ |
---|
144 | 'match_keys': [pygame.K_UP, pygame.K_w] |
---|
145 | }, \ |
---|
146 | |
---|
147 | 'right': { \ |
---|
148 | 'command': 'turn_right', \ |
---|
149 | 'active': False, \ |
---|
150 | 'button_image': '3-upper_right-white.png', \ |
---|
151 | 'activated_image': '3-upper_right-orange.png', \ |
---|
152 | 'image_x': 157, \ |
---|
153 | 'image_y': 0, \ |
---|
154 | 'match_keys': [pygame.K_RIGHT, pygame.K_d, pygame.K_e] |
---|
155 | }, \ |
---|
156 | |
---|
157 | 'reverse_left': { \ |
---|
158 | 'command': 'turn_left_in_reverse', \ |
---|
159 | 'active': False, \ |
---|
160 | 'button_image': '7-lower_left-white.png', \ |
---|
161 | 'activated_image': '7-lower_left-orange.png', \ |
---|
162 | 'image_x': 0, \ |
---|
163 | 'image_y': 220, \ |
---|
164 | 'match_keys': [pygame.K_z] |
---|
165 | }, \ |
---|
166 | |
---|
167 | 'reverse': { \ |
---|
168 | 'command': 'drive_reverse', \ |
---|
169 | 'active': False, \ |
---|
170 | 'button_image': '8-down-white.png', \ |
---|
171 | 'activated_image': '8-down-orange.png', \ |
---|
172 | 'image_x': 98, \ |
---|
173 | 'image_y': 220, \ |
---|
174 | 'match_keys': [pygame.K_DOWN, pygame.K_s, pygame.K_x] |
---|
175 | }, \ |
---|
176 | |
---|
177 | 'reverse_right': { \ |
---|
178 | 'command': 'turn_right_in_reverse', \ |
---|
179 | 'active': False, \ |
---|
180 | 'button_image': '9-lower_right-white.png', \ |
---|
181 | 'activated_image': '9-lower_right-orange.png', \ |
---|
182 | 'image_x': 157, \ |
---|
183 | 'image_y': 220, \ |
---|
184 | 'match_keys': [pygame.K_PAGEDOWN, pygame.K_c] |
---|
185 | }, \ |
---|
186 | |
---|
187 | } # BUTTON_LAYOUT |
---|
188 | |
---|
189 | |
---|
190 | ##################################################################### |
---|
191 | |
---|
192 | FLASH_POLICY_FILE_REQUEST = \ |
---|
193 | '<policy-file-request/>%c' % 0 # NULL byte termination |
---|
194 | FLASH_SOCKET_POLICY_FILE = '''<?xml version="1.0"?> |
---|
195 | <!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd"> |
---|
196 | <cross-domain-policy> |
---|
197 | <site-control permitted-cross-domain-policies="all" /> |
---|
198 | <allow-access-from domain="*" to-ports="%i" /> |
---|
199 | </cross-domain-policy>%c''' % (THINKGEAR_SERVER_PORT, 0) |
---|
200 | |
---|
201 | ##################################################################### |
---|
202 | # Configuration File Parser |
---|
203 | ##################################################################### |
---|
204 | |
---|
205 | if os.path.exists(CONFIGURATION_FILE_PATH): |
---|
206 | |
---|
207 | file = open(CONFIGURATION_FILE_PATH, 'r') |
---|
208 | |
---|
209 | for line in file.readlines(): |
---|
210 | line = line.strip() |
---|
211 | if len(line) == 0: |
---|
212 | continue |
---|
213 | if line[0] == '#': |
---|
214 | continue |
---|
215 | if line.find('=') == -1: |
---|
216 | continue |
---|
217 | try: |
---|
218 | exec line |
---|
219 | except: |
---|
220 | if DEBUG: |
---|
221 | print "Error recognizing configuration option:", |
---|
222 | print line |
---|
223 | |
---|