-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathexamples.py
More file actions
140 lines (116 loc) · 4.92 KB
/
Copy pathexamples.py
File metadata and controls
140 lines (116 loc) · 4.92 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import asyncio
import argparse
import logging
from even_glasses.bluetooth_manager import GlassesManager
from even_glasses.commands import send_text, send_rsvp, send_notification, send_image
from even_glasses.models import RSVPConfig, NCSNotification
from even_glasses.notification_handlers import handle_incoming_notification
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
def parse_args():
parser = argparse.ArgumentParser(description="Even Glasses Text Display Tests")
# Create mutually exclusive group for test type
test_type = parser.add_mutually_exclusive_group(required=True)
test_type.add_argument("--rsvp", action="store_true", help="Run RSVP test")
test_type.add_argument("--text", action="store_true", help="Run text test")
test_type.add_argument(
"--notification", action="store_true", help="Run notification test"
)
test_type.add_argument('--image', action='store_true', help='Send image')
# Optional arguments for RSVP configuration
parser.add_argument(
"--wpm", type=int, default=1200, help="Words per minute for RSVP (default: 750)"
)
parser.add_argument(
"--words-per-group",
type=int,
default=4,
help="Number of words per group for RSVP (default: 3)",
)
parser.add_argument(
"--input-file",
type=str,
default="./even_glasses/rsvp_story.txt",
help="Input text file path (default: ./even_glasses/rsvp_story.txt)",
)
args = parser.parse_args()
return args
async def test_rsvp(manager: GlassesManager, text: str, config: RSVPConfig):
if not manager.left_glass or not manager.right_glass:
logger.error("Could not connect to glasses devices.")
return
await send_text(
manager, "Init message!"
) # Initialize Even AI message sending
await asyncio.sleep(5)
await send_rsvp(manager, text, config)
await asyncio.sleep(3)
await send_text(manager, "RSVP Done! Restarting in 3 seconds")
await asyncio.sleep(3)
async def test_text(manager: GlassesManager, text: str):
if not manager.left_glass or not manager.right_glass:
logger.error("Could not connect to glasses devices.")
return
await send_text(manager, text)
async def test_notification(manager: GlassesManager, notification: NCSNotification):
if not manager.left_glass or not manager.right_glass:
logger.error("Could not connect to glasses devices.")
return
await send_notification(manager, notification)
async def test_image(manager: GlassesManager, image_path: str):
if not manager.left_glass or not manager.right_glass:
logger.error("Could not connect to glasses devices.")
return
with open(image_path, 'rb') as f:
image_data = f.read()
await send_image(manager=manager, image_data=image_data)
logger.info("Image sent successfully.")
async def main():
args = parse_args()
try:
with open(args.input_file, "r", encoding="utf-8") as f:
text = f.read()
except FileNotFoundError:
logger.error(f"Input file not found: {args.input_file}")
return
config = RSVPConfig(
words_per_group=args.words_per_group, wpm=args.wpm, padding_char="..."
)
manager = GlassesManager(left_address=None, right_address=None)
connected = await manager.scan_and_connect()
if connected:
# Assign notification handlers
if manager.left_glass:
manager.left_glass.notification_handler = handle_incoming_notification
if manager.right_glass:
manager.right_glass.notification_handler = handle_incoming_notification
counter = 1
try:
while True:
if args.image:
await test_image(manager=manager, image_path='image_2.bmp')
elif args.rsvp:
await test_rsvp(manager=manager, text=text, config=config)
elif args.text:
message = f"Test message {counter}"
await test_text(manager=manager, text=message)
elif args.notification:
notification = NCSNotification(
msg_id=1,
title="Test Notification Title",
subtitle="Test Notification Subtitle",
message="This is a test notification",
display_name="Test Notification",
app_identifier="org.telegram.messenger",
)
await test_notification(manager=manager, notification=notification)
counter += 1
await asyncio.sleep(1) # Prevent tight loop
except KeyboardInterrupt:
logger.info("Interrupted by user.")
finally:
await manager.disconnect_all()
else:
logger.error("Failed to connect to glasses.")
if __name__ == "__main__":
asyncio.run(main())