Beispiel #1
0
    def __init__(self, config):

        self.config = config

        if _SENSOR_DISPLAY:
            self.papirus = Papirus(rotation=180)
            self.clear()
Beispiel #2
0
 def __init__(self, autoUpdate=True, rotation=0):
     # Set up the PaPirus and dictionary for text
     self.papirus = Papirus(rotation=rotation)
     self.allText = dict()
     self.image = Image.new('1', self.papirus.size, WHITE)
     self.autoUpdate = autoUpdate
     self.partialUpdates = False
Beispiel #3
0
def main(argv):
    """main program - display list of images"""
    dir_path = os.path.dirname(os.path.realpath(__file__))
    subprocess.call(shlex.split(dir_path + '/speedtest2.sh'))
    x = 0
    with open('graph.txt') as f:
        lines = f.readlines()
        y = [line.split()[0] for line in lines]

    with open('graph2.txt') as f2:
        lines = f2.readlines()
        y2 = [line.split()[0] for line in lines]
        #x = [x++1 for line in lines]

    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    ax1.set_title("Speed Test")
    ax1.plot(y, c='r', label='Down')
    ax1.plot(y2, c='b', label='Up')
    leg = ax1.legend()
    fig.set_size_inches(3.8, 2.5)
    fig.savefig('temp.png', dpi=75)

    epd = Papirus()

    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))

    display_file(epd, 'temp.png')
Beispiel #4
0
 def __init__(self, config, logFilename):
     self.my_papirus = Papirus(rotation=180)
     self.WHITE = 1
     self.BLACK = 0
     super().__init__(config, logFilename)
     while True:
         time.sleep(self.fullUpdateInterval*60)
         self.fullUpdate = True
Beispiel #5
0
def main(argv):
    """main program - draw and display time and date"""

    papirus = Papirus(rotation=int(argv[0]) if len(sys.argv) > 1 else 0)

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

    papirus.clear()

    timer(papirus, 10)
Beispiel #6
0
    def __init__(self, autoUpdate = True, rotation = 0):
        # Set up the PaPirus and dictionary for text
        self.papirus = Papirus(rotation = rotation)
        self.allText = dict()
        self.image = Image.new('1', self.papirus.size, WHITE)
        self.autoUpdate = autoUpdate
	self.partial_updates = False
Beispiel #7
0
def main():
    """main program - draw and display time and date"""

    papirus = Papirus()

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

    demo(papirus)
Beispiel #8
0
def main(argv):
    """main program - draw and display time and date"""

    setup_gpio()

    papirus = Papirus(rotation=int(argv[0]) if len(sys.argv) > 1 else 0)

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

    papirus.clear()

    while True:
        if GPIO.input(SW1) == False:
            timer(papirus, 10)
        if GPIO.input(SW2) == False:
            timer(papirus, 64)
Beispiel #9
0
def main():
    GPIO.setmode(GPIO.BCM)

    GPIO.setup(SW1, GPIO.IN)
    GPIO.setup(SW2, GPIO.IN)
    GPIO.setup(SW3, GPIO.IN)
    GPIO.setup(SW4, GPIO.IN)
    GPIO.setup(SW5, GPIO.IN)

    # Need this to overcome an issue when the script is run from the cron job at startup
    sleep(10)

    papirus = Papirus()

    displayimage(papirus, imagename="hello.bmp")

    while True:
        displayimage(papirus, imagename='andrewonly.bmp', partial=1)
        sleep(1)
        displayimage(papirus, imagename='andrewmarshall.bmp', partial=1)
        sleep(3)
        displayimage(papirus, imagename='DSmonochrome.bmp', partial=1)
        sleep(2)
        displayimage(papirus, imagename='mobileapps.bmp', partial=1)
        sleep(2)
        displayimage(papirus, imagename='gadgetstoo.bmp', partial=1)
        sleep(2)
        displayimage(papirus, imagename="hello.bmp")
        sleep(2)
Beispiel #10
0
def main():
    papirus = Papirus()
    p = argparse.ArgumentParser()
    p.add_argument('filepath', type=str)
    args = p.parse_args()
    if args.filepath:
        draw_image(papirus, args.filepath)
