source: remote_control/puzzlebox_brainstorms_configuration.py @ 57

Last change on this file since 57 was 57, checked in by sc, 11 years ago

client_thinkgear:

  • ThinkGear? authorization added
  • response processing added

configuration:

  • comment/whitespace cleanup

server_thinkgear:

File size: 6.2 KB
RevLine 
[5]1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Puzzlebox - Brainstorms - Configuration
5#
[31]6# Copyright Puzzlebox Productions, LLC (2010)
[5]7#
[31]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
[5]10#
[55]11# Last Update: 2010.06.21
[5]12#
13#####################################################################
14
[43]15import os, sys
[27]16import pygame
[12]17
[5]18#####################################################################
19# General configuration
20#####################################################################
21
22DEBUG = 1
23
[45]24CONFIGURATION_FILE_PATH = 'puzzlebox_brainstorms_configuration.ini'
25
[43]26DISCRETE_CONTROL_COMMANDS = True
[42]27
[45]28DEFAULT_WINDOWS_BLUETOOTH_DEVICE = 'COM1'
29DEFAULT_LINUX_BLUETOOTH_DEVICE = '/dev/rfcomm0'
30
[5]31#####################################################################
32# Logging
33#####################################################################
34
35LOG_LEVEL_DEBUG = 2
36LOG_LEVEL_INFO = 1
37LOG_LEVEL_ERROR = 0
38LOG_LEVEL_DISABLE = -1
39
40DEFAULT_LOG_LEVEL = LOG_LEVEL_DEBUG
41DEFAULT_LOGFILE = 'puzzlebox'
42
43LOGFILE_DIR = '/var/log/puzzlebox'
44LOGFILE_SUFFIX = '.log'
45LOGFILE_SUFFIX_DEBUG = '_debug.log'
46LOGFILE_SUFFIX_INFO = '_info.log'
47LOGFILE_SUFFIX_ERROR = '_error.log'
48
49SPLIT_LOGFILES = False
50
[23]51#BRAINSTORMS_LOGFILE = 'brainstorms'
[5]52
53
54#####################################################################
55# Network addresses
56#####################################################################
57
[26]58SERVER_INTERFACE = '' # listen on all of server's network interfaces
[44]59#SERVER_HOST = '172.16.1.1'
[42]60SERVER_HOST = '127.0.0.1' # localhost
[5]61SERVER_PORT = 8194
62
[48]63THINKGEAR_SERVER_HOST = '127.0.0.1'
64THINKGEAR_SERVER_PORT = 13854
[5]65
[48]66
[5]67#####################################################################
68# Remote Control configuration
69#####################################################################
70
[43]71if (sys.platform == 'win32'):
[45]72        BLUETOOTH_DEVICE = DEFAULT_WINDOWS_BLUETOOTH_DEVICE
[43]73else:
[45]74        BLUETOOTH_DEVICE = DEFAULT_LINUX_BLUETOOTH_DEVICE
[43]75
[5]76MOTORS_MOUNTED_BACKWARDS = True
77MOTOR_PORT_RIGHT = 'a'
78MOTOR_PORT_LEFT = 'b'
[7]79DEFAULT_RC_COMMAND = 'test_drive'
[5]80
81
82#####################################################################
[6]83# Server configuration
[5]84#####################################################################
85
[6]86MAX_COMPONENTS = 16
[5]87
88
[6]89#####################################################################
90# Client configuration
91#####################################################################
[5]92
93MAX_CONNECTION_ATTEMPTS = 5
94HEALTH_CHECK_CONNECTION_ATTEMPTS = 5
95NO_REPLY_WAIT = 10 # how many seconds before considering a component dead
96
[11]97
98#####################################################################
[48]99# ThinkGear Connect configuration
100#####################################################################
101
102THINKGEAR_AUTHORIZATION_REQUEST = { \
103        "appName": "Puzzlebox Brainstorms", \
104        "appKey": "2e285d7bd5565c0ea73e7e265c73f0691d932408"
105        }
106
107
108#####################################################################
[12]109# Client Interface configuration
[11]110#####################################################################
111
112DISPLAY_WINDOW_X_COORDINATE = 0
113DISPLAY_WINDOW_Y_COORDINATE = 0
[21]114DISPLAY_WINDOW_X_DIMENSION = 254
115DISPLAY_WINDOW_Y_DIMENSION = 424
[11]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
120WINDOW_BACKGROUND_COLOR = (0,0,0)       # black background
121
122IMAGE_DIRECTORY = os.path.join(os.getcwd(), 'images')
123
[27]124# Keyboard key reference at http://www.pygame.org/docs/ref/key.html#pygame.key
[18]125BUTTON_LAYOUT = { \
[27]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
[45]189
190#####################################################################
[57]191# Flash socket policy handling
192#####################################################################
[55]193
[56]194FLASH_POLICY_FILE_REQUEST = \
195        '<policy-file-request/>%c' % 0 # NULL byte termination
[55]196FLASH_SOCKET_POLICY_FILE = '''<?xml version="1.0"?>
197<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
198<cross-domain-policy>
[56]199   <site-control permitted-cross-domain-policies="all" />
[55]200   <allow-access-from domain="*" to-ports="%i" />
[56]201</cross-domain-policy>%c''' % (THINKGEAR_SERVER_PORT, 0)
[55]202
[57]203
[55]204#####################################################################
[45]205# Configuration File Parser
206#####################################################################
207
208if os.path.exists(CONFIGURATION_FILE_PATH):
209       
210        file = open(CONFIGURATION_FILE_PATH, 'r')
211       
212        for line in file.readlines():
213                line = line.strip()
214                if len(line) == 0:
215                        continue
216                if line[0] == '#':
217                        continue
218                if line.find('=') == -1:
219                        continue
220                try:
221                        exec line
222                except:
223                        if DEBUG:
224                                print "Error recognizing configuration option:",
225                                print line
226
Note: See TracBrowser for help on using the repository browser.