示例#1
0
def main():
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    text = textwrap.fill("test of the longest sentence you can write",width=12)


    # For simplicity, the arguments are explicit numerical coordinates
    # print("Width"+str(epd2in13.EPD_WIDTH))
    # print("Height"+str(epd2in13.EPD_HEIGHT))
    image = Image.new('1', (epd2in13.EPD_WIDTH,epd2in13.EPD_HEIGHT), 255)  # 255: clear the frame
    image2 = Image.new('1', (epd2in13.EPD_HEIGHT,epd2in13.EPD_WIDTH), 255)
    draw = ImageDraw.Draw(image2)
    font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 30)
    draw.text((15, 15), text, font = font, fill = 0)

    

    # image.save("image.png")
    image2 = image2.rotate(270,expand=True)
    # image2.save("image2.png")
    
    epd.clear_frame_memory(0xFF)
    epd.set_frame_memory(image2, 0, 0)
    epd.display_frame()
示例#2
0
def wipe_screen():
    step = 16
    x = 0
    f = True

    epd = epd2in13.EPD()
    epd.init(epd.lut_partial_update)
    while (f):
        bimage = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT),
                           255)  # 255: clear the frame
        bdraw = ImageDraw.Draw(bimage)
        bdraw.rectangle((x, 0, step + x - 1, epd2in13.EPD_HEIGHT - 1), fill=0)
        epd.clear_frame_memory(0xFF)
        epd.set_frame_memory(bimage, 0, 0)
        epd.display_frame()

        bimage = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT),
                           255)  # 255: clear the frame
        bdraw = ImageDraw.Draw(bimage)
        bdraw.rectangle((x, 0, step + x - 1, epd2in13.EPD_HEIGHT - 1), fill=0)
        epd.clear_frame_memory(0xFF)
        epd.set_frame_memory(bimage, 0, 0)
        epd.display_frame()

        x += step
        f = (x <= epd2in13.EPD_WIDTH)
示例#3
0
def main():
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT),
                      255)  # 255: clear the frame
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype('./FreeMonoBold.ttf', 12)
    draw.rectangle((0, 10, 128, 30), fill=0)
    draw.text((30, 14), 'Hello Alan!', font=font, fill=255)
    draw.text((30, 36), 'Hello Nari!', font=font, fill=0)
    """
    draw.line((16, 60, 56, 60), fill = 0)
    draw.line((56, 60, 56, 110), fill = 0)
    draw.line((16, 110, 56, 110), fill = 0)
    draw.line((16, 110, 16, 60), fill = 0)
    draw.line((16, 60, 56, 110), fill = 0)
    draw.line((56, 60, 16, 110), fill = 0)
    draw.arc((70, 60, 130, 120), 0, 360, fill = 0)
    draw.rectangle((16, 130, 56, 180), fill = 0)
    draw.chord((70, 130, 130, 190), 0, 360, fill = 0)
    """

    draw.text((0, 50), get_ip_address("wlan0"), font=font, fill=0)

    epd.clear_frame_memory(0xFF)
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()
示例#4
0
def main():
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH),
                      255)  # clear the frame

    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype('/usr/share/fonts/AmaticSC-Bold.ttf', 40)
    draw.rectangle((0, 0, 250, 60), fill=0)
    draw.text((30, 10), 'WHERE IS FOO?', font=font, fill=255)

    data = get_location()
    ds = "unknown"
    print(data)

    if (u'description' in data):
        print(data["description"])
        ds = data["description"]

    draw.text((30, 60), ds, font=font, fill=0)
    img = image.rotate(90, expand=True)
    epd.set_frame_memory(img, 0, 0)
    epd.display_frame()
    epd.set_frame_memory(img, 0, 0)

    epd.display_frame()
示例#5
0
 def showImageOnScreen(image):
     epd = epd2in13.EPD()
     epd.init(epd.lut_full_update)
     epd.clear_frame_memory(0xFF)
     epd.set_frame_memory(image, 0, 0)
     epd.display_frame()
     epd.sleep()
