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 98659c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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
14 changes: 11 additions & 3 deletions owo_suit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# pyright: reportMissingImports=false
from OWOGame import OWO, Sensation, SensationsFactory, Muscle, MicroSensation, ConnectionState
from pythonosc import dispatcher
import time
import clr
clr.AddReference('./owo/OWO')
from OWOGame import OWO, Sensation, SensationsFactory, Muscle, MicroSensation, ConnectionState

# Sensations that are predefined
# 'Ball', 'GunRecoil', 'Bleed', 'Insvects', 'Wind', 'Dart', 'MachineGunRecoil', 'Punch', 'DaggerEntry', 'DaggerMovement', 'FastDriving', 'IdleSpeed', 'InsectBites', 'ShotEntry', 'ShotExit', 'Shot', 'Dagger', 'Hug', 'HeartBeat'
Expand Down 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 98659c3

Please sign in to comment.