Skip to content

Commit

Permalink
Finished mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
shadorki committed Sep 24, 2023
1 parent 0fc5f0e commit dfa346b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def update(self, key: str, nextValue):
def read_config_from_disk(self):
appdata_path = os.environ.get('LOCALAPPDATA')
app_directory = os.path.join(appdata_path, self.APP_NAME)
print(app_directory)
os.makedirs(app_directory, exist_ok=True)
config_path = os.path.join(app_directory, 'config.json')
if os.path.exists(config_path):
Expand Down
25 changes: 15 additions & 10 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Element(Enum):
CONNECT_BUTTON = auto()
SAVE_SETTINGS_BUTTON = auto()
CLEAR_CONSOLE_BUTTON = auto()
TOGGLES_INTERACTIONS_BUTTON = auto()
CONNECT_ON_STARTUP_CHECKBOX = auto()
CONTRIBUTE_BUTTON = auto()

Expand All @@ -36,11 +37,10 @@ def __init__(self, config: config.Config, window_width: int, window_height: int,
self.window_width = window_width
self.window_height = window_height
self.logo_path = logo_path
self.on_disconnect_clicked = Event()
self.on_connect_clicked = Event()
self.on_save_settings_clicked = Event()
self.on_clear_console_clicked = Event()
self.on_intensity_change = Event()
self.on_toggle_interaction_clicked = Event()
self.elements = {
Element.IP_ADDRESS_INPUT: None,
Element.DETECT_IP_ADDRESS_CHECKBOX: None,
Expand All @@ -60,6 +60,7 @@ def __init__(self, config: config.Config, window_width: int, window_height: int,
Element.CONNECT_BUTTON: None,
Element.SAVE_SETTINGS_BUTTON: None,
Element.CLEAR_CONSOLE_BUTTON: None,
Element.TOGGLES_INTERACTIONS_BUTTON: None,
Element.CONNECT_ON_STARTUP_CHECKBOX: None,
Element.CONTRIBUTE_BUTTON: None,
}
Expand Down Expand Up @@ -88,21 +89,15 @@ def __init__(self, config: config.Config, window_width: int, window_height: int,
def handle_connect_callback(self, sender, app_data):
self.on_connect_clicked.dispatch(sender, app_data)

def handle_disconnect_callback(self, sender, app_data):
self.on_disconnect_clicked.dispatch(sender, app_data)

def handle_save_settings_callback(self):
self.config.write_config_to_disk()
self.print_terminal("Settings Saved!")

def handle_clear_console_callback(self, sender, app_data):
self.on_clear_console_clicked.dispatch(sender, app_data)

def handle_intensity_change(self, sender, app_data):
parameter = ""
value = 1
# figure out how to get these values from sender and app data
self.on_intensity_change.dispatch(parameter, value)
def handle_toggle_interactions_callback(self, sender, app_data):
self.on_toggle_interaction_clicked.dispatch()

def handle_input_change(self, sender, app_data):
element = self.ids_to_elements.get(sender)
Expand Down Expand Up @@ -233,6 +228,8 @@ def create_button_group(self):
callback=self.handle_save_settings_callback)
self.elements[Element.CLEAR_CONSOLE_BUTTON] = dpg.add_button(label="Clear Console",
callback=self.handle_clear_console_callback)
self.elements[Element.TOGGLES_INTERACTIONS_BUTTON] = dpg.add_button(label="Toggle Interactions",
callback=self.handle_toggle_interactions_callback)

def create_connect_startup_checkbox(self):
should_connect_on_startup = self.config.get_by_key(
Expand All @@ -252,6 +249,13 @@ def create_footer(self):
callback=self.handle_contribute_callback
)

def validate_connect_on_startup(self):
should_connect_on_startup = self.config.get_by_key(
"should_connect_on_startup"
)
if should_connect_on_startup:
self.handle_connect_callback(Element.CONNECT_BUTTON, None)

def init(self):
dpg.create_context()
with dpg.window(tag="MAIN_WINDOW"):
Expand Down Expand Up @@ -287,6 +291,7 @@ def init(self):
dpg.set_primary_window("MAIN_WINDOW", True)

def run(self):
self.validate_connect_on_startup()
dpg.start_dearpygui()

def cleanup(self):
Expand Down
19 changes: 14 additions & 5 deletions owo_suit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ def __init__(self, config: Config, gui: Gui):
self.muscles_to_parameters: dict[Muscle, str] = {
value: key for key, value in self.osc_parameters.items()}
self.is_connecting = False
self.is_paused = False
self.on_connection_state_change = Event()

def toggle_interactions(self):
self.is_paused = not self.is_paused
if self.is_paused:
self.gui.print_terminal(
"Interactions Paused.")
else:
self.gui.print_terminal(
"Interactions Continued.")

def create_sensation(self, parameter: str):
frequency = self.config.get_by_key("frequency") or 50
intensities = self.config.get_by_key("intensities")
Expand All @@ -42,12 +52,11 @@ def create_sensation(self, parameter: str):

def watch(self) -> None:
while True:
if len(self.active_muscles) > 0:
if len(self.active_muscles) > 0 and not self.is_paused:
for muscle in self.active_muscles:
parameter = self.muscles_to_parameters.get(muscle)
sensation = self.create_sensation(parameter)
OWO.Send(sensation, muscle)
print("\033[SSending sensation to: ", parameter)
time.sleep(.1)

def on_collission_enter(self, address: str, *args) -> None:
Expand Down Expand Up @@ -96,15 +105,15 @@ def retry_connect(self, *args) -> None:
ok = self.connect()
while not ok:
self.gui.print_terminal(
"Failed to connect to suit, trying again...")
print(
"Failed to connect to suit, trying again...")
"Failed to connect to suit, trying again..."
)
ok = self.connect()
time.sleep(1)
self.is_connecting = False
self.dispatch_connection_state_change()

def init(self) -> None:
self.gui.on_connect_clicked.add_listener(self.retry_connect)
self.gui.on_toggle_interaction_clicked.add_listener(self.toggle_interactions)
self.on_connection_state_change.add_listener(
self.gui.handle_connecting_state_change)

0 comments on commit dfa346b

Please sign in to comment.