Exemplo n.º 1
0
    def volume(self, args):
        # get player
        player = self.get_player(args['content_id'], True)
        if player is None:
            logger.w('not founded content id({}).'.format(args['content_id']))
            return

        player.set_volume(args['val'])
        logger.i('[{}]volume = {}'.format(args['content_id'], args['val']))
Exemplo n.º 2
0
    def resume(self, args):
        # get player
        player = self.get_player(args['content_id'])
        if player is None:
            logger.w('not founded content id({}).'.format(args['content_id']))
            return

        player.do_resume()
        logger.i('[{}]resume'.format(args['content_id']))
Exemplo n.º 3
0
    def pause(self, args):
        # get player
        logger.i(type(args))
        player = self.get_player(args['content_id'], True)
        if player is None:
            logger.w('not founded content id({}).'.format(args['content_id']))
            return

        player.do_pause()
        logger.i('[{}]pause'.format(args[0]))
Exemplo n.º 4
0
def vol():
    logger.i('call volume rest-api audio module.\n' + str(request.data))
    req = get_request()
    q.put({
        'cmd': s.volume,
        'args': {
            'content_id': req.get('content_id'),
            'val': req.get('val', 0.5)
        }
    })
    return ""
Exemplo n.º 5
0
def play():
    logger.i('call play rest-api audio module.\n' + str(request.data))
    req = get_request()
    args = {
        'content_id': req.get('content_id'),
        'wav': req.get('wav'),
        'loop': req.get('loop', False),
        'and_stop': req.get('and_stop', False)
    }
    q.put({'cmd': s.play, 'args': args})
    return ""
Exemplo n.º 6
0
    def stop(self, args):
        if args['content_id'] is None:
            self.all_stop()
            return

        # get player
        player = self.get_player(args['content_id'])
        if player is None:
            logger.w('not founded content id({}).'.format(args['content_id']))
            return

        player.do_stop()
        logger.i('[{}]stop'.format(args['content_id']))
Exemplo n.º 7
0
    def play(self, args):
        # get player
        player = self.get_player(args['content_id'], True)
        if player is None:
            logger.w('null argument content id.')
            return

        # do play
        wav = args['wav']
        if wav is None:
            logger.w('null argument wavefile = ')
            return
        loop = args['loop']

        and_stop = args['and_stop']
        if and_stop:
            player.do_pause()

        player.do_play(wav, loop)
        logger.i('[{}]play {}, loop({})'.format(args['content_id'], wav, loop))
Exemplo n.º 8
0
    def run(self):
        self.run_async()

        try:
            while True:
                if self.aborted:
                    break
                time.sleep(0.5)

        except KeyboardInterrupt:
            logger.d('keyboard Ctrl+C in simple_run_loop.run()')
            self.on_keyboard_interrupt()
            raise
        except Exception:
            logger.e('Unexpected error: {}'.format(str(sys.exc_info()[0])))
            logger.e(traceback.format_exc())
            raise
        finally:
            self.aborted = True
            logger.i('finish run')
                        return port
                sleep(0.1)
        except (OSError, serial.SerialException, ValueError):
            pass
        finally:
            if s is not None:
                s.close()

    return None


port = None
s = None
try:
    flask.check_error()
    logger.i("searching controller....")
    port = find_controller_port()

    if port is None:
        logger.e('game pad not found.')
        exit
    logger.i("find port: " + str(port))
    s = serial.Serial(port, 9600)

    logger.i("gamepad server has started on port" + str(tcp_port))

    while True:
        line = s.readline().strip()
        gamepad_state = line
        socket.send_string(line)
Exemplo n.º 10
0
def resume():
    logger.i('call resume rest-api audio module.\n' + str(request.data))
    req = get_request()
    q.put({'cmd': s.resume, 'args': {'content_id': req.get('content_id')}})
    return ""
Exemplo n.º 11
0
        player.do_resume()
        logger.i('[{}]resume'.format(args['content_id']))


# server
# リクエストデータ(json)をパースしてobjectとしてキューに格納するまでを行う。
# リクエスト処理はなる早で返す。SoundPlayerの実行結果は返さない。

app = Flask(__name__)
tcp_port = 5701
pull_port = 5751
q = Queue()
s = SoundPlayingServer()
ctx = zmq.Context()
pull = ctx.socket(zmq.PULL)
logger.i("Collecting updates from audio server...")
abort = False


def run():
    # run_flask()
    run_pull()


def run_pull():
    logger.d('connecting tcp://localhost:{}'.format(pull_port))
    pull.bind('tcp://*:{}'.format(pull_port))
    pool = Pool(1)
    pool.apply_async(parse)
    s.run()  # block
    logger.d('block out pool.')
from time import sleep
from threading import Thread
import pyrealsense as pyrs
from pyrealsense.constants import rs_option
from libled.util.led_draw_util import *
import zmq
import libled.util.logger as logger
from libled.util.zmq_util import *
import sys

context = zmq.Context()
socket = context.socket(zmq.PUB)

target = "tcp://*:5501"
socket.bind(target)
logger.i("ZMQ PUB Socket Start: " + target)

dev = None

# FRAME_WIDTH = 16
# FRAME_HEIGHT = 32
FRAME_WIDTH = 15
FRAME_HEIGHT = 50

try:
    pyrs.start()
    dev = pyrs.Device()
    logger.i("initialize realsense is successfull.")
    dev.apply_ivcam_preset(0)
    dev.set_device_option(rs_option.RS_OPTION_F200_LASER_POWER, 15.0)
    while True:
Exemplo n.º 13
0
def gamepad():
    global gamepad_state
    return json.dumps(gamepad_state)


flask = FlaskOnThread(app, port=tcp_port)
flask.daemon = True
flask.start()

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:" + str(zmq_port))

try:
    flask.check_error()
    logger.i("searching controller....")

    while True:
        try:
            socket.send_string(q.get(timeout=1))
        except KeyboardInterrupt:
            break
        except:
            continue

except:
    logger.e('HwControllerManager.init() failed.' + str(sys.exc_info()[0]))
    logger.e(traceback.format_exc())
finally:
    if socket is not None:
        socket.close()
from pyrealsense.constants import rs_option
from libled.util.led_draw_util import *
import zmq
import libled.util.logger
from libled.util.zmq_util import *

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5501")

dev = None

try:
    pyrs.start()
    dev = pyrs.Device()
    logger.i("initialize realsense is successfull.")
    dev.apply_ivcam_preset(0)
    dev.set_device_option(rs_option.RS_OPTION_F200_LASER_POWER, 15.0)
    while True:

        # [r,g,b,深度] の形式に変換する

        dev.wait_for_frames()

        c = dev.color
        c = cv2.cvtColor(c, cv2.COLOR_RGB2BGR)

        d = dev.depth / 256.0

        scale = max(32.0 / 640, 16.0 / 480)