Exemplo n.º 1
0
def main():
    """main program - display list of images"""

    epd = EPD()

    epd.clear()

    print(
        "panel = {p:s} {w:d} x {h:d}  version={v:s} COG={g:d} FILM={f:d}".format(
            p=epd.panel, w=epd.width, h=epd.height, v=epd.version, g=epd.cog, f=epd.film
        )
    )

    while True:
        for cam in cams:
            fp = urllib2.urlopen(cam)
            file_name = cStringIO.StringIO(fp.read())

            image = Image.open(file_name)
            image = ImageOps.grayscale(image)

            rs = image.resize((epd.width, epd.height))
            bw = rs.convert("1", dither=Image.FLOYDSTEINBERG)

            epd.display(bw)
            epd.update()
            time.sleep(5)  # delay in seconds
Exemplo n.º 2
0
def main_display():
    from EPD import EPD
    epd = EPD()
    #epd.clear()

    previous_messages = []
    while True:
        try:
            messages = json.loads(urllib2.urlopen("http://fjas.no:8181/messages").read())
        except: #urllib2.URLError:
            print "Got problems, sleeping 13s"
            time.sleep(13)
            continue
        #messages = [ { 'x': 25, 'y': 70, 'text':'hei på deg', 'fontsize': 22 } ]
        if not listsDifferent(messages, previous_messages):
            print "No change, sleeping 1.3s"
            time.sleep(1.300)
            continue
        previous_messages = messages

        print "Got new message, updating screen"
        image = getImage(epd.size, messages)

        epd.display(image)
        epd.update()
Exemplo n.º 3
0
    def render(self):
        fin = self.img.rotate(90)
        # fin.save("halibut.png", 'png')

        epd = EPD()
        epd.clear()
        epd.display(fin)
        epd.update()
Exemplo n.º 4
0
def send_to_display(canvas):
    try:
        epd = EPD()
        epd.display(canvas)
        epd.update()

    except IOError:
        print("EPD not supported")
        canvas.show()
Exemplo n.º 5
0
def demo(now):
    epd = EPD('/dev/epd')
    #print('panel = {p:s} {w:d} x {h:d}  version={v:s} COG={g:d}'.format(p=epd.panel, w=epd.width, h=epd.height, v=epd.version, g=epd.cog))
    #epd.clear()

    #font = ImageFont.truetype("freesansbold.ttf", 12)
    font = ImageFont.truetype('/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf', 56)
    image = Image.new('1', epd.size, WHITE)
    draw  = ImageDraw.Draw(image)

    draw.text((30, 30), '%s' % now.strftime('%H:%M'), fill=BLACK, font=font)

    epd.display(image)
    epd.update()
Exemplo n.º 6
0
def main(argv):
    """main program - display image"""

    # print('panel = {p:s} {w:d} x {h:d}  version={v:s} COG={g:d} FILM={f:d}'.format(p=epd.panel, w=epd.width, h=epd.height, v=epd.version, g=epd.cog, f=epd.film))

    # open image and convert to grayscale
    image = Image.open(sys.argv[1])
    image = ImageOps.grayscale(image)

    # convert to 8-bit format
    bw = image.convert("1", dither=Image.FLOYDSTEINBERG)

    # display the image
    epd = EPD()
    epd.display(bw)
    epd.update()
Exemplo n.º 7
0
def main(argv):
    """main program - display image"""

    # print('panel = {p:s} {w:d} x {h:d}  version={v:s} COG={g:d} FILM={f:d}'.format(p=epd.panel, w=epd.width, h=epd.height, v=epd.version, g=epd.cog, f=epd.film))

    # open image and convert to grayscale
    image = Image.open(sys.argv[1])
    image = ImageOps.grayscale(image)

    # convert to 8-bit format
    bw = image.convert("1", dither=Image.FLOYDSTEINBERG)

    # display the image
    epd = EPD()
    epd.display(bw)
    epd.update()
