コード例 #1
0
def draw(filename):
    path = os.path.join(PICTURE_PATH, filename)

    if os.path.isfile(path):
        image = PapirusImage()
        image.write(path)
        return 'ok'

    else:
        return '404', 404
コード例 #2
0
def write_text(papirus, text, size, flag):

    screen = PapirusImage()
    print(flag)

    if flag == 1:
        screen.write('./images/light1.bmp')

    if flag == 2:
        screen.write('./images/light2.bmp')

    if flag == 3:
        screen.write('./images/tv.bmp')

    if flag == 4:
        screen.write('./images/fan.bmp')
コード例 #3
0
class PapirusDisplay(Display):
    _WHITE = (255, 255, 255)
    _IMAGE_SUFFIX = "-papirus.bmp"

    def __init__(self):
        self._screen = Papirus()
        self._image = PapirusImage()
        self._text = PapirusText()

    def draw(self, notification):
        self._screen.update()
        if isinstance(notification, TextNotification):
            self._text.write(notification.get_text())
        elif isinstance(notification, ImageNotification):
            image_path = notification.get_image_path()
            converted_image_path = image_path + self._IMAGE_SUFFIX

            if not os.path.exists(converted_image_path):
                convert_bmp(image_path, converted_image_path)

            self._image.write(converted_image_path)

    @staticmethod
    def get_supported_notifications():
        return [TextNotification, ImageNotification]

    @staticmethod
    def get_id():
        return "papirus"

    def __str__(self):
        return "Papirus display"

    @staticmethod
    def get_config_factory():
        return PapirusConfig()
コード例 #4
0
ファイル: displaytrump.py プロジェクト: admiralstrand/papirus
from papirus import Papirus
from papirus import PapirusImage
from papirus import PapirusText

screen = Papirus()
image = PapirusImage()
text = PapirusText()

screen.update()

image.write('/home/pi/papirus/epapertrump.bmp')

#text.write("hello")


コード例 #5
0
# Run like this:
#   python3 papirus_server.py --machine-name:$(hostname -I)
#
import json
import sys
import threading
import traceback
import time
from http.server import HTTPServer, BaseHTTPRequestHandler
from time import sleep
from papirus import PapirusText   # See the README.md
from papirus import PapirusImage

rot = 00
papirus_display = PapirusText(rotation=rot)
papirus_image   = PapirusImage(rotation=rot)

sample_data = {  # Used for non-implemented operations. Fallback.
    "1": "First",
    "2": "Second",
    "3": "Third",
    "4": "Fourth"
}
server_port = 8080
REST_DEBUG = False


class CoreFeatures:
    """
    Implements the methods used in the REST operations below
    """
コード例 #6
0
#!/usr/bin/env python3

import os
import requests
from papirus import PapirusImage

result = requests.get(os.environ['URL'], stream=True)
image = result.raw

screen = PapirusImage()

screen.write(image)
コード例 #7
0
ファイル: santa.py プロジェクト: westy48/santa
import random
import os
from papirus import PapirusImage
from gpiozero import Button, PWMLED, LED

randomfile=""

button = Button(27)
led = PWMLED(22)
folder = 'santa/'
image = PapirusImage()

while True:
    button.wait_for_press()
    led.pulse(n=3)
    randomfile = random.sample(os.listdir("santa/"), 1)[0]
    image.write(folder + randomfile)
コード例 #8
0
from papirus import Papirus
from papirus import PapirusImage
from papirus import PapirusText
from papirus import PapirusTextPos
import time
from twython import TwythonStreamer

screen = Papirus()
image = PapirusImage()
text = PapirusTextPos()

TERMS = '#alembic'

#login codes

APP_KEY = 'xCR6gEUjadgEAuYH5Oh2ehvhT'
APP_SECRET = 'PyhW6JM0EfqUS1l6sER8O8pSmoJxM2vmfJ2pQgOblHO2fx0Bjr'
OAUTH_TOKEN = '20427648-xL2sPwZRpi2V7jxuLFYHxqsOw8FytIgi9KA0e1K9v'
OAUTH_TOKEN_SECRET = 'Xho6kqVa38S4kJ742mNi9pDALM4jqXEvZTeE5lUziWnrT'

#setup callback from twython streamer

class BlinkyStreamer(TwythonStreamer):
        def on_success(self, data):
                if 'text' in data:
                        print data['text'].encode('utf-8')
                        print
                        text.AddText("#alembic", 60, 20, Id="Start", invert=True)
                        time.sleep(5.0)
                        image.write('/home/pi/papirus/epapertrump.bmp')
#screen.update()
コード例 #9
0
 def __init__(self):
     self._screen = Papirus()
     self._image = PapirusImage()
     self._text = PapirusText()
