Exemple #1
0
def main():
    epd = epd4in2.EPD()
    epd.init()

    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 1)    # 1: clear the frame
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24)
    draw.rectangle((0, 6, 400, 30), fill = 0)
    draw.text((100, 10), 'e-Paper demo', font = font, fill = 255)
    draw.rectangle((200, 80, 360, 280), fill = 0)
    draw.arc((240, 80, 380, 220), 0, 360, fill = 255)
    draw.rectangle((0, 80, 160, 280), fill = 255)
    draw.arc((40, 80, 180, 220), 0, 360, fill = 0)
    
    epd.display_frame(epd.get_frame_buffer(image))

    image = Image.open('image3.bmp')
    img = Image.open('hearts1.bmp')
    img_w, img_h = img.size
    bg_w, bg_h = image.size
    #offset = ((bg_w - img_w) // 2, (bg_h - img_h) // 2)
    offset = (0,0)
    image.paste(img, offset)
    epd.display_frame(epd.get_frame_buffer(image))
Exemple #2
0
    def __init__(self, debug_mode=False):
        self._debug_mode = debug_mode

        if not debug_mode:
            self._display_type = os.environ.get("EPAPER_TYPE", "epd2in7")
            if self._display_type == "epd2in7":
                import epd2in7
                self._display_width = epd2in7.EPD_HEIGHT  # inversed
                self._display_height = epd2in7.EPD_WIDTH
                self._epd = epd2in7.EPD()
                self._epd.init()
            elif self._display_type == "epd4in2":
                import epd4in2
                self._display_width = epd4in2.EPD_WIDTH
                self._display_height = epd4in2.EPD_HEIGHT
                self._epd = epd4in2.EPD()
                self._epd.init()
            else:
                raise "Invalid display config"
        else:
            self._display_width = EPD_WIDTH
            self._display_height = EPD_HEIGHT

        self._time_zone = tzlocal.get_localzone()
        self._str_time = "XXXX"
        self._drawing = drawing.Drawing(self._display_width,
                                        self._display_height)
def main():
    epd = epd4in2.EPD()
    epd.init()
    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.open(choose_random_loading_image('images/'))
    epd.display(epd.get_frame_buffer(image))
    time.sleep(10)  # change the image every minute
    main()
Exemple #4
0
def main():
    epd = epd4in2.EPD()
    epd.init()

    # For simplicity, the arguments are explicit numerical coordinates
    #image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 1)    # 1: clear the frame
    image = Image.open('tajmahal.bmp')
    epd.display_frame(epd.get_frame_buffer(image))
Exemple #5
0
    def __init__(self, debug_mode=False):

        self._debug_mode = debug_mode
        if not debug_mode:
            import epd4in2
            self._epd = epd4in2.EPD()
            self._epd.init()

        self._str_time = "XXXX"
Exemple #6
0
def update_screen(png):
    epd = epd4in2.EPD()
    image = Image.new('RGBA', (epd.width, epd.height), (255, 255, 255, 255))
    png = Image.open(TMP_PATH)
    image = Image.alpha_composite(image, png)
    epd.init()
    epd.Clear()
    epd.display(epd.getbuffer(image.convert("1")))
    time.sleep(2)
    epd.sleep()
Exemple #7
0
def display(text):
    epd = epd4in2.EPD()
    epd.init()

    image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 1)  # 1: clear the frame
    draw = ImageDraw.Draw(image)

    font = ImageFont.truetype(
        '/home/pi/.local/share/fonts/FiraCode-Regular.ttf', 24)
    draw.text((10, 35), text, font=font, fill=000)

    epd.display_frame(epd.get_frame_buffer(image))
