Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ docs/_build/

# PyBuilder
target/

# vim swap files
.*.swp
.*.swo
31 changes: 0 additions & 31 deletions INSTALL

This file was deleted.

File renamed without changes.
File renamed without changes.
25 changes: 0 additions & 25 deletions config.py

This file was deleted.

25 changes: 0 additions & 25 deletions config.py.example

This file was deleted.

2 changes: 0 additions & 2 deletions display_image.sh

This file was deleted.

File renamed without changes.
30 changes: 30 additions & 0 deletions odroidshow/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from odroidshow.tabs.hello import HelloTab
#from odroidshow.tabs.bitcoin import BitcoinPrice, Bitcoind
#from odroidshow.tabs.sysinfo import SystemStats, DiskUsage
#from odroidshow.tabs.uptime import WebsiteUptime

import os

# Add any tabs you want to be visible here
tabs = [
HelloTab(),

# Track a running Bitcoin node
#Bitcoind({"host": "http://127.0.0.1:8332",
# "username": "bitcoinrpc",
# # Read the password from a file
# "password": "password" }),

# A Bitcoin price ticker
#BitcoinPrice(),

# Displays CPU, RAM usage and uptime
#SystemStats(),

# Displays disk usage
#DiskUsage(),

# Tracks website uptime
#WebsiteUptime({"websites": [ {"name": "Google",
# "url": "http://google.com"} ] })
]
69 changes: 38 additions & 31 deletions context.py → odroidshow/context.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import time
import subprocess
import tempfile
import atexit
import os
import sys
import serial

from PIL import Image

from utils import split_string_into_chunks
from odroidshow.utils import split_string_into_chunks

sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))

Expand Down Expand Up @@ -34,7 +36,7 @@ def __init__(self, port_name):
self.port_name = port_name
self.port = None

self.buffer = unicode("")
self.buffer = ""

# Current text size
self.text_size = 2
Expand Down Expand Up @@ -77,22 +79,13 @@ def open_port(self):
"""
Opens the serial port for writing
"""
self.port = open(self.port_name, "w")

# Run the port_open executable, which sets attributes necessary
# to input commands correctly
try:
subprocess.call([ "./port_open", self.port_name ])
except OSError as e:
print "Couldn't execute the port_open executable to set terminal parameters!"

raise e
self.port = serial.Serial(self.port_name, baudrate=500000)

def cleanup(self):
"""
Closes the serial port
"""
self.buffer = unicode("\ec\e[2s\e[1r\r")
self.buffer = "\ec\e[2s\e[1r\r"
self.sleep(0.1)

self.port.close()
Expand All @@ -101,10 +94,9 @@ def push_to_serial(self):
"""
Uploads the current content of the buffer into the screen
"""
list = [ "echo", "-ne"]

list.append(self.buffer)
subprocess.call(list, stdout=self.port)
self.buffer = self.buffer.replace("\\e", "\x1B")
self.port.write(bytes(self.buffer, encoding="ascii"))
self.port.flush()
self.buffer = ""