Beispiel #11
0
class PapirusText():
    def __init__(self):
        self.papirus = Papirus()

    def write(self,
              text,
              size=20,
              font_path='/usr/share/fonts/truetype/freefont/FreeMono.ttf'):

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

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

        font = ImageFont.truetype(font_path, size)

        # Calculate the max number of char to fit on line
        line_size = (self.papirus.width / (size * 0.65))

        current_line = 0
        # unicode by default
        text_lines = [u""]

        # Compute each line
        for word in text.split():
            # If there is space on line add the word to it
            if (len(text_lines[current_line]) + len(word)) < line_size:
                text_lines[current_line] += " " + word
            else:
                # No space left on line so move to next one
                text_lines.append("")
                current_line += 1
                text_lines[current_line] += " " + word

        current_line = 0
        for l in text_lines:
            current_line += 1
            draw.text((0, ((size * current_line) - size)),
                      l,
                      font=font,
                      fill=BLACK)

        self.papirus.display(image)
        self.papirus.update()
def main(argv):
    global SIZE
    global FIAT
    global SATS

    GPIO.setmode(GPIO.BCM)

    GPIO.setup(SW1, GPIO.IN)
    GPIO.setup(SW2, GPIO.IN)
    GPIO.setup(SW3, GPIO.IN)
    GPIO.setup(SW4, GPIO.IN)
    GPIO.setup(SW5, GPIO.IN)

    papirus = Papirus(rotation=int(argv[0]) if len(sys.argv) > 1 else 0)

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

    update_startup_screen()

    # papirus.clear()

    btcprice = price.getbtcprice(CURRENCY)
    satprice = round((1 / (btcprice * 100)) * 100000000, 2)

    while True:

        if (GPIO.input(SW1) == False) and (GPIO.input(SW4) == False):
            FIAT = 0
            SATS = 0
            update_startup_screen()

        if GPIO.input(SW1) == False:
            FIAT += 0.01
            SATS = FIAT * 100 * satprice
            update_amount_screen(papirus, SIZE)

        if GPIO.input(SW2) == False:
            FIAT += 0.02
            SATS = FIAT * 100 * satprice
            update_amount_screen(papirus, SIZE)

        if GPIO.input(SW3) == False:
            FIAT += 0.05
            SATS = FIAT * 100 * satprice
            update_amount_screen(papirus, SIZE)

        if GPIO.input(SW4) == False:
            FIAT += 0.1
            SATS = FIAT * 100 * satprice
            update_amount_screen(papirus, SIZE)

        if GPIO.input(SW5) == False:
            update_payout_screen(papirus, SIZE)

        sleep(0.1)
Beispiel #13
0
    def __init__(self):
        #button setup
        self.SW1 = 21
        self.SW2 = 16
        self.SW3 = 20
        self.SW4 = 19
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.SW1, GPIO.IN)
        GPIO.setup(self.SW2, GPIO.IN)
        GPIO.setup(self.SW3, GPIO.IN)
        GPIO.setup(self.SW4, GPIO.IN)

        #config file
        self.Config = ConfigParser.ConfigParser()
        self.Config.read('./config.ini')

        rotation = int(self.Config.get('PAPIRUS', 'rotation'))
        fontPath = self.Config.get('PAPIRUS', 'fontPath')
        self.fontSize = int(self.Config.get('PAPIRUS', 'fontSize'))
        backgroundPath = self.Config.get('PAPIRUS', 'backgroundPath')
        self.defaultDisplayOption = self.Config.get('HOMEHUB',
                                                    'defaultDisplayOption')
        self.url = self.Config.get('HOMEHUB', 'url')

        self.currentLightGroup = 0
        self.ResetLightGroups(True)

        #papirus setup
        self.initX = 15
        self.initY = 40

        self.papirusDisplay = Papirus(rotation=rotation)
        self.papirusDisplay.clear()

        #papirus screen setup
        rsimg = Image.open(backgroundPath)
        self.image = Image.new('1', self.papirusDisplay.size, 1)
        self.image.paste(rsimg, (0, 0))

        self.draw = ImageDraw.Draw(self.image)
        self.font = ImageFont.truetype(fontPath, self.fontSize)
        self.CreateTextObject(self.lightGroups[self.currentLightGroup])

        self.ButtonRead()