コード例 #10
0
def drawOnScreen():
    image = PapirusImage()
    image.write('output-trimmed.png')
コード例 #11
0
def main():
    global SIZE
    global FLAG

    GPIO.setmode(GPIO.BCM)

    GPIO.setup(SW1, GPIO.IN)
    GPIO.setup(SW2, GPIO.IN)
    GPIO.setup(SW3, GPIO.IN)
    GPIO.setup(SW4, GPIO.IN)
    if SW5 != -1:
        GPIO.setup(SW5, GPIO.IN)

    papirus = Papirus()
    screen = PapirusImage()

    # Use smaller font for smaller dislays
    if papirus.height <= 96:
        SIZE = 18

    papirus.clear()

    # Initialize Screen
    screen.write('./images/light1.bmp')
    while True:
        # Exit when SW1 and SW2 are pressed simultaneously
        if (GPIO.input(SW1) == False) and (GPIO.input(SW2) == False):
            write_text(papirus, "Exiting ...", SIZE)
            sleep(0.2)
            papirus.clear()
            sys.exit()

        # Up Arrow
        if GPIO.input(SW1) == False:
            if FLAG == 4:
                FLAG = 1
            else:
                FLAG += 1
            write_text(papirus, "placeholder", SIZE, FLAG)

        # Down Arrow
        if GPIO.input(SW2) == False:
            if FLAG == 1:
                FLAG = 4
            else:
                FLAG -= 1
            write_text(papirus, "placeholder", SIZE, FLAG)

        # Function 3
        if GPIO.input(SW3) == False:
            function_three(FLAG)

        # Function 2
        if GPIO.input(SW4) == False:
            function_two(FLAG)

        # Function 1
        if (SW5 != -1) and (GPIO.input(SW5) == False):
            function_one(FLAG)

        sleep(0.05)
コード例 #12
0
import os
import smbus
import RPi.GPIO as GPIO
import datetime

import Image
import ImageDraw
import ImageFont

from papirus import Papirus
from papirus import PapirusImage
from papirus import PapirusComposite

# Set Screen rotation
# Optional rotation argument: rot = 0, 90, 180 or 270
image = PapirusImage(180)


# Loops through displays infinitely
while True:
  # 1 Original Screen Major / Minor / Graduation displays for 15 seconds
  # Write image to the epaper screen
  image.write('./nametagmajorbox.png')

  # Wait / display for 15 seconds
  time.sleep(15)
  #time.sleep(3) # For dev

  # 2 Display Hobbies and Interests 15 seconds
  # Write image to the epaper screen
  image.write('./factsnametagbox.png')
コード例 #13
0
def drawOnScreen():
    image = PapirusImage()
    image.write('output-inverted.png')
