-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.py
88 lines (73 loc) · 2.43 KB
/
stream.py
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
from lib.usb_dev import USBDev
from lib.fifo_writer import FIFOWriter
import time
from utils.yaml_wrapper import YamlHandler
StatusInterval = 0.5
headset = USBDev()
headset.startDevCheckThread()
fifo = FIFOWriter()
fifo.Open()
# State globals:
BytesWritten = 0
LastStatus = 0
StatusData = dict()
StatusData['Msg'] = "Starting Up"
###############################################################################
def PrintStatus(update):
"""Update the program status"""
global LastStatus
now = time.time()
if (now - LastStatus) < StatusInterval:
return
print(update['Msg'] + " ", end='\r')
LastStatus = now
def main(opts):
flag = True
time_sleep = opts['time_sleep']
global BytesWritten
while True:
PrintStatus(StatusData)
# print(StatusData)
# just run at first epoch
if headset.DevicePresent != False:
data = headset.RecvData()
else:
# print("Waiting on headset...")
StatusData['Msg'] = "Waiting on headset..."
# If we are waiting on a headset and data has been written, everything needs to be reset:
if BytesWritten:
BytesWritten = 0
fifo.Reset()
# No sense being speedy on the loop when we are waiting on a human
time.sleep(time_sleep)
continue
if data != None:
out = fifo.Write(data)
'''
if flag:
print('out2file ...')
flag=False
else:
print('out2file .....')
flag = True
'''
else:
# print("RecvData() returned None: {}".format(headset.LastError.strerror))
StatusData['Msg'] = "Device State: " + headset.DeviceStatus
continue
if out:
BytesWritten += out
StatusData['Total'] = BytesWritten
#print('byte2out')
else:
# print("Pausing fifo, no readers...")
StatusData['Msg'] = "Output buffer full, pausing fifo..."
time.sleep(time_sleep)
continue
# print("In write loop, error: " + str(fifo.LastError) + ", total bytes written: " + str(BytesWritten))
StatusData['Msg'] = "Device State: " + headset.DeviceStatus
# time.sleep(.5)
# exit()
if __name__ == '__main__':
opts = YamlHandler('./options/settings.yaml').read_yaml()
main(opts)