示例#6
0
def main():
    # Set up the display parameters
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    epd.clear_frame_memory(0xFF)
    epd.display_frame()

    while (True):

        # Check that you have a token before making the call
        if (token == None):
            print "Can't get token for", username
            sys.exit()

        # Loop through the spotify results
        sp = spotipy.Spotify(auth=token)
        results = sp.current_user_saved_tracks()
        for item in results['items']:
            track = item['track']
            print track['name'] + ' - ' + track['artists'][0]['name']
            print track['external_urls']['spotify']

            # Pass in the url to the qr code generator
            command = "qrencode " + track['external_urls'][
                'spotify'] + " -o qr_code.bmp"
            os.system(command)

            # clear out the canvas and set up all the font parameters
            image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT),
                              255)  # 255: clear the frame
            draw = ImageDraw.Draw(image)
            font = ImageFont.truetype(
                '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 12)

            # Doing that cool line wrapping business with the artist name and playlist name
            margin = offset = 120
            for line in textwrap.wrap(track['name'] + ' - ' +
                                      track['artists'][0]['name'],
                                      width=16):
                print("Broke into: " + line)
                draw.text((10, offset), line, font=font, fill=0)
                offset += font.getsize(line)[1]

            # Load the words into memory but don't display yet
            epd.set_frame_memory(image, 0, 0)

            # for partial update -- won't overwrite the words
            # epd.init(epd.lut_partial_update)

            # Open the image and resize it correctly
            image = Image.open('qr_code.bmp')
            size = 120, 120
            image.thumbnail(size, Image.ANTIALIAS)

            # load and display the e-paper
            epd.set_frame_memory(image, 0, 0)
            epd.display_frame()

            time.sleep(3)
示例#7
0
def main():
    while True:
        try:
            # Get dimensions
            width = epd2in13.EPD_WIDTH
            height = epd2in13.EPD_HEIGHT

            # Download image
            base_url = "http://lifeboxes.herokuapp.com/work"
            # base_url = "http://4a707c28.ngrok.io/work"
            url = base_url + "?width={}&height={}".format(width, height)
            image_data = requests.get(url, stream=True).raw
            image = Image.open(image_data)

            # Display image
            epd = epd2in13.EPD()
            epd.init(epd.lut_full_update)
            epd.clear_frame_memory(0xFF)

            epd.set_frame_memory(image, 0, 0)
            epd.display_frame()
        except KeyboardInterrupt:
            raise
        except Exception as e:
            print "Rescued error {0}: {1}".format(e.__doc__, e.message)
        finally:
            time.sleep(30 * 60)
示例#8
0
def main():
    # To fix the path issue when script runs by crontab
    os.chdir(os.path.dirname(os.path.abspath(__file__)))

    # initialize e-paper device
    epd = epd2in13.EPD()

    # draw background image
    epd.init(epd.lut_full_update)
    image = Image.open('resize_background_empty.bmp')

    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

    # draw time, temperature, humidity
    epd.init(epd.lut_partial_update)

    # set image size
    time_image = Image.new('1', (200, 17), 255)
    temp_image = Image.new('1', (100, 50), 255)
    humid_image = Image.new('1', (76, 38), 255)

    drawTime = ImageDraw.Draw(time_image)
    drawTemp = ImageDraw.Draw(temp_image)
    drawHumid = ImageDraw.Draw(humid_image)

    # select 7-segment like font
    fontTime = ImageFont.truetype('/usr/share/fonts/truetype/lcd/DS-DIGIB.TTF', 20)
    fontTemp = ImageFont.truetype('/usr/share/fonts/truetype/lcd/DS-DIGIB.TTF', 60)
    fontHumid = ImageFont.truetype('/usr/share/fonts/truetype/lcd/DS-DIGIB.TTF', 45)

    time_width, time_height = time_image.size
    temp_width, temp_height  = temp_image.size
    humid_width, humid_height = humid_image.size

    while (True):
        # clear drawing area
        drawTime.rectangle((0, 0, time_width, time_height), fill=255)
        drawTemp.rectangle((0, 0, temp_width, temp_height), fill = 255)
        drawHumid.rectangle((0, 0, humid_width, humid_height), fill=255)

        # retrieve temperature & humidity data
        humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 4)

        # draw text
        drawTime.text((0, 0), strftime('%Y-%m-%d %H:%M:%S', localtime()), font=fontTime, fill=0)
        drawTemp.text((0, 0), '{0:0.1f}'.format(temperature), font = fontTemp, fill = 0)
        drawHumid.text((0, 0), '{0:0.1f}'.format(humidity), font = fontHumid, fill = 0)

        # copy image data to buffer
        epd.set_frame_memory(time_image.transpose(Image.ROTATE_270), TIME_X_POS, TIME_Y_POS)
        epd.set_frame_memory(temp_image.transpose(Image.ROTATE_270), TEMP_X_POS, TEMP_Y_POS)
        epd.set_frame_memory(humid_image.transpose(Image.ROTATE_270), HUMID_X_POS, HUMID_Y_POS)

        # update e-paper
        epd.display_frame()
def eInkInit():
    epd = epd2in13.EPD()
    epd.init(epd.FULL_UPDATE)
    epd.Clear(0xFF)

    #epd.clear_frame_memory(0xFF)
    #    epd.set_frame_memory(image, 0, 0)
    #    epd.display_frame()
    #    epd.init(epd.lut_partial_update)
    return epd
def main():
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT), 255)  # 255: clear the frame
    draw = ImageDraw.Draw(image)
    epd.clear_frame_memory(0xFF)
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

#    epd.delay_ms(2000)

    # for partial update
    epd.init(epd.lut_partial_update)

