-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christoph Hirtz
committed
Oct 15, 2014
1 parent
364d8b2
commit dc3b4c9
Showing
17 changed files
with
473 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
from socket_protocol import BlinkClient | ||
from blinkconfig import * | ||
import cmd | ||
|
||
|
||
class Prompt(cmd.Cmd): | ||
prompt = '> ' | ||
|
||
def do_add(self, line): | ||
ret = connector.add_to_playlist(line) | ||
print(ret) | ||
|
||
def help_add(self): | ||
print("Adds a file to the playlist.") | ||
|
||
def do_load_file(self, line): | ||
line = line.split(" ") | ||
ret = connector.load_clip(*line) | ||
print(ret) | ||
|
||
def help_load_file(self): | ||
print("Loads a .bml file to the storage") | ||
|
||
def do_clear(self, line): | ||
ret = connector.clear_playlist() | ||
print(ret) | ||
|
||
def do_remove(self, line): | ||
try: | ||
i = int(line) | ||
ret = connector.remove_from_playlist(i) | ||
print(ret) | ||
except ValueError: | ||
print("ERR") | ||
|
||
def do_show(self, line): | ||
ret = connector.get_playlist() | ||
print(ret) | ||
|
||
def do_show_clips(self, line): | ||
ret = connector.get_available_clips() | ||
print(ret) | ||
|
||
def help_load_file(self): | ||
print("Reads a file and adds it to the list of available clips.") | ||
|
||
if __name__ == '__main__': | ||
connector = BlinkClient(getstring("ethernet_host"), getint("ethernet_port")) | ||
Prompt().cmdloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import os | ||
import time | ||
import json | ||
import socket | ||
from socket_protocol import * | ||
import threading | ||
from blinkconfig import * | ||
from collections import namedtuple | ||
from avrconnector import AVRConnector, ConnectionType | ||
from threading import Thread | ||
from threading import Condition | ||
from bmlparser import BMLReader | ||
Size = namedtuple("size", "width height") | ||
grid_size = Size(3, 3) | ||
|
||
playlist_items = [] | ||
continue_condition = Condition() | ||
|
||
|
||
class AVRPlayer(): | ||
def __init__(self): | ||
self.connector = AVRConnector() | ||
ret = self.connector.connect(ConnectionType.bluetooth) | ||
if not ret: | ||
print("ERR") | ||
sys.exit(1) | ||
self.clips = {} | ||
|
||
def load_clips(self, file_names): | ||
""" | ||
:param files: {} | ||
:return: | ||
""" | ||
reader = BMLReader() | ||
for f in file_names: | ||
fra, info, (width, height) = reader.read_xml(file_names[f]) | ||
frames = [] | ||
for frame in fra: | ||
packet = self.connector.pack_mcuf(frame.tile_colors, grid_size, False) | ||
frames.append((frame.duration/1000, packet)) | ||
self.clips[f] = frames | ||
|
||
def play(self, video): | ||
v = self.clips[video] | ||
for frame in v: | ||
self.connector.write(frame[1]) | ||
time.sleep(frame[0]) | ||
|
||
|
||
class BlinkDisplayThread(Thread): | ||
def __init__(self): | ||
Thread.__init__(self) | ||
|
||
def run(self): | ||
while True: | ||
playlist = list(playlist_items) | ||
if len(playlist) == 0: | ||
with continue_condition: | ||
continue_condition.wait() | ||
for msg in playlist: | ||
item = msg["alias"] | ||
player.play(item) | ||
|
||
|
||
class EthernetSocket(BlinkServer): | ||
def __init__(self): | ||
BlinkServer.__init__(self, getstring("ethernet_host"), getint("ethernet_port")) | ||
|
||
@staticmethod | ||
def add_to_playlist(sock, alias): | ||
if not alias in player.clips: | ||
send_one_message(sock, "ERROR") | ||
return | ||
di = {"alias": alias} | ||
playlist_items.append(di) | ||
with continue_condition: | ||
continue_condition.notifyAll() | ||
send_one_message(sock, str(len(playlist_items)-1)) | ||
|
||
@staticmethod | ||
def remove_from_playlist(sock, it_id): | ||
item_id = int(it_id) | ||
try: | ||
del playlist_items[item_id] | ||
send_one_message(sock, "OK") | ||
except IndexError: | ||
send_one_message(sock, "ERROR") | ||
|
||
@staticmethod | ||
def clear_playlist(sock): | ||
global playlist_items | ||
playlist_items = [] | ||
send_one_message(sock, "OK") | ||
|
||
@staticmethod | ||
def load_clip(sock, params): | ||
file_name, alias = params.split(",") | ||
player.load_clips({alias: file_name}) | ||
send_one_message(sock, "OK") | ||
|
||
@staticmethod | ||
def get_available_clips(sock): | ||
send_one_message(sock, str(list(player.clips.keys()))) | ||
|
||
@staticmethod | ||
def get_playlist(sock): | ||
lis = ["%d -> %s" % (idx, str(item["alias"])) for idx, item in enumerate(playlist_items)] | ||
send_one_message(sock, str(lis)) | ||
|
||
|
||
if __name__ == "__main__": | ||
player = AVRPlayer() | ||
if len(sys.argv) == 2: | ||
files = json.load(open(sys.argv[1], "r")) | ||
player.load_clips(files) | ||
elif os.path.isfile("playlist.cfg"): | ||
files = json.load(open("playlist.cfg", "r")) | ||
player.load_clips(files) | ||
thread = BlinkDisplayThread() | ||
thread.start() | ||
socket = EthernetSocket() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.