diff options
author | Maximilien Cuony <maximilien@theglu.org> | 2016-09-11 12:33:01 +0200 |
---|---|---|
committer | Maximilien Cuony <maximilien@theglu.org> | 2016-09-11 12:33:01 +0200 |
commit | 3e932df42dce7d9c44e6c71112951eb64abb8374 (patch) | |
tree | 39b716f01a1583ee79a41764a08c3f47be0d2eb4 | |
parent | 0891138200bb8f400bf9e0d4abaf20793d3f7b57 (diff) | |
download | glutte-serial-web-3e932df42dce7d9c44e6c71112951eb64abb8374.tar.gz glutte-serial-web-3e932df42dce7d9c44e6c71112951eb64abb8374.tar.bz2 glutte-serial-web-3e932df42dce7d9c44e6c71112951eb64abb8374.zip |
Last 1000 lines are displayed
-rwxr-xr-x | glutte_serial_web.py | 6 | ||||
-rw-r--r-- | serialrx.py | 11 | ||||
-rw-r--r-- | templates/index.html | 2 |
3 files changed, 15 insertions, 4 deletions
diff --git a/glutte_serial_web.py b/glutte_serial_web.py index 016c8da..00d131c 100755 --- a/glutte_serial_web.py +++ b/glutte_serial_web.py @@ -37,7 +37,7 @@ ser = serialrx.SerialRX() @app.route('/') def index(): - return render_template('index.html') + return render_template('index.html', last_lines=ser.get_last_lines()) @sockets.route('/stream') @@ -50,7 +50,7 @@ def stream(socket): while not socket.closed: # Force to check if the client is still here try: - with Timeout(0.1, False): + with Timeout(0.05, False): socket.receive() except: pass @@ -59,7 +59,7 @@ def stream(socket): socket.send(line) except IndexError: pass - sleep(0.1) + sleep(0.05) except: raise finally: diff --git a/serialrx.py b/serialrx.py index 37855f6..11a91de 100644 --- a/serialrx.py +++ b/serialrx.py @@ -29,6 +29,7 @@ import collections SERIALPORT = "/dev/ttyACM0" BAUDRATE = 9600 LINES_TO_KEEP = 200 +LAST_LINE_TO_KEEP = 1000 class SerialRX(threading.Thread): @@ -45,6 +46,7 @@ class SerialRX(threading.Thread): self.clients = [] self.line_accumulator = [] + self.last_lines = [] print("Serial port ready") @@ -63,6 +65,12 @@ class SerialRX(threading.Thread): if len(queue) > LINES_TO_KEEP: queue.popleft() + + self.last_lines.append("".join(self.line_accumulator)) + + if len(self.last_lines) > LAST_LINE_TO_KEEP: + self.last_lines.pop(0) + except: raise finally: @@ -73,6 +81,9 @@ class SerialRX(threading.Thread): self.event_stop.set() self.join() + def get_last_lines(self): + return self.last_lines + def register_client(self): self.data_lock.acquire() try: diff --git a/templates/index.html b/templates/index.html index 0cf5a09..c8c773b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,7 +7,7 @@ </head> <body> <h1>Ceci n'est pas une Glutte</h1> - <pre id="output"></pre> + <pre id="output">{% for l in last_lines %}{{l}}{% endfor %}</pre> <script> var output = document.getElementById('output'); |