コード例 #1
0
def on_message(client, userdata, msg):
    print(msg.topic + " " + str(msg.payload))

    x = msg.payload.split(",")

    if (len(x) == 2):
        #print(" length ==2")
        with canvas(oled) as draw:
            draw.text((0, 0), "Channel " + msg.topic, font=font2, fill=255)
            draw.text((0, 22), "Item " + x[0], font=font2, fill=255)
            draw.text((0, 40), "Price " + x[1], font=font2, fill=255)
            #draw.text((0, 38), network('wlan0'), font=font2, fill=255)
    if (len(x) == 3):
        #print(" length ==2")
        with canvas(oled) as draw:
            draw.text((0, 0), x[0], font=font2, fill=255)
            draw.text((0, 22), "Rs " + x[1], font=font2, fill=255)
            draw.text((0, 40), x[2], font=font1, fill=255)
            #draw.text((0, 38), network('wlan0'), font=font2, fill=255)

    if (len(x) == 1):
        #print(" length ==1")
        with canvas(oled) as draw:
            draw.text((0, 0), msg.topic, font=font2, fill=255)
            draw.text((0, 22), x[0], font=font4, fill=255)
コード例 #2
0
def main():
    colors = ["red", "green", "blue", "yellow", "magenta", "cyan"]
    hist = history(device)

    while True:

        # Phase 1: Redraw on a fresh canvas each loop
        for idx, color in enumerate(colors):
            with canvas(hist) as draw:
                render_box(draw, idx, color)

            hist.savepoint()
            time.sleep(1)

        while len(hist) > 0:
            # Drop every other save point
            hist.restore(drop=1)
            time.sleep(1)

        # Phase 2: Notice the difference with the above?
        # ... redraw on the *same* canvas
        c = canvas(hist)
        for idx, color in enumerate(colors):
            with c as draw:
                render_box(draw, idx, color)

            hist.savepoint()
            time.sleep(1)

        while len(hist) > 0:
            hist.restore()
            time.sleep(1)
コード例 #3
0
def main():
    print("Testing basic canvas graphics...")
    with canvas(device) as draw:
        primitives(draw)

    time.sleep(10)

    print("Testing display ON/OFF...")
    for _ in range(10):
        time.sleep(0.5)
        device.hide()

        time.sleep(0.5)
        device.show()

    print("Testing clear display...")
    time.sleep(2)
    device.clear()

    print("Testing screen updates...")
    time.sleep(2)
    for x in range(30):
        with canvas(device) as draw:
            now = datetime.datetime.now()
            draw.text((x, 10), str(now.date()), fill=255)
            draw.text((10, 24), str(now.time()), fill=255)
            time.sleep(1)
コード例 #4
0
def main():
    img_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'images', 'starwars.png'))
    logo = Image.open(img_path)

    virtual = viewport(device, width=128, height=768)

    for _ in range(2):
        with canvas(virtual) as draw:
            draw.text((0, 0), "A long time ago", fill="white")
            draw.text((0, 12), "in a galaxy far", fill="white")
            draw.text((0, 24), "far away....", fill="white")

    time.sleep(5)

    for _ in range(2):
        with canvas(virtual) as draw:
            draw.bitmap((20, 0), logo, fill="white")
            for i, line in enumerate(blurb.split("\n")):
                draw.text((0, 40 + (i * 12)), text=line, fill="white")

    time.sleep(2)

    # update the viewport one position below, causing a refresh,
    # giving a rolling up scroll effect when done repeatedly
    for y in range(450):
        virtual.set_position((0, y))
        time.sleep(0.01)
コード例 #5
0
def main():
    img_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'images', 'balloon.png'))
    balloon = Image.open(img_path) \
        .transform(device.size, Image.AFFINE, (1, 0, 0, 0, 1, 0), Image.BILINEAR) \
        .convert(device.mode)

    while True:
        # Image display
        device.display(balloon)
        time.sleep(5)

        # Cycle through some primary colours
        for color in [
                "black", "white", "red", "orange", "yellow", "green", "blue",
                "indigo", "violet"
        ]:
            with canvas(device) as draw:
                draw.rectangle(device.bounding_box, fill=color)
                size = draw.textsize(color)
                left = (device.width - size[0]) / 2
                top = (device.height - size[1]) / 2
                right = left + size[0]
                bottom = top + size[1]
                draw.rectangle((left - 1, top, right, bottom), fill="black")
                draw.text((left, top), text=color, fill="white")

            time.sleep(3)

        # Rainbow
        w = 4
        with canvas(device) as draw:
            for i in range(device.width / w):
                r = int(math.sin(0.3 * i + 0) * 127) + 128
                g = int(math.sin(0.3 * i + 2) * 127) + 128
                b = int(math.sin(0.3 * i + 4) * 127) + 128
                rgb = (r << 16) | (g << 8) | b
                draw.rectangle((i * w, 0, (i + 1) * w, device.height),
                               fill=rgb)
        time.sleep(5)

        # Random blocks
        w = device.width / 12
        h = device.height / 8
        for _ in range(40):
            with canvas(device) as draw:
                for x in range(12):
                    for y in range(8):
                        color = random.randint(0, 2**24)
                        left = x * w
                        right = (x + 1) * w
                        top = y * h
                        bottom = (y + 1) * h
                        draw.rectangle((left, top, right - 2, bottom - 2),
                                       fill=color)

                time.sleep(0.25)
コード例 #6
0
ファイル: display.py プロジェクト: jvanburen/rif
 def welcome_screen(self):
     with canvas(self.device) as draw:
         draw.rectangle((0, 0, self.device.width, self.device.height),
                        outline=0,
                        fill=0)
         draw.text((20, 20), "Insert", fill=255, font=self.font)
         draw.text((20, 35), "Resistor", fill=255, font=self.font)
コード例 #7
0
    def __build(self):
        # adjust the start/end positions of the range
        if (self.highlightOption is None) or (self.highlightOption <
                                              self.rowCount):
            start = 0
            end = self.rowCount
        elif self.highlightOption >= (len(self.options) - self.rowCount):
            end = len(self.options)
            start = end - self.rowCount
        else:
            start = self.highlightOption
            end = start + self.rowCount

        # draw the menu options
        with canvas(self.oled) as draw:
            top = 0
            for x in range(start, end):
                fill = 1
                if self.highlightOption is not None and self.highlightOption == x:
                    self.draw.rectangle([0, top, self.oled.width, top + 11],
                                        outline=0,
                                        fill=1)
                    fill = 0
                draw.text((3, top + 1),
                          self.options[x],
                          font=self.font,
                          fill=fill)
                top += 10
