diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2025-05-04 16:47:24 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2025-05-05 17:36:00 +0200 |
commit | c15dc5a0b4f061de73b5d97fa09b311bdb976743 (patch) | |
tree | f42cab19f9059a1f39452a5b147b8b43c8926f7e | |
parent | 98963f3f4ff313a0ec180572c55ab478c4b03f56 (diff) |
Updated the logic in the endpoint interface
-rwxr-xr-x | client.py | 4 | ||||
-rwxr-xr-x | interfaces/endpoint.py | 10 |
2 files changed, 10 insertions, 4 deletions
@@ -37,11 +37,11 @@ elif config.has_section("connection.serial"): # Connect to the endpoint right now
component.provideAdapter(endpoint.EndPoint)
s = component.queryAdapter(conn, endpoint.IEndpoint)
-s.connect()
if args.layer is not None:
print(args.layer)
s.queue = Queue()
+ s.connect()
with open(args.layer, "r") as json_file:
json_data = json_file.read()
j = json.loads(json_data)
@@ -58,6 +58,7 @@ class Conn(Thread): self.queue = queue
self.in_queue = Queue()
s.queue = self.in_queue
+ s.connect()
def run(self):
@@ -76,7 +77,6 @@ class Conn(Thread): s.connect()
continue
-
s.fetch()
while not self.in_queue.empty():
diff --git a/interfaces/endpoint.py b/interfaces/endpoint.py index 2fbf792..2d77b66 100755 --- a/interfaces/endpoint.py +++ b/interfaces/endpoint.py @@ -65,10 +65,17 @@ class EndPoint(object): return self.state != self.STATE_DISCONNECTED
def connect(self):
+ state = self.state
try:
self.connection.connect()
self.state = self.STATE_CONNECTED
component.handle(Debug("Connected"))
+ if state == self.STATE_DISCONNECTED:
+ # This is the first connection
+ # Otherwise the state should be STATE_CONNECTING
+ # Initialize with the default layer
+ self.queue.put ( ("default", None) )
+
except Exception as e:
print(e)
self.state = self.STATE_DISCONNECTED
@@ -90,7 +97,6 @@ class EndPoint(object): # If we do not have any entry from the macropad, just return
return
- print("recv", received)
layout = str(received, "utf-8").strip()
desktop = component.queryUtility(desktopEvent.IDesktop)
if desktop is not None:
@@ -100,7 +106,7 @@ class EndPoint(object): self.queue.put((layout, title))
def send(self, data: list[dict[str, str]]):
- """ Send the data to the macropad. The data must be the representation
+ """ Send the data to the endpoint. The data must be the representation
of a json element.
"""
if self.state != self.STATE_CONNECTED:
|