-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_realsense_service.py
56 lines (43 loc) · 1.32 KB
/
main_realsense_service.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
# coding: UTF-8
from libled.led_run_loop import LedRunLoop
import codecs
import sys
import platform
import time
import json
from Queue import Queue
from flask import Flask, request
from libled.util.flask_on_thread import FlaskOnThread
from libled.util.sound_interface import SoundInterface
q = Queue()
app = Flask(__name__)
@app.route('/api/audio', methods=['POST'])
def audio():
volume = float(json.loads(request.data)['volume'])
SoundInterface.volume(val=volume/100.0)
return ""
class LedRawTextClient(LedRunLoop):
def __init__(self):
super(LedRawTextClient, self).__init__()
if sys.platform == 'win32':
sys.stdin = codecs.getreader('shift_jis')(sys.stdin) # set input codec
SoundInterface.content_id = 'realsense'
def on_keyboard_interrupt(self):
q.put('abort')
pass
def on_exception_at_runloop(self, exception):
return LedRunLoop.EXIT
def read_data(self):
print("waiting data.")
while True:
if self.aborted:
break
if q.empty():
time.sleep(0.1)
else:
return q.get()
q.put('show:{"orders":[{"id":"filter-zanzo"},{"id":"object-realsense", "lifetime":0}]}')
flask = FlaskOnThread(app, port=5402)
flask.daemon = True
flask.start()
LedRawTextClient().run()