コード例 #8
0
ファイル: price.py プロジェクト: aziotdev/mqttorange
def stats(oled):
    font = ImageFont.load_default()
    font2 = ImageFont.truetype('C&C Red Alert [INET].ttf', 14)
    with canvas(oled) as draw:
        draw.text((0, 0), "Channel ", font=font2, fill=255)
        draw.text((0, 18), "Item ", font=font2, fill=255)
        draw.text((0, 32), "Price ", font=font2, fill=255)
コード例 #9
0
    def info_screen(self):
        title = ""
        if self.index_screen == 1:
            title = "4G"
        else:
            title = "3G"

        if self.index_screen >= self.num_current_meter:
            return

        U = self.data["voltage"]
        I = self.data["current_item"][self.index_screen - 1]
        P = round(
            self.data["voltage"] *
            self.data["current_item"][self.index_screen - 1], 1)

        try:
            with canvas(self.device) as draw:
                draw.text((0, 10), title, font=self.font, fill=255)
                draw.text((0, 22),
                          "U: " + str(U) + "V",
                          font=self.font,
                          fill=255)
                draw.text((60, 22),
                          "I: " + str(I) + "A",
                          font=self.font,
                          fill=255)
                draw.text((0, 34),
                          "P: " + str(P) + "W",
                          font=self.font,
                          fill=255)
        except Exception as e:
            debug(e)
コード例 #10
0
ファイル: greyscale.py プロジェクト: bjerrep/ssd1306
def main():
    img_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'images', 'balloon.png'))
    balloon = Image.open(img_path) \
        .transform(device.size, Image.AFFINE, (1, 0, 0, 0, 1, 0), Image.BILINEAR) \
        .convert("L") \
        .convert(device.mode)

    while True:
        # Image display
        device.display(balloon)
        device.display(balloon)
        time.sleep(5)

        # Greyscale
        shades = 16
        w = device.width / shades
        for _ in range(2):
            with canvas(device, dither=True) as draw:
                for i, color in enumerate(range(0, 256, shades)):
                    rgb = (color << 16) | (color << 8) | color
                    draw.rectangle((i * w, 0, (i + 1) * w, device.height),
                                   fill=rgb)

                size = draw.textsize("greyscale")
                left = (device.width - size[0]) // 2
                top = (device.height - size[1]) // 2
                right = left + size[0]
                bottom = top + size[1]
                draw.rectangle((left - 1, top, right, bottom), fill="black")
                draw.rectangle(device.bounding_box, outline="white")
                draw.text((left, top), text="greyscale", fill="white")

        time.sleep(5)
コード例 #11
0
ファイル: main3.py プロジェクト: rafalantas/RS41-OLED
def tele(device):
    # use custom font
    font2 = ImageFont.truetype('../fonts/C&C Red Alert [INET].ttf', 12)
    with canvas(device) as draw:
        draw.text((0, 0),
                  SondeID(last_line(telemetry)),
                  font=font2,
                  fill="white")
        if device.height >= 16:
            draw.text((0, 14),
                      date(last_line(telemetry)),
                      font=font2,
                      fill="white")
        if device.height >= 32:
            draw.text((0, 26),
                      longitute(last_line(telemetry)),
                      font=font2,
                      fill="white")
        if device.height >= 48:
            draw.text((0, 38),
                      latitude(last_line(telemetry)),
                      font=font2,
                      fill="white")
            try:
                draw.text((0, 50),
                          altitude(last_line(telemetry)),
                          font=font2,
                          fill="white")
            except KeyError:
                pass
