diff options
author | Maximilien Cuony <maximilien@theglu.org> | 2016-09-12 17:53:28 +0200 |
---|---|---|
committer | Maximilien Cuony <maximilien@theglu.org> | 2016-09-12 17:53:28 +0200 |
commit | 2e679e549baca6d3573dacaa925672189b5e034a (patch) | |
tree | 44a6534448f58e5ed6054683ff2d892af4ff2b3f | |
parent | 259bef01537a56ee6d484d0b6958a350af3045eb (diff) | |
download | glutte-serial-web-2e679e549baca6d3573dacaa925672189b5e034a.tar.gz glutte-serial-web-2e679e549baca6d3573dacaa925672189b5e034a.tar.bz2 glutte-serial-web-2e679e549baca6d3573dacaa925672189b5e034a.zip |
Add a configuration file
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | config.py.dist | 4 | ||||
-rw-r--r-- | serialrx.py | 13 |
4 files changed, 13 insertions, 8 deletions
@@ -4,3 +4,4 @@ lib pip-selfcheck.json *.pyc .ropeproject +config.py @@ -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: |