diff options
| author | Yuval Adam <yuv.adm@gmail.com> | 2014-06-08 22:22:25 +0300 |
|---|---|---|
| committer | Yuval Adam <yuv.adm@gmail.com> | 2014-06-08 22:22:25 +0300 |
| commit | c6f222c1e4d1a5ed7dfb4017f3bc7d4289642c41 (patch) | |
| tree | 2922087fca5b05c700c623813ea23ac9f3f01182 /client.py | |
| parent | 60d5a883bba03693e2c2492daaeaa44390415758 (diff) | |
Out to file works
Diffstat (limited to 'client.py')
| -rw-r--r-- | client.py | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -1,4 +1,6 @@ +from itertools import cycle from pprint import pprint +from time import sleep from unipath import FSPath as Path DATA_DIR = Path(__file__).absolute().ancestor(1).child('data') @@ -8,12 +10,17 @@ class LightLoopClient(object): def __init__(self): self.sequences = {} self.composition = [] - self.tempo = 300 + self.tempo = 0.3 + self.init_serial() self.init_data() + self.prepare_data() def __str__(self): return '{}\n{}\n{}'.format(self.sequences, self.composition, self.tempo) + def init_serial(self): + self.serial = open(DATA_DIR.child('serial.out'), 'a') + def init_data(self): with open(DATA_DIR.child('data.txt'), 'r') as f: sequence_data, composition_data = f.read().split('\n===\n') @@ -28,7 +35,7 @@ class LightLoopClient(object): def init_composition(self, composition_data): composition_data = filter(lambda x: x != '', composition_data.split('\n')) - self.tempo = composition_data[0].split('_')[1] + self.tempo = float(composition_data[0].split('_')[1]) / 1000.0 self.composition = [c.split(',') for c in composition_data[1:]] def gen_packet(self, tree, channel, mode): @@ -47,7 +54,7 @@ class LightLoopClient(object): self.data_packets = [] for sequence in data: for frame in sequence: - frame_packets = [] + frame_packets = bytearray() for tree, tree_frame in enumerate(frame): for channel, mode in enumerate(tree_frame): tree, channel, mode = map(int, [tree, channel, mode]) @@ -57,10 +64,14 @@ class LightLoopClient(object): self.data_packets.append(frame_packets) # print 'sleep' + def write(self, packets): + self.serial.write(packets) + self.serial.flush() def loop(self): - self.prepare_data() - print self.data_packets + for frame in cycle(self.data_packets): + self.write(frame) + sleep(self.tempo) if __name__ == '__main__': |
