Пример #1
0
class Display:
    def __init__(self, saturation=0.5):
        self.inky = Inky()
        self.saturation = saturation

    def resize_for_screen(self, image):
        copied = image.copy()

        # Apply rotation in exif data
        copied = ImageOps.exif_transpose(image)

        copied.thumbnail([600, 448])
        size = copied.size
        print(size)
        background = Image.new("RGB", (600, 448), (255, 255, 255))
        background.paste(copied, (int(
            (600 - size[0]) / 2), int((448 - size[1]) / 2)))
        return background

    def _show_latest(self):
        latest_image = self.resize_for_screen(Image.open("latest"))

        self.inky.set_image(latest_image, saturation=self.saturation)
        self.inky.show(busy_wait=False)
        print("done")

    def show_latest(self):
        task = threading.Thread(target=self._show_latest, args=())
        task.start()
Пример #2
0
def test_init_7colour_setup(spidev, smbus2, GPIO):
    """Test initialisation and setup of 7-colour Inky.

    Verify our expectations for GPIO setup in order to catch regressions.

    """
    from inky.inky_uc8159 import Inky

    # TODO: _busy_wait should timeout after N seconds
    GPIO.input.return_value = GPIO.LOW

    inky = Inky()
    inky.setup()

    # Check GPIO setup
    GPIO.setwarnings.assert_called_with(False)
    GPIO.setmode.assert_called_with(GPIO.BCM)
    GPIO.setup.assert_has_calls([
        mock.call(inky.dc_pin, GPIO.OUT, initial=GPIO.LOW, pull_up_down=GPIO.PUD_OFF),
        mock.call(inky.reset_pin, GPIO.OUT, initial=GPIO.HIGH, pull_up_down=GPIO.PUD_OFF),
        mock.call(inky.busy_pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
    ])

    # Check device will been reset
    GPIO.output.assert_has_calls([
        mock.call(inky.reset_pin, GPIO.LOW),
        mock.call(inky.reset_pin, GPIO.HIGH)
    ])

    # Check API will been opened
    spidev.SpiDev().open.assert_called_with(0, inky.cs_channel)
Пример #3
0
def test_init_7colour_setup_no_gpio(spidev, smbus2):
    from inky.inky_uc8159 import Inky

    inky = Inky()

    with pytest.raises(ImportError):
        inky.setup()
Пример #4
0
def test_init_7colour_setup_no_gpio(spidev, smbus2):
    """Test initialisation and setup of 7-colour Inky.

    Verify an error is raised when RPi.GPIO is not present.

    """
    from inky.inky_uc8159 import Inky

    inky = Inky()

    with pytest.raises(ImportError):
        inky.setup()
Пример #5
0
def test_eeprom_7color_5_7_inch(spidev, smbus2_eeprom, PIL):
    """Test EEPROM for 7color 5.7" Inky"""
    from inky.inky_uc8159 import Inky
    from inky.eeprom import EPDType

    eeprom_data = EPDType(600, 448, 0, 0, 14).encode()

    smbus2_eeprom.SMBus(1).read_i2c_block_data.return_value = eeprom_data

    inky = Inky()

    assert inky.resolution == (600, 448)
Пример #6
0
def clear_inky():
    inky = Inky()

    for _ in range(4):
        for y in range(inky.height - 1):
            for x in range(inky.width - 1):
                inky.set_pixel(x, y, CLEAN)

        inky.show()
        time.sleep(1.0)
Пример #7
0
#!/usr/bin/env python3
import time

from inky.inky_uc8159 import Inky

inky = Inky()

colors = ['Black', 'White', 'Green', 'Blue', 'Red', 'Yellow', 'Orange']

for color in range(7):
    print("Color: {}".format(colors[color]))
    for y in range(inky.height):
        for x in range(inky.width):
            inky.set_pixel(x, y, color)
    inky.set_border(color)
    inky.show()
    time.sleep(5.0)
Пример #8
0
deviceRef = db.reference("devices").child(serial)

deviceRef.update({
    "last-boot": datetime.now().isoformat(),
    "network-adapters": ips,
    "public-ip": wanip
})

settingsRef = deviceRef.child("settings")
settings = settingsRef.get()
print(settings)

if (settings == None):
    settings = {}

inky_display = Inky()

if ("wanted-time" not in settings):
    nowTmp = datetime.now().__add__(timedelta(hours=1))
    now = ceil_dt(nowTmp, timedelta(minutes=15))
    settings["wanted-time"] = now.isoformat()
    settingsRef.update(settings)

#setDisplayTimer(settings)

BUTTONS = [5, 6, 16, 24]
LABELS = ['A', 'B', 'C', 'D']
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP)

Пример #9
0
print("""

Requires the seaborn library: suso python3 -m pip install seaborn
You may need to: sudo apt install libatlas-base-dev

""")

# Convert the built-in palette to a list of colours usable by seaborn,
# This nets us 6 colours: Green, Blue, Red, Yellow, Orange, Black
palette_colors = [(c[0] / 255.0, c[1] / 255.0, c[2] / 255.0) for c in DESATURATED_PALETTE[2:6] + [(0, 0, 0)]]