Beispiel #14
0
def main():
    GPIO.setmode(GPIO.BCM)

    GPIO.setup(SW1, GPIO.IN)
    GPIO.setup(SW2, GPIO.IN)
    GPIO.setup(SW3, GPIO.IN)
    GPIO.setup(SW4, GPIO.IN)

    papirus = Papirus()

    write_text(papirus, defaultText, SIZE)

    while True:
        if GPIO.input(SW1) == False:
            stats = statistics.get()
            btcBlockHeight = stats.total_blocks
            # The blockchain api returns bits, need to convert to kB
            btcBlockSizeCleaned = (stats.blocks_size) / 125000

            write_text(
                papirus,
                "%s --BITCOIN--\nBlockheight:%d \nBlocksize    : %d kB" %
                (todayCleaned(), btcBlockHeight, btcBlockSizeCleaned), SIZE)

            time.sleep(10)
            write_text(papirus, defaultText, SIZE)

        if GPIO.input(SW2) == False:
            responseBlockr = urllib2.urlopen(
                "http://ltc.blockr.io/api/v1/coin/info")
            htmlResponse = simplejson.load(responseBlockr)
            ltcBlockHeight = int(htmlResponse["data"]["last_block"]["nb"])

            write_text(
                papirus, "%s --LITECOIN--\nBlockheight:%d" %
                (todayCleaned(), ltcBlockHeight), SIZE)

            time.sleep(10)
            write_text(papirus, defaultText, SIZE)

        if GPIO.input(SW3) == False:
            write_text(papirus, "Three", SIZE)

            time.sleep(10)
            write_text(papirus, defaultText, SIZE)

        if GPIO.input(SW4) == False:
            write_text(papirus, "Shutdown Begun \nCheers!", SIZE)
            time.sleep(2)
            write_text(papirus, "", SIZE)
            shutdown()

            #time.sleep(10)
            #write_text(papirus, defaultText, SIZE)

        time.sleep(0.1)
Beispiel #15
0
class PapirusText(object):

    def __init__(self, rotation=0):
        self.papirus = Papirus(rotation=rotation)

    def write(self, text, size=20, fontPath='/usr/share/fonts/truetype/freefont/FreeMono.ttf', maxLines=100):
        
        # initially set all white background
        image = Image.new('1', self.papirus.size, WHITE)

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

        font = ImageFont.truetype(fontPath, size)

        # Calculate the max number of char to fit on line
        lineSize = (self.papirus.width / (size*0.65))

        currentLine = 0
        # unicode by default
        textLines = [u""]

        # Compute each line
        for word in text.split():
            # Always add first word (even when it is too long)
            if len(textLines[currentLine]) == 0:
                textLines[currentLine] += word
            elif (draw.textsize(textLines[currentLine] + " " + word, font=font)[0]) < self.papirus.width:
                textLines[currentLine] += " " + word
            else:
                # No space left on line so move to next one
                textLines.append(u"")
                if currentLine < maxLines:
                    currentLine += 1
                    textLines[currentLine] += word

        currentLine = 0
        for l in textLines:
            draw.text( (0, size*currentLine) , l, font=font, fill=BLACK)
            currentLine += 1

        self.papirus.display(image)
        self.papirus.update()
Beispiel #16
0
def main(argv):
    """main program - draw and display a test image"""

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(SW1, GPIO.IN)

    papirus = Papirus()

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

    papirus.clear()

    demo(papirus)
Beispiel #17
0
    class PapirusDisplay:
        def __init__(self):
            self.papirus = Papirus(rotation=180)
            self.papirus.clear()
            self.first_draw = True

        def update(self, im):
            self.papirus.display(im)
            if self.first_draw:
                self.papirus.update()
                self.first_draw = False
            else:
                self.papirus.partial_update()
Beispiel #18
0
class PapirusImage():
    def __init__(self, rotation=0):
        self.papirus = Papirus(rotation=rotation)

    def write(self, image):
        image = Image.open(image)
        image = ImageOps.grayscale(image)

        # crop to the middle
        w, h = image.size
        x = w / 2 - self.papirus.width / 2
        y = h / 2 - self.papirus.height / 2

        rs = image
        if w != self.papirus.width or h != self.papirus.height:
            rs = image.resize((self.papirus.width, self.papirus.height))
        bw = rs.convert("1", dither=Image.FLOYDSTEINBERG)

        self.papirus.display(bw)
        self.papirus.update()