コード例 #12
0
ファイル: maze.py プロジェクト: bjerrep/ssd1306
def demo(iterations):
    for loop in range(iterations):
        for scale in [2, 3, 4, 3]:
            sz = list(map(lambda z: z // scale - 1, device.size))
            with canvas(device) as draw:
                Maze(sz).render(draw, lambda z: int(z * scale))
                time.sleep(1)
コード例 #13
0
 def home_screen(self):
     U = self.data["voltage"]
     I = self.data["current"]
     T = self.data["temperature"]
     SOH = self.data["SOH"]
     SOC = self.data["SOC"]
     time_now = datetime.now().strftime("%H:%M")
     try:
         with canvas(self.device) as draw:
             draw.text((0, 10), "Breedlife", font=self.font, fill=255)
             draw.text((60, 10), time_now, font=self.font, fill=255)
             draw.text((0, 22),
                       "U: " + str(U) + "V",
                       font=self.font,
                       fill=255)
             draw.text((60, 22),
                       "I: " + str(I) + "A",
                       font=self.font,
                       fill=255)
             draw.text((0, 34),
                       "T: " + str(T) + "C",
                       font=self.font,
                       fill=255)
             draw.text((0, 46),
                       "SOH: " + str(SOH) + "%",
                       font=self.font,
                       fill=255)
             draw.text((60, 46),
                       "SOC: " + str(SOC) + "%",
                       font=self.font,
                       fill=255)
     except Exception as e:
         debug(e)
コード例 #14
0
ファイル: sspmeteo2_oled.py プロジェクト: sersope/SSPMeteo2
    def update(cls, ddatos):
        for k, v in ddatos.items():
            ddatos[k] = float(v)
        with canvas(cls.oled) as draw:
            # Line 1 - Temp. and humidity
            line = '{:.1f}º {:.0f}%'.format(ddatos['temp'], ddatos['humi'])
            font = cls.font0
            if draw.textsize(line, font)[0] > cls.oled.width:
                font = cls.font1
            of = int((cls.oled.width - draw.textsize(line, font)[0]) / 2)
            draw.text((0 + of, 0), line, 1, font)

            # Line 2 - Rain
            line = ''
            if ddatos['llud'] > 0 or ddatos['lluh'] > 0:
                if ddatos['lluh'] > 0:
                    line = '{:.1f}mm/h {:.0f}mm'.format(ddatos['lluh'], ddatos['llud'])
                    #~ status = '¡ LLUEVE !   '
                else:
                    line = 'Lluvia diaria {:.0f}mm'.format(ddatos['llud'])
            draw.text((0, 28), line, 1, cls.font2)

            # Line 3 - Pressure and wind
            line = '{:.0f}mb {:.0f}kph {:.0f}º'.format(ddatos['pres'], ddatos['vven'], ddatos['dven'])
            font = cls.font2
            draw.text((0, 40), line, 1, font)

            # Line 4 - Status
            d, resto = divmod(ddatos['wdog'] * 5, 24 * 60)
            h, m = divmod(resto, 60)
            line = '{} {}d{}:{}'.format(datetime.now().strftime('%H:%M:%S'), int(d), int(h), int(m))
            draw.text((0, 52), line, 1, cls.font2)
コード例 #15
0
 def disable(self):
     with canvas(device) as draw:
         draw.rectangle(
             (0, 0, self.device.width - 1, self.device.height - 1),
             outline='black',
             fill='black')
     self.enabled = False
コード例 #16
0
    def logo(self, lanip="", wlanip=""):
        text = [
            '               ___',
            '              /\\_ \\                        __',
            ' __  __    ___\\//\\ \\    __  __    ___ ___ /\\_\\    ___',
            '/\\ \\/\\ \\  / __`\\\\ \\ \\  /\\ \\/\\ \\ /\' __` __`\\/\\ \\  / __`\\',
            '\\ \\ \\_/ |/\\ \\L\\ \\\\_\\ \\_\\ \\ \\_\\ \\/\\ \\/\\ \\/\\ \\ \\ \\/\\ \\L\\ \\',
            ' \\ \\___/ \\ \\____//\\____\\\\ \\____/\\ \\_\\ \\_\\ \\_\\ \\_\\ \\____/',
            '  \\/__/   \\/___/ \\/____/ \\/___/  \\/_/\\/_/\\/_/\\/_/\\/___/',
        ]
        with canvas(device) as draw:
            draw.rectangle(
                (0, 0, self.device.width - 1, self.device.height - 1),
                outline='black',
                fill='black')

            for i, line in enumerate(text):
                draw.text((8, 5 + i * 4),
                          line,
                          font=self.fonts['tiny'],
                          fill='white')

            if lanip != '':
                ip = lanip
            elif wlanip != '':
                ip = wlanip
            else:
                ip = "volumio"

            draw.text((3, 40),
                      'NanoSound v1.5.2',
                      font=self.fonts['small'],
                      fill='white')
            draw.text((3, 50), ip, font=self.fonts['small'], fill='white')
コード例 #17
0
ファイル: display.py プロジェクト: jvanburen/rif
 def draw_resistance(self, new_resistance):
     with canvas(self.device) as draw:
         self.draw_border(draw)
         if new_resistance is None:
             if self.update_time + self.HOLD_TIME < monotonic():
                 draw.text((20, 25), "Resistor", fill=255, font=self.font)
                 draw.text((15, 40), "not found", fill=255, font=self.font)
             else:
                 res_text = Display.format_resistance(self.resistance)
                 width, height = draw.textsize(res_text, font=self.font)
                 totalWidth = width + 20
                 draw.text(((128 - totalWidth) / 2, (64 - height) / 2),
                           res_text,
                           fill=255,
                           font=self.font)
                 draw.bitmap(((128 - totalWidth) / 2 + width,
                              (64 - height) / 2 - 2),
                             self.ohm,
                             fill=255)
         else:
             draw.bitmap((128 - 28, 50), self.resistor, fill=255)
             res_text = Display.format_resistance(new_resistance)
             width, height = draw.textsize(res_text, font=self.font)
             totalWidth = width + 20
             draw.text(((128 - totalWidth) / 2, (64 - height) / 2),
                       res_text,
                       fill=255,
                       font=self.font)
             draw.bitmap(
                 ((128 - totalWidth) / 2 + width, (64 - height) / 2 - 2),
                 self.ohm,
                 fill=255)
             self.resistance = new_resistance
             self.update_time = monotonic()
コード例 #18
0
def print_status():
    #       round up the value in python array then remove the '[]' while print
    #                str(np.around(fan_freq, 3)).strip('[]')
    #                        ^        ^      ^        ^
    #                        |        |      |_       |__________
    #                    round up  number      |                |
    #                    function  value  number upto        function
    #                                      given to         that remove
    #                                     be rounded           '[]'
    #

    fan_freq1 = str(np.around(fan_freq, 3)).strip('[]')
    microwave_freq1 = str(np.around(microwave_freq, 2)).strip('[]')
    hairdryer_freq1 = str(np.around(hairdryer_freq, 2)).strip('[]')
    font = ImageFont.load_default()
    with canvas(oled) as draw:
        if fan_report == False:
            draw.text((0, 0), "Fan:Off", font=font, fill=255)
        if fan_report == True:
            draw.text((0, 0), "Fan's freq:", font=font, fill=255)
            draw.text((65, 0), fan_freq1, font=font, fill=255)
        if microwave_report == False:
            draw.text((0, 14), "M.wave:Off", font=font, fill=255)
        if microwave_report == True:
            draw.text((0, 14), "M.wave's freq:", font=font, fill=255)
            draw.text((81, 14), microwave_freq1, font=font, fill=255)
        if hairdryer_report == False:
            draw.text((0, 28), "H.dryer:Off", font=font, fill=255)
        if hairdryer_report == True:
            draw.text((0, 28), "H.dryer's freq:", font=font, fill=255)
            draw.text((85, 28), hairdryer_freq1, font=font, fill=255)
コード例 #19
0
ファイル: main3.py プロジェクト: rafalantas/RS41-OLED
def log(device):
    # use custom font
    font2 = ImageFont.truetype('../fonts/C&C Red Alert [INET].ttf', 12)
    with canvas(device) as draw:
        if line_count(systemlog) < 4:
            draw.text((0, 14), "waiting for logs", font=font2, fill="white")
        if line_count(systemlog) >= 4:
            draw.text((0, 0),
                      function_last_line_log(systemlog, 1),
                      font=font2,
                      fill="white")
        if device.height >= 16 and line_count(systemlog) >= 4:
            draw.text((0, 14),
                      function_last_line_log(systemlog, 2),
                      font=font2,
                      fill="white")
        if device.height >= 32 and line_count(systemlog) >= 4:
            draw.text((0, 26),
                      function_last_line_log(systemlog, 3),
                      font=font2,
                      fill="white")
        if device.height >= 48 and line_count(systemlog) >= 4:
            draw.text((0, 38),
                      function_last_line_log(systemlog, 4),
                      font=font2,
                      fill="white")
        if device.height >= 48 and line_count(systemlog) >= 4:
            draw.text((0, 50),
                      function_last_line_log(systemlog, 5),
                      font=font2,
                      fill="white")
コード例 #20
0
ファイル: starfield.py プロジェクト: bjerrep/ssd1306
def move_and_draw_stars(stars, max_depth):
    origin_x = device.width // 2
    origin_y = device.height // 2

    with canvas(device) as draw:
        for star in stars:
            # The Z component is decreased on each frame.
            star[2] -= 0.19

            # If the star has past the screen (I mean Z<=0) then we
            # reposition it far away from the screen (Z=max_depth)
            # with random X and Y coordinates.
            if star[2] <= 0:
                star[0] = randrange(-25, 25)
                star[1] = randrange(-25, 25)
                star[2] = max_depth

            # Convert the 3D coordinates to 2D using perspective projection.
            k = 128.0 / star[2]
            x = int(star[0] * k + origin_x)
            y = int(star[1] * k + origin_y)

            # Draw the star (if it is visible in the screen).
            # We calculate the size such that distant stars are smaller than
            # closer stars. Similarly, we make sure that distant stars are
            # darker than closer stars. This is done using Linear Interpolation.
            if 0 <= x < device.width and 0 <= y < device.height:
                size = (1 - float(star[2]) / max_depth) * 4
                if (device.mode == "RGB"):
                    shade = (int(100 + (1 - float(star[2]) / max_depth) * 155),) * 3
                else:
                    shade = "white"
                draw.rectangle((x, y, x + size, y + size), fill=shade)
コード例 #21
0
def make_decision(oled):
    # set default value
    decision = "off"
    # get current time
    ct = datetime.datetime.now()
    # construct 'interval'
    delta = datetime.timedelta(hours=daytime_duration_hours,
                               minutes=daytime_duration_minutes)
    # derive today's and yesterday's start times
    dt_begin_today = datetime.datetime(ct.year, ct.month, ct.day,
                                       daytime_start_hours,
                                       daytime_start_minutes, 0)
    dt_begin_yesterday = datetime.datetime(
        ct.year, ct.month, ct.day, daytime_start_hours, daytime_start_minutes,
        0) - datetime.timedelta(days=1)
    # derive today's and yesterday's end times
    dt_end_today = dt_begin_today + delta
    dt_end_yesterday = dt_begin_yesterday + delta

    # the most important part - here a decision to turn on thermostat is made
    if ((ct >= dt_begin_today) and
        (ct <= dt_end_today)) or ((ct >= dt_begin_yesterday) and
                                  (ct <= dt_end_yesterday)):
        decision = "on"

    # initialize fonts for render on the screen
    font = ImageFont.load_default()
    font2 = ImageFont.truetype('../fonts/red_alert.ttf', 14)
    font3 = ImageFont.truetype('../fonts/red_alert.ttf', 20)

    # display status information on the screen
    with canvas(oled) as draw:
        # display current decision (ON or OFF)
        draw.text((0, 0), decision.upper(), font=font3, fill=255)
        # display last time when thermostat control script was executed
        draw.text((0, 18),
                  ct.strftime('LAST: %y/%m/%d %H:%M'),
                  font=font2,
                  fill=255)
        # show time interval when thermostat should be ON
        draw.text((0, 32),
                  'When ON: ' + dt_begin_today.strftime('%H:%M') + ' - ' +
                  dt_end_today.strftime('%H:%M'),
                  font=font2,
                  fill=255)
        # show IP address of wifi adapter
        draw.text((0, 46),
                  "IP: " + get_ip_address('wlan0'),
                  font=font2,
                  fill=255)

    # send the command to relay using GPIO pins on raspberry
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(thermostat_relay_gpio_channel, GPIO.OUT)
    if decision == 'on':
        GPIO.output(thermostat_relay_gpio_channel, True)
    else:
        GPIO.output(thermostat_relay_gpio_channel, False)
コード例 #22
0
	def splashpage( self, text ):
		try:
			with canvas( self.device ) as draw:
				draw.text( (horz_centre( text, STD_FONTSIZE), 0), text,  font=self.font, fill=255)
				draw.text( (horz_centre( TITLE1, VD_FONTSIZE)-10, 13), TITLE1,  font=self.vd_font, fill=255)
				draw.text( (horz_centre( TITLE2, VD_FONTSIZE)-10, 38), TITLE2,  font=self.vd_font, fill=255)
		except Exception, e:
			print "Failed to display splashscreen : %s " % (str(e))
def stats(oled):
    with canvas(oled) as draw:
        font = ImageFont.truetype('fonts/FreeMonoBold.ttf', 20)
        draw.text((0, 0), hostname(), font=font, fill=255)
        font = ImageFont.truetype('fonts/FreeMono.ttf', 16)   
        draw.text((0, 18), rate_ul(), font=font, fill=255)
        draw.text((0, 30), rate_dl(), font=font, fill=255)
        draw.text((0, 50), getLeechingData(), font=font, fill=255)
コード例 #24
0
ファイル: sys_info.py プロジェクト: reactiff/ssd1306
def stats(oled):
    font = ImageFont.load_default()
    font2 = ImageFont.truetype('../fonts/C&C Red Alert [INET].ttf', 12)
    with canvas(oled) as draw:
        draw.text((0, 0), cpu_usage(), font=font2, fill=255)
        draw.text((0, 14), mem_usage(), font=font2, fill=255)
        draw.text((0, 26), disk_usage('/'), font=font2, fill=255)
        draw.text((0, 38), network('wlan0'), font=font2, fill=255)
コード例 #25
0
ファイル: screen.py プロジェクト: xlevel/GreenHouse
def Write(dateTime, temp, humidity):
	device = ssd1306(port=1, address=0x3C)

	with canvas(device) as draw:
		font = ImageFont.truetype("FreeSans.ttf", 12)
		draw.text((10,5), "Time: {0}".format(time.strftime('%Y-%m-%d %H:%M:%S', dateTime)), font=font, fill=255)
		draw.text((10,25), "Temp: {0:0.1f}\xb0C".format(temp), font=font, fill=255)
		draw.text((10,45), "Humi: {0:0.1f}%".format(humidity), font=font, fill=255)
コード例 #26
0
def stats(oled):
    font = ImageFont.load_default()
    font2 = ImageFont.truetype('../fonts/C&C Red Alert [INET].ttf', 12)
    with canvas(oled) as draw:
        draw.text((0, 0), cpu_usage(), font=font2, fill=255)
        draw.text((0, 14), mem_usage(), font=font2, fill=255)
        draw.text((0, 26), disk_usage('/'), font=font2, fill=255)
        draw.text((0, 38), network('wlan0'), font=font2, fill=255)
コード例 #27
0
ファイル: maze.py プロジェクト: fragfutter/ssd1306
def demo(iterations):
    screen = (128, 64)
    for loop in range(iterations):
        for scale in [2, 3, 4, 3]:
            sz = list(map(lambda z: z / scale - 1, screen))
            with canvas(device) as draw:
                Maze(sz).render(draw, lambda z: int(z * scale))
                time.sleep(1)
コード例 #28
0
def stats(oled):
    font = ImageFont.load_default()
    font2 = ImageFont.truetype('fonts/alert.ttf', 12)
    font3 = ImageFont.truetype('fonts/alert.ttf', 36)
    with canvas(oled) as draw:
        draw.text((0, 0), date_and_time(), font=font2, fill=255)
        draw.text((0, 14), "Total / With Positions", font=font2, fill=255)
        draw.text((0, 28), str(aircraft_total()) + "/" + str(aircraft_with_positions()), font=font3, fill=255)
コード例 #29
0
 def initScreen():
     try:
         if (device != "null"):
             img = Image.open(banner).convert('1')
             with canvas(device) as draw:
                 draw.bitmap((0, 0), img, fill=1)
     except:
         print("Banner Error")
コード例 #30
0
def stats(oled):
    with canvas(oled) as draw:
        font = ImageFont.truetype('fonts/FreeMonoBold.ttf', 20)
        draw.text((0, 0), "benmichae", font=font, fill=255)
        font = ImageFont.truetype('fonts/FreeMono.ttf', 16)   
        draw.text((0, 18), "rpi oled", font=font, fill=255)
        draw.text((0, 30), "i2c test", font=font, fill=255)
        draw.text((0, 42), "more text!", font=font, fill=255)
def stats(oled):
    with canvas(oled) as draw:
        font = ImageFont.truetype('fonts/FreeMonoBold.ttf', 20)
        draw.text((0, 0), hostname(), font=font, fill=255)
        font = ImageFont.truetype('fonts/FreeMono.ttf', 16)
        draw.text((0, 18), rate_ul(), font=font, fill=255)
        draw.text((0, 30), rate_dl(), font=font, fill=255)
        draw.text((0, 50), getLeechingData(), font=font, fill=255)
コード例 #32
0
	def systemscreen( self ):
		self.sys.grab()

		with canvas( self.device ) as draw:
			sfont = ImageFont.truetype( BASE_FONT, 9)
			self.bar_meter( draw, 0, 5, int(self.sys.status['cpu_load']), "CPU", sfont)
			self.bar_meter( draw, 0, 20, int(self.sys.status['mpd_load']), "MPD", sfont)
			self.bar_meter( draw, 0, 35, int(self.sys.status['shairport_load']), "Shair", sfont)
			self.bar_meter( draw, 0, 50, int(self.sys.status['disk_used']), "Disk", sfont)
コード例 #33
0
def test_gifanim_write():
    reference = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'reference', 'anim.gif'))

    fname = NamedTemporaryFile(suffix=".gif").name
    device = gifanim(filename=fname)

    with canvas(device) as draw:
        baseline_data.primitives(device, draw)

    with canvas(device) as draw:
        draw.text((30, 10), text="Blipvert", fill="white")

    with canvas(device) as draw:
        baseline_data.primitives(device, draw)

    device.write_animation()
    assert md5(reference) == md5(fname)
