aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <jaseg@jaseg.net>2014-03-07 03:44:29 +0100
committerjaseg <jaseg@jaseg.net>2014-03-07 03:44:29 +0100
commit39884b49ed4e9917ef7d64962070c68f6908fb5f (patch)
tree44ba730bd8723ed208ff583cdf20e3c418f9749e
parentd8fba4ec52a8c62ebf31ce9f9ead41b175b92b8e (diff)
downloadmatelight-39884b49ed4e9917ef7d64962070c68f6908fb5f.tar.gz
matelight-39884b49ed4e9917ef7d64962070c68f6908fb5f.tar.bz2
matelight-39884b49ed4e9917ef7d64962070c68f6908fb5f.zip
default scrolling works now
-rwxr-xr-xhost/server.py29
1 files changed, 25 insertions, 4 deletions
diff --git a/host/server.py b/host/server.py
index a8be98b..b942af4 100755
--- a/host/server.py
+++ b/host/server.py
@@ -13,10 +13,8 @@ import numpy as np
from matelight import sendframe, DISPLAY_WIDTH, DISPLAY_HEIGHT, FRAME_SIZE
-
UDP_TIMEOUT = 3.0
-
class COLOR(Structure):
_fields_ = [('r', c_uint8), ('g', c_uint8), ('b', c_uint8), ('a', c_uint8)]
@@ -193,6 +191,10 @@ def udp_sub_loop():
break
def tcp_sub_loop():
+ """
+ Send as many frames as there are texts in the buffer until the text deque
+ is empty.
+ """
while True:
next_frame = tserver.get_next_frame()
if next_frame is not None:
@@ -200,14 +202,33 @@ def tcp_sub_loop():
else:
break
+class MateLightDefaultScroller():
+ def __init__(self, *args, **kwargs):
+ # A deque for the texts, contains a tuple of the form (text, width, height)
+ self.text_deque = deque(maxlen=32)
+ self.current_text = None
+
+ def get_next_frame(self):
+ if self.current_text is None or self.i > self.current_text[1][0]:
+ self.current_text = None
+ text = next(defaulttexts).text
+ self.current_text = (text, compute_text_bounds(text))
+ self.i = -DISPLAY_WIDTH
+
+ frame = render_text(self.current_text[0], self.i)
+ self.i += 1
+ return frame
+
+
if __name__ == '__main__':
+ print('\033[?1049h'+'\n'*9)
+ default_scroller = MateLightDefaultScroller()
while True:
udp_sub_loop()
tcp_sub_loop()
+ sendframe(default_scroller.get_next_frame())
-
def bla():
- print('\033[2J'+'\n'*9)
while True:
if current_entry.entrytype == 'text':
if scroll(current_entry.text):