Exemplo n.º 8
0
def display_file(file_name):
    epd = EPD()
    epd.clear()

    print('panel = {p:s} {w:d} x {h:d}  version={v:s}'.format(p=epd.panel, w=epd.width, h=epd.height, v=epd.version))
    # Open image and convert to black and white
    image = PImage.open(file_name)
    image = PImageOps.grayscale(image)

    # Cropping the image as too large to display on panel.
    # Note: the height and width are backwards on purpose as I am forcing it to portrait and rotate the image a bit further down
    # (I couldn't get xhtml2pdf to recognise the flag in the html style sheet, but could be the version of the lib...)
    cropped = image.crop((0, 0, epd.height, epd.width))
    bw = cropped.convert("1", dither=PImage.FLOYDSTEINBERG)
    bw = bw.rotate(90)

    epd.display(bw)
    epd.update()
Exemplo n.º 9
0
Arquivo: ip.py Projeto: mikerr/gratis
from PIL import Image
from PIL import ImageDraw
from EPD import EPD
import commands

WHITE = 1
BLACK = 0


epd = EPD()
epd.clear()



# initially set all white background
image = Image.new('1', epd.size, WHITE)

# prepare for drawing
draw = ImageDraw.Draw(image)


# stuff

output = commands.getoutput('hostname -I');

# text
draw.text((30, 30), output, fill=BLACK)
epd.display(image)
epd.update()