コード例 #34
0
def demo(iterations):
    device = sh1106(dc=25, spi=SPI.SpiDev(0, 0, max_speed_hz=8000000))
    screen = (128, 64)
    for loop in range(iterations):
        for scale in [2, 3, 4, 3]:
            sz = map(lambda z: z / scale - 1, screen)
            with canvas(device) as draw:
                Maze(sz).render(draw, lambda z: int(z * scale))
                time.sleep(5)
コード例 #35
0
ファイル: maze.py プロジェクト: imccie/raspberrypi_oleds
def demo(iterations):
    device = sh1106(dc=25, spi=SPI.SpiDev(0, 0, max_speed_hz=8000000))
    screen = (128, 64)
    for loop in range(iterations):
        for scale in [2,3,4,3]:
            sz = map(lambda z: z/scale-1, screen)
            with canvas(device) as draw:
                Maze(sz).render(draw, lambda z: int(z * scale))
                time.sleep(5)
コード例 #36
0
ファイル: maze.py プロジェクト: LuisDiazUgena/ssd1306
def demo(iterations):
    device = ssd1306(port=1, address=0x3C)
    screen = (128, 64)
    for loop in range(iterations):
        for scale in [2,3,4,3]:
            sz = map(lambda z: z/scale-1, screen)
            with canvas(device) as draw:
                Maze(sz).render(draw, lambda z: int(z * scale))
                time.sleep(1)
