Esempio n. 1
0
    def run(self):
        log.debug('PongVictory.run() START')
        # Wait for a swipe (indicated by setting self.delay to not None)
        ScoreBoard().display('P%d Swipe!' % self.player)
        log.info('Waiting for player %d swipe...' % self.player)
        while self.terminate is False and self.delay is None:
            time.sleep(0.1)
        if self.terminate:
            return False

        while self.idx < len(self.puffers):
            if self.terminate:
                return 'Quit'
            log.info("%s idx=%02d id=%08X" %
                     (self.puff_type, self.idx, self.puffers[self.idx]))
            e = FpEvent(self.puffers[self.idx], self.puff_type,
                        struct.pack('<H', self.puff_duration))
            log.info(str(e))
            Visualizer().info(e)
            FpSerial().write(e.serialize())
            time.sleep(self.delay)
            self.idx += 1
        log.info('LARGE PUFFER id=%08X duration (ms)=%d' %
                 (self.large_puffer, self.large_puff_duration_ms))
        e = FpEvent(self.large_puffer, 'FP_EVENT_PUFF',
                    struct.pack('<H', self.large_puff_duration_ms))
        Visualizer().info(e)
        FpSerial().write(e.serialize())
Esempio n. 2
0
    def run(self):
        ''' Return None if Quit was pressed, else return the winner of the game, i.e. 1 or 2 '''
        log.debug('PongGame.run()')

        while self.win is None:
            if self.terminate:
                return
            if self.idx < 0:
                self.win = 2
                break
            elif self.idx >= len(self.puffers):
                self.win = 1
                break
            elif self.idx >= 0 and self.idx < len(self.puffers):
                log.info("%s idx=%02d id=%08X" %
                         (self.puff_type, self.idx, self.puffers[self.idx]))
                e = FpEvent(self.puffers[self.idx], self.puff_type,
                            struct.pack('<H', self.puff_duration))
                log.info(str(e))
                Visualizer().info(e)
                FpSerial().write(e.serialize())
            time.sleep(self.delay)
            self.idx += self.inc
        if self.quit:
            return None
        else:
            death_puffer = self.large_puffers[1 if self.win == 1 else 0]
            e = FpEvent(death_puffer, 'FP_EVENT_PUFF',
                        struct.pack('<H', self.large_puff_duration))
            log.info(str(e))
            Visualizer().info(e)
            FpSerial().write(e.serialize())
            return self.win
Esempio n. 3
0
    def run(self):
        log.debug('ContinuousModePuffs.run() START')

        ScoreBoard().display('CP')
        while self.terminate is False:
            # Print a little graphic of the puffers showing which one is active...
            log.info("%s idx=%02d id=%08X" %
                     (self.puff_type, self.idx, self.puffers[self.idx]))
            e = FpEvent(self.puffers[self.idx], self.puff_type,
                        struct.pack('<H', self.puff_duration))
            log.info(str(e))
            Visualizer().info(e)
            FpSerial().write(e.serialize())

            # Move the frixel by inc
            self.idx += self.inc

            # Bounce if necessary
            if self.idx == -1:
                self.idx = 1
                self.inc = 1
            elif self.idx == len(self.puffers):
                self.idx = len(self.puffers) - 2
                self.inc = -1

            # Wait a little bit...
            time.sleep(self.delay)

        log.debug('ContinuousModePuffs.run() END')
Esempio n. 4
0
 def display(self, message):
     message = str(message)[0:FpEvent.FP_MAX_DATA_LEN]
     disp_id = self.get_id()
     if disp_id is not None:
         e = FpEvent(disp_id, 'FP_EVENT_DISPLAY', message)
         log.info('DISPLAY: %s' % message)
         Visualizer().update(e)
         if self.muted is False:
             FpSerial().write(e.serialize())
     if self.keyboard is not None:
         self.keyboard.display_text(message)
Esempio n. 5
0
    def run(self):
        log.debug('ManualMode.run() START')
        ScoreBoard().display(
            'Yellow=random small puff; Green=Large 1; Blue=Large 2')
        while not self.terminate:
            if self.puffer_mask != 0:
                e = FpEvent(self.puffer_mask, self.puff_type,
                            pack('<H', self.duration))
                log.info('Event: %s' % str(e))
                Visualizer().info(e)
                FpSerial().write(e.serialize())
                self.puffer_mask = 0
            time.sleep(0.1)

        log.debug('ManualMode.run() END')
Esempio n. 6
0
    def run(self):
        log.debug('MusicPlayMode.run() START')
        time.sleep(0.5)
        try:
            self.start_playback()
            while not self.terminate:
                l, data = self.inp.read()
                self.inp.pause(1)
                if l:
                    try:
                        matrix = self.calculate_levels(data)
                        puffer_state = (len(self.channels) * 2) * ['    ']
                        puffcount = 0
                        puffmask = 0x00000000
                        for i in range(0, len(self.channels)):
                            diff = matrix[i] - self.means[i].mean()
                            if diff > 0:
                                self.means[i].set(matrix[i])
                                if diff > self.threshold:
                                    puffer_idx = i * 2
                                    if self.channels[i]:
                                        puffer_idx += 1
                                    self.channels[i] = not (self.channels[i])
                                    puffer_state[puffer_idx] = 'PUFF'
                                    puffmask = puffmask | self.all_puffers[
                                        puffer_idx]
                                    puffcount += 1
                            else:
                                self.means[i].push(matrix[i])

                        self.puff_frequency.push(puffcount)
                        puff_density = self.puff_frequency.mean()
                        if self.target_density > puff_density and self.threshold > self.min_threshold:
                            self.threshold -= self.threshold_step
                        elif self.threshold < self.max_threshold:
                            self.threshold += self.threshold_step
                        log.debug('Music t=%5.2f d=%5.3f t=%5.3f' %
                                  (time.time() - self.start, puff_density,
                                   self.threshold))
                        if self.manual_mask > 0:
                            puffmask = puffmask | self.manual_mask
                            self.manual_mask = 0
                        if puffmask != 0:
                            e = FpEvent(puffmask, self.puff_type,
                                        pack('<H', self.puff_duration))
                            log.info('Event: %s' % str(e))
                            Visualizer().info(e)
                            FpSerial().write(e.serialize())
                        self.out.write(data)
                    except Exception as e:
                        log.exception("END: %s: %s" % (type(e), e))
                        break
                self.inp.pause(0)
            self.stop_playback()
        finally:
            try:
                self.inp.close()
                self.out.close()
            except Exception as e:
                log.error('while closing ALSA devices %s: %s' % (type(e), e))
        log.debug('MusicPlayMode.run() END')
Esempio n. 7
0
 def callback(self, idmask):
     log.info("%s id=%08X" % (self.puff_type, idmask))
     e = FpEvent(idmask, self.puff_type, struct.pack('<H', self.duration))
     log.info(str(e))
     Visualizer().info(e)
     FpSerial().write(e.serialize())