Exemple #1
0
    def __init__(self, num_stars, max_depth):
 
        self.tft = SerialTFT("/dev/ttyAMA0", 9600, True, False)

        self.start_col = 0
        self.max_col = 7
        self.max_size = 2

        # This colour setup is best if you have firmware support

        # -- COLOR SETUP --
        if(MY_FIRMWARE_IS_MODIFIED):
            self.tft.set_color_hex(8,"#000000")
            self.tft.set_color_hex(9,"#333333")
            self.tft.set_color_hex(10,"#555555")
            self.tft.set_color_hex(11,"#777777")
            self.tft.set_color_hex(12,"#999999")
            self.tft.set_color_hex(13,"#BBBBBB")
            self.tft.set_color_hex(14,"#DDDDDD")
            self.tft.set_color_hex(15,"#FFFFFF")
            self.start_col = 8
            self.max_col = 15
            self.max_size = 2
        # -- END COLOR SETUP ---

        # Clear Screen
        self.tft.screen_rotation(SerialTFT.Rotation.landscape)
        self.tft.bg_color(SerialTFT.Color.black)
        self.tft.fg_color(SerialTFT.Color.white)
        self.tft.clear_screen()

        self.num_stars = num_stars
        self.max_depth = max_depth
 
        self.init_stars()
Exemple #2
0
CLOCK_RADIUS		= SerialTFT.Screen.height_half-20
CLOCK_BACKGROUND 	= SerialTFT.Color.black
CLOCK_OUTLINE		= SerialTFT.Color.magenta
CLOCK_CENTER		= SerialTFT.Color.blue
CLOCK_NUMBERS		= SerialTFT.Color.green
CLOCK_DIGITAL		= SerialTFT.Color.blue
CLOCK_HOUR_HAND 	= SerialTFT.Color.cyan
CLOCK_MINUTE_HAND 	= SerialTFT.Color.cyan
CLOCK_SECOND_HAND 	= SerialTFT.Color.red

# Setup the SerialTFT library, we want to clean up the LCD on exit
# so specify true for clear_on_exit
# We're driving the SerialTFT within sane limits,
# so we can turn off flush safely.
# SerialTFT( device, baud_rate, clear_on_exit, flush )
tft = SerialTFT("/dev/ttyAMA0", 9600, True, False)


# Uncomment the colour setup if you have firmware support
# for user-colours. Modified firmware can be found here:
# https://github.com/Gadgetoid/serial_tft_18/

# -- COLOR SETUP --
#tft.set_theme(SerialTFT.Theme.matrix)
#CLOCK_BACKGROUND 	= SerialTFT.Color.user_black
#CLOCK_OUTLINE		= SerialTFT.Color.user_magenta
#CLOCK_CENTER		= SerialTFT.Color.user_blue
#CLOCK_NUMBERS		= SerialTFT.Color.user_green
#CLOCK_DIGITAL		= SerialTFT.Color.user_blue
#CLOCK_HOUR_HAND	= SerialTFT.Color.user_cyan
#CLOCK_MINUTE_HAND 	= SerialTFT.Color.user_cyan
# requires python2, python2-pyserial
# requires serialtft: https://github.com/Gadgetoid/Serial-TFT-Python

import sys, os
import time, datetime
from time import strftime, strptime

# sys.path.append(os.path.abspath("/path/to/serial-tft-python"))
from serialtft import SerialTFT

# setup the serialtft library, we dont want to clean up the lcd on exit
# so specify false for clear_on_exit. we're not sure whether we are driving
# the serialtft within sane limits, so we will turn on flush.
#
# serialtft( device, baud_rate, clear_on_exit, flush )
tft = SerialTFT("/dev/ttyAMA0", 9600, False, True)

# read supporter count from file
# kindly ask support for API access (ref ticket #AW-3028)
count_file = "./counter"  # adjust /path/to/.
modified_time = 0
supporter_count = "Err0"
try:
    dump = open(count_file)
    supporter_count = str(dump.read())
    modified_time = int(os.path.getmtime(count_file))
    modified_time = datetime.datetime.fromtimestamp(modified_time)
    modified_time = modified_time.strftime("%d.%m.%Y %H:%M:%S")
except IOError:
    print "Oops! Could not read file."
    supporter_count = "Err1"
