From 2e679e549baca6d3573dacaa925672189b5e034a Mon Sep 17 00:00:00 2001 From: Maximilien Cuony Date: Mon, 12 Sep 2016 17:53:28 +0200 Subject: Add a configuration file --- .gitignore | 1 + README.md | 3 +++ config.py.dist | 4 ++++ serialrx.py | 13 +++++-------- 4 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 config.py.dist diff --git a/.gitignore b/.gitignore index 2f0f98c..216734f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ lib pip-selfcheck.json *.pyc .ropeproject +config.py diff --git a/README.md b/README.md index 9b8e271..51bfea7 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ How to setup 1. Install virtualenv 2. Clone this repo 3. Setup a new virtualenv + 4. Copy config.py.dist to config.py. Edit variables inside Step-by-step @@ -13,3 +14,5 @@ Step-by-step virtualenv . source bin/activate pip install -r requirements.txt + cp config.py.dist config.py + vim config.py diff --git a/config.py.dist b/config.py.dist new file mode 100644 index 0000000..8edb5d8 --- /dev/null +++ b/config.py.dist @@ -0,0 +1,4 @@ +SERIALPORT = "/dev/ttyUSB0" +BAUDRATE = 9600 +LINES_TO_KEEP = 200 +LAST_LINE_TO_KEEP = 1000 diff --git a/serialrx.py b/serialrx.py index 11a91de..77a7d0f 100644 --- a/serialrx.py +++ b/serialrx.py @@ -26,10 +26,7 @@ import serial import threading import collections -SERIALPORT = "/dev/ttyACM0" -BAUDRATE = 9600 -LINES_TO_KEEP = 200 -LAST_LINE_TO_KEEP = 1000 +import config class SerialRX(threading.Thread): @@ -37,8 +34,8 @@ class SerialRX(threading.Thread): def __init__(self): threading.Thread.__init__(self) - print("Open Serial on {} at {}".format(SERIALPORT, BAUDRATE)) - self.ser = serial.Serial(SERIALPORT, baudrate=BAUDRATE) + print("Open Serial on {} at {}".format(config.SERIALPORT, config.BAUDRATE)) + self.ser = serial.Serial(config.SERIALPORT, baudrate=config.BAUDRATE) self.event_stop = threading.Event() @@ -63,12 +60,12 @@ class SerialRX(threading.Thread): for queue in self.clients: queue.append("".join(self.line_accumulator)) - if len(queue) > LINES_TO_KEEP: + if len(queue) > config.LINES_TO_KEEP: queue.popleft() self.last_lines.append("".join(self.line_accumulator)) - if len(self.last_lines) > LAST_LINE_TO_KEEP: + if len(self.last_lines) > config.LAST_LINE_TO_KEEP: self.last_lines.pop(0) except: -- cgit v1.2.3