Skip to content

Commit

Permalink
Added retry logic to prevent suit from disconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
shadorki committed Sep 3, 2023
1 parent 85b1293 commit 113e4df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 76 deletions.
74 changes: 0 additions & 74 deletions .github/workflows/main.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
tags:
- "*.*.*"
- '*.*.*-beta-*'

defaults:
run:
Expand Down
12 changes: 10 additions & 2 deletions owo_suit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def ping_muscles(self) -> None:

def watch(self) -> None:
while True:
if not self.is_connected():
self.retry_connect()
if len(self.active_muscles) > 0:
OWO.Send(self.touch_sensation, list(self.active_muscles))
print("\033[SSending sensation to: ", self.active_muscles)
Expand Down Expand Up @@ -73,16 +75,22 @@ def map_parameters(self, dispatcher: dispatcher.Dispatcher) -> None:
def connect(self) -> bool:
if self.owo_ip != "":
OWO.Connect(self.owo_ip)
if OWO.ConnectionState == ConnectionState.Connected:
if self.is_connected():
return True
OWO.AutoConnect()
return self.is_connected()

def is_connected(self) -> bool:
return OWO.ConnectionState == ConnectionState.Connected

def init(self) -> None:
def retry_connect(self) -> None:
ok = self.connect()
while not ok:
print(
f'Failed to connect to suit, trying again... IP: {self.owo_ip or "N/A"}')
ok = self.connect()
time.sleep(1)

def init(self) -> None:
self.retry_connect()
print("Successfully connected to OWO suit!")

0 comments on commit 113e4df

Please sign in to comment.