Beispiel #19
0
class PapirusText():

    def __init__(self):
        self.papirus = Papirus()

    def write(self, text, size = 20):

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

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

        font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', size)

        # Calculate the max number of char to fit on line
        line_size = (Papirus().width / (size*0.65))

        current_line = 0
        text_lines = [""]

        # Compute each line
        for word in text.split():
            # If there is space on line add the word to it
            if (len(text_lines[current_line]) + len(word)) < line_size:
                text_lines[current_line] += " " + word
            else:
                # No space left on line so move to next one
                text_lines.append("")
                current_line += 1
                text_lines[current_line] += " " + word

        current_line = 0
        for l in text_lines:
            current_line += 1
            draw.text( (0, ((size*current_line)-size)) , l, font=font, fill=BLACK)

        self.papirus.display(image)
        self.papirus.update()
Beispiel #20
0
class PapirusImage():

    def __init__(self):
        self.papirus = Papirus()

    def write(self, image):
        image = Image.open(image)
        image = ImageOps.grayscale(image)

        # crop to the middle
        w,h = image.size
        x = w / 2 - self.papirus.width / 2
        y = h / 2 - self.papirus.height / 2

        rs = image
        if w != self.papirus.width or h != self.papirus.height:
            rs = image.resize((self.papirus.width, self.papirus.height))
        bw = rs.convert("1", dither=Image.FLOYDSTEINBERG)

        self.papirus.display(bw)
        self.papirus.update()
Beispiel #21
0
class PapirusImage(object):
    def __init__(self, rotation=0):
        self.papirus = Papirus(rotation=rotation)

    def write(self, imagefile):
        fileimg = Image.open(imagefile)

        w, h = fileimg.size

        rsimg = fileimg
        if w > self.papirus.width or h > self.papirus.height:
            rsimg.thumbnail(self.papirus.size)

        xpadding = (self.papirus.width - rsimg.size[0]) // 2
        ypadding = (self.papirus.height - rsimg.size[1]) // 2

        image = Image.new('1', self.papirus.size, WHITE)
        image.paste(rsimg, (xpadding, ypadding))

        self.papirus.display(image)
        self.papirus.update()
Beispiel #22
0
    def __init__(self):
        # Check EPD_SIZE is defined
        EPD_SIZE = 0.0
        if os.path.exists('/etc/default/epd-fuse'):
            exec(open('/etc/default/epd-fuse').read())
        if EPD_SIZE == 0.0:
            print(
                "Please select your screen size by running 'papirus-config'.")

        self.papirus = Papirus(rotation=0)
        self.papirus.clear()

        # Setting the screen color
        self.BLACK = 0
        self.WHITE = 1

        # Initally set all white background
        self.image = Image.new('1', self.papirus.size, self.WHITE)

        # Prepare for drawing
        self.draw = ImageDraw.Draw(self.image)
        self.width, self.height = self.image.size

        # Setting the size/font for the name
        self.nameSize = int((self.width - 4) / (8 * 0.65))
        self.nameFont = ImageFont.truetype(nameFont, self.nameSize)

        # Setting the size/font for the data
        self.dataSize = int(
            (self.width - MAX_DATA_SIZE) / (MAX_DATA_SIZE * 0.65))
        self.dataFont = ImageFont.truetype(dataFont, self.dataSize)

        # Setting the size/font for time and date
        self.clockSize = int((self.width - 4) / (8 * 0.65))
        self.clockFont = ImageFont.truetype(
            '/usr/share/fonts/truetype/freefont/FreeMonoOblique.ttf',
            self.clockSize)
        self.dateSize = int((self.width - 10) / (10 * 0.65))
        self.dateFont = ImageFont.truetype(
            '/usr/share/fonts/truetype/freefont/FreeMono.ttf', self.dateSize)
Beispiel #23
0
def main(argv):
    global SIZE
    global FIAT
    global SATS

    GPIO.setmode(GPIO.BCM)

    GPIO.setup(SW1, GPIO.IN)
    GPIO.setup(SW2, GPIO.IN)
    GPIO.setup(SW3, GPIO.IN)
    GPIO.setup(SW4, GPIO.IN)
    GPIO.setup(SW5, GPIO.IN)

    papirus = Papirus(rotation=int(argv[0]) if len(sys.argv) > 1 else 0)

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

    papirus.clear()

    while True:

        if GPIO.input(SW1) == False:
            update_img_screen(papirus)

        if GPIO.input(SW2) == False:
            pass

        if GPIO.input(SW3) == False:
            pass

        if GPIO.input(SW4) == False:
            pass

        if (GPIO.input(SW5) == False):
            pass

        sleep(0.1)
