Ejemplo n.º 1
0
    def capture(self):
        def shutter(result=None):
            d = self.camera.capture_image()
            return d

        interval = Config.getint('camera', 'countdown-interval')
        c = task.LoopingCall(bell0.play)
        d = c.start(interval)
        d = d.addCallback(shutter)
        task.deferLater(reactor, 3 * interval, c.stop)
        return d
Ejemplo n.º 2
0
def new():
    import time

    # turn on all the relays on the arduino
    # the lights are wired on NC, so this turns lights off
    def lights_out():
        arduino.sendCommand(0x81, 0)
        arduino.sendCommand(0x81, 1)
        arduino.sendCommand(0x81, 2)
        arduino.sendCommand(0x81, 3)

    logger.debug('starting photo booth service')
    session = Session()

    # preview frame producer
    logger.debug('starting camera preview service')
    preview_port = 23453
    factory = protocol.Factory()
    factory.protocol = session.camera.create_producer
    reactor.listenTCP(preview_port, factory)

    # get the arduino going
    logger.debug('starting arduino')
    arduino = Arduino(session)
    try:
        s = SerialPort(arduino, Config.get('arduino', 'port'), reactor,
                       baudrate=Config.getint('arduino', 'baudrate'))
    except serial.serialutil.SerialException:
        raise

    # give arduino a couple seconds to be ready to accept data
    time.sleep(5)
    reactor.callWhenRunning(lights_out)

    # arduino servo tilt server
    logger.debug('starting tilt command listener')
    reactor.listenTCP(Config.getint('arduino', 'tcp-port'),
                      ServoServiceFactory(arduino))

    return reactor
Ejemplo n.º 3
0
logger = logging.getLogger("purikura.kiosk-loader")

DEFAULT_VKEYBOARD_LAYOUT = 'email'

# because i hate typing
jpath = os.path.join

# set keyboard behaviour to be a little like ios
Config.set('kivy', 'keyboard_mode', 'dock')
Config.set('kivy', 'keyboard_layout', DEFAULT_VKEYBOARD_LAYOUT)

# set the display up
Config.set('graphics', 'fullscreen',
           pkConfig.get('display', 'fullscreen'))
Config.set('graphics', 'width',
           pkConfig.getint('display', 'width'))
Config.set('graphics', 'height',
           pkConfig.getint('display', 'height'))

# the display/touch input i use needs some love
Config.set('postproc', 'retain_time',
           pkConfig.getint('kiosk', 'touch-retain-time'))
Config.set('postproc', 'retain_distance',
           pkConfig.getint('kiosk', 'touch-retain-distance'))

# paths
all_images_path = pkConfig.get('paths', 'images')
event_name = pkConfig.get('event', 'name')
event_images_path = jpath(all_images_path, event_name)
composites_path = jpath(event_images_path, 'composites')
styles_path = jpath(app_root_path, 'pyrikura', 'resources', 'styles')
Ejemplo n.º 4
0
def load():
    global sounds, images, music, loaded

    if loaded:
        logger.debug('want to load resources, but already have')
        return

    logger.debug('loading resources...')

    sounds = dict()
    images = dict()
    music = dict()

    if Config.has_section('sound-files'):
        vol = Config.getint('sound', 'sound-volume') / 100.
        for name, filename in Config.items('sound-files'):
            path = jpath(resource_path, 'sounds', filename)
            logger.info("loading %s", path)
            sound = pygame.mixer.Sound(path)
            sound.set_volume(vol)
            sounds[name] = sound

    if Config.has_section('image-files'):
        for name, filename in Config.items('image-files'):
            path = jpath(resource_path, 'images', filename)
            logger.info("loading %s", path)
            # image = pygame.image.load(path)
            #images[name] = image

    if Config.has_section('music-files'):
Ejemplo n.º 5
0
    def start(self, result=None, arduino=None):
        global in_session

        logger.debug('start new session')

        if in_session:
            defer.returnValue(None)

        in_session = True

        if arduino:
            arduino.sendCommand(0x82, 0)
            arduino.sendCommand(0x82, 1)
            arduino.sendCommand(0x82, 2)
            arduino.sendCommand(0x82, 3)

        countdown_delay = Config.getint('camera', 'countdown-delay')
        needed_captures = template.needed_captures(self.template)
        captures = 0
        errors = 0

        # PLUGINS
        p = self.plugins
        fc0 = p['FileCopy'].new(originals_path)
        fc1 = p['FileCopy'].new(composites_path)
        #fc3 = p['FileCopy'].new(thumbs_path)
        #fc4 = p['FileCopy'].new(details_path)
        #fc5 = p['FileCopy'].new(template_path)
        spool = p['FileCopy'].new(shared_path)

        #th0 = p['ImageThumb'].new(size='256x256', destination='thumbnail.png')
        #th1 = p['ImageThumb'].new(size='1024x1024', destination='thumbnail.png')

        cm = p['Composer'].new(self.template)
        #fd0 = p['FileDelete'].new()
        #fd1 = p['FileDelete'].new()

        filenames = list()

        while captures < needed_captures and errors < 3:
            try:
                filename = yield task.deferLater(reactor, countdown_delay,
                                                 self.capture)
            except:
                traceback.print_exc(file=sys.stdout)
                errors += 1
                logger.debug('failed capture %s/3', errors)
                task.deferLater(reactor, 0, error.play)
                task.deferLater(reactor, .15, error.play)
                task.deferLater(reactor, .30, error.play)
                continue

            captures += 1
            errors = 0
            logger.debug('successful capture (%s/%s)',
                         captures, needed_captures)

            if captures < needed_captures:
                finished.play()
            else:
                bell1.play()

            # C A L L B A C K S
            fn = filename
            original = yield fc0.process(fn)
            filenames.append(original)

            #thumb = yield th0.process(original)
            #thumb = yield fc3.process(thumb)
            #detail = yield th1.process(original)
            #detail = yield fc4.process(detail)

        if arduino:
            arduino.sendCommand(0x81, 0)
            arduino.sendCommand(0x81, 1)
            arduino.sendCommand(0x81, 2)
            arduino.sendCommand(0x81, 3)

        # composite
        d = cm.process(filenames.pop(0))
        d.addCallback(fc1.process)
        if Config.getboolean('kiosk', 'print'):
            d.addCallback(spool.process)
        for fn in filenames:
            cm.process(fn)

        in_session = False
        logger.debug('finished the session')
Ejemplo n.º 6
0
originals_path = jpath(event_images_path, 'originals')
composites_path = jpath(event_images_path, 'composites')
paths = ('thumbnails', 'detail', 'originals', 'composites')

# make sure directory structure is usuable
if Config.getboolean('paths', 'make-images-path'):
    for d in (thumbs_path, details_path, originals_path, composites_path):
        try:
            isdir = os.path.isdir(d)
        except:
            raise
        if not isdir:
            os.makedirs(d, 0755)

# mixer must be initialized before sounds will play
pygame.mixer.init(frequency=Config.getint('sound', 'mixer-frequency'),
                  buffer=Config.getint('sound', 'mixer-buffer'))

# load all the stuff
resources.load()

# i'm lazy!
bell0 = resources.sounds['bell0']
bell1 = resources.sounds['bell1']
error = resources.sounds['error']
finished = resources.sounds['finished']

# manage volumes a bit
bell1.set_volume(bell1.get_volume() * 1.0)
finished.set_volume(finished.get_volume() * .9)