##
 # there are 2 memory areas embedded in the e-paper display
 # and once the display is refreshed, the memory area will be auto-toggled,
 # i.e. the next action of SetFrameMemory will set the other memory area
 # therefore you have to set the frame memory twice.
 ##     


    font = ImageFont.truetype('FreeMonoBold.ttf', 18)
    image_width, image_height  = image.size
    ballx=16
    bally= 16
    dx = 1
    dy = 1
    while (True):
        # draw a rectangle to clear the image
#        draw.rectangle((0, 0, image_width, image_height), fill = 255)

#        cond = getWeather()
#        msg = cond.text() + " " +  str(int((float(cond.temp()) - 32.0) / 1.8)) + "C"

        msg = "Bouncing ball"
        
        draw.text((0, 0), msg, font = font, fill = 0)

        draw.point ((ballx, bally), fill = 0)

        ballx = ballx + dx
        bally = bally + dy
        
#        epd.set_frame_memory(image.rotate(270), 0, 0)
        img = image.rotate(90)

        epd.set_frame_memory(img, 0, 0)
        epd.display_frame()
        epd.set_frame_memory(img, 0, 0)
        epd.display_frame()

        time.sleep(1)
示例#11
0
def main():
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT),
                      255)  # 255: clear the frame
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(
        '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 12)
    draw.rectangle((0, 10, 128, 30), fill=0)
    draw.text((30, 14), 'Hello world!', font=font, fill=255)
    draw.text((30, 36), 'e-Paper Demo', font=font, fill=0)
    draw.line((16, 60, 56, 60), fill=0)
    draw.line((56, 60, 56, 110), fill=0)
    draw.line((16, 110, 56, 110), fill=0)
    draw.line((16, 110, 16, 60), fill=0)
    draw.line((16, 60, 56, 110), fill=0)
    draw.line((56, 60, 16, 110), fill=0)
    draw.arc((70, 60, 130, 120), 0, 360, fill=0)
    draw.rectangle((16, 130, 56, 180), fill=0)
    draw.chord((70, 130, 130, 190), 0, 360, fill=0)

    epd.clear_frame_memory(0xFF)
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

    epd.delay_ms(2000)

    # for partial update
    epd.init(epd.lut_partial_update)
    image = Image.open('monocolor.bmp')
    ##
    # there are 2 memory areas embedded in the e-paper display
    # and once the display is refreshed, the memory area will be auto-toggled,
    # i.e. the next action of SetFrameMemory will set the other memory area
    # therefore you have to set the frame memory twice.
    ##
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

    time_image = Image.new('1', (96, 32), 255)  # 255: clear the frame
    draw = ImageDraw.Draw(time_image)
    font = ImageFont.truetype(
        '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 32)
    image_width, image_height = time_image.size
    while (True):
        # draw a rectangle to clear the image
        draw.rectangle((0, 0, image_width, image_height), fill=255)
        draw.text((0, 0), time.strftime('%M:%S'), font=font, fill=0)
        epd.set_frame_memory(time_image.transpose(Image.ROTATE_270), 80, 80)
        epd.display_frame()
示例#12
0
def main():
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    # Display resolution in epd2in13.py
    #EPD_WIDTH       = 128
    #EPD_HEIGHT      = 250

    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT), 255)  # 255: clear the frame
    draw = ImageDraw.Draw(image)
    epd.clear_frame_memory(0xFF)
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

#    epd.delay_ms(2000)

    # for partial update
    epd.init(epd.lut_partial_update)

##
 # there are 2 memory areas embedded in the e-paper display
 # and once the display is refreshed, the memory area will be auto-toggled,
 # i.e. the next action of SetFrameMemory will set the other memory area
 # therefore you have to set the frame memory twice.
 ##     


    #the TOP RIGHT angle is 0,0, BOTTOM LEFT is max
    font = ImageFont.truetype('FreeMonoBold.ttf', 18)
    image_width, image_height  = image.size

    imgWeather = Image.open ("sunny.png")
    draw.bitmap ( (0, 160), imgWeather)

    #draw.rectangle(x1,y1,x2,y2)
    draw.rectangle((16, 16, 16+8, 16+8), fill = 0)
    draw.rectangle((96, 16, 96+16, 16+16), fill = 0)
    draw.rectangle((16, 16+128, 16+8, 16+128+8), fill = 0)
        
    draw.line ([(0,0),(epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT)], fill=0)


    draw.text((32, 32), "[TEST!]", font = font, fill = 0)

    
    #img = image.rotate(90)
    img = image

    epd.set_frame_memory(img, 0, 0)
    epd.display_frame()
    epd.set_frame_memory(img, 0, 0)
    epd.display_frame()
示例#13
0
 def __init__(self):
     super(DisplayThread, self).__init__()
     self.epd = epd2in13.EPD()
     self.ports = [
         Port((80, 184), -90),
         Port((80, 107), -90),
         Port((80, 27), -90),
         Port((10, 5), None)
     ]
     self.img_cls = Image.new('1',
                              (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT),
                              255)
     self.init()
     self.last_dt = [None, None]
     self.date_image = None
     self.font = ImageFont.truetype(
         '/usr/share/fonts/truetype/liberation2/LiberationSerif-Bold.ttf',
         22)