Exemple #8
0
def main():
    epd = epd4in2.EPD()
    epd.init()

    # For simplicity, the arguments are explicit numerical coordinates
    for x in range(5):
        image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT),
                          1)  # 1: clear the frame
        draw = ImageDraw.Draw(image)
        font = ImageFont.truetype(
            '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24)
        draw.rectangle((0, 6, 400, 30), fill=0)
        draw.text((100, 10), 'e-Paper demo', font=font, fill=255)

        draw.text((40, 200), '%s' % (datetime.datetime.now()), font=font)

        epd.display_frame(epd.get_frame_buffer(image))
Exemple #9
0
def main():
    epd = epd4in2.EPD()
    epd.init()

    # For simplicity, the arguments are explicit numerical coordinates
    image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 1)  # 1: clear the frame
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(
        '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24)
    draw.rectangle((0, 6, 400, 30), fill=0)
    draw.text((100, 10), 'e-Paper demo', font=font, fill=255)
    draw.rectangle((200, 80, 360, 280), fill=0)
    draw.arc((240, 80, 380, 220), 0, 360, fill=255)
    draw.rectangle((0, 80, 160, 280), fill=255)
    draw.arc((40, 80, 180, 220), 0, 360, fill=0)

    epd.display_frame(epd.get_frame_buffer(image))

    image = Image.open('monocolor.bmp')
    epd.display_frame(epd.get_frame_buffer(image))
Exemple #10
0
def main():
    epd = epd4in2.EPD() #fepd2in13.EPD()
    epd.Init()

    print "width", epd.width, "height", epd.height

    GPIO.setup(PIN_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    last_button_state = GPIO.input(PIN_BUTTON)
    
    encoder = EncoderThread(encoders
                            =[{"pin_a": PIN_ENC_A, "pin_b": PIN_ENC_B, "min_pos": 0, "max_pos": epd.height-1},
                              {"pin_a": PIN_ENC_A2, "pin_b": PIN_ENC_B2, "min_pos": 0, "max_pos": epd.width-1, "invert": True}],
                            store_points = True)
    encoder.start()

    framebuf = [0xFF] * (epd.width * epd.height / 8)
    epd.DisplayPartialScott(framebuf, 0, 0, epd.width, epd.height)

    while (True):
        button_state = GPIO.input(PIN_BUTTON)
        if (button_state != last_button_state):
            if not button_state:
                framebuf = [0xFF] * (epd.width * epd.height / 8)
                epd.DisplayPartialScott(framebuf, 0, 0, epd.width, epd.height)
            last_button_state = button_state

        points = encoder.get_points()
        if points:
            points = [(p[0], p[1]) for p in points]
            drawPoints(framebuf, epd, points)
            (minX,minY,maxX,maxY) = calculateBoundingBox(points)
            #print "bounding", minX,minY,maxX,maxY
            minX=(minX/8)*8
            maxX=(maxX/8)*8

            #print "update", minX,minY,maxX+8,maxY+1
            epd.DisplayPartialScott(framebuf, minX, minY, maxX + 8, maxY + 1, black=False)
        time.sleep(0.01)

    epd.Sleep()
def main():
    epd = epd4in2.EPD()
    epd.init()
    epd.Clear(0xFF)

    while True:
        Himage = Image.new('1', (epd4in2.EPD_WIDTH, epd4in2.EPD_HEIGHT),
                           255)  # 255: clear the frame
        draw = ImageDraw.Draw(Himage)
        clock_current = datetime.datetime.now(tz)
        clock_dest = clock_current.replace(
            second=0, microsecond=0) + datetime.timedelta(minutes=1, seconds=1)

        clock = clock_current.strftime("%H:%M")
        draw.text(((epd4in2.EPD_WIDTH - len(clock) * font_clock_width) / 2, 0),
                  clock,
                  font=font_clock,
                  fill=0)

        draw.line((0, font_clock_height + 10, epd4in2.EPD_WIDTH,
                   font_clock_height + 10),
                  fill=0,
                  width=5)

        date = clock_current.strftime("%a - %d.%m.%y")
        draw.text(((epd4in2.EPD_WIDTH - len(date) * font_misc_width) / 2,
                   font_clock_height + 20),
                  date,
                  font=font_misc,
                  fill=0)

        weather, forecast = get_weather()
        if weather == None:
            clock_last = clock_last_fail
            epd.display(epd.getbuffer(Himage))
            continue
        weather_list = forecast.get_weathers()
        forecast_disp = []

        for w in weather_list:
            w_time = w.get_reference_time('date')
            w_time = w_time.astimezone(tz)
            w_time_cur = clock_current + datetime.timedelta(hours=3)
            if w_time < w_time_cur:
                continue
            forecast_disp.append(w)

        draw_weather(draw, Himage, 0,
                     (font_clock_height + font_misc_height + 30), weather,
                     "Now")
        draw_weather(draw, Himage, 100,
                     (font_clock_height + font_misc_height + 30),
                     forecast_disp[0], conv_weather_time(forecast_disp[0]))
        draw_weather(draw, Himage, 200,
                     (font_clock_height + font_misc_height + 30),
                     forecast_disp[2], conv_weather_time(forecast_disp[2]))
        draw_weather(draw, Himage, 300,
                     (font_clock_height + font_misc_height + 30),
                     forecast_disp[4], conv_weather_time(forecast_disp[4]))
        epd.display(epd.getbuffer(Himage))

        clock_current = datetime.datetime.now(tz)

        if clock_dest < clock_current:
            continue
        time.sleep(int((clock_dest - clock_current).total_seconds()))

    epd.sleep()
Exemple #12
0
def get_epd4in2():
    return epd4in2.EPD()
Exemple #13
0
 def InitDisplay(self):
     self.epd = display.EPD()
     self.epd.init()
def main():
    """Run the pi finder."""
    epd = epd4in2.EPD()
    epd.init()

    #  Here's the real shit
    debug = False
    range_max = 1000000  # bigger numbers here give better accuaracy
    x_coords = [0, range_max, range_max, 0]
    y_coords = [0, 0, range_max, range_max]
    colours = [0, 0, 0, 0]
    cap = 7200  # bigger numbers here give better accuaracy, but take longer

    while True:
        for i in range(cap):
            x = random.randint(0, range_max)
            y = random.randint(0, range_max)
            x_coords.append(x)
            y_coords.append(y)
            if in_circle(range_max, pt=(x, y)):
                colours.append(1)
            else:
                colours.append(0)

            num_tests = len(colours)
            num_in = sum(colours)
            # num_out   = num_tests-num_in
            pi_approx = (4 * num_in) / num_tests

            if i > 2:
                value_output = (
                    "π  ≅{pi_approx:.4f}\n"  # π≅
                    "πΔ ={delta:.4f}\n"  # πΔ=
                    "N  ={N}").format(
                        pi_approx=pi_approx,  # N=
                        delta=math.pi - pi_approx,
                        N=num_tests)
                fig = plt.scatter(x_coords,
                                  y_coords,
                                  c=[sub_colour(c) for c in colours],
                                  alpha=0.5,
                                  marker="2")
                plt.axis('equal')
                plt.axis('off')
                fig.axes.get_xaxis().set_ticks([])
                fig.axes.get_yaxis().set_ticks([])
                plt.subplots_adjust(left=-0.25)

                plt.text(range_max * 1.13,
                         range_max * 0.5,
                         value_output,
                         style='italic',
                         bbox={
                             'facecolor': 'red',
                             'alpha': 0.2,
                             'pad': 6
                         },
                         size=12)

                circle = plt.Circle((range_max * 0.5, range_max * 0.5),
                                    range_max * 0.5,
                                    color='r',
                                    fill=False,
                                    alpha=0.5,
                                    linewidth=2,
                                    linestyle=":",
                                    edgecolor='b')
                plt.gcf().gca().add_artist(circle)
                print(value_output)
                if debug:
                    plt.show()  # you can show or save, not both
                else:
                    filename = "p"  # +str(i)
                    plt.savefig(filename + ".png", dpi=100)

                    #  convert a .png image file to a .bmp image file using PIL
                    file_in = filename + ".png"
                    img = PILimage.open(file_in)
                    img2 = img.rotate(180)
                    img2.save(filename + ".bmp")

                plt.clf()

                image = Image.open('p.bmp')
                epd.display_frame(epd.get_frame_buffer(image))

                time.sleep(0.1)
Exemple #15
0
def main():
    # 电子墨水屏初始化
    epd = epd4in2.EPD()
    epd.init()
    # 创建空图像
    image = Image.new('1', (400, 300), 1)
    draw = ImageDraw.Draw(image)
    # 主屏幕上下分割线
    draw.line([0, 100, 399, 100], fill=0, width=2)
    # 定义字体格式
    font_calibril_super = ImageFont.truetype('/usr/share/fonts/song/calibril',
                                             90)
    font_song_small = ImageFont.truetype('/usr/share/fonts/song/simsun', 24)
    font_song_mid = ImageFont.truetype('/usr/share/fonts/song/simsun', 28)
    font_song_big = ImageFont.truetype('/usr/share/fonts/song/simsun', 32)
    font_song_large = ImageFont.truetype('/usr/share/fonts/song/simsun', 40)
    font_icon = ImageFont.truetype('/usr/share/fonts/Weather&Time', 86)
    font_icon_mid = ImageFont.truetype('/usr/share/fonts/Weather&Time', 40)
    draw.ink = 256 + 256 * 256 + 256 * 256 * 256

    # 计数君
    count = 0
    isfailed = True

    while True:
        # 清空上半部分显示区域
        draw.rectangle([0, 0, 399, 98], fill='white')
        draw.rectangle([200, 102, 399, 159], fill='white')

        # 获取日期时间
        datetime = get_datetime()
        draw.text([0, 10], datetime['time'], font=font_calibril_super)
        draw.text([250, 10], datetime['date'], font=font_song_small)
        draw.text([250, 40], datetime['week'], font=font_song_small)
        draw.text([250, 70], u'农历' + '', font=font_song_small)

        # 获取室内温度
        wet_indoor, temp_indoor = Adafruit_DHT.read(Adafruit_DHT.DHT22, 4)
        draw.text([190, 120], 'k', font=font_icon_mid)
        if temp_indoor is not None:
            draw.text([220, 120],
                      str(int(temp_indoor)) + u'℃',
                      font=font_song_large)
        draw.text([300, 120], 'j', font=font_icon_mid)
        if wet_indoor is not None:
            draw.text([330, 120],
                      str(int(wet_indoor)) + u'%',
                      font=font_song_large)

        if count == 0:
            #清空下半部分显示区域
            draw.rectangle([0, 102, 199, 299], fill='white')
            draw.rectangle([200, 160, 399, 299], fill='white')

            try:
                # 获取室外温度
                s = get_instance_weather()
                temp_outdoor = int(s['weather']['temperature'])
                wet_outdoor = int(s['weather']['humidity'])
                draw.text([220, 160],
                          str(temp_outdoor) + u'℃',
                          font=font_song_big)
                draw.text([330, 160],
                          str(wet_outdoor) + u'%',
                          font=font_song_big)

                # 获取天气状况
                weather = get_weather()
                draw.text([100, 130],
                          weather['city_name'],
                          font=font_song_small)
                #draw.text([230, 170], weather['real_temp'], font = font_song_large)
                draw.text([100, 160], u'今日', font=font_song_small)
                draw.text([10, 110],
                          str2icon(weather['day_weather']),
                          font=font_icon)
                draw.line([53, 240, 53, 290], fill=0)
                if weather.has_key('night_weather'):
                    if weather['day_weather'] == weather['night_weather']:
                        draw.text([20, 200],
                                  weather['day_weather'],
                                  font=font_song_mid)
                    else:
                        draw.text([20, 200],
                                  weather['day_weather'] + u'/' +
                                  weather['night_weather'],
                                  font=font_song_mid)
                else:
                    draw.text([20, 200],
                              weather['day_weather'],
                              font=font_song_mid)
                if weather.has_key('night_temp'):
                    draw.text([0, 240],
                              u'气温 ' + weather['day_temp'] + u'/' +
                              weather['night_temp'],
                              font=font_song_small)
                else:
                    draw.text([0, 240],
                              u'气温 ' + weather['day_temp'],
                              font=font_song_small)
                draw.text([0, 270],
                          u'风力 ' + weather['wind_dir'] + weather['wind_class'],
                          font=font_song_small)
                draw.line([293, 240, 293, 290], fill=0)
                draw.text([240, 240],
                          u'明日 ' + weather['tomorrow_weather'],
                          font=font_song_small)
                draw.text([240, 270],
                          u'天气 ' + weather['tomorrow_temp'],
                          font=font_song_small)
                isfailed = False

            except Exception, e:
                print e
                draw.rectangle([0, 102, 399, 299], fill='white')
                draw.text([0, 200], u'数据获取失败!请检查网络连接!', font=font_song_small)
                isfailed = True
                #epd.display_frame(epd.get_frame_buffer(image))

        if isfailed == False:
            count = count + 1

        if count == 20:
            count = 0

        epd.display_frame(epd.get_frame_buffer(image))
        time.sleep(60)
Exemple #16
0
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
sys.path.append(r'../lib')

import epd4in2
import epdconfig
import time
from PIL import Image, ImageDraw, ImageFont
import traceback

try:
    print("epd4in2 Demo")

    epd = epd4in2.EPD()
    print("init and Clear")
    epd.init()
    epd.Clear()

    font24 = ImageFont.truetype('../lib/Font.ttc', 24)
    font18 = ImageFont.truetype('../lib/Font.ttc', 18)

    # Drawing on the Horizontal image
    print("1.Drawing on the Horizontal image...")
    Himage = Image.new('1', (epd.width, epd.height),
                       255)  # 255: clear the frame
    draw = ImageDraw.Draw(Himage)
    draw.text((10, 0), 'hello world', font=font24, fill=0)
    draw.text((10, 20), '4.2inch e-Paper', font=font24, fill=0)
    draw.text((150, 0), u'微雪电子', font=font24, fill=0)
    draw.line((20, 50, 70, 100), fill=0)
Exemple #17
0
def main():
    while True:
        epd = epd4in2.EPD()
        epd.init()

        # For simplicity, the arguments are explicit numerical coordinates
        image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 1)    # 1: clear the frame
        baseUrl='http://api.openweathermap.org/data/2.5/weather?APPID=7fc3ac4f362f14bb2dfc885872364d9c&units=metric&id='
        forecastUrl='http://api.openweathermap.org/data/2.5/forecast?APPID=7fc3ac4f362f14bb2dfc885872364d9c&units=metric&id='
        cityId='1277333' #Bangalore

        url=baseUrl+cityId
        json_data=requests.get(url).json()
        url=forecastUrl+cityId
        forecast=requests.get(url).json()

        weather_icon=json_data["weather"][0]["icon"]

        temp = json_data["main"]["temp"]

        currDate = datetime.today().strftime('%d-%B')
        currTime = datetime.today().strftime('%I:%M')
        amPm = datetime.today().strftime('%p')

        image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 1)
        draw = ImageDraw.Draw(image)
        font16 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 16)
        font24 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24)
        font32 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 32)
        font40 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 40)
        font100 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 100)
        draw.rectangle((0, 0, EPD_WIDTH, EPD_HEIGHT), fill = 255)
        # Row-1 (Temp and Date)
        currWeather = Image.open('/home/pi/learn/epaper/DisplayStats/images/weather/'+weather_icon+'.jpg')
        offset=(2,5)
        image.paste(currWeather,offset)
        draw.text((40, 2), ('%.0f' % temp), font = font40, fill = 0)
        draw.arc((95, 10, 100, 15), 0, 360, fill = 0)
        draw.text((102, 2), "C", font = font40, fill = 0)
        draw.rectangle((139, 0, 141, 50),fill=0)
        draw.text((150, 2), str(currDate), font = font40, fill = 0)
        draw.rectangle((0, 50, EPD_WIDTH, 52), fill = 0)

        # Row-2 (Time)
        draw.text((25, 55), str(currTime), font = font100, fill = 0)
        draw.text((345, 105), str(amPm), font = font40, fill = 0)
        draw.rectangle((0, 150, EPD_WIDTH, 152), fill = 0)

        # Row-3 (Hourly Forecast)
        row3=160
        imagey=row3
        text1=imagey+40
        text2=text1+20
        fdict={}
        itemsToShow=4
        fcastSpacing=(400//itemsToShow)
        lists=forecast["list"]
        for index in range(itemsToShow):
            img = Image.open('/home/pi/learn/epaper/DisplayStats/images/weather/'+lists[index]["weather"][0]["icon"]+'.jpg')
            opic,otext1,otext2=((25+(index*fcastSpacing),imagey),(5+(index*fcastSpacing),text1),(5+(index*fcastSpacing),text2))
            image.paste(img,opic)
            draw.text(otext1,datetime.fromtimestamp(lists[index]["dt"]).strftime('%I:%M %p'), font = font16, fill = 0)
            draw.text(otext2,lists[index]["weather"][0]["main"], font = font16, fill = 0)
        draw.rectangle((0, 240, EPD_WIDTH, 242), fill = 0)

        #Row-4 (IP Address, CPU temp and RAM usage)
        # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
        row4=245
        cmd = "hostname -I | cut -d\' \' -f1"
        IP = subprocess.check_output(cmd, shell = True )
        cmd = "top -bn1 | grep load | awk '{print $(NF-2)}' | awk '{split($0,load,\",\"); printf \"%.1f%%\", (load[1]*100)}'"
        CPU = subprocess.check_output(cmd, shell = True )
        cmd = "/opt/vc/bin/vcgencmd measure_temp | awk '{split($0,temp,\"=\"); print temp[2]}'"
        TEMP = subprocess.check_output(cmd, shell = True )
        TEMP = TEMP.rstrip()
        cmd = "free -m | awk 'NR==2{printf \"%.2f%%\", (100-($3*100/$2)) }'"
        MemUsage = subprocess.check_output(cmd, shell = True )
        internet = Image.open('/home/pi/learn/epaper/DisplayStats/images/stats/wifi.jpg')
        offset=(2,row4)
        image.paste(internet,offset)
        draw.text((30, row4+4), IP, font = font16, fill = 0)
        internet = Image.open('/home/pi/learn/epaper/DisplayStats/images/stats/globe.jpg')
        offset=(2,row4+25)
        image.paste(internet,offset)
        draw.text((30, row4+29), "CONNECTED", font = font16, fill = 0)
        draw.rectangle((184, row4, 186, EPD_HEIGHT),fill=0)
        img = Image.open('/home/pi/learn/epaper/DisplayStats/images/stats/thermometer.jpg')
        offset=(195,row4)
        image.paste(img,offset)
        draw.text((223, row4+4), TEMP, font = font16, fill = 0)
        img = Image.open('/home/pi/learn/epaper/DisplayStats/images/stats/chip.jpg')
        offset=(195,row4+25)
        image.paste(img,offset)
        draw.text((223, row4+29), CPU, font = font16, fill = 0)
        draw.rectangle((309, row4, 311, EPD_HEIGHT),fill=0)
        img = Image.open('/home/pi/learn/epaper/DisplayStats/images/stats/ram.jpg')
        offset=(322,row4)
        image.paste(img,offset)
        draw.text((322, row4+27), MemUsage, font = font16, fill = 0)
        
        epd.display_frame(epd.get_frame_buffer(image))
        time.sleep(30)