From 113e4df83875d4afdc446a815a3f3c1c2dbe5ea5 Mon Sep 17 00:00:00 2001 From: Uzair Ashraf Date: Sun, 3 Sep 2023 10:54:28 -0700 Subject: [PATCH] Added retry logic to prevent suit from disconnecting --- .github/workflows/main.yml | 74 ----------------------------------- .github/workflows/release.yml | 1 + owo_suit.py | 12 +++++- 3 files changed, 11 insertions(+), 76 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index d2cd377..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Release -on: - push: - tags: - - "*.*.*" - -defaults: - run: - shell: bash - -jobs: - Build: - name: Build release - runs-on: windows-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: 3.10.9 - - - name: Install Python dependencies - run: | - python -m pip install --upgrade pip pyinstaller - pip install -r requirements.txt - - name: Build with pyinstaller - run: pyinstaller --hidden-import=clr --add-binary "./owo/OWO.dll;owo" --onefile --distpath ./build --name=vrc-owo-suit main.py - - - name: Deploy EXE - uses: actions/upload-artifact@v3 - with: - name: vrc-owo-suit - path: ./build/vrc-owo-suit.exe - if-no-files-found: error - - - name: Deploy Unity Package - uses: actions/upload-artifact@v3 - with: - name: OWO_Suit - path: ./OWO_Suit.unitypackage - if-no-files-found: error - - - release: - needs: build - permissions: - contents: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/download-artifact@v3 - with: - name: vrc-owo-suit - path: artifact/vrc-owo-suit - - - uses: actions/download-artifact@v3 - with: - name: OWO_Suit - path: artifact/OWO_Suit - - - name: Display structure of downloaded files - run: ls -R - working-directory: artifact - - - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - files: | - artifact/vrc-owo-suit/vrc-owo-suit.exe - artifact/OWO_Suit/OWO_Suit.unitypackage diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4d00cf8..e21e0c6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,6 +3,7 @@ on: push: tags: - "*.*.*" + - '*.*.*-beta-*' defaults: run: diff --git a/owo_suit.py b/owo_suit.py index 6595113..aee336f 100644 --- a/owo_suit.py +++ b/owo_suit.py @@ -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) @@ -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!")