示例#14
0
def main():
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT),
                      255)  # 255: clear the frame
    draw = ImageDraw.Draw(image)
    epd.clear_frame_memory(0xFF)
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

    #    epd.delay_ms(2000)

    # for partial update
    epd.init(epd.lut_partial_update)

    ##
    # there are 2 memory areas embedded in the e-paper display
    # and once the display is refreshed, the memory area will be auto-toggled,
    # i.e. the next action of SetFrameMemory will set the other memory area
    # therefore you have to set the frame memory twice.
    ##

    font = ImageFont.truetype('FreeMonoBold.ttf', 16)
    image_width, image_height = image.size

    # draw a rectangle to clear the image
    draw.rectangle((0, 0, image_width, image_height), fill=255)

    draw.text((0, 0), getWeatherToday(), font=font, fill=0)
    draw.text((0, 32), getWeatherTomorrow(), font=font, fill=0)
    draw.text((0, 64), time.strftime('%M:%S'), font=font, fill=0)

    img = image.rotate(90, expand=True)
    #img = image
    image2 = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH),
                       255)  # 255: clear the frame
    draw2 = ImageDraw.Draw(image2)

    draw2.bitmap((0, image_width), img)

    epd.set_frame_memory(image2, 0, 0)
    epd.display_frame()
示例#15
0
    def __init__(self, Waveshare=True, Layout=None, partial_update=True):
        if Waveshare == True:
            import epd2in13
            self.epd = epd2in13.EPD()
        else:
            import epd2in13_mock
            self.epd = epd2in13_mock.EPD_2in13_MOCK()

        self.image_frame = Image.new('1', (128, 250),
                                     255)  # 255: clear the frame
        self.components = []

        if Layout != None:
            self.add(Layout.components)

        self.partial_update = partial_update

        if self.partial_update == True:
            self.epd.init(self.epd.lut_partial_update)
        else:
            self.epd.init(self.epd.lut_full_update)

        # display and switch to partial update mode if needed
        self.display_image_full_update()
示例#16
0
def main():
    # Initialisation de l'afficheur
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)
    epd.clear_frame_memory(0xFF)
    # Affichage d'une image noire pour "nettoyer" l'ecran
    image = Image.open('/opt/coin-ticker/start.bmp')
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

    NH_WALLET   = ''
    NH_API_KEY  = ''
    NH_API_ID   = ''
    ETHOS_ID    = ''

    while True:
        # Check si la connexion internet est fonctionnelle
        if connection_check():
            WAN = 'OK'
        else:
            WAN = 'FAIL'

        # API call BTC value 
        gBTC = requests.get('https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR')
        if gBTC.status_code == 200:
            BTC = json.loads(gBTC.text)
        else: 
            BTC = 0

        # Recuperation des wallet balances
        gBTCBAL = requests.get('https://api.nicehash.com/api?method=balance&id=' + NH_API_ID + '&key=' + NH_API_KEY)
        if gBTCBAL.status_code == 200:
            BTCBAL = float(json.loads(gBTCBAL.text)['result']['balance_confirmed'])
        else: 
            BTCBAL = 0

        # Recuperation impayés et profitabilité
        gNH = requests.get('https://api.nicehash.com/api?method=stats.provider&addr=' + NH_WALLET)
        if gNH.status_code == 200:
            NH_UNPAID = float(json.loads(gNH.text)['result']['stats'][0]['balance'])
        else: 
            NH_UNPAID = 0

        gNHE = requests.get('https://api.nicehash.com/api?method=stats.provider.ex&addr=' + NH_WALLET)
        if gNHE.status_code == 200:
            NH_PROFITABILITY = float(json.loads(gNHE.text)['result']['current'][0]['profitability']) * 100
        else: 
            NH_PROFITABILITY = 0

        # Recuperation des hashrate ethos
        gETHOS = requests.get('http://' + ETHOS_ID + '.ethosdistro.com/?json=yes')
        if gETHOS.status_code == 200:
            ETHOS = json.loads(gETHOS.text)
        else: 
            ETHOS = 0

        # Traitements et calculs des valeurs 
        # BITCOIN
        BTC_PRICE_NOW = float(BTC[0]['price_eur'])
        BTC_EUR_NOW = BTCBAL * BTC_PRICE_NOW
        NH_PROFITABILITY_EUR_NOW = NH_PROFITABILITY * BTC_PRICE_NOW
        # Initialisation Afficheur (mode partial update)
        epd.init(epd.lut_partial_update)
        image = Image.new('1', (255, 128), 255)
        draw = ImageDraw.Draw(image)
        # Gestion Police
        color = 0
        police = '/usr/share/fonts/truetype/freefont/FreeSans.ttf'
        big = ImageFont.truetype(police, 60)
        medium = ImageFont.truetype(police, 25)
        xsmall = ImageFont.truetype(police, 10)
        small = ImageFont.truetype(police, 16)
        smalll = ImageFont.truetype(police, 20)
        # Generation de l'image a afficher
        draw.text((65, 0), time.strftime('%d/%m/%y // %H:%M // WAN ') + str(WAN), font = xsmall, fill = 0)
        draw.text((95, 10), 'hashrate', font = small, fill = color)
        draw.text((70, 20), str(ETHOS['total_hash']) + 'mh/s', font = medium, fill = color)
        draw.text((95, 45), 'balance', font = small, fill = color)
        draw.text((25, 57), str("%.5f" % BTCBAL) + ' btc (' + str("%.2f" % BTC_EUR_NOW) + ' eur)', font = smalll, fill = color)
        draw.text((10, 80), 'unpaid balance', font = small, fill = color)
        draw.text((10, 100), str("%.5f" % NH_UNPAID) + ' btc', font = small, fill = color)
        draw.text((160, 80), str("%.2f" % NH_PROFITABILITY_EUR_NOW) + ' eur/day', font = small, fill = color)
        draw.text((155, 100), str("%.0f" % BTC_PRICE_NOW) + ' eur/btc', font = small, fill = color)
        # Sauvegarde de l'image et rotation
        image.save('/opt/coin-ticker/image.jpg')
        rotate = Image.open('/opt/coin-ticker/image.jpg')
        result = rotate.rotate(90, expand = 1)
        result.save('/opt/coin-ticker/result.jpg')
        # Affichage et attente 
        epd.set_frame_memory(Image.open('/opt/coin-ticker/result.jpg'), 0, 0)
        epd.display_frame()
        epd.delay_ms(2000)
        time.sleep(30)