def main():
    global SIZE
    global PapirusDevice
    global CurrentTime

    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)

    PapirusDevice = Papirus(rotation=0)

    # Use smaller font for smaller displays
    if PapirusDevice.height <= 96:
        SIZE = 18

    PapirusDevice.clear()

    write_text(PapirusDevice, "Ready... SW1 + SW2 to exit.", SIZE)
    sleep(5.0)

    print("Starting...")

    while True:
        CurrentTime = datetime.now()
        forceRefresh = False
        try:
            # Exit when SW1 and SW2 are pressed simultaneously
            if (GPIO.input(SW1) == False) and (GPIO.input(SW2) == False):
                write_text(PapirusDevice, "Exiting ...", SIZE)
                sleep(0.2)
                PapirusDevice.clear()
                sys.exit()

            if GPIO.input(SW1) == False:
                # Press twice to shutdown
                handleShutdown()
                forceRefresh = True
            elif GPIO.input(SW2) == False:
                # Press twice to reboot
                handleReboot()
                forceRefresh = True
            elif GPIO.input(SW3) == False:
                # switch to next usb network interface
                use_next_usb_tether_device()
                forceRefresh = True
            elif GPIO.input(SW4) == False:
                # do nothing...
                forceRefresh = True

            clear_pending_states(False)
            refresh_dashboard(forceRefresh)
        except Exception as ex:
            write_text(PapirusDevice, str(ex), SIZE)
        sleep(0.1)
Beispiel #25
0
def main(argv):
    global SIZE

    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(rotation = int(argv[0]) if len(sys.argv) > 1 else 0)

    # timestamp to be set when this program is initiated.. used for the location file
    # and remains the same for the rest of the duration of the program. If the program
    # is restarted the location file's name changes.

    location_file = '/home/pi/location'+datetime.now().strftime('%Y%m%d%H%M%S')+'.txt'

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

    papirus.clear()

    write_text(papirus, "Ready... SW1 + SW2 to exit.", SIZE)

    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:
            write_text(papirus, "One", SIZE)

        if GPIO.input(SW2) == False:
            write_text(papirus, "Two", SIZE)

        if GPIO.input(SW3) == False:
            write_text(papirus, "Track Motion", SIZE)
            lt = gl.get_loc_time()
            write_text(papirus,str(lt['Alt'])+","+str(lt['Lat'])+","+str(lt['Lon'])+","+str(lt['Time']), SIZE)
            with open(location_file,'a+') as lf:
                lf.write(str(lt['Alt'])+","+str(lt['Lat'])+","+str(lt['Lon'])+","+str(lt['Time'])+"\n") 
        if GPIO.input(SW4) == False:
            write_text(papirus, "Rebooting...", SIZE)
            os.system("sudo reboot") 

        if (SW5 != -1) and (GPIO.input(SW5) == False):
            write_text(papirus, "Shutting Down at\n" + str(datetime.now()), SIZE)
            os.system("sudo shutdown now -h") 
 
        sleep(0.1)
Beispiel #26
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()
Beispiel #27
0
def main(argv):
    global SIZE

    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(rotation=int(argv[0]) if len(sys.argv) > 1 else 0)

    # Use smaller font for smaller displays
    if papirus.height <= 96:
        SIZE = 12

    papirus.clear()

    loc_time = gl.get_loc_time()
    write_text(
        papirus, "Booted up at: \nLat: " + str(loc_time['Lat']) + "\nLon: " +
        str(loc_time['Lon']) + "\nTime: " + loc_time['Time'], SIZE)
Beispiel #28
0
def startupdisplay(argv):
    papirus = Papirus(rotation=int(argv[0]) if len(sys.argv) > 1 else 0)

    image = PIL.Image.new('1', papirus.size, WHITE)

    draw = ImageDraw.Draw(image)

    draw.text((20, 10), 'Welcome to the', fill=BLACK, font=font1)
    draw.text((10, 20), 'LightningATM', fill=BLACK, font=font)
    draw.text((7, 75), '- please insert coins -', fill=BLACK, font=font2)

    papirus.display(image)
    papirus.update()
