aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2024-08-11 15:56:58 +0200
committerSébastien Dailly <sebastien@dailly.me>2024-08-11 15:56:58 +0200
commit6e9a435813870c964dd6b4d4d3bd65f02da6e2be (patch)
tree92cbad69d77d51f3f48b9a56b13b77eea85419ed
parent75ed856be70d0fbdd6aa92f503f98c7f7b9123b6 (diff)
Updated the connection between the application and the deviceHEADmaster
-rwxr-xr-xinterfaces/endpoint.py7
-rwxr-xr-xserial_conn.py1
2 files changed, 5 insertions, 3 deletions
diff --git a/interfaces/endpoint.py b/interfaces/endpoint.py
index 15356c2..2fbf792 100755
--- a/interfaces/endpoint.py
+++ b/interfaces/endpoint.py
@@ -100,13 +100,14 @@ class EndPoint(object):
self.queue.put((layout, title))
def send(self, data: list[dict[str, str]]):
- """ Send the data to the macropad
+ """ Send the data to the macropad. The data must be the representation
+ of a json element.
"""
if self.state != self.STATE_CONNECTED:
return
try:
- j = json.dumps( data )
- self.connection.write(bytes(j, "utf-8"))
+ j = json.JSONEncoder().encode( data ) + "\n"
+ self.connection.write(str.encode(j))
except Exception as e:
print("send error", e)
self.state = self.STATE_DISCONNECTED
diff --git a/serial_conn.py b/serial_conn.py
index a08543a..7925673 100755
--- a/serial_conn.py
+++ b/serial_conn.py
@@ -44,3 +44,4 @@ class SerialConnection(object):
""" Write into the connection.
Raise an exception if disconnected """
self.s.write(content)
+ self.s.write(bytes("\n", "utf-8"))