示例#17
0
def get_epd2in13():
    return epd2in13.EPD()
示例#18
0
文件: startup.py 项目: edwios/dotIoT
def main():

    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_disconnect = on_disconnect
    client.on_message = on_message

    client.connect_async(MQTT_HOST, 1883, 60)

    # Non-Blocking call that processes network traffic, dispatches callbacks and
    # handles reconnecting.
    # Other loop*() functions are available that give a threaded interface and a
    # manual interface.
    client.loop_start() #start loop to process received messages

    image = Image.open('dotIoT.tif')

    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    wipe_screen()
##
 # there are 2 memory areas embedded in the e-paper display
 # and once the display is refreshed, the memory area will be auto-toggled,
 # i.e. the next action of SetFrameMemory will set the other memory area
 # therefore you have to set the frame memory twice.
 ##     
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

    blank_image = Image.new('1', (24, 24), 255)  # 255: clear the frame
    conn_image = Image.new('1', (24, 24), 255)  # 255: clear the frame
    time_image = Image.new('1', (40, 16), 255)  # 255: clear the frame
    date_image = Image.new('1', (64, 16), 255)  # 255: clear the frame
    info_image = Image.new('1', (112, 18), 255)  # 255: clear the frame
    mesg_image = Image.new('1', (200, 32), 255)  # 255: clear the frame
    cmd_image  = Image.new('1', (120, 28), 255)  # 255: clear the frame

    blank_draw = ImageDraw.Draw(blank_image)
    conn_draw = ImageDraw.Draw(conn_image)
    time_draw = ImageDraw.Draw(time_image)
    date_draw = ImageDraw.Draw(date_image)
    info_draw = ImageDraw.Draw(info_image)
    mesg_draw = ImageDraw.Draw(mesg_image)
    cmd_draw = ImageDraw.Draw(cmd_image)
    conn_font = ImageFont.truetype('/home/edwintam/epap/fonts/entypo/Entypo.otf', 24)
    mesg_font = ImageFont.truetype('/home/edwintam/epap/fonts/nunito/Nunito-Bold.ttf', 28)
    cmd_font = ImageFont.truetype('/home/edwintam/epap/fonts/Bitstream-Vera-Sans/Vera-Bold.ttf', 24)
    info_font = ImageFont.truetype('/home/edwintam/epap/fonts/noto-mono/NotoMono-Regular.ttf', 12)
    datetime_font = ImageFont.truetype('/home/edwintam/epap/fonts/noto-mono/NotoMono-Regular.ttf', 12)
    blank_image_width, blank_image_height  = blank_image.size
    conn_image_width, conn_image_height  = conn_image.size
    time_image_width, time_image_height  = time_image.size
    date_image_width, date_image_height  = date_image.size
    info_image_width, info_image_height  = info_image.size
    mesg_image_width, mesg_image_height  = mesg_image.size
    cmd_image_width, cmd_image_height  = cmd_image.size
    h = socket.gethostname()+".local"
    lastTime = time.monotonic()
    ipaddr = socket.gethostbyname(h)
    while (True):
        thisTime = time.monotonic()
        if (thisTime - lastTime) > 10:
            lastTime = time.monotonic()
            h = socket.gethostname()+".local"
            ipaddr = socket.gethostbyname(h)
        # draw a rectangle to clear the image
        blank_draw.rectangle((0, 0, blank_image_width, blank_image_height), fill = 255)
        conn_draw.rectangle((0, 0, conn_image_width, conn_image_height), fill = 255)
        time_draw.rectangle((0, 0, time_image_width, time_image_height), fill = 255)
        date_draw.rectangle((0, 0, date_image_width, date_image_height), fill = 255)
        info_draw.rectangle((0, 0, info_image_width, info_image_height), fill = 255)
        mesg_draw.rectangle((0, 0, mesg_image_width, mesg_image_height), fill = 255)
        cmd_draw.rectangle((0, 0, cmd_image_width, cmd_image_height), fill = 255)
        if connected:
            conn_draw.text((0, 0), "Q", font = conn_font, fill = 0)
        else:
            conn_draw.text((0, 0), "X", font = conn_font, fill = 0)
        time_draw.text((0, 0), time.strftime('%H:%M'), font = datetime_font, fill = 0)
        date_draw.text((0, 0), time.strftime('%d/%m'), font = datetime_font, fill = 0)
        info_draw.text((0, 6), ipaddr, font=info_font, fill=0)
        mesg_draw.text((0, 0), m_broadcast, font=mesg_font, fill=0)
        cmd_draw.text((0, 4), m_cmd, font=cmd_font, fill=0)
        epd.set_frame_memory(conn_image.rotate(270, expand=1), 104, 2)
        epd.set_frame_memory(time_image.rotate(270, expand=1), 104, 208)
        epd.set_frame_memory(date_image.rotate(270, expand=1), 104, 16)
        epd.set_frame_memory(info_image.rotate(270, expand=1), 8, 134)
        epd.set_frame_memory(mesg_image.rotate(270, expand=1), 72, 52)
        epd.set_frame_memory(cmd_image.rotate(270, expand=1), 32, 92)


        epd.display_frame()
