def handle_packet(self, packet): if len(packet) >= 2 and packet[0:2] == 'OF': self.switchstatus('off') elif len(packet) >= 2 and packet[0:2] == 'ON': self.switchstatus('on') elif len(packet) >= 4 and packet[0:2] == 'TG': if self.status == 'startup': self.status = 'off' if not (self.status == 'off' or self.status == 'on'): return try: n = int(packet[2:4]) except ValueError: return if n < 0 or n >= WIDTH * HEIGHT: return if self.toggled[n] == '\x00': self.toggled = self.toggled[:n] + '\x01' + self.toggled[n + 1:] else: self.toggled = self.toggled[:n] + '\x00' + self.toggled[n + 1:] self.send(mcuf.packet_bool(self.toggled, WIDTH, HEIGHT)) elif len(packet) >= 2 and packet[0:2] == 'AN': self.switchstatus('anim') elif len(packet) >= 2 and packet[0:2] == 'VU': self.switchstatus('vu') self.vu_direction = True self.vu_timeout_time = time() elif len(packet) >= 2 and packet[0:2] == 'UV': self.switchstatus('vu') self.vu_direction = False self.vu_timeout_time = time() elif len(packet) > 2 and packet[0:2] == 'IN': self.switchstatus('interactive', param=packet[2:]) self.in_timeout_time = time() elif len(packet) >= 3 and packet[0:2] == 'ID': if self.status == 'interactive': self.blinker.keypress(packet[2:]) elif len(packet) > 2 and packet[0:2] == 'TX': self.switchstatus('text', param=packet[2:]) elif len(packet) >= 2 and packet[0:2] == 'HB': self.in_timeout_time = time() elif len(packet) >= 3 and packet[0:2] == 'VD': if self.status == 'startup' or self.status == 'anim': self.switchstatus('vu') if self.status != 'vu': return data = WIDTH * HEIGHT * '\x00' vol = ord(packet[2]) if vol > HEIGHT: vol = HEIGHT for i in range(vol): if self.vu_direction: data = data[:(HEIGHT - 1 - i) * WIDTH] + '\x01' + \ data[(HEIGHT - 1 - i) * WIDTH + 1:] else: data = data[:i * WIDTH] + '\x01' + data[i * WIDTH + 1:] if len(packet) > 3: vol2 = ord(packet[3]) if vol2 > HEIGHT: vol2 = HEIGHT for i in range(vol2): if self.vu_direction: data = data[:(HEIGHT - 1 - i) * WIDTH + 1] + '\x01' + \ data[(HEIGHT - 1 - i) * WIDTH + 2:] else: data = data[:i * WIDTH + 1] + '\x01' + \ data[i * WIDTH + 2:] self.send(mcuf.packet_bool(data, WIDTH, HEIGHT)) self.vu_timeout_time = time() elif len(packet) >= 3 and packet[0:2] == 'LU': if not self.status == 'lukas': self.switchstatus('lukas') value = float(packet[2:]) if value == 0: self.blinker.reset() else: self.blinker.hau(value)