コード例 #37
0
ファイル: main.py プロジェクト: vjammar/aws-iot-python
def setupRace(hexUID, name):
    # Display Red
    with canvas(disp) as draw:
        draw.text((0, 0), 'READY', font=raceFont, fill=255)
    color(100, 0, 0, 2.0)

    # Display Yellow
    with canvas(disp) as draw:
        draw.text((0, 0), 'SET', font=raceFont, fill=255)
    color(65, 100, 0, 2.0)

    # Disyplay Green
    with canvas(disp) as draw:
        draw.text((0, 0), 'GO!', font=raceFont, fill=255)
    color(0, 100, 0, 0)

    # Display stopwatch
    stopwatch(hexUID, name)
コード例 #38
0
def main():
    with canvas(device) as draw:
        draw.multiline_text(offset, "Please do\nnot adjust\nyour set", fill="white", align="center", spacing=-1)

    images = [snow() for _ in range(20)]
    while True:
        random.shuffle(images)
        for background in images:
            device.display(background)
コード例 #39
0
def demo(iterations):
    device = ssd1306(port=1, address=0x3C)
    screen = (128, 64)
    for loop in range(iterations):
        for scale in [2, 3, 4, 3]:
            sz = map(lambda z: z / scale - 1, screen)
            with canvas(device) as draw:
                Maze(sz).render(draw, lambda z: int(z * scale))
                time.sleep(1)
コード例 #40
0
ファイル: sys_info.py プロジェクト: iMouath/Raspberry
def stats(oled):
    font = ImageFont.load_default()
    font2 = ImageFont.truetype('c-and-c.ttf', 12)
    with canvas(oled) as draw:
        draw.text((0, 00), myip('wlan0'), font=font2, fill=255)
        draw.text((0, 14), mem_usage(), font=font2, fill=255)
        draw.text((0, 26), disk_usage('/'), font=font2, fill=255)
        #draw.text((0, 38), network('wlan0'), font=font2, fill=255)
        draw.text((0, 50), cpu_usage(), font=font2, fill=255)
コード例 #41
0
ファイル: main.py プロジェクト: vjammar/aws-iot-python
def displayUserData(hexUID):
    r = requests.get(flaskHost + '/users/' + hexUID)
    userData = r.json()[u'user']
    with canvas(disp) as draw:
        draw.text((0, 0), userData[u'name'], font=defaultFont, fill=255)
        imageURLResponse = requests.get(userData[u'avatar'])
        img = Image.open(StringIO(imageURLResponse.content))
        draw.bitmap((0, 15), img, fill=1)
    time.sleep(2.5)
    setupRace(hexUID, userData[u'name'])
