示例#1
0
def start():
    config = get_config()
    # TODO: perhaps be more explicit and not rely on this convention of 'ws'
    if config['hmd']['camera_mono_url'].lower().startswith('ws'):
        cs = CameraServer()
        cs.start()
    main_loop()
示例#2
0
    def __init__(self, joystick_id=0, **args):
        super(Joystick, self).__init__(**args)

        self._value = (0, 0)
        self.joystick_id = joystick_id
        self.joystick = InputController(self.joystick_id)
        self.joystick.add_listener(self.joystick_event)

        self._x_axis_name = None
        self._y_axis_name = None

        config = get_config()
        config_section = 'joystick_{}'.format(self.joystick_id)
        self.ws_port = config.getint('www', 'ws_port', fallback=8001)
        self.invert_x_axis = config.getboolean(config_section, 'invert_x_axis', fallback=False)
        self.invert_y_axis = config.getboolean(config_section, 'invert_y_axis', fallback=False)

        self.messages = MessageReceiver(self.ws_port)           # a 'shared' (singleton) resource
        self.messages.add_listener(self.message_recv)

        if joystick_id == 1:
            self._x_axis_name, self._y_axis_name = ('lx', 'ly')
        else:
            self._x_axis_name, self._y_axis_name = ('rx', 'ry')

        logger.info(self)
示例#3
0
 def __init__(self, callee, ws_port = None, ws_class=DefaultWebSocketHandler, ):
     self.ws_thread = None
     self.ws_port = ws_port if ws_port else get_config().getboolean('www', 'ws_port', fallback=8001)
     self.ws = None
     self.ws_class = ws_class
     self.ws_class.callee = callee
     self._keep_running = True
示例#4
0
 def __init__(self, pan=None, tilt=None):
     super(PanTilt, self).__init__(
         pan_servo=PiCraftServo(pan),
         tilt_servo=PiCraftServo(tilt),
         _order=('pan_servo', 'tilt_servo'))
     config = get_config()
     config_section = 'pantilt_0'
     self.invert_pan_axis = config.getboolean(config_section, 'invert_pan_axis', fallback=False)
     self.invert_tilt_axis = config.getboolean(config_section, 'invert_tilt_axis', fallback=False)
示例#5
0
def main():
    logger.info('Initializing camera')
    with picamera.PiCamera() as camera:
        config = get_config()
        w = config.getint('camera', 'width', fallback=640)
        h = config.getint('camera', 'height', fallback=480)
        camera.resolution = (w, h)
        camera.framerate = config.getint('camera', 'framerate', fallback=24)
        camera.rotation = config.getint('camera', 'rotation', fallback=0)
        camera.hflip = config.getboolean('camera', 'hflip', fallback=False)
        camera.vflip = config.getboolean('camera', 'vflip', fallback=False)
        camera.led = config.getboolean('camera', 'led', fallback=False)
        sleep(1)  # camera warm-up tim
        logger.info('Initializing websockets server on port %d' % WS_PORT)
        websocket_server = make_server(
            '',
            WS_PORT,
            server_class=WSGIServer,
            handler_class=HTTP11WebSocketWSGIRequestHandler,
            app=WebSocketWSGIApplication(handler_cls=StreamingWebSocket))
        websocket_server.initialize_websockets_manager()
        websocket_thread = Thread(target=websocket_server.serve_forever)
        #logger.info('Initializing HTTP server on port %d' % HTTP_PORT)
        #http_server = StreamingHttpServer()
        #http_thread = Thread(target=http_server.serve_forever)
        logger.debug('Initializing broadcast thread')
        output = BroadcastOutput(camera)
        broadcast_thread = BroadcastThread(output.converter, websocket_server)
        logger.info('Starting recording')
        camera.start_recording(output, 'yuv')
        try:
            logger.debug('Starting websockets thread')
            websocket_thread.start()
            #logger.info('Starting HTTP server thread')
            #http_thread.start()
            logger.debug('Starting broadcast thread')
            broadcast_thread.start()
            while True:
                camera.wait_recording(1)
        except KeyboardInterrupt:
            pass
        finally:
            logger.info('Stopping recording')
            camera.stop_recording()
            logger.debug('Waiting for broadcast thread to finish')
            broadcast_thread.join()
            logger.debug('Shutting down HTTP server')
            #http_server.shutdown()
            logger.debug('Shutting down websockets server')
            websocket_server.shutdown()
            logger.debug('Waiting for HTTP server thread to finish')
            #http_thread.join()
            logger.debug('Waiting for websockets thread to finish')
            websocket_thread.join()
示例#6
0
import os
import threading
from picraftzero.utils import arduino_map
from picraftzero.log import logger
from picraftzero.zero import Button
from picraftzero.config import get_config

config = get_config()

USE_EVENT = True
USE_PYGAME = True
USE_BLUEDOT = config.getboolean('joystick', 'use_bluedot', fallback=False)

HAVE_EVENT = False
HAVE_PYGAME = False
HAVE_BLUEDOT = False

# ---------------------------------------------------------------------------------------------------------

# TODO: other joypads
# TODO: test the PyGame impl. on Windows
# TODO: shared common behaviour refactor

# ---------------------------------------------------------------------------------------------------------
# Look for Event support first (Linux) then PyGame (Linux, Windows, Mac, other)
try:
    from evdev import InputDevice, categorize, AbsEvent, KeyEvent, list_devices
    from evdev.ecodes import KEY, SYN, REL, ABS
    HAVE_EVENT = True
except ImportError:
    logger.info("Optional EventDev library not found")
示例#7
0
 def __init__(self, http_port = None):
     self.http_thread = None
     self.http_port = http_port if http_port else get_config().getint('www', 'http_port', fallback=8000)
     TCPServer.allow_reuse_address = True
     self.httpd = None