Beispiel #29
0
class Driver():
    papirus = Papirus()
    line_position = 0

    def write_lines(self, lines, fontsize):
        # initially set all white background
        image = Image.new('1', self.papirus.size, WHITE)
        # prepare for drawing
        draw = ImageDraw.Draw(image)
        self.line_position = 0
        for line in lines:
            self.line_position += 1
            self.write_text(draw, line, fontsize)

        self.papirus.display(image)
        self.papirus.update()

    def write_text(self, draw, text, size):
        font = ImageFont.truetype(
            '/usr/share/fonts/truetype/freefont/FreeMono.ttf', size)
        # Calculate the max number of char to fit on line
        line_size = (self.papirus.width / (size * 0.65))
        current_line = 0
        text_lines = [""]
        # Compute each line
        for word in text.split():
            # If there is space on line add the word to it
            if (len(text_lines[current_line]) + len(word)) < line_size:
                text_lines[current_line] += " " + word
            else:
                # No space left on line so move to next one
                text_lines.append("")
                current_line += 1
                text_lines[current_line] += " " + word
        current_line = self.line_position - 1
        for l in text_lines:
            current_line += 1
            draw.text((0, ((size * current_line) - size)),
                      l,
                      font=font,
                      fill=BLACK)
        self.line_position += (current_line - 1)
Beispiel #30
0
    def _init_display(self):
        if self._is_inky():
            from inky import InkyPHAT
            self._display = InkyPHAT(self._display_color)
            self._display.set_border(InkyPHAT.BLACK)
            self._render_cb = self._inky_render

        elif self._is_papirus():
            from papirus import Papirus
            os.environ['EPD_SIZE'] = '2.0'
            self._display = Papirus()
            self._display.clear()
            self._render_cb = self._papirus_render

        elif self._is_waveshare1():
            from pwnagotchi.ui.waveshare.v1.epd2in13 import EPD
            # core.log("display module started")
            self._display = EPD()
            self._display.init(self._display.lut_full_update)
            self._display.Clear(0xFF)
            self._display.init(self._display.lut_partial_update)
            self._render_cb = self._waveshare_render

        elif self._is_waveshare2():
            from pwnagotchi.ui.waveshare.v2.waveshare import EPD
            # core.log("display module started")
            self._display = EPD()
            self._display.init(self._display.FULL_UPDATE)
            self._display.Clear(WHITE)
            self._display.init(self._display.PART_UPDATE)
            self._render_cb = self._waveshare_render

        else:
            core.log("unknown display type %s" % self._display_type)

        self.on_render(self._on_view_rendered)

        core.log("display type '%s' initialized (color:%s)" %
                 (self._display_type, self._display_color))
Beispiel #31
0
def main(argv):
    global SIZE

    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(rotation=int(argv[0]) if len(sys.argv) > 1 else 0)

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

    papirus.clear()

    write_text(papirus, "Ready... SW1 + SW2 to exit.", SIZE)

    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:
            write_text(papirus, "One", SIZE)

        if GPIO.input(SW2) == False:
            write_text(papirus, "Two", SIZE)

        if GPIO.input(SW3) == False:
            write_text(papirus, "Three", SIZE)

        if GPIO.input(SW4) == False:
            write_text(papirus, "Four", SIZE)

        if (SW5 != -1) and (GPIO.input(SW5) == False):
            write_text(papirus, "Five", SIZE)

        sleep(0.1)
Beispiel #32
0
def main():
    """Main function"""
    global g_image

    try:
        # *** PaPiRus ePaper / eInk Screen HAT for Raspberry Pi - 2.7" ***
        from papirus import Papirus
        papirus = Papirus(rotation=0)
        g_image = Image.new('1', papirus.size, WHITE)
        draw_image()
        g_image.save(image_filename)
        papirus.display(g_image)
        papirus.update()
        return
    except:
        logging.debug("Papirus failed.", exc_info=1)

    try:
        # *** Waveshare 2.7inch e-Paper HAT ***
        libdir = os.path.realpath(
            os.getenv('HOME') + '/e-Paper/RaspberryPi_JetsonNano/python/lib')
        if os.path.exists(libdir):
            sys.path.append(libdir)
        else:
            libdir = os.path.realpath(
                os.getenv('HOME') +
                '/e-Paper/RaspberryPi&JetsonNano/python/lib')
            if os.path.exists(libdir):
                sys.path.append(libdir)
        from waveshare_epd import epd2in7
        epd = epd2in7.EPD()
        epd.init()
        g_image = Image.new('1', (epd.height, epd.width), 255)
        draw_image()
        g_image.save(image_filename)
        epd.display(epd.getbuffer(g_image))
        epd.sleep()
        return
    except:
        logging.debug("Waveshare failed.", exc_info=1)

    # *** no known screen: just save the bmp
    logging.debug("No known screen.")
    g_image = Image.new('1', (264, 176), WHITE)
    draw_image()
    g_image.save(image_filename)