return self
Expand All @@ -114,18 +106,18 @@ def get_columns(self):
Returns the amount of columns, depending on the current text size
"""
if self.orientation == Screen.HORIZONTAL:
return Screen.WIDTH / (self.text_size * 6)
return Screen.WIDTH // (self.text_size * 6)
else:
return Screen.HEIGHT / (self.text_size * 6)
return Screen.HEIGHT // (self.text_size * 6)

def get_rows(self):
"""
Returns the amount of rows, depending on the current text size
"""
if self.orientation == Screen.HORIZONTAL:
return Screen.HEIGHT / (self.text_size * 8)
return Screen.HEIGHT // (self.text_size * 8)
else:
return Screen.WIDTH / (self.text_size * 8)
return Screen.WIDTH // (self.text_size * 8)

# WRITING FUNCTIONS HERE
def fg_color(self, color):
Expand Down Expand Up @@ -166,16 +158,15 @@ def write(self, text, split=True):
"""
Prints provided text to screen
"""

self.characters_on_line += len(text)
if (self.characters_on_line >= self.get_columns()):
self.characters_on_line = self.characters_on_line % self.get_columns()

# If the text is longer than 25 characters or so
# sending it all at once will cause artifacts as
# the serial port can't keep up
# Split the string into chunks to prevent this

# If the text sends more characters at once than the device can handle,
# artifacts appear. So, split the string into chunks to prevent this.
if split:
text_chunks = split_string_into_chunks(text, 25)
text_chunks = split_string_into_chunks(text, 10)

for chunk in text_chunks:
self.buffer += chunk
Expand Down Expand Up @@ -265,22 +256,35 @@ def set_rotation(self, rotation):

def set_cursor_pos(self, x, y):
"""
Set cursor position
Set cursor position (in pixels)
"""
self.buffer += "\e[%s;%sH" % (str(x), str(y))

self.sleep()

return self


def set_cursor_loc(self, row, column):
"""
Set cursor position (in text character coordinates)
"""
self.buffer += "\e[%s;%sH" % (str(column * self.text_size * 6), str(row * self.text_size * 6))

self.sleep()

return self

def draw_image(self, img_path, x, y):
"""
Draw image at the specified position
THIS METHOD ISN'T RELIABLE
"""

_, raw_path = tempfile.mkstemp()

# Convert the image
subprocess.call([ "ffmpeg", "-y", "-loglevel", "8","-i", img_path, "-vcodec",
"rawvideo", "-f", "rawvideo", "-pix_fmt", "rgb565", "temp.raw" ])
"rawvideo", "-f", "rawvideo", "-pix_fmt", "rgb565", raw_path ])

image = Image.open(img_path)

Expand All @@ -292,7 +296,10 @@ def draw_image(self, img_path, x, y):
self.sleep(0.05)
# Call a script to cat the image data to the serial port,
# perhaps we could handle this in Python somehow?
subprocess.call([ "./display_image.sh" ])
raw_file = open(raw_path, "rb")
raw_data = raw_file.read()
self.port.write(raw_data)
self.port.flush()
self.sleep(0.05)

# Add a linebreak to prevent glitches when printing text again
Expand Down
4 changes: 2 additions & 2 deletions header.py → odroidshow/header.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from context import Screen, ScreenContext
from odroidshow.context import Screen, ScreenContext
import time

class Header:
Expand Down Expand Up @@ -29,4 +29,4 @@ def render_header(self, ctx, tab, tab_name, tab_count):
# Draw the time
ctx.write(empty_line + time_str)

ctx.bg_color(Screen.BLACK)
ctx.bg_color(Screen.BLACK)
19 changes: 7 additions & 12 deletions showtime.py → odroidshow/showtime.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/usr/bin/env python

from context import Screen, ScreenContext
import config

# Import tabs here
from tabs.bitcoin import Bitcoind, BitcoinPrice
from tabs.sysinfo import SystemStats, DiskUsage

from header import Header
from odroidshow.context import Screen, ScreenContext
from odroidshow.header import Header
import odroidshow.config as config

import atexit
import time
Expand Down Expand Up @@ -37,20 +32,20 @@
atexit.register(ctx.cleanup)

# Wait 6 seconds for the screen to boot up before we start uploading anything
ctx.sleep(6).reset_lcd().set_rotation(0)
ctx.sleep(6).reset_lcd().set_rotation(Screen.VERTICAL)

# Header
header = Header()

print "Started"
print("Started")

time_since_tab_change = 0
last_time = time.time()

while True:
header.render_header(ctx, current_tab, tabs[current_tab].title, len(tabs))
tabs[current_tab].render_tab(ctx)

time_since_tab_change += time.time() - last_time
last_time = time.time()

Expand All @@ -64,4 +59,4 @@
# the font size to 4
ctx.set_text_size(4)
ctx.erase_rows(1, ctx.get_rows()-1)
ctx.set_text_size(2)
ctx.set_text_size(2)
File renamed without changes.
4 changes: 2 additions & 2 deletions tabs/bitcoin.py → odroidshow/tabs/bitcoin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from context import Screen, ScreenContext
from tab import Tab
from tabs.tab import Tab

from utils import format_timespan

Expand Down Expand Up @@ -225,4 +225,4 @@ def render_tab(self, ctx):
#ctx.fg_color(Screen.WHITE).write("24hr high").fg_color(Screen.YELLOW).linebreak().write_line("$%.2f" % self.high)
#ctx.fg_color(Screen.WHITE).write("24hr low").fg_color(Screen.YELLOW).linebreak().write_line("$%.2f" % self.low)

ctx.set_text_size(2)
ctx.set_text_size(2)
15 changes: 15 additions & 0 deletions odroidshow/tabs/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odroidshow.context import Screen, ScreenContext
from odroidshow.tabs.tab import Tab

import time

class HelloTab(Tab):
def __init__(self):
self.title = "Hello World Tab"

def render_tab(self, ctx):

ctx.bg_color(Screen.BLACK)
ctx.fg_color(Screen.WHITE)

ctx.write_line("Hello, World!")
Loading