parser = argparse.ArgumentParser()
parser.add_argument("--dataset", "-d", choices=["penguins", "dots", "mpg"], default="mpg")
args = parser.parse_args()

inky = Inky()
saturation = 0
dpi = 80
buf = io.BytesIO()

seaborn.set_theme(style="white")

if args.dataset == "mpg":
    palette = seaborn.color_palette(palette_colors, n_colors=3)
    mpg = seaborn.load_dataset("mpg")

    plot = seaborn.relplot(
        x="horsepower", y="mpg", hue="origin", size="weight",
        sizes=(40, 400), alpha=1.0, palette=palette,
        data=mpg)
Пример #10
0
 def __init__(self, saturation=0.5):
     self.inky = Inky()
     self.saturation = saturation
Пример #11
0
from inky.inky_uc8159 import Inky, CLEAN
import time
import paho.mqtt.client as mqtt
import sys
from PIL import Image, ImageDraw, ImageFont

if (len(sys.argv) < 3):
    print("first argument mqtt server, second topic")
    quit

inky = Inky()


def on_connect(client, userdata, flags, rc):
    print("Connected with result code " + str(rc))
    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe(sys.argv[2])


# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(msg.topic + " " + str(msg.payload))
    array = msg.payload.split(";", 10)
    cmd = array[0]
    print(cmd)
    if (cmd == "cls"):
        clean()
    if (cmd == "showbuffer"):
        show_buffer()
    if (cmd == "helloworld"):
Пример #12
0
You will need to install hitherdither from GitHub:

sudo python3 -m pip install git+https://www.github.com/hbldh/hitherdither


usage: ./dither.py <image_file> <saturation>

- Image file should be RGB and can be a jpg, PNG or otherwise.

- Saturation should be from 0.0 to 1.0 and changes the palette that's used to dither the image.
  a higher saturation will generally result in a more saturated end image due to how colours are mixed.

""")

inky = Inky()
saturation = 0.5  # Saturation of palette
thresholds = [64, 64, 64]  # Threshold for snapping colours, I guess?

if len(sys.argv) == 1:
    print("""
Usage: {file} image-file
""".format(file=sys.argv[0]))
    sys.exit(1)

if len(sys.argv) > 2:
    saturation = float(sys.argv[2])

palette = hitherdither.palette.Palette(
    inky._palette_blend(saturation, dtype='uint24'))
Пример #13
0
import os
import json
from PIL import Image, ImageDraw, ImageFont
from inky.inky_uc8159 import Inky
from datetime import datetime as dt
from bots.orgbot import get_org_image
from bots.twitterbot import get_tweet_img
from bots.twitterbot import get_recent_care_tweet
from bots.pomodorobot import get_pomodoro_time
from bots.pomodorobot import get_pomodoro
from bots.calendarbot import get_next_event
from bots.calendarbot import get_event_img

# Inky display information
inky_display = Inky()  # Global because only one inky to pass around...

DESATURATED_PALETTE = (
    0,
    0,
    0,
    255,
    255,
    255,
    0,
    255,
    0,
    0,
    0,
    255,
    255,
    0,
Пример #14
0
#!/usr/bin/env python3
import time

from inky.inky_uc8159 import Inky, CLEAN

inky = Inky()

for _ in range(2):
    for y in range(inky.height - 1):
        for x in range(inky.width - 1):
            inky.set_pixel(x, y, CLEAN)

    inky.show()
    time.sleep(1.0)
Пример #15
0
parser = argparse.ArgumentParser()

parser.add_argument('--type',
                    '-t',
                    choices=['css', 'act', 'raw', 'pal', 'gpl'],
                    help='Type of palette to output')
parser.add_argument('--saturation',
                    '-s',
                    type=float,
                    default=0.5,
                    help='Colour palette saturation')
parser.add_argument('--file', '-f', type=pathlib.Path, help='Output file')

args = parser.parse_args()

inky = Inky()

names = ['black', 'white', 'green', 'blue', 'red', 'yellow', 'orange']

if args.file is None:
    print("You must specify an output palette file.")
    sys.exit(1)


def raw_palette():
    palette = bytearray(768)
    palette[0:8 * 3] = inky._palette_blend(args.saturation, dtype='uint8')
    return palette


if args.type == 'css':
Пример #16
0
    #Setup button 'A' on the inky
    pin = 5
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    def btn_A_handler(pin):
        global capture
        capture = True

    GPIO.add_event_detect(pin, GPIO.FALLING, btn_A_handler, bouncetime=250)

    fps = 8
    thermal_camera = ThermalCamera(fps)
    print("Started recording")
    thermal_camera.start_recording()
    inky = Inky()
    try:
        while True:
            with thermal_camera.condition:
                thermal_camera.condition.wait()
                if capture == True:
                    print('Capture image')
                    time.sleep(5)
                    print('Ready')

                    capture = False
                    frame = thermal_camera.frame
                    vmin = min(frame)
                    vmax = max(frame)
                    img = Image.new('RGB', (32, 24), 'black')