コード例 #14
0
def main():
    global SIZE
    global FLAG

    heading = []
    roll = []
    pitch = []

    GPIO.setmode(GPIO.BCM)

    GPIO.setup(SW1, GPIO.IN)
    GPIO.setup(SW2, GPIO.IN)
    GPIO.setup(SW3, GPIO.IN)
    GPIO.setup(SW4, GPIO.IN)
    if SW5 != -1:
        GPIO.setup(SW5, GPIO.IN)

    papirus = Papirus()
    screen = PapirusImage()

    # Use smaller font for smaller dislays
    if papirus.height <= 96:
        SIZE = 18

    papirus.clear()

    # Initialize Screen
    screen.write('../final_project_code/images/light1.bmp')
    while True:
        # Exit when SW1 and SW2 are pressed simultaneously
        if (GPIO.input(SW1) == False) and (GPIO.input(SW2) == False):
            write_text(papirus, "Exiting ...", SIZE)
            sleep(0.2)
            papirus.clear()
            sys.exit()

        if GPIO.input(SW1) == False:
            if FLAG == 4:
                FLAG = 1
            else:
                FLAG += 1
            write_text(papirus, "placeholder", SIZE, FLAG)

        if GPIO.input(SW2) == False:
            if FLAG == 1:
                FLAG = 4
            else:
                FLAG -= 1
            write_text(papirus, "placeholder", SIZE, FLAG)

        input_state = GPIO.input(18)
        if input_state == False:
            # print('Button Pressed')
            # Read the Euler angles for heading, roll, pitch (all in degrees).
            heading_temp, pitch_temp, roll_temp = bno.read_euler()
            # store orientation angles into list arrays
            heading.append(heading_temp)
            roll.append(roll_temp)
            pitch.append(pitch_temp)
            # Read the calibration status, 0=uncalibrated and 3=fully calibrated.
            sys, gyro, accel, mag = bno.get_calibration_status()
            sleep(.01)

        elif len(heading) != 0:
            # Print everything out.

            if debug == 1:
                print "heading list: "

            rounded_heading = []
            rounded_pitch = []

            rounded_heading = round_angles(heading)
            rounded_pitch = round_angles(pitch)

            rounded_heading = np.array(rounded_heading)
            rounded_pitch = np.array(rounded_pitch)

            # Center heading
            centered_heading = rounded_heading[:] - rounded_heading[1]

            if debug == 1:
                print "Centered heading data: "
                print centered_heading
                print "Pitch data: "
                print rounded_pitch

            # Convert heading data to project position data
            position_array_length = len(centered_heading[:])

            if debug == 1:
                print "Array Length: "
                print position_array_length

            pitch_array_length = len(rounded_pitch[:])

            if debug == 1:
                print "pitch array length: "
                print pitch_array_length

            heading_array_length = len(rounded_heading[:])

            if debug == 1:
                print "heading array length: "
                print heading_array_length

            #Convert heading and pitch angles into cartesion coordinates
            #y_length was arbitrarily set to 10
            y_length = 10
            x_position = y_length * np.tan(np.deg2rad(centered_heading[:]))
            y_position = y_length * np.tan(np.deg2rad(rounded_pitch[:]))

            if debug == 1:
                print "x_position array: "
                print x_position

                print "y_position array: "
                print y_position

            data_points = np.vstack((x_position, y_position))

            if debug == 1:
                print "data points: "
                print data_points

            #generate vectors from data_points
            vectors = np.zeros((position_array_length, 3))

            #create vectors connecting each points
            for k in range(0, position_array_length - 2):
                vectors[k, 0] = data_points[0, k + 1] - data_points[0, k]
                vectors[k, 1] = data_points[1, k + 1] - data_points[1, k]

            #creates final vector between starting and ending points
            vectors[position_array_length - 1,
                    0] = data_points[0, position_array_length -
                                     1] - data_points[0, 0]
            vectors[position_array_length - 1,
                    1] = data_points[1, position_array_length -
                                     1] - data_points[1, 0]

            if debug == 1:
                print "Vectors Array: "
                print vectors

            #remove duplicate vectors from array
            vectors = vectors[~(vectors == 0).all(1)]

            if debug == 1:
                print "Vectors with duplicates removed: "
                print vectors

            #generate array of vector angles by reference vector array to a zero degree reference vector
            ref_vector = [1, 0, 0]
            cross_variable = np.cross(ref_vector, vectors)
            vector_array_length = len(vectors)

            vector_angles = []

            for k in range(0, vector_array_length - 1):
                dot_product = np.dot(ref_vector, vectors[k])
                np.arctan2(cross_variable[:, 2],
                           np.dot(ref_vector, vectors[k]))
                vector_angles.append(
                    np.arctan2(cross_variable[k, 2],
                               np.dot(ref_vector, vectors[k])) * 180 / pi)

            if debug == 1:
                print "Vector Angles List: "
                print np.around(vector_angles)

            #replace negative angles to form unit circle values from 0 to 360 degrees
            for k in range(0, vector_array_length - 1):
                if vector_angles[k] <= 0:
                    vector_angles[k] = 360 + vector_angles[k]

            if debug == 1:
                print "Vector Angles List: "
                print np.around(vector_angles)

            #bin vector angles for frequency analysis
            edges = np.linspace(0, 360, 73)  #0 5 10 ...360
            frequency_hist = np.histogram(vector_angles, edges)

            if debug == 1:
                print "Freqency Bins: "
                print frequency_hist[0]

            frequency_hist = np.array(frequency_hist[0])

            #generate shape charactersistics that can be used to identify drawn shape
            dominant_angle_number = len(
                frequency_hist[np.where(frequency_hist > 4)])
            dominant_angle_index = np.argmax(frequency_hist)
            dominant_angle_value = 5 * dominant_angle_index

            print "Dominant Angle: "
            print dominant_angle_value

            #Use frequency analysis to determine shape drawn
            choices = {1: 'line', 3: 'triangle', 4: 'square', 0: 'none'}
            result = choices.get(dominant_angle_number,
                                 'Sorry no ID made! Try again...')

            print "Shape Matched: "
            print result

            if result == 'line':
                if dominant_angle_value < 15 or dominant_angle_value > 345:
                    result = 'right_swipe'
                elif dominant_angle_value < 60 and dominant_angle_value > 15:
                    result = 'quad_diagonal_1'
                elif dominant_angle_value > 135 and dominant_angle_value < 225:
                    result = 'left_swipe'
                elif dominant_angle_value > 60 and dominant_angle_value < 135:
                    result = 'up_swipe'
                elif dominant_angle_value > 235 and dominant_angle_value < 345:
                    result = 'down_swipe'

            print "Shape Matched: "
            print result

            shapes.append(result)
            logic.roku_command(shapes)
            shapes.remove(result)

            # Reset heading list
            heading = []
            pitch = []

        sleep(0.1)