Exemplo n.º 10
0
class PiBus:
    options = None
    scheduler = None
    currentJSON = None
    logger = None
    session = None
    fontTiny = None
    fontMedium = None
    fontLarge = None
    fontHuge = None
    panel = None
    partialCount = None
    lastFetchTime = None
    renderSuspended = None

    def __init__(self, options, scheduler):
        self.options = options
        self.scheduler = scheduler
        self.logger = logging.getLogger("PiBus")
        self.session = requests.Session()

        if options.debug:
            self.logger.setLevel(logging.DEBUG)

        self.logger.debug("Command line options: %s" % self.options)

        if not self.options.busStopID or not self.options.busLine:
            self.logger.error("You must provide both bus stop and bus route")
            sys.exit(1)

        self.partialCount = 0
        self.renderSuspended = False

        self.fontTiny = ImageFont.truetype("font.ttf", size=10)
        self.fontMedium = ImageFont.truetype("font.ttf", size=20)
        self.fontLarge = ImageFont.truetype("font.ttf", size=75)
        self.fontHuge = ImageFont.truetype("font.ttf", size=150)

        try:
            self.panel = EPD()

            self.logger.debug("Panel: {w:d}x{h:d}".format(w=self.panel.width,
                                                          h=self.panel.height))
        except Exception as e:
            self.panel = None
            self.logger.warn("No panel found: %s" % e)

        self.scheduler.add_job(self.updateBusInfo,
                               trigger='interval',
                               seconds=30,
                               next_run_time=datetime.datetime.now(),
                               max_instances=1)
        self.scheduler.add_job(self.renderBusInfo,
                               trigger='interval',
                               seconds=10,
                               next_run_time=datetime.datetime.now(),
                               max_instances=1)

    def prettifyJSON(self, jsonText):
        """Neatly format JSON to make it human readable"""
        return json.dumps(jsonText, sort_keys=True, indent=4,
                          separators=(',', ': '))

    def fetchBusJSON(self, baseURL, stopID):
        """Fetch the JSON for a bus stop"""
        try:
            url = "%s/StopPoint/%s/arrivals" % (baseURL, stopID)
            self.logger.debug("Fetching: %s" % url)
            result = self.session.get(url, timeout=20)
        except Exception as e:
            self.logger.error("fetchBusJSON error. Stop %s: %s" % (stopID, e))
            return None

        jsonResult = result.json()
        self.logger.debug("Raw JSON: %s" % self.prettifyJSON(jsonResult))

        return jsonResult

    def updateBusInfo(self):
        """Update the bus information"""
        rawJSON = self.fetchBusJSON(self.options.baseURL,
                                    self.options.busStopID)
        if not rawJSON:
            self.currentJSON = None
            self.lastFetchTime = -1
            return False

        self.currentJSON = []
        for busItem in rawJSON:
            if busItem[u'lineName'].lower() == \
               self.options.busLine.lower():
                self.currentJSON.append(busItem)

        self.lastFetchTime = time.strftime("%H:%M:%S %d/%m/%Y",
                                           time.localtime())

        return True

    def getTimes(self):
        """Fetch the number of minutes until each bus is due"""
        if not self.currentJSON:
            return None

        times = []

        now = datetime.datetime.now(datetime.timezone.utc)
        for bus in self.currentJSON:
            due = iso8601.parse_date(bus["expectedArrival"])
            dueDiff = due - now
            minutesDue = divmod(dueDiff.total_seconds(), 60)[0]
            times.append("%02d" % max(minutesDue, 0))

        times.sort()

        if len(times) == 0:
            times.append("--")
        if len(times) == 1:
            times.append("--")
        if len(times) == 2:
            times.append("--")

        return times

    def renderBusInfo(self):
        """Render the available bus information to the e-Ink display"""
        # the first argument means we get a 1 bit depth
        image = PIL.Image.new('1', self.panel.size, WHITE)
        draw = ImageDraw.Draw(image)

        # Draw a box on the screen
        draw.line(((0, 0), (self.panel.width, 0)), fill=BLACK, width=1)
        draw.line(((0, 0), (0, self.panel.height)), fill=BLACK, width=1)
        draw.line(((self.panel.width - 1, 0),
                  (self.panel.width - 1, self.panel.height)),
                  fill=BLACK, width=1)
        draw.line(((0, self.panel.height - 1),
                  (self.panel.width - 1, self.panel.height - 1)),
                  fill=BLACK, width=1)

        times = self.getTimes()
        if not times and not self.renderSuspended:
            draw.text((0, 0), "No data available",
                      font=self.fontMedium, fill=BLACK)
            draw.text((0, 25),
                      time.strftime("%H:%M:%S %d/%m/%Y",
                                    time.localtime()),
                      font=self.fontMedium, fill=BLACK)
            self.panel.display(image)
            self.panel.update()
            self.renderSuspended = True
        elif not times:
            self.logger.debug("Skipping, rendering is suspended")
        else:
            self.renderSuspended = False
            # Divide up the box
            draw.line(((self.panel.width * 0.66, 0),
                      (self.panel.width * 0.66, self.panel.height)),
                      fill=BLACK, width=1)
            draw.line(((self.panel.width * 0.66, self.panel.height * 0.5),
                      (self.panel.width, self.panel.height * 0.5)),
                      fill=BLACK, width=1)

            # Render the times
            draw.text((-3, 20), times[0], font=self.fontHuge, fill=BLACK)
            draw.text((174, 10), times[1], font=self.fontLarge, fill=BLACK)
            draw.text((174, 100), times[2], font=self.fontLarge, fill=BLACK)

            # Render the bus route
            draw.text((1, 0), self.options.busLine,
                      font=self.fontTiny, fill=BLACK)

            # Render the time of last successful data fetch
            draw.text((1, self.panel.height - 10),
                      "Fetched: %s" % self.lastFetchTime,
                      font=self.fontTiny, fill=BLACK)

            self.panel.display(image)

            if self.partialCount >= 10:
                self.panel.update()
                self.partialCount = 0
            else:
                self.panel.partial_update()
                self.partialCount += 1

    def dummyShowBusInfo(self):
        """blah"""
        times = self.getTimes()

        print("")

        if not times:
            print("No time information is available")
            return

        if len(times) == 0:
            print("Times info is empty")
            return

        for aTime in times:
            print("Bus due in %d minutes" % aTime)
Exemplo n.º 11
0
import sys
from PIL import Image
from PIL import ImageDraw
from EPD import EPD
import commands

WHITE = 1
BLACK = 0

epd = EPD()
epd.clear()

# initially set all white background
image = Image.new('1', epd.size, WHITE)

# prepare for drawing
draw = ImageDraw.Draw(image)

# stuff

output = commands.getoutput('hostname -I')

# text
draw.text((30, 30), output, fill=BLACK)
epd.display(image)
epd.update()