Beispiel #33
0
def main():
    GPIO.setmode(GPIO.BCM)

    GPIO.setup(SW1, GPIO.IN)
    GPIO.setup(SW2, GPIO.IN)
    GPIO.setup(SW3, GPIO.IN)
    GPIO.setup(SW4, GPIO.IN)
    GPIO.setup(SW5, GPIO.IN)

    papirus = Papirus()

    draw(papirus, text="Press any\r\nbutton\r\nto start", size=L_SIZE)

    while True:
        if GPIO.input(SW1) == False or GPIO.input(SW2) == False or GPIO.input(
                SW3) == False or GPIO.input(SW4) == False or GPIO.input(
                    SW5) == False:
            while 1:
                draw(papirus, 'Photo-Name.bmp',
                     "Name: Francesco\r\n" + "Surname: Vannini")
                sleep(1)
                draw(papirus, 'DireStraits.bmp',
                     "Favourite band:\r\nDire Straits")
                sleep(1)
                draw(papirus, 'Pi-Supply_web.bmp', "Website:\r\npi-supply.com")
                sleep(1)
                draw(papirus, imagePath='Photo-200x96-1.bmp')
                sleep(0.3)
                draw(papirus, imagePath='Photo-200x96-2.bmp', partial=1)
                sleep(0.3)
                draw(papirus, imagePath='Photo-200x96-3.bmp', partial=1)
                sleep(0.3)
                draw(papirus, imagePath='Photo-200x96-2.bmp', partial=1)
                sleep(0.3)
                draw(papirus, imagePath='Photo-200x96-1.bmp', partial=1)
                sleep(1)
                draw(papirus, imagePath='logo-JustBoom200x96.bmp')
                sleep(1)
Beispiel #34
0
class PapirusPlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.ProgressPlugin):
    def on_after_startup(self):
        self._logger.info("Hello World!")
        self.papirus = Papirus()
        self.font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 14)
        self.papirus.clear()
        self.last_update = datetime.now()
    
    def on_print_progress(self, storage, path, progress):
        pass

    def on_slicing_progress(self, slicer, source_location, source_path, dest_location, dest_path, progress):
        if progress == 0 or progress == 100 or (datetime.now() - self.last_update).total_seconds() > 3:
            width, height = self.papirus.size
            self.last_update = datetime.now()
            image = Image.new('1', (width, height), 1)
            
            draw = ImageDraw.Draw(image)
            
            #Draw progress
            start_x = width / 10
            end_x = width - start_x
            start_y = height / 2
            end_y = start_y + 20
            draw.rectangle((start_x, start_y, end_x, end_y), 1, 0)
            fillWidth = (end_x - start_x) * progress / 100
            try:
                self._logger.info("On slicing progress : ({}, {}, {}, {}, {})".format(start_x, end_x, start_y, end_y, fillWidth))
            except:
                self._logger.info("Error writing log")
            draw.rectangle((start_x, start_y, start_x + fillWidth, end_y), 0, 0)
            
            # Draw text
            draw.text((0, 0), dest_path, font=self.font, fill=0)

            del draw

            self.papirus.display(image)
            self.papirus.update()
Beispiel #35
0
 def __init__(self, rotation = 0):
     self.papirus = Papirus(rotation = rotation)
Beispiel #36
0
 def on_after_startup(self):
     self._logger.info("Hello World!")
     self.papirus = Papirus()
     self.font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 14)
     self.papirus.clear()
     self.last_update = datetime.now()