コード例 #42
0
ファイル: sys_info.py プロジェクト: imccie/raspberrypi_oleds
def stats(oled,i):
    font = ImageFont.load_default()
    font = ImageFont.truetype("/usr/share/fonts/truetype/msyhl.ttc",12)
    font2 = ImageFont.truetype('../fonts/C&C Red Alert [INET].ttf', 12)
    with canvas(oled) as draw:
        draw.text((i, 0), cpu_usage(), font=font2, fill=255)
        draw.text((i, 14), mem_usage(), font=font2, fill=255)
        draw.text((i, 26), disk_usage('/'), font=font2, fill=255)
        draw.text((i, 38), network('wlan0'), font=font2, fill=255)
        draw.text((i, 50), u"当前系统时间"+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())),font=font, fill=255)
コード例 #43
0
	def tracksscreen( self ):
		self.metadata.grab()
		#print self.metadata
		with canvas( self.device ) as draw:
			draw.text((0,0),    self.metadata.song,  font=self.font, fill=255)
			draw.text((0,15),    self.metadata.artist,  font=self.font, fill=255)
			draw.text((0,30),    self.metadata.album,  font=self.font, fill=255)
			#draw.text((0,50),    self.metadata.genre,  font=self.font, fill=255)
			time = secs_to_mins(self.metadata.elapsed) + " / " + secs_to_mins(self.metadata.duration)
			draw.text((0,52),    time,  font=self.font, fill=255)
			draw.text((66,50),    playicon( self.metadata.state ),  font=self.font, fill=255)
			draw.text((78,52),    'Vol '+self.metadata.volume,  font=self.font, fill=255)
コード例 #44
0
def test_diplay():
    device = sh1106(bus)
    bus.reset()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        baseline_data.primitives(device, draw)

    assert len(bus.recordings) == 40

    for i in range(40):
        assert bus.recordings[i] == baseline_data.demo_sh1106[i]
コード例 #45
0
	def bitratescreen( self ):
		# update the screen according to the mode defined
		self.metadata.grab()
		#print self.metadata
		bigger_font = ImageFont.truetype( BASE_FONT, 22 )
		status_font = ImageFont.truetype( BASE_FONT, 18 )

		with canvas( self.device ) as draw:
			draw.text((20,20),    self.metadata.bitrate,  font=self.bigger_font, fill=255)
			draw.text((77,0),    self.metadata.samplerate,  font=self.font, fill=255)
			draw.text((0,0),    self.metadata.bitsize,  font=self.font, fill=255)
			draw.text((50,52),    'Volume '+ self.metadata.volume,  font=self.font, fill=255)
			draw.text((3,45),    playicon( self.metadata.state ),  font=self.status_font, fill=255)
コード例 #46
0
def trello(oled):
    ourkey = open('.trello-screen-api-key').read();
    ourtoken = open('.trello-screen-token').read();
    ourlist = open('.trello-screen-list').read();
    trello = TrelloApi(ourkey, token=ourtoken)
    cards = trello.lists.get_card(ourlist)
    index = 0
    font2 = ImageFont.truetype('redalert.ttf', 12)
    with canvas(oled) as draw:
        draw.text((0,0), "Working on " + str(len(cards)) + " things:", font=font2, fill=255)
        while index < len(cards) and index < 4:
            draw.text((12,13+(index*13)),cards[index]['name'], font=font2, fill=255)
            index = index + 1
コード例 #47
0
ファイル: main.py プロジェクト: netwokz/Garage-Door-Project
def stats(oled):
    font = ImageFont.truetype('font.ttf', 12)
    mClosed = "Closed"
    mOpen = "Open"
    garage = ""
    if isGarageClosed == True:
        garage = "Garage is Closed"
    else:
        garage = "Garage is Open"
    with canvas(oled) as draw:
        draw.text((0, 12), temperature(), font=font, fill=255)
        draw.text((0, 26), humidity(), font=font, fill=255)
        draw.text((0, 40), garage, font=font, fill=255)
コード例 #48
0
ファイル: OLEDController.py プロジェクト: benrad/carputer
 def draw_frame(animation, message, i, counterclockwise=False):
     """Draws a single frame of the loading spin animation with message underneath"""
     if counterclockwise:
         stop = 0
         start = max(int(animation(i / 360.0) * 360), 1)
     else:
         stop = max(int(animation(i / 360.0) * 360), 1)
         start = 0
     font_size = self.font.getsize(message)
     with canvas(self.device) as draw:
         draw.text(((self.width / 2) - (font_size[0] / 2), (3 * self.height / 4) - (font_size[1] / 2)), message,
                   font=self.font, fill=255)
         draw.arc(((self.width / 2) - (self.height / 4), 0, (self.width / 2) + (self.height / 4),
                   self.height / 2), start, stop, fill=255)
コード例 #49
0
ファイル: lcd-zmq.py プロジェクト: dnezic/wisense
    def do_draw(self, _id, msg):
        print(msg)
        tm = strftime("%H:%M:%S")

        if _id == "BME28":
            t,h,p = msg.split(":")
            with canvas(self.oled) as draw:
                draw.text((0, 0), "INDOOR - " + tm, font=self.deja_vu_sm, fill=255)
                draw.text((0, 10), t + "°C", font=self.deja_vu, fill=255)
                #draw.text((0, 20), h + "%", font=self.deja_vu, fill=255)
                draw.text((0, 50), p + "hPa " + h + "%", font=self.deja_vu_sm, fill=255)
        if _id == "NRF24":
            t,h,p = msg.split(":")
            with canvas(self.oled) as draw:
                draw.text((0, 0), "OUTDOOR - " + tm, font=self.deja_vu_sm, fill=255)
                draw.text((0, 10), t + "°C", font=self.deja_vu, fill=255)
                #draw.text((0, 20), h + "%", font=self.deja_vu, fill=255)
                draw.text((0, 50), p + "hPa " + h + "%", font=self.deja_vu_sm, fill=255)

        if _id == "CLOCK":
            t = msg
            with canvas(self.oled) as draw:
                draw.text((0, 10), t, font=self.deja_vu, fill=255)
コード例 #50
0
def test_diplay():
    device = ssd1306(bus)
    bus.reset()

    # Use the same drawing primitives as the demo
    with canvas(device) as draw:
        baseline_data.primitives(device, draw)

    assert len(bus.recordings) == 33

    # Initial command to reset the display
    assert bus.recordings[0] == mock.recording(60, 0, [33, 0, 127, 34, 0, 7])

    # Next 32 recordings are data representing the drawn image
    for i in range(32):
        assert bus.recordings[i + 1] == baseline_data.demo_ssd1306[i]
