-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_data.py
More file actions
78 lines (58 loc) · 2.48 KB
/
generate_data.py
File metadata and controls
78 lines (58 loc) · 2.48 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
async def generateData(client):
global print_status, exercise, sample
try:
# Initialize process
setInitialDateTimeStamp()
updateExerciseNumber()
print_status = "ready"
print(f" Ready to start exercise {exercise}!")
# Start notifications
await client.start_notification(HANDLE_READ_DATA)
while True:
if exercise == -1:
break
await asyncio.sleep(0)
# Keyboard management
if keyboard.is_pressed("x"): # Exit
if print_status == "recording":
print(f" ...End data collection exercise {exercise} / sample {sample}")
client.data_file.close()
print('File closed')
print("Data collection terminated")
break
elif keyboard.is_pressed("s"): # Start collecting data
if print_status != "recording":
sample += 1
print(f" Start data collection exercise {exercise} / sample {sample}...")
print_status = "recording"
client.data_file = openFile()
elif keyboard.is_pressed("e"): # Stop data collection
if print_status == "recording":
print(f" ...End data collection exercise {exercise} / sample {sample}")
print_status = "stopped"
client.data_file.close()
print('File closed')
elif keyboard.is_pressed("n"): # Prepare system for new exercise
if print_status != "ready":
if print_status == "recording":
print(f" ...End data collection exercise {exercise} / sample {sample}")
client.data_file.close()
print('File closed')
updateExerciseNumber()
print(f" Ready to start exercise {exercise}")
print_status = "ready"
sample = 0
# Stop notifications
await client.stop_notification(HANDLE_READ_DATA)
except Exception as e:
print(f"AIR Error: {e}")
finally:
try:
client.data_file.close()
print('File closed')
except:
pass
finally:
keyboard.send('esc')
print('Data capture complete')
return