Beispiel #37
0
class PapirusTextPos(object):
    def __init__(self, autoUpdate = True, rotation = 0):
        # Set up the PaPirus and dictionary for text
        self.papirus = Papirus(rotation = rotation)
        self.allText = dict()
        self.image = Image.new('1', self.papirus.size, WHITE)
        self.autoUpdate = autoUpdate
	self.partial_updates = False

    def AddText(self, text, x=0, y=0, size = 20, Id = None, invert=False, font_path='/usr/share/fonts/truetype/freefont/FreeMono.ttf'):
        # Create a new Id if none is supplied
        if Id == None:
            Id = str(uuid.uuid4())

        # If the Id doesn't exist, add it  to the dictionary
	if Id not in self.allText:
            self.allText[Id] = DispText(text, x, y, size, invert)
            # add the text to the image
            self.addToImageText(Id, font_path)
            #Automatically show?
            if self.autoUpdate:
                self.WriteAll()

    def UpdateText(self, Id, newText, font_path='/usr/share/fonts/truetype/freefont/FreeMono.ttf'):
        # If the ID supplied is in the dictionary, update the text
        # Currently ONLY the text is update
        if Id in self.allText:
            self.allText[Id].text = newText

            # Remove from the old text from the image (that doesn't use the actual text)
            self.removeImageText(Id)
            # Add the new text to the image
            self.addToImageText(Id, font_path)
            #Automatically show?
            if self.autoUpdate:
                self.WriteAll()

    def RemoveText(self, Id):
        # If the ID supplied is in the dictionary, remove it.
        if Id in self.allText:
            self.removeImageText(Id)
            del self.allText[Id]

            #Automatically show?
            if self.autoUpdate:
                self.WriteAll()

    def removeImageText(self, Id):
        # prepare for drawing
        draw = ImageDraw.Draw(self.image)
        # Draw over the top of the text with a rectangle to cover it
        draw.rectangle([self.allText[Id].x, self.allText[Id].y, self.allText[Id].endx, self.allText[Id].endy], fill="white")


    def addToImageText(self, Id, font_path='/usr/share/fonts/truetype/freefont/FreeMono.ttf'):
        # Break the text item back in to parts
        size = self.allText[Id].size
        x =  self.allText[Id].x
        y =  self.allText[Id].y
        font_col = BLACK
        back_col = WHITE

        if self.allText[Id].invert:
            font_col = WHITE
            back_col = BLACK

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

        # Grab the font to use, fixed at the moment
        font = ImageFont.truetype(font_path, size)

        # Calculate the max number of char to fit on line
        # Taking in to account the X starting position
        line_size = ((self.papirus.width - x) / (size*0.65))

        # Starting vars
        current_line = 0
        # unicode by default
        text_lines = [u""]

        # Split the text by \n first
        toProcess = self.allText[Id].text.splitlines()

        # Go through the lines and add them
        for line in toProcess:
            # Add in a line to add the words to
            text_lines.append("")
            # Compute each line
            for word in line.split():
                # If there is space on line add the word to it
                if (len(text_lines[current_line]) + len(word)) < line_size:
                    # Only add a space if there`s something on the line
                    if len(text_lines[current_line]) > 0:
                        text_lines[current_line] += " "
                    text_lines[current_line] += word
                else:
                    # No space left on line so move to next one
                    text_lines.append("")
                    current_line += 1
                    text_lines[current_line] += " " + word
            # Move the pointer to next line
            current_line +=1

        #  Go through all the lines as needed, drawing them on to the image

        # Reset the ending position of the text
        self.allText[Id].endy = y
        self.allText[Id].endx = x

        # Start at the beginning, calc all the end locations
        current_line = 0
        for l in text_lines:
            current_line += 1
            # Find out the size of the line to be drawn
            textSize = draw.textsize(l, font=font)
            # Adjust the x end point if needed
            if textSize[0]+x > self.allText[Id].endx:
                self.allText[Id].endx = textSize[0] + x
            # Add on the y end point
            self.allText[Id].endy += textSize[1]

        # Little adjustment to make sure the text gets covered
        self.allText[Id].endy += 3

        # If the text is wanted inverted, put a rectangle down first
        if self.allText[Id].invert:
            draw.rectangle([self.allText[Id].x, self.allText[Id].y, self.allText[Id].endx, self.allText[Id].endy], fill=back_col)

        # Start at the beginning, add all the lines to the image
        current_line = 0
        for l in text_lines:
            current_line += 1
            # Draw the text to the image
            draw.text( (x, ((size*current_line)-size) + y) , l, font=font, fill=font_col)

    def WriteAll(self, partial_update=False):
        # Push the image to the PaPiRus device, and update only what's needed
        # (unless asked to do a full update)
        self.papirus.display(self.image)
        if partial_update or self.partial_updates:
            self.papirus.partial_update()
        else:
            self.papirus.update()

    def Clear(self):
        # Clear the image, clear the text items, do a full update to the screen
        self.image = Image.new('1', self.papirus.size, WHITE)
        self.allText = dict()
        self.papirus.clear()
Beispiel #38
0
 def __init__():
     self.papirus = Papirus()