-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathearbud_emulator.py
More file actions
executable file
·51 lines (46 loc) · 1.49 KB
/
earbud_emulator.py
File metadata and controls
executable file
·51 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import atexit
import sys
"""
Earbud Emulator: Terminal interface to simulate earbud button presses.
Displays current mode in prompt and calls corresponding actions.
"""
from earbud_input import (
fn_mapping,
getMode,
set_ipc,
get_ipc,
shared_memory_cleanup
)
from common import IPC
def cleanup():
print("Cleaning up resources...")
ipc = get_ipc()
shared_memory_cleanup()
ipc.cleanup()
def main():
try:
ipc = IPC("emulator") # Create an IPC instance for the emulator
set_ipc(ipc) # Set the ipc instance in earbud_input module
# we don't need to think about button codes here, just the actions
print("Earbud Emulator Started. Type 'exit' to quit.")
while True:
# use the mode_mapping to get the actions, take input
user_input = input(f"[{getMode()}] Enter action (cc, roc, h, m, tn, so, po): ").strip().lower()
if user_input == "exit":
print("Exiting Earbud Emulator.")
break
elif user_input in fn_mapping:
fn_mapping[user_input]() # Call the corresponding function
else:
print("Invalid input. Please try again.")
except KeyboardInterrupt:
print("\nExiting Earbud Emulator.")
except Exception as e:
print(f"An error occurred: {e}")
finally:
print("Exiting Earbud Emulator.")
cleanup()
if __name__ == "__main__":
atexit.register(cleanup)
main()