Exemple #4
0
class Simulation:
    def __init__(self, num_stars, max_depth):
 
        self.tft = SerialTFT("/dev/ttyAMA0", 9600, True, False)

        self.start_col = 0
        self.max_col = 7
        self.max_size = 2

        # This colour setup is best if you have firmware support

        # -- COLOR SETUP --
        if(MY_FIRMWARE_IS_MODIFIED):
            self.tft.set_color_hex(8,"#000000")
            self.tft.set_color_hex(9,"#333333")
            self.tft.set_color_hex(10,"#555555")
            self.tft.set_color_hex(11,"#777777")
            self.tft.set_color_hex(12,"#999999")
            self.tft.set_color_hex(13,"#BBBBBB")
            self.tft.set_color_hex(14,"#DDDDDD")
            self.tft.set_color_hex(15,"#FFFFFF")
            self.start_col = 8
            self.max_col = 15
            self.max_size = 2
        # -- END COLOR SETUP ---

        # Clear Screen
        self.tft.screen_rotation(SerialTFT.Rotation.landscape)
        self.tft.bg_color(SerialTFT.Color.black)
        self.tft.fg_color(SerialTFT.Color.white)
        self.tft.clear_screen()

        self.num_stars = num_stars
        self.max_depth = max_depth
 
        self.init_stars()
 
    def init_stars(self):
        """ Create the starfield """
        self.stars = []
        for i in range(self.num_stars):
            # A star is represented as a list with this format: [X,Y,Z]
            star = [randrange(-15,15), randrange(-15,15), randrange(1, self.max_depth)]
            self.stars.append(star)
 
    def move_and_draw_stars(self):
        """ Move and draw the stars """
        origin_x = self.tft.Screen.width / 2
        origin_y = self.tft.Screen.height / 2
 
        for star in self.stars:


            # Erase old position of star
            
            k = 128.0 / star[2]
            x = int(star[0] * k + origin_x)
            y = int(star[1] * k + origin_y)

            if 0 <= x < self.tft.Screen.width and 0 <= y < self.tft.Screen.height:
                size = int((1 - float(star[2]) / self.max_depth) * self.max_size) + 1
                if(MY_FIRMWARE_IS_MODIFIED):
                    self.tft.draw_pixel(x,y,0)
                    #self.tft.draw_box(x,y,size,size,0)
                else:
                    self.tft.fg_color(0)
                    self.tft.draw_rect(x,y,size,size)
            


            # The Z component is decreased on each frame.
            # Decease this number for a smoother, slower starfield
            star[2] -= 0.40
 
            # If the star has past the screen (I mean Z<=0) then we
            # reposition it far away from the screen (Z=max_depth)
            # with random X and Y coordinates.
            if star[2] <= 0:
                star[0] = randrange(-15,15)
                star[1] = randrange(-15,15)
                star[2] = self.max_depth
 
            # Convert the 3D coordinates to 2D using perspective projection.
            k = 128.0 / star[2]
            x = int(star[0] * k + origin_x)
            y = int(star[1] * k + origin_y)
 
            # Draw the star (if it is visible in the screen).
            # We calculate the size such that distant stars are smaller than
            # closer stars. Similarly, we make sure that distant stars are
            # darker than closer stars. This is done using Linear Interpolation.
            if 0 <= x < self.tft.Screen.width and 0 <= y < self.tft.Screen.height:
                size = int((1 - float(star[2]) / self.max_depth) * self.max_size) + 1
                shade = self.start_col + int((1 - float(star[2]) / self.max_depth) * 7) + 3

                if(shade > self.max_col):
                    shade = self.start_col

                if(MY_FIRMWARE_IS_MODIFIED):
                    self.tft.draw_pixel(x,y,shade)
                    #self.tft.draw_box(x,y,size,size,shade)
                else:
                    self.tft.fg_color(shade)
                    self.tft.draw_rect(x,y,size,size)

 
    def run(self):
        while 1:
            self.move_and_draw_stars()
Exemple #5
0
# It has been included for posterity and is subject to change.
#
# The tests below have been used for determining
# optimum delay times at 9600baud
#
# Certain commands will cause a serial buffer overflow
# if they are not allowed time to complete

import time
from time import localtime, strftime
from random import randint
from serialtft import SerialTFT

from functools import reduce

tft = SerialTFT("/dev/ttyAMA0", 9600, True, False)

BAR_WIDTH = 4
BAR_MARGIN = 1

# Clear Screen
tft.screen_rotation(SerialTFT.Rotation.landscape)
tft.bg_color(SerialTFT.Color.black)
tft.clear_screen()

colors = [
	SerialTFT.Color.blue,
	SerialTFT.Color.red,
	SerialTFT.Color.green,
	SerialTFT.Color.cyan,
	SerialTFT.Color.magenta,