def write(self, line, pattern): size = len(pattern) array = [] if len(pattern) > Stick.LED_HEIGHT: array = pattern else: logger.d('conv color pattern to rgb pattern') for color in pattern: array.extend(self.__get_led_rgb(color)) carray = c_byte * len(array) cpattern = carray(*array) self.lib.write_line(line, cpattern)
def show(stick, lines): logger.d('show lines({})'.format(lines)) while True: try: a = stick.accel() line = (a[1] + 0x8000) * lines / 0x10000 stick.show(line) time.sleep(0.0001) except KeyboardInterrupt: break except Exception: raise
def write(stick, im, lines): len_ = Stick.LED_HEIGHT im = im.resize((lines, len_)) # px = np.array(im) px = np.array(im).transpose((1, 0, 2)) # change array pos px = (px // Stick.LED_FACTOR * Stick.LED_FACTOR).astype(np.int) # down color # logger.d('px shape={}'.format(px.shape)) for x in range(im.width): # pattern = [0] * (len_ * 3) # for y in range(im.height): # try: # r, g, b = px[y, x] # pattern[y * 3] = int(r) # pattern[y * 3 + 1] = int(g) # pattern[y * 3 + 2] = int(b) # except Exception: # logger.e('x={}, y={}'.format(x, y)) # raise pattern = np.ravel(px[x]) stick.write(x, pattern) logger.d('line={}, pattern={}'.format(x, pattern))
player = SoundPlayer() dicmd = { 'play': player.do_play, 'pause': player.do_pause, 'resume': player.do_resume, 'stop': player.do_stop, 'help': myhelp, 'exit': sys.exit } # sys.stdout = codecs.getw_piter('utf_8')(sys.stdout) sys.stdout = codecs.getwriter('shift_jis')(sys.stdout) myhelp() while True: userinput = raw_input('audio interface >> ').lower() logger.d('thread count = {}'.format(threading.active_count())) if len(userinput) == 0: continue cmds = userinput.split(' ') if cmds[0] not in dicmd: continue cmd = dicmd[cmds[0]] if len(cmds) > 1: cmd(cmds[1]) else: cmd() player.play(file) # player.playsound(file)
import util.logger as logger from stick_sdk import Stick if __name__ == '__main__': s = Stick() s.init_sdk() s.stop_demo() h = 32 patterns = ([0x000000 for _ in range(h)], [0xff0000 for _ in range(h)], [0x00ff00 for _ in range(h)], [0x0000ff for _ in range(h)], [0xffff00 for _ in range(h)], [0xff00ff for _ in range(h)], [0x00ffff for _ in range(h)], [0xffffff for _ in range(h)]) for i in range(len(patterns)): s.write(i, patterns[i]) logger.d('write pattern line={}, pattern={}'.format(i, patterns[i])) # s.write(0, [0x000000 for _ in range(h)]) # s.write(1, [0xff0000 for _ in range(h)]) # s.write(2, [0x00ff00 for _ in range(h)]) # s.write(3, [0x0000ff for _ in range(h)]) # s.write(4, [0xffff00 for _ in range(h)]) # s.write(5, [0xff00ff for _ in range(h)]) # s.write(6, [0x00ffff for _ in range(h)]) # s.write(7, [0xffffff for _ in range(h)]) while True: try: accel = s.accel() gyro = s.gyro() logger.d('get accel = ({},{},{})'.format(accel[0], accel[1],
logger.d('show lines({})'.format(lines)) while True: try: a = stick.accel() line = (a[1] + 0x8000) * lines / 0x10000 stick.show(line) time.sleep(0.0001) except KeyboardInterrupt: break except Exception: raise if __name__ == '__main__': file = sys.argv[1] im = Image.open(file).convert('RGB') s = Stick() s.init_sdk() s.stop_demo() im = ImageOps.mirror(im) lines = Stick.LED_WIDTH # lines = int(round(im.height / Stick.LED_HEIGHT)) logger.d('writing image...') write(s, im, lines) logger.d('complete!') show(s, lines)