コード例 #51
0
	def volumioscreen( self ):
		self.metadata.grab()

		with canvas( self.device ) as draw:
			padding = 5
			top = 2
			bottom = self.device.height - padding - 1
			fontsize = 11
			font = ImageFont.truetype( BASE_FONT, fontsize)
			sfont = ImageFont.truetype( BASE_FONT, 8)

			draw.rectangle( (0, 0, self.device.width-1, self.device.height-1) , fill=0, outline=255)

			# draw the left Song duration counter
			song_duration = 3 * 60  # until it can be found assume songs are 3 mins
			song_time = self.metadata.elapsedpc
			#print song_time
			y = 5+ (4 * padding)
			x = padding
			draw.pieslice( (x, y, x+CONTROLS_WIDTH, y+CONTROLS_WIDTH), 270, int(270+360*song_time), outline=0, fill=255)
			i = 7
			draw.ellipse( (x+i, y+i, x+CONTROLS_WIDTH-i, y+CONTROLS_WIDTH-i), outline=0, fill=0)
			t = 6
			draw.text( (x+i+t-4, y+i+t), 'Time',  font=sfont, fill=255)

			# Draw right volume status
			x = 90
			vol = self.metadata.vol
			draw.pieslice( (x, y, x+CONTROLS_WIDTH, y+CONTROLS_WIDTH), 135, int(135+(270*vol/100)), outline=0, fill=255)
			i = 7
			draw.ellipse( (x+i, y+i, x+CONTROLS_WIDTH-i, y+CONTROLS_WIDTH-i), outline=0, fill=0)
			t = 6
			draw.text( (x+i+t, y+i+t), 'Vol',  font=sfont, fill=255)

			# Draw the Text info
			fontsize = 11
			font = ImageFont.truetype( BASE_FONT, fontsize)

			a = self.metadata.artist
			s = self.metadata.song
			m = self.metadata.bitrate
			p = playicon( self.metadata.state )

			draw.text( (horz_centre( s, fontsize, padding), top),  s,  font=font, fill=255)
			draw.text( (horz_centre( a, fontsize, padding), top+10),  a,  font=font, fill=255)
			draw.text( (horz_centre( m, fontsize, padding), bottom-10),  m,  font=font, fill=255)
			draw.text( (horz_centre( p, fontsize, padding), SCREEN_HEIGHT/2),  p,  font=font, fill=255)
コード例 #52
0
def make_decision(oled):
    # set default value
    decision = "off"
    # get current time
    ct = datetime.datetime.now()
    # construct 'interval'
    delta = datetime.timedelta(hours = daytime_duration_hours, minutes = daytime_duration_minutes)
    # derive today's and yesterday's start times
    dt_begin_today = datetime.datetime(ct.year, ct.month, ct.day, daytime_start_hours, daytime_start_minutes, 0)
    dt_begin_yesterday = datetime.datetime(ct.year, ct.month, ct.day, daytime_start_hours, daytime_start_minutes, 0) - datetime.timedelta(days=1)
    # derive today's and yesterday's end times
    dt_end_today = dt_begin_today + delta
    dt_end_yesterday = dt_begin_yesterday + delta

    # the most important part - here a decision to turn on thermostat is made
    if ((ct >= dt_begin_today) and (ct <= dt_end_today)) or ((ct >= dt_begin_yesterday) and (ct <= dt_end_yesterday)):
        decision = "on"

    # initialize fonts for render on the screen
    font = ImageFont.load_default()
    font2 = ImageFont.truetype('fonts/red_alert.ttf', 14)
    font3 = ImageFont.truetype('fonts/red_alert.ttf', 20)

    # display status information on the screen
    with canvas(oled) as draw:
        # display current decision (ON or OFF)
        draw.text((0, 0), decision.upper(), font=font3, fill=255)
        # display last time when thermostat control script was executed
        draw.text((0, 18), ct.strftime('LAST: %y/%m/%d %H:%M'), font=font2, fill=255)
        # show time interval when thermostat should be ON
        draw.text((0, 32), 'When ON: ' + dt_begin_today.strftime('%H:%M') + ' - ' + dt_end_today.strftime('%H:%M'), font=font2, fill=255)
        # show IP address of wifi adapter
        draw.text((0, 46), "IP: " + get_ip_address('wlan0'), font=font2, fill=255)

    # send the command to relay using GPIO pins on raspberry
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(thermostat_relay_gpio_channel, GPIO.OUT)
    if decision == 'on':
        GPIO.output(thermostat_relay_gpio_channel, True)
    else:
        GPIO.output(thermostat_relay_gpio_channel, False)
コード例 #53
0
	def airplayscreen( self ):
		self.metadata.grab()

		with canvas( self.device ) as draw:
			padding = 5
			top = 2
			bottom = self.device.height - padding - 1
			fontsize = 11
			font = ImageFont.truetype( BASE_FONT, fontsize)
			sfont = ImageFont.truetype( BASE_FONT, 8)
			# outside box
			B = self.device.height-15
			draw.rectangle( (0, 0, self.device.width-1, B) , fill=0, outline=255)
			#airplay triange
			W = 30
			H = 20
			Xt= (self.device.width/2)-W/2
			Y_OFF = -3
			Yt= B+Y_OFF
			draw.polygon( (Xt,Yt+H, Xt+W/2, Yt, Xt+W, Yt+H), fill=255, outline=255)

			#Add Volume and Track data


			# Draw the Text info
			fontsize = 11
			font = ImageFont.truetype( BASE_FONT, fontsize)

			a = self.metadata.artist
			s = self.metadata.song
			m = self.metadata.album

			top = 2

			draw.text( (horz_centre( s, fontsize, padding), top),  s,  font=font, fill=255)
			draw.text( (horz_centre( a, fontsize, padding), top+12),  a,  font=font, fill=255)
			draw.text( (horz_centre( m, fontsize, padding), top+25),  m,  font=font, fill=255)
			draw.text((78,52),    'Vol '+self.metadata.volume,  font=font, fill=255)
font_dir = '/home/pi/ssd1306/fonts/C&C Red Alert [INET].ttf'
font_dir2 = '/home/pi/ssd1306/fonts/arial.ttf'
#font = ImageFont.load_default()
font1 = ImageFont.truetype(font_dir, 18)
font2 = ImageFont.truetype(font_dir, 12)
font3 = ImageFont.truetype(font_dir2, 16)
font4 = ImageFont.truetype(font_dir2, 12)

stage = 0
current_stage = 1
continue_bit = 0
wifi = 0
err=0

GPIO.output(18, GPIO.HIGH)
with canvas(device) as draw:
  logo = Image.open('ESPert_logo.bmp')
  draw.bitmap((32, 0), logo, fill=1)
time.sleep(2)

try:
 while True:
  if (GPIO.input(21) == 0):
   wifi = wifi + 1
   if(wifi > 1):
    wifi = 0
   with canvas(device) as draw:
    draw.text((0,16), 'WiFi selected:', font=font3, fill=255)
    if(wifi==0):
     draw.text((0,33), 'Cytron Yes', font=font3, fill=255)
    elif(wifi==1):
