Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serial connection on Linux #85

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions BabbleApp/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from colorama import Fore
from config import BabbleConfig, BabbleSettingsConfig
from utils.misc_utils import get_camera_index_by_name, list_camera_names
from utils.misc_utils import get_camera_index_by_name, list_camera_names, is_nt
from enum import Enum
import sys

Expand Down Expand Up @@ -86,7 +86,8 @@ def run(self):
self.config.capture_source is not None
and self.config.capture_source != ""
):
if "COM" in str(self.config.capture_source):
ports = ("COM", "/dev/ttyACM")
if any(x in str(self.config.capture_source) for x in ports):
if (
self.serial_connection is None
or self.camera_status == CameraState.DISCONNECTED
Expand Down Expand Up @@ -150,7 +151,7 @@ def run(self):
if should_push and not self.capture_event.wait(timeout=0.02):
continue
if self.config.capture_source is not None:
ports = ("COM", "/dev/tty")
ports = ("COM", "/dev/ttyACM")
if any(x in str(self.config.capture_source) for x in ports):
self.get_serial_camera_picture(should_push)
else:
Expand Down Expand Up @@ -266,17 +267,19 @@ def start_serial_connection(self, port):
rate = 115200 if sys.platform == "darwin" else 3000000 # Higher baud rate not working on macOS
conn = serial.Serial(baudrate=rate, port=port, xonxoff=False, dsrdtr=False, rtscts=False)
# Set explicit buffer size for serial.
conn.set_buffer_size(rx_size=BUFFER_SIZE, tx_size=BUFFER_SIZE)
if is_nt:
conn.set_buffer_size(rx_size=BUFFER_SIZE, tx_size=BUFFER_SIZE)

print(
f'{Fore.CYAN}[{lang._instance.get_string("log.info")}] {lang._instance.get_string("info.ETVRConnected")} {port}{Fore.RESET}'
)
self.serial_connection = conn
self.camera_status = CameraState.CONNECTED
except Exception:
except Exception as e:
print(
f'{Fore.CYAN}[{lang._instance.get_string("log.info")}] {lang._instance.get_string("info.ETVRFailiure")} {port}{Fore.RESET}'
)
print(e)
self.camera_status = CameraState.DISCONNECTED

def clamp_max_res(self, image: MatLike) -> MatLike:
Expand Down
4 changes: 2 additions & 2 deletions BabbleApp/camera_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def render(self, window, event, values):
# if value not in self.camera_list:
# self.config.capture_source = value
# if "COM" not in value:
ports = ("COM", "/dev/tty")
ports = ("COM", "/dev/ttyACM")
if any(x in str(value) for x in ports):
self.config.capture_source = value
else:
Expand All @@ -344,7 +344,7 @@ def render(self, window, event, values):
and ".mp4" not in value
and "udp" not in value
and "COM" not in value
and "/dev/tty" not in value
and "/dev/ttyACM" not in value
and value not in self.camera_list
): # If http is not in camera address, add it.
self.config.capture_source = (
Expand Down