예제 #1
0
def init_epd():
    # epd = epd2in7.EPD() # B/W only
    epd = epd2in7b.EPD()  # B/W/R
    logging.info("init and Clear")
    epd.init()
    epd.Clear()
    return epd
예제 #2
0
 def __init__(self):
     # import pdb
     # pdb.set_trace()
     self.epd = epd2in7b.EPD()
     self.height = self.epd.height
     self.width = self.epd.width
     self.epd.init()
예제 #3
0
    def _draw(self):
        epd = epd2in7b.EPD()
        epd.init()
        epd.Clear()

        font24 = ImageFont.truetype(os.path.join(pic_dir, 'Font.ttc'), 24)
        # font18 = ImageFont.truetype(os.path.join(pic_dir, 'Font.ttc'), 18)

        # Horizontal orientation size: 298x126
        h_black_img = Image.new('1', (epd.height, epd.width), 255)
        h_red_img = Image.new('1', (epd.height, epd.width), 255)

        draw_black = ImageDraw.Draw(h_black_img)
        draw_red = ImageDraw.Draw(h_red_img)

        draw_black.text((10, 0), 'Hello World', font=font24, fill=0)
        draw_black.text((10, 20),
                        'Temp: ' + str(self.target_temp),
                        font=font24,
                        fill=0)
        draw_black.line((20, 50, 70, 100), fill=0)
        draw_black.line((70, 50, 20, 100), fill=0)
        draw_black.rectangle((20, 50, 70, 100), outline=0)

        draw_red.line((165, 50, 165, 100), fill=0)
        draw_red.line((140, 75, 190, 75), fill=0)
        draw_red.arc((140, 50, 190, 100), 0, 360, fill=0)
        draw_red.rectangle((80, 50, 130, 100), fill=0)
        draw_red.chord((200, 50, 250, 100), 0, 360, fill=0)
        epd.display(epd.getbuffer(h_black_img), epd.getbuffer(h_red_img))
def main(image_file: str):

    #if verbose: logging.basicConfig(level=logging.DEBUG) 
    #else: logging.basicConfig(level=logging.INFO)
    with open("./tom.txt", "w+") as f:
        f.write("Python received file name")
        f.write(image_file)

    try:
        logging.info("QR Code DRAW")
    
        epd = epd2in7b.EPD()
        logging.info("init and Clear")
        epd.init()
        epd.Clear()
        time.sleep(2)
    
        # Drawing on the image
        logging.info("Drawing QR Code")
        blackimage = Image.new('1', (epd.width, epd.height), 255)  # 255: clear the frame
        redimage = Image.new('1', (epd.width, epd.height), 255)  # 255: clear the frame
    
        logging.info(f"width = {epd.width}, height = {epd.height}")

        # Drawing on the Horizontal image
        todraw = Image.new('1', (epd.height, epd.width), 255)  # 298*126
        qrcode = Image.open(image_file)
        qrcode = qrcode.resize((epd.width,epd.width), Image.ANTIALIAS)
        qrcode = qrcode.convert("RGB")

        image_enhancer = ImageEnhance.Sharpness(qrcode)
        qrcode = image_enhancer.enhance(2.0)
        qrcode = qrcode.convert("L")
        qrcode.save("sample.bmp")

        image = Image.open("sample.bmp")
        todraw.paste(image, (0,0))
    
        epd.display(epd.getbuffer(todraw), epd.getbuffer(todraw))


        time.sleep(50)
    
        logging.info("Clear...")
        epd.init()
        epd.Clear()
    
        logging.info("Goto Sleep...")
        epd.sleep()
        
    except IOError as e:
        logging.info(e)
    
    except KeyboardInterrupt:    
        logging.info("ctrl + c:")
        epd2in7b.epdconfig.module_exit()
        exit()
예제 #5
0
    def __init__(self, settings: Settings):
        self.settings = settings
        self.eInk = epd.EPD()

        self.settings = settings
        self.digital = self.settings.mode == 'digital'

        # horizontal display, so switch width and height
        self.screen_size = (self.eInk.height, self.eInk.width)

        self.last_refresh_start = datetime.datetime.fromtimestamp(0)
        self.buffers = []
예제 #6
0
if os.path.exists(libdir):
    sys.path.append(libdir)