示例#19
0
def main():
    # Initialisation de l'afficheur
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)
    epd.clear_frame_memory(0xFF)
    # Affichage d'une image noire pour "nettoyer" l'ecran
    image = Image.open('/opt/coin-ticker/start.bmp')
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

    while True:
        # API call ETH value
        gETH = requests.get(
            'https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=EUR')
        if gETH.status_code == 200:
            ETH = json.loads(gETH.text)
        else:
            ETH = 0
        gBTC = requests.get(
            'https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR')
        if gBTC.status_code == 200:
            BTC = json.loads(gBTC.text)
        else:
            BTC = 0
        gBLK = requests.get('https://blockchain.info/fr/q/getblockcount')
        if gBLK.status_code == 200:
            BTCBLK = gBLK.text
        else:
            BTCBLK = 0

        # Check si la connexion internet est fonctionnelle
        if connection_check():
            WAN = 'OK'
        else:
            WAN = 'FAIL'

        # Traitements et calculs des valeurs
        # ETHEREUM
        ETH_PRICE_NOW = float(ETH[0]['price_eur'])
        ETH_PRICE_1H = ETH_PRICE_NOW - (
            (float(ETH[0]['percent_change_1h']) / 100) * ETH_PRICE_NOW)
        ETH_PRICE_24H = ETH_PRICE_NOW - (
            (float(ETH[0]['percent_change_24h']) / 100) * ETH_PRICE_NOW)
        ETH_PRICE_7D = ETH_PRICE_NOW - (
            (float(ETH[0]['percent_change_7d']) / 100) * ETH_PRICE_NOW)
        ETH_EUR_NOW = ETHBAL * ETH_PRICE_NOW
        ETH_EUR_1H = ETHBAL * ETH_PRICE_1H
        ETH_EUR_24H = ETHBAL * ETH_PRICE_24H
        ETH_EUR_7D = ETHBAL * ETH_PRICE_7D
        # BITCOIN
        BTC_PRICE_NOW = float(BTC[0]['price_eur'])
        BTC_PRICE_1H = BTC_PRICE_NOW - (
            (float(BTC[0]['percent_change_1h']) / 100) * BTC_PRICE_NOW)
        BTC_PRICE_24H = BTC_PRICE_NOW - (
            (float(BTC[0]['percent_change_24h']) / 100) * BTC_PRICE_NOW)
        BTC_PRICE_7D = BTC_PRICE_NOW - (
            (float(BTC[0]['percent_change_7d']) / 100) * BTC_PRICE_NOW)
        BTC_EUR_NOW = BTCBAL * BTC_PRICE_NOW
        BTC_EUR_1H = BTCBAL * BTC_PRICE_1H
        BTC_EUR_24H = BTCBAL * BTC_PRICE_24H
        BTC_EUR_7D = BTCBAL * BTC_PRICE_7D
        # TOTAL EUR
        TOTALEUR_NOW = ETH_EUR_NOW + BTC_EUR_NOW
        TOTALEUR_1H = ETH_EUR_1H + BTC_EUR_1H
        TOTALEUR_24H = ETH_EUR_24H + BTC_EUR_24H
        TOTALEUR_7D = ETH_EUR_7D + BTC_EUR_7D
        # TOTAL PERCENT VARIATION
        PERCENT_TOTAL_NOW_FROM_BASE = (TOTALEUR_NOW - BASE) / BASE * 100
        PERCENT_TOTAL_NOW_FROM_1H = (TOTALEUR_NOW -
                                     TOTALEUR_1H) / TOTALEUR_1H * 100
        PERCENT_TOTAL_NOW_FROM_24H = (TOTALEUR_NOW -
                                      TOTALEUR_24H) / TOTALEUR_24H * 100
        PERCENT_TOTAL_NOW_FROM_7D = (TOTALEUR_NOW -
                                     TOTALEUR_7D) / TOTALEUR_7D * 100
        # Initialisation Afficheur (mode partial update)
        epd.init(epd.lut_partial_update)
        image = Image.new('1', (255, 128), 255)
        draw = ImageDraw.Draw(image)
        # Gestion Police
        color = 0
        police = '/usr/share/fonts/truetype/freefont/FreeSans.ttf'
        big = ImageFont.truetype(police, 60)
        medium = ImageFont.truetype(police, 25)
        small = ImageFont.truetype(police, 16)
        # Generation de l'image a afficher
        draw.text((10, 0), time.strftime('%H:%M'), font=small, fill=0)
        draw.text((183, 0), 'WAN ' + str(WAN), font=small, fill=0)
        draw.text((115, 10), 'jour', font=small, fill=color)
        draw.text((70, 20),
                  str("%.2f" % PERCENT_TOTAL_NOW_FROM_24H),
                  font=big,
                  fill=color)
        draw.text((10, 80), 'heure', font=small, fill=color)
        draw.text((10, 95),
                  str("%.2f" % PERCENT_TOTAL_NOW_FROM_1H),
                  font=medium,
                  fill=color)
        draw.text((95, 80), 'semaine', font=small, fill=color)
        draw.text((95, 95),
                  str("%.2f" % PERCENT_TOTAL_NOW_FROM_7D),
                  font=medium,
                  fill=color)
        draw.text((200, 80), 'base', font=small, fill=color)
        draw.text((193, 95),
                  str("%.2f" % PERCENT_TOTAL_NOW_FROM_BASE),
                  font=medium,
                  fill=color)
        # Sauvegarde de l'image et rotation
        image.save('/opt/coin-ticker/image.jpg')
        rotate = Image.open('/opt/coin-ticker/image.jpg')
        result = rotate.rotate(90, expand=1)
        result.save('/opt/coin-ticker/result.jpg')
        # Affichage et attente
        epd.set_frame_memory(Image.open('/opt/coin-ticker/result.jpg'), 0, 0)
        epd.display_frame()
        epd.delay_ms(2000)
        time.sleep(30)