コード例 #55
0
ファイル: screen.py プロジェクト: jamez70/stratux
    def run(self):
        font2 = ImageFont.truetype('/etc/stratux-screen/CnC_Red_Alert.ttf', 12)
        oled = ssd1306(port=1, address=0x3C)

        with canvas(oled) as draw:
            logo = Image.open('/etc/stratux-screen/stratux-logo-64x64.bmp')
            draw.bitmap((32, 0), logo, fill=1)

        time.sleep(10)
        n = 0

        while 1:
            time.sleep(1)
            response = urllib2.urlopen('http://localhost/getStatus')
            getStatusHTML = response.read()
            getStatusData = json.loads(getStatusHTML)
            CPUTemp = getStatusData["CPUTemp"]
            uat_current = getStatusData["UAT_messages_last_minute"]
            uat_max = getStatusData["UAT_messages_max"]
            es_current = getStatusData["ES_messages_last_minute"]
            es_max = getStatusData["ES_messages_max"]
    
            response = urllib2.urlopen('http://localhost/getTowers')
            getTowersHTML = response.read()
            getTowersData = json.loads(getTowersHTML)
            NumTowers = len(getTowersData)

            with canvas(oled) as draw:
                pad = 2 # Two pixels on the left and right.
                text_margin = 25
                # UAT status.
                draw.text((50, 0), "UAT", font=font2, fill=255)
                # "Status bar", 2 pixels high.
                status_bar_width_max = oled.width - (2 * pad) - (2 * text_margin)
                status_bar_width = 0
                if uat_max > 0:
                    status_bar_width = int((float(uat_current) / uat_max) * status_bar_width_max)
                draw.rectangle((pad + text_margin, 14, pad + text_margin + status_bar_width, 20), outline=255, fill=255) # Top left, bottom right.
                # Draw the current (left) and max (right) numbers.
                draw.text((pad, 14), str(uat_current), font=font2, fill=255)
                draw.text(((2*pad) + text_margin + status_bar_width_max, 14), str(uat_max), font=font2, fill=255)
                # ES status.
                draw.text((44, 24), "1090ES", font=font2, fill=255)
                status_bar_width = 0
                if es_max > 0:
                    status_bar_width = int((float(es_current) / es_max) * status_bar_width_max)
                draw.rectangle((pad + text_margin, 34, pad + text_margin + status_bar_width, 40), outline=255, fill=255) # Top left, bottom right.
                # Draw the current (left) and max (right) numbers.
                draw.text((pad, 34), str(es_current), font=font2, fill=255)
                draw.text(((2*pad) + text_margin + status_bar_width_max, 34), str(es_max), font=font2, fill=255)
                # Other stats.
                seq = (n / 5) % 2
                t = ""
                if seq == 0:
                    t = "CPU: %0.1fC, Towers: %d" % (CPUTemp, NumTowers)
                if seq == 1:
                    t = "GPS Sat: %d/%d/%d" % (getStatusData["GPS_satellites_locked"], getStatusData["GPS_satellites_seen"], getStatusData["GPS_satellites_tracked"])
                    if getStatusData["GPS_solution"] == "GPS + SBAS (WAAS / EGNOS)":
                        t = t + " (WAAS)"
                #print t
                draw.text((pad, 45), t, font=font2, fill=255)

            n = n+1
コード例 #56
0
ファイル: sspmeteo2_oled.py プロジェクト: sersope/SSPMeteo2
 def begin(cls):
     with canvas(cls.oled) as draw:
         draw.text((8, 14), 'SSPMeteo2', 1, cls.font1)
         draw.text((0, 50), 'Esperando datos...', 1, cls.font2)
コード例 #57
0
ファイル: OLEDController.py プロジェクト: benrad/carputer
 def clear(self):
     with canvas(self.device) as draw:
         draw.rectangle((0, 0, self.width, self.height), outline=0, fill=0)
コード例 #58
0
ファイル: controller-oled.py プロジェクト: surak/Raspberry
def printOled(message):
    with canvas(oled) as draw:
        draw.text((0, 0), message, font=font, fill=255)
コード例 #59
0
ファイル: ispresso.py プロジェクト: grahamBamber/coffie
def lcdControlProc(lcd_child_conn):
    p = current_process()
    logger = logging.getLogger("ispresso").getChild("lcdControlProc")
    logger.info('Starting:' + p.name + ":" + str(p.pid))

    #lcd = lcddriver.lcd()
    lcd = ssd1306(port=1, address=0x3C)
    font = ImageFont.truetype('courier.ttf', 14)
    font2 = ImageFont.truetype('courier.ttf', 18)

    last_line1 = ""
    last_line2 = ""

    while (True):
        time.sleep(0.25)
        while lcd_child_conn.poll():
            #try:
            #    line1, line2, duration = lcd_child_conn.recv()
            #    if line1 is not None:
            #        if last_line1 != line1:
            #            #lcd.lcd_display_string(line1.ljust(16), 1)
            #            last_line1 = line1
            #            time.sleep(duration)
            #
            #    if line2 is not None:
            #        if last_line2 != line2:
            #            #lcd.lcd_display_string(line2.ljust(16), 2)
            #            last_line2 = line2
            #            time.sleep(duration)

            #except:
            #    exc_type, exc_value, exc_traceback = sys.exc_info()
            #    logger.error(''.join('!! ' + line for line in traceback.format_exception(exc_type, exc_value, exc_traceback)))
            #    subprocess.call(['i2cdetect', '-y', '1'])
            #    try:
            #        lcd = None
            #        time.sleep(0.1)
            #        #lcd = lcddriver.lcd()
            #        time.sleep(0.1)
            #    except:
            #        logger.error("Trying to re-initialize the LCD by nulling it out and re-instantiating.  Couldln't pull it off :(")
            #    continue
            with canvas(lcd) as draw:
                  line1, line2, duration = lcd_child_conn.recv()
                  if line1 is not None:
                     if last_line1 != line1:
            #            #lcd.lcd_display_string(line1.ljust(16), 1)
                        last_line1 = line1
            #            time.sleep(duration)
            #
                  if line2 is not None:
                     if last_line2 != line2:
            #            #lcd.lcd_display_string(line2.ljust(16), 2)
                         last_line2 = line2
            #            time.sleep(duration)
                  padding = 0
                  shape_width = 20
                  top = padding
                  bottom = lcd.height - padding - 1
                  draw.text((1, top),   last_line1,  font=font, fill=255)
                  draw.text((1, top+16), last_line2, font=font2, fill=255)
                  time.sleep(duration)