import logging
from waveshare_epd import epd2in7b
import time
from PIL import Image, ImageDraw, ImageFont
import traceback

logging.basicConfig(level=logging.DEBUG)

try:
    logging.info("module::epd2in7b")

    epd = epd2in7b.EPD()
    logging.info("Init and Clear")
    epd.init()
    epd.Clear()
    time.sleep(1)

    # Drawing on the image
    logging.info("Drawing")
    blackimage = Image.new('1', (epd.width, epd.height),
                           255)  # 255: clear the frame
    redimage = Image.new('1', (epd.width, epd.height),
                         255)  # 255: clear the frame

    font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
    font18 = ImageFont.truetype(os.path.join(picdir, 'FiraCode-SemiBold.ttf'),
                                16)
예제 #7
0
파일: reset.py 프로젝트: uaraven/paperclock
# Copyright 2020 Oleksiy Voronin
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import waveshare_epd.epd2in7b as epd

# Clears and gracefully disconnects display

display = epd.EPD()
display.init()
display.Clear()
display.sleep()
display.Dev_exit()
예제 #8
0
     def count():
         #Initiative Imports & Modules
         from waveshare_epd import epd2in7b
         from PIL import Image,ImageDraw,ImageFont
         import traceback
         datetimeFormat='%Y-%m-%d %H:%M:%S'
         rad_Earth=6378100.0
         computer_time = strftime("%Y-%m-%d %H:%M:%S")

         #Gps Variables
         gps_time=gpsd.utc
         gps_altitude=gpsd.fix.altitude
         gps_latitude=gpsd.fix.latitude
         gps_longitude=gpsd.fix.longitude
         gps_on=gps()#Checking for Gps Signal
         f_mode=int(gpsd.fix.mode) #store number of sats
         has_fix=False
         if f_mode > 2 :
             has_fix=True
         if has_fix==True and gps_on==1:
             global lat1,lon1,rho1,z1,x1,y1,t1
             lat1=math.pi*gps_latitude/180.0
             lon1=math.pi*gps_longitude/180.0
             rho1=rad_Earth*math.cos(lat1)
             z1=rad_Earth*math.sin(lat1)
             x1=rho1*math.cos(lon1)
             y1=rho1*math.sin(lon1)
             t1=computer_time
         if has_fix==True and gps_on==2:
             global lat2,lon2,rho2,z2,x2,y2,t2,dot,cos_theta,theta,dist,t2,vel
             lat2=math.pi*gps_latitude/180.0
             lon2=math.pi*gps_longitude/180.0
             rho2=rad_Earth*math.cos(lat2)
             z2=rad_Earth*math.sin(lat2)
             x2=rho2*math.cos(lon2)
             y2=rho2*math.sin(lon2)
             dot=(x1*x2+y1*y2+z1*z2)
             cos_theta=dot/(rad_Earth*rad_Earth)
             if cos_theta < 1 and cos_theta > -1:
                theta=math.acos(cos_theta)
             else: theta=float("nan")
             dist=rad_Earth*theta
             t2=computer_time
             diff=datetime.datetime.strptime(t2,datetimeFormat)-datetime.datetime.strptime(t1,datetimeFormat)
             vel=dist/diff.seconds
             lat1=lat2
             lon1=lon2
             rho1=rho2
             z1=z2
             x1=x2
             y1=y2
             t1=t2
             gps()

         #Calculating Variables
         dht22_humidity, dht22_temperature = Adafruit_DHT.read_retry(dht22_sensor, dht22_pin)
         dht22_temperature_raw=round(dht22_temperature,5)
         dht22_temperature_calib=round(dht22_temperature * temperature_cal_a1 + temperature_cal_a0,3)
         dht22_temperature = dht22_temperature_calib
         saturation_vappress_ucalib = 0.6113 * numpy.exp((2501000.0/461.5)*((1.0/273.15)-(1.0/(dht22_temperature_raw+273.15))))
         saturation_vappress_calib = 0.6113 * numpy.exp((2501000.0/461.5)*((1.0/273.15)-(1.0/(dht22_temperature_calib+273.15))))
         dht22_vappress=(dht22_humidity/100.0)*saturation_vappress_ucalib
         dht22_vappress_raw=round(dht22_vappress,5)
         dht22_vappress_calib=round(dht22_vappress * vappress_cal_a1 + vappress_cal_a0,5)
         dht22_vappress = dht22_vappress_calib
         dht22_humidity_raw=round(dht22_humidity,3)
         dht22_humidity = round(100 * (dht22_vappress_calib / saturation_vappress_calib),3)
         if dht22_humidity >100:dht22_humidity=100
         
         if cnt == 0:
             global temperature_prev,humidity_prev,vappress_prev
             temperature_prev = 0
             humidity_prev = 0
             vappress_prev = 0
             
         tendency_temperature = dht22_temperature - temperature_prev
         tendency_humidity = dht22_humidity - humidity_prev
         tendency_vappress = dht22_vappress - vappress_prev
         
         if cnt % 5 == 0:
            temperature_prev = dht22_temperature
            humidity_prev = dht22_humidity
            vappress_prev = dht22_vappress
         
         #ePaper Begins
         epd = epd2in7b.EPD()
         epd.init()

         #Font Description 
         font_dir='/home/pi/e-Paper/RaspberryPi&JetsonNano/python/pic'
         font18 = ImageFont.truetype(os.path.join(font_dir, 'Font.ttc'), 18)
         font14 = ImageFont.truetype(os.path.join(font_dir, 'Font.ttc'), 14)

         left_spacing = 3
         first_line = 4
         last_line = 255
         line_spacing_18 = 23
         line_spacing_14 = 16

         #Descriptive image 
         if cnt == 0:#1st run
             
             print('Hello '+studentname+', Welcome to Meteobike #'+raspberryid)
             
             LBlackimage = Image.new('1', (epd.width, epd.height), 255)  # 255: clear the frame
             LRedimage= Image.new('1', (epd.width, epd.height), 255)  # 255: clear the frame
             
             drawblack = ImageDraw.Draw(LBlackimage)
             drawred = ImageDraw.Draw(LRedimage)
             
             drawblack.text((4, 4),  'Hello '+studentname, font = font18, fill = 0)
             drawblack.text((4, 40),  'Meteobike #'+raspberryid , font = font14, fill = 0)
             if get_ip()=='127.0.0.1':
               drawred.text((4,55), 'No WiFi connection', font = font14, fill = 0)
             else: drawblack.text((4,55), 'IP: ' +get_ip(), font = font14, fill = 0)   
             
             drawblack.text((4, 90),  'Key 1: Pause Recording' , font = font14, fill = 0)
             drawblack.text((4, 105), 'Key 2: Resume Recording' , font = font14, fill = 0)
             drawblack.text((4, 120), 'Key 4: Exit Recording' , font = font14, fill = 0)
             drawblack.text((4, 180), 'Hold keys for 2 seconds.', font = font14, fill = 0)  
             drawred.text((4, 200), 'Your Meteobike will \nstart automatically now \nif you press no key.', font = font14, fill = 0)  
             epd.display(epd.getbuffer(LBlackimage),epd.getbuffer(LRedimage))
             time.sleep(8)

         if recording == True:#cnt+1
             counter()

         # Data Recording
         if recording:# and has_fix: it depends
             f0=open(logfile,"a")
             f0.write(raspberryid+",")
             f0.write(str(cnt)+",")
             f0.write(computer_time+",")
             if has_fix:f0.write(gps_time+",")
             else:f0.write("nan,")
             f0.write("{0:.3f}".format(gps_altitude)+",")
             f0.write("{0:.6f}".format(gps_latitude)+",")
             f0.write("{0:.6f}".format(gps_longitude)+",")
             f0.write(str(dht22_temperature)+",")
             f0.write(str(dht22_temperature_raw)+",")
             f0.write(str(dht22_humidity)+",")
             f0.write(str(dht22_humidity_raw)+",")
             f0.write(str(dht22_vappress)+",")
             f0.write(str(dht22_vappress_raw)+",")
             if has_fix==True and gps_on==2:f0.write(str(vel)+"\n")
             else:f0.write("nan\n")
             f0.close()
                   
        # ---------------------------------
        # E-Paper 
        # ---------------------------------        
           
         #Measurement Screen
        
         LBlackimage = Image.new('1', (epd.width, epd.height), 255)  # 255: clear the fram
         LRedimage= Image.new('1', (epd.width, epd.height), 255)  # 255: clear the frame

         drawblack = ImageDraw.Draw(LBlackimage)
         drawred = ImageDraw.Draw(LRedimage)
         
         arrow_temperature = '' 
         if tendency_temperature > 0 and cnt > 1:
          arrow_temperature = u'↑'
         if tendency_temperature < 0 and cnt > 1:
          arrow_temperature = u'↓'
         if tendency_temperature == 0 and cnt > 1:
          arrow_temperature = u'→'
         
         arrow_humidity = '' 
         if tendency_humidity > 0 and cnt > 1:
          arrow_humidity = u'↑'
         if tendency_humidity < 0 and cnt > 1:
          arrow_humidity = u'↓'
         if tendency_humidity == 0 and cnt > 1:
          arrow_humidity = u'→'
         
         arrow_vappress = '' 
         if tendency_vappress > 0 and cnt > 1:
          arrow_vappress = u'↑'
         if tendency_vappress < 0 and cnt > 1:
          arrow_vappress = u'↓'
         if tendency_vappress == 0 and cnt > 1:
          arrow_vappress = u'→'
                    
         if gpsd.fix.latitude < 0:
           latitude_ns = "S"   
         else: latitude_ns = "N"        
         if gpsd.fix.longitude < 0:
           longitude_ew = "W"   
         else: longitude_ew = "E"  
                    
         drawblack.text((left_spacing,first_line+0*line_spacing_18), 'T: ' +"{0:.1f}".format(dht22_temperature)+u'°C '+arrow_temperature, font = font18, fill = 0)
         drawblack.text((left_spacing,first_line+1*line_spacing_18), 'RH: '+"{0:.1f}%".format(dht22_humidity)+' '+arrow_temperature, font = font18, fill = 0)
         drawblack.text((left_spacing,first_line+2*line_spacing_18), 'Vap.Prs.: '+"{0:.2f} kPa".format(dht22_vappress)+' '+arrow_vappress, font = font18, fill = 0) 
         if has_fix==True and gps_on==2: #presents Velocity if available
             drawblack.text((left_spacing,first_line+3*line_spacing_18), 'Speed: ' +"{0:.1f} m/s".format(vel), font = font18, fill= 0)
         else:drawred.text((left_spacing,first_line+3*line_spacing_18), 'Error: No GPS Signal', font = font18, fill = 0)
         if has_fix==True and gps_on==2:
             drawblack.text((left_spacing,first_line+10+3*line_spacing_18+1*line_spacing_14), 'Altitude: ' +"{0:.1f} m".format(gpsd.fix.altitude), font = font14, fill = 0)
             drawblack.text((left_spacing,first_line+10+3*line_spacing_18+2*line_spacing_14), 'Pos.: ' +"{0:.3f}".format(abs(gpsd.fix.latitude))+u'°'+latitude_ns+'/'+"{0:.3f}".format(abs(gpsd.fix.longitude))+u'°'+longitude_ew, font = font14, fill = 0)
             drawblack.text((left_spacing,first_line+10+3*line_spacing_18+3*line_spacing_14), 'Date: ' +gps_time[0:10], font = font14, fill = 0)
             drawblack.text((left_spacing,first_line+10+3*line_spacing_18+4*line_spacing_14), 'Time: ' +gps_time[11:19]+' UTC', font = font14, fill = 0)
         
         drawblack.line((left_spacing, 170, epd.width-left_spacing, 170), fill = 0)
         drawblack.text((left_spacing,last_line-5*line_spacing_14), studentname+"'s Meteobike", font = font14, fill = 0)
         drawblack.text((left_spacing,last_line-4*line_spacing_14), 'Meteobike #' +raspberryid, font = font14, fill = 0)
         if get_ip()=='127.0.0.1':
             drawred.text((left_spacing,last_line-3*line_spacing_14), 'No WiFi connection', font = font14, fill = 0)
         else: drawblack.text((left_spacing,last_line-3*line_spacing_14), 'IP: ' +get_ip(), font = font14, fill = 0)   
         if status_record=="On" and has_fix==True and gps_on==2:
             drawblack.text((left_spacing,last_line-2*line_spacing_14), 'Recording : On', font = font14, fill = 0)
         else: drawred.text((left_spacing,last_line-2*line_spacing_14), 'Recording: Off', font = font14, fill = 0)
         drawblack.text((left_spacing,last_line-1*line_spacing_14), 'Record No: '+str(cnt), font = font14, fill = 0)
         if cnt % display_interval == 0:
            epd.display(epd.getbuffer(LBlackimage),epd.getbuffer(LRedimage))
         if cnt == 1:
            epd.display(epd.getbuffer(LBlackimage),epd.getbuffer(LRedimage))
            
         #Decision Phase
         t=0
         while True:
             GPIO.setmode(GPIO.BCM)
             key1 = 5
             key2 = 6
             key3 = 13
             key4 = 19
             GPIO.setup(key1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
             GPIO.setup(key2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
             GPIO.setup(key3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
             GPIO.setup(key4, GPIO.IN, pull_up_down=GPIO.PUD_UP)   
             '''2Gray(Black and white) display'''
             key1state = GPIO.input(key1)
             key2state = GPIO.input(key2)
             key3state = GPIO.input(key3)
             key4state = GPIO.input(key4)
             
             LBlackimage = Image.new('1', (epd.width, epd.height), 255)  # 255: clear the fram
             LRedimage= Image.new('1', (epd.width, epd.height), 255)  # 255: clear the frame
             drawblack = ImageDraw.Draw(LBlackimage)
             drawred = ImageDraw.Draw(LRedimage)
             
             drawblack.line((left_spacing, 170, epd.width-left_spacing, 170), fill = 0)
             drawblack.text((left_spacing,last_line-5*line_spacing_14), studentname+"'s Meteobike", font = font14, fill = 0)
             drawblack.text((left_spacing,last_line-4*line_spacing_14), 'Meteobike #' +raspberryid, font = font14, fill = 0)
             if get_ip()=='127.0.0.1':
                 drawred.text((left_spacing,last_line-3*line_spacing_14), 'No WiFi connection', font = font14, fill = 0)
             else: drawblack.text((left_spacing,last_line-3*line_spacing_14), 'IP: ' +get_ip(), font = font14, fill = 0)   
             drawblack.text((left_spacing,last_line-1*line_spacing_14), 'Record No: '+str(cnt), font = font14, fill = 0)
             
             if key1state == False:
                 drawred.text((left_spacing, first_line), 'Recording \npaused' , font = font18, fill = 0)
                 drawred.text((left_spacing,last_line-2*line_spacing_14), 'Recording : Paused', font = font14, fill = 0)
                 epd.display(epd.getbuffer(LBlackimage),epd.getbuffer(LRedimage))
                 print('Key1 Pressed')
                 stop_data()
                 break
             if key2state == False:
                 drawblack.text((left_spacing, first_line), 'Recording started' , font = font18, fill = 0)
                 drawblack.text((left_spacing,last_line-2*line_spacing_14), 'Recording : On', font = font14, fill = 0)
                 epd.display(epd.getbuffer(LBlackimage),epd.getbuffer(LRedimage))
                 print('Key2 Pressed')
                 record_data()
                 break
             if key3state == False:
                 print('Key3 Pressed')
                 break
             if key4state == False:
                 drawred.text((left_spacing, first_line+0*line_spacing_18), 'Meteobike' , font = font18, fill = 0)
                 drawred.text((left_spacing, first_line+1*line_spacing_18), 'stopped' , font = font18, fill = 0)
                 drawblack.text((left_spacing, first_line+10+3*line_spacing_18+1*line_spacing_14), 'To resume logging, you' , font = font14, fill = 0)
                 drawblack.text((left_spacing, first_line+10+3*line_spacing_18+2*line_spacing_14), 'must reboot your system' , font = font14, fill = 0)
                 drawred.text((left_spacing,last_line-2*line_spacing_14), 'Recording : Off', font = font14, fill = 0)
                 epd.display(epd.getbuffer(LBlackimage),epd.getbuffer(LRedimage))
                 print('Key4 Pressed')
                 exit_program()
                 break     
             if t==5:
                 break
             t+=1
             time.sleep(1)