示例#20
0
#!/usr/bin/python
# -*- coding:utf-8 -*-

import epd2in13
import time
from PIL import Image, ImageDraw, ImageFont
import traceback

try:
    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)
    epd.Clear(0xFF)

    # read bmp file on window
    print("read bmp file on window")
    epd.Clear(0xFF)
    image1 = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT),
                       255)  # 255: clear the frame
    bmp = Image.open('100x100.bmp')
    image1.paste(bmp, (10, 10))
    epd.display(epd.getbuffer(image1))
    time.sleep(2)

    # Drawing on the image
    image2 = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH),
                       255)  # 255: clear the frame
    # read bmp file
    print("read bmp file")
    epd.Clear(0xFF)
    image2 = Image.open('2in13.bmp')
    epd.display(epd.getbuffer(image2.rotate(180)))
示例#21
0
def main():
    global m_temp
    global m_rh
    global m_aqi
    global m_co2
    global connected
    global btconnected

    image = Image.open('dotIoT.tif')

    epd = epd2in13.EPD()
    epd.init(epd.lut_full_update)

    wipe_screen()
    ##
    # there are 2 memory areas embedded in the e-paper display
    # and once the display is refreshed, the memory area will be auto-toggled,
    # i.e. the next action of SetFrameMemory will set the other memory area
    # therefore you have to set the frame memory twice.
    ##
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()
    epd.set_frame_memory(image, 0, 0)
    epd.display_frame()

    blank_image = Image.new('1', (24, 24), 255)  # 255: clear the frame
    conn_image = Image.new('1', (24, 24), 255)  # 255: clear the frame
    time_image = Image.new('1', (40, 16), 255)  # 255: clear the frame
    date_image = Image.new('1', (64, 16), 255)  # 255: clear the frame
    info_image = Image.new('1', (112, 18), 255)  # 255: clear the frame
    temp_image = Image.new('1', (126, 48), 255)  # 255: clear the frame
    rh_image = Image.new('1', (62, 32), 255)  # 255: clear the frame
    aqi_image = Image.new('1', (180, 28), 255)  # 255: clear the frame

    blank_draw = ImageDraw.Draw(blank_image)
    conn_draw = ImageDraw.Draw(conn_image)
    time_draw = ImageDraw.Draw(time_image)
    date_draw = ImageDraw.Draw(date_image)
    info_draw = ImageDraw.Draw(info_image)
    temp_draw = ImageDraw.Draw(temp_image)
    rh_draw = ImageDraw.Draw(rh_image)
    aqi_draw = ImageDraw.Draw(aqi_image)
    conn_font = ImageFont.truetype(
        '/home/edwintam/epap/fonts/entypo/Entypo.otf', 24)
    temp_font = ImageFont.truetype(
        '/home/edwintam/epap/fonts/nunito/Nunito-Bold.ttf', 48)
    rh_font = ImageFont.truetype(
        '/home/edwintam/epap/fonts/nunito/Nunito-Bold.ttf', 28)
    aqi_font = ImageFont.truetype(
        '/home/edwintam/epap/fonts/Bitstream-Vera-Sans/Vera-Bold.ttf', 24)
    info_font = ImageFont.truetype(
        '/home/edwintam/epap/fonts/noto-mono/NotoMono-Regular.ttf', 12)
    datetime_font = ImageFont.truetype(
        '/home/edwintam/epap/fonts/noto-mono/NotoMono-Regular.ttf', 12)
    blank_image_width, blank_image_height = blank_image.size
    conn_image_width, conn_image_height = conn_image.size
    time_image_width, time_image_height = time_image.size
    date_image_width, date_image_height = date_image.size
    info_image_width, info_image_height = info_image.size
    temp_image_width, temp_image_height = temp_image.size
    rh_image_width, rh_image_height = rh_image.size
    aqi_image_width, aqi_image_height = aqi_image.size
    h = socket.gethostname() + ".local"
    lastTime = time.monotonic()
    getEnvInfoFromBLEDevices()
    ipaddr = socket.gethostbyname(h)
    while (True):
        thisTime = time.monotonic()
        if (thisTime - lastTime) > 300:
            lastTime = time.monotonic()
            getEnvInfoFromBLEDevices()
            ipaddr = socket.gethostbyname(h)
        taqi = m_aqi + "/" + m_co2
        # draw a rectangle to clear the image
        blank_draw.rectangle((0, 0, blank_image_width, blank_image_height),
                             fill=255)
        conn_draw.rectangle((0, 0, conn_image_width, conn_image_height),
                            fill=255)
        time_draw.rectangle((0, 0, time_image_width, time_image_height),
                            fill=255)
        date_draw.rectangle((0, 0, date_image_width, date_image_height),
                            fill=255)
        info_draw.rectangle((0, 0, info_image_width, info_image_height),
                            fill=255)
        temp_draw.rectangle((0, 0, temp_image_width, temp_image_height),
                            fill=255)
        rh_draw.rectangle((0, 0, rh_image_width, rh_image_height), fill=255)
        aqi_draw.rectangle((0, 0, aqi_image_width, aqi_image_height), fill=255)
        if connected:
            conn_draw.text((0, 0), "Q", font=conn_font, fill=0)
        else:
            conn_draw.text((0, 0), "X", font=conn_font, fill=0)
        time_draw.text((0, 0),
                       time.strftime('%H:%M'),
                       font=datetime_font,
                       fill=0)
        date_draw.text((0, 0),
                       time.strftime('%d/%m'),
                       font=datetime_font,
                       fill=0)
        info_draw.text((0, 6), ipaddr, font=info_font, fill=0)
        temp_draw.text((0, 0), m_temp, font=temp_font, fill=0)
        rh_draw.text((0, 4), m_rh, font=rh_font, fill=0)
        aqi_draw.text((0, 4), taqi, font=aqi_font, fill=0)
        epd.set_frame_memory(conn_image.rotate(270, expand=1), 104, 2)
        epd.set_frame_memory(time_image.rotate(270, expand=1), 104, 208)
        epd.set_frame_memory(date_image.rotate(270, expand=1), 104, 16)
        epd.set_frame_memory(info_image.rotate(270, expand=1), 8, 134)
        epd.set_frame_memory(temp_image.rotate(270, expand=1), 72, 52)
        epd.set_frame_memory(rh_image.rotate(270, expand=1), 72, 180)
        epd.set_frame_memory(aqi_image.rotate(270, expand=1), 32, 66)
        if btconnected:
            epd.set_frame_memory(conn_image.rotate(270, expand=1), 88, 2)
        else:
            epd.set_frame_memory(blank_image.rotate(270, expand=1), 88, 2)

        epd.display_frame()