コード例 #1
0
ファイル: test_ssd1351.py プロジェクト: youmo110/luma.oled
def test_16bit_rgb_packing(bit, expected_16_bit_color):
    """
    Checks that 8 bit red component is packed into first 5 bits
    Checks that 8 bit green component is packed into next 6 bits
    Checks that 8 bit blue component is packed into remaining 5 bits
    """
    device = ssd1351(serial)
    serial.reset_mock()

    rgb_color = (2 ** bit,) * 3
    expected = expected_16_bit_color * device.width * device.height
    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline=rgb_color, fill=rgb_color)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [21]}, {'data': [0, 127]},
        {'command': [117]}, {'data': [0, 127]},
        {'command': [92]}, {'data': expected}
    ]
コード例 #2
0
    def set_address(self, address):
        super(terrariumOLED, self).set_address(address)
        try:
            address = i2c(port=int(self.bus),
                          address=int('0x' + str(self.address), 16))

            if self.get_type() == terrariumOLEDSSD1306.TYPE:
                self.device = ssd1306(address)
            elif self.get_type() == terrariumOLEDSSD1309.TYPE:
                self.device = ssd1309(address)
            elif self.get_type() == terrariumOLEDSSD1322.TYPE:
                self.device = ssd1322(address)
            elif self.get_type() == terrariumOLEDSSD1325.TYPE:
                self.device = ssd1325(address)
            elif self.get_type() == terrariumOLEDSSD1327.TYPE:
                self.device = ssd1327(address)
            elif self.get_type() == terrariumOLEDSSD1331.TYPE:
                self.device = ssd1331(address)
            elif self.get_type() == terrariumOLEDSSD1351.TYPE:
                self.device = ssd1351(address)
            elif self.get_type() == terrariumOLEDSH1106.TYPE:
                self.device = sh1106(address)

        except DeviceNotFoundError as ex:
            print(
                '%s - WARNING - terrariumDisplay     - %s' %
                (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:23],
                 ex))
            self.device = None

        self.init()
コード例 #3
0
ファイル: test_ssd1351.py プロジェクト: youmo110/luma.oled
def test_display():
    """
    SSD1351 OLED screen can draw and display a color image.
    """
    device = ssd1351(serial)
    serial.reset_mock()

    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

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

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [21]}, {'data': [0, 127]},
        {'command': [117]}, {'data': [0, 127]},
        {'command': [92]}, {'data': get_json_data('demo_ssd1351')}
    ]
コード例 #4
0
def test_hide():
    """
    SSD1351 OLED screen content can be hidden.
    """
    device = ssd1351(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
コード例 #5
0
def test_show():
    """
    SSD1351 OLED screen content can be displayed.
    """
    device = ssd1351(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
コード例 #6
0
ファイル: test_ssd1351.py プロジェクト: youmo110/luma.oled
def test_init_96x96_with_BGR():
    """
    SSD1351 OLED with a 96 x 96 resolution and BGR pixels works correctly.
    """
    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    ssd1351(serial, width=96, height=96, bgr=True)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [253]}, {'data': [18]},
        {'command': [253]}, {'data': [177]},
        {'command': [174]},
        {'command': [179]}, {'data': [241]},
        {'command': [202]}, {'data': [127]},
        {'command': [21]}, {'data': [0, 95]},
        {'command': [117]}, {'data': [0, 95]},
        {'command': [160]}, {'data': [118]},
        {'command': [161]}, {'data': [0]},
        {'command': [162]}, {'data': [0]},
        {'command': [181]}, {'data': [0]},
        {'command': [171]}, {'data': [1]},
        {'command': [177]}, {'data': [50]},
        {'command': [180]}, {'data': [160, 181, 85]},
        {'command': [190]}, {'data': [5]},
        {'command': [199]}, {'data': [15]},
        {'command': [182]}, {'data': [1]},
        {'command': [166]},
        {'command': [193]}, {'data': [255, 255, 255]},
        {'command': [21]}, {'data': [0, 95]},
        {'command': [117]}, {'data': [0, 95]},
        {'command': [92]}, {'data': [0] * (96 * 96 * 2)},
        {'command': [175]}
    ]
コード例 #7
0
ファイル: test_ssd1351.py プロジェクト: youmo110/luma.oled
def test_init_128x128():
    """
    SSD1351 OLED with a 128 x 128 resolution works correctly.
    """
    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    ssd1351(serial)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [
        {'command': [253]}, {'data': [18]},
        {'command': [253]}, {'data': [177]},
        {'command': [174]},
        {'command': [179]}, {'data': [241]},
        {'command': [202]}, {'data': [127]},
        {'command': [21]}, {'data': [0, 127]},
        {'command': [117]}, {'data': [0, 127]},
        {'command': [160]}, {'data': [116]},
        {'command': [161]}, {'data': [0]},
        {'command': [162]}, {'data': [0]},
        {'command': [181]}, {'data': [0]},
        {'command': [171]}, {'data': [1]},
        {'command': [177]}, {'data': [50]},
        {'command': [180]}, {'data': [160, 181, 85]},
        {'command': [190]}, {'data': [5]},
        {'command': [199]}, {'data': [15]},
        {'command': [182]}, {'data': [1]},
        {'command': [166]},
        {'command': [193]}, {'data': [255, 255, 255]},
        {'command': [21]}, {'data': [0, 127]},
        {'command': [117]}, {'data': [0, 127]},
        {'command': [92]}, {'data': [0] * (128 * 128 * 2)},
        {'command': [175]}
    ]
コード例 #8
0
ファイル: main.py プロジェクト: asrashley/pi-weather-monitor
 def __init__(self, dev: bool, width: int = 128, height: int = 128):
     self.devmode = dev
     self.width = width
     self.height = height
     self.image = Image.new('RGB', (width, height), 'white')
     self.page = len(self.PROBES)
     self.finished = False
     self.fonts = [
         ModeFont(ImageFont.truetype("FreeSansBold.ttf", 12),
                  ImageFont.truetype("FreeSansBold.ttf", 20), None),
         ModeFont(ImageFont.truetype("FreeSansBold.ttf", 18),
                  ImageFont.truetype("FreeSansBold.ttf", 26),
                  ImageFont.truetype("FreeSansBold.ttf", 14)),
         ModeFont(ImageFont.truetype("FreeSansBold.ttf", 10), None, None),
     ]
     self.samples: List[Sample] = []
     self.next_display_timeout = time.time() + self.DISPLAY_TIMEOUT
     self.next_page_timeout = time.time() + self.PAGE_TIMEOUT
     self.hidden = False
     self.display_off = False
     self.probe_thread = threading.Thread(target=self.read_probes,
                                          daemon=True)
     self.cond = threading.Condition()
     if dev:
         self.device = DevDisplay()
     else:
         serial = spi(device=0, port=0)
         self.device = ssd1351(serial, rotate=2, bgr=True)
         self.device.clear()
         GPIO.setmode(GPIO.BCM)
         GPIO.setup(self.RED_BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
         GPIO.add_event_detect(self.RED_BUTTON_GPIO,
                               GPIO.FALLING,
                               callback=self.on_red_button,
                               bouncetime=250)
         GPIO.setup(self.BLUE_BUTTON_GPIO,
                    GPIO.IN,
                    pull_up_down=GPIO.PUD_UP)
         GPIO.add_event_detect(self.BLUE_BUTTON_GPIO,
                               GPIO.FALLING,
                               callback=self.on_blue_button,
                               bouncetime=250)
         GPIO.setup(self.GREEN_BUTTON_GPIO,
                    GPIO.IN,
                    pull_up_down=GPIO.PUD_UP)
         GPIO.add_event_detect(self.GREEN_BUTTON_GPIO,
                               GPIO.FALLING,
                               callback=self.on_green_button,
                               bouncetime=250)
         GPIO.setup(self.YELLOW_BUTTON_GPIO,
                    GPIO.IN,
                    pull_up_down=GPIO.PUD_UP)
         GPIO.add_event_detect(self.YELLOW_BUTTON_GPIO,
                               GPIO.FALLING,
                               callback=self.on_yellow_button,
                               bouncetime=250)
コード例 #9
0
 def __init__(self, rst, dc):
     self.RST = rst
     self.DC = dc
     self.SPI_PORT = 0
     self.SPI_DEVICE = 0
     serial = spi(port=self.SPI_PORT, device=self.SPI_DEVICE)
     self.disp = ssd1351(serial, width=128, height=128, rotate=0)
     self.disp.show()
     self.width = 128
     self.height = 128
     self.disp.clear()
コード例 #10
0
ファイル: main.py プロジェクト: calston/gps_clock
    def __init__(self):
        self._run = True
        self.count = 0
        self.ip = ""

        self.device = ssd1351(spi(), rotate=2, bgr=True)
        self.gpsd = gps.gps(mode=gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

        self.fontawesome = self.load_font('fa-solid-900.ttf', 16)
        self.default_font = self.load_font('DejaVuSansMono-Bold.ttf', 24)
        self.small_font = self.load_font('DejaVuSans.ttf', 10)
コード例 #11
0
def display(source, *args):
    """
Usage: {0}
        Show whether display is on or not

Usage: {0} on
        Turns on display

Usage: {0} off
        Turns off display

Usage: {0} type
        Describes the display device

Usage: {0} reset
        resets the display device if it glitches
        """
    global screenState, device, googleJukes
    if len(args) != 0:
        if args[0].lower() == "on":
            if not WINDOWS_DEBUG_ON:
                device.show()
            screenState = True
        elif args[0].lower() == "off":
            screenState = False
            googleJukes.skipper.wait(1)
            if not WINDOWS_DEBUG_ON:
                device.hide()
        elif args[0].lower() == "type":
            if WINDOWS_DEBUG_ON:
                source.put("Windows does not have a display. :(")
            elif isinstance(device, ssd1351):
                source.put("(Adafruit?) SSD1351 Based SPI OLED Screen, 128x128px.")
        elif args[0].lower() == "reset":
            if WINDOWS_DEBUG_ON:
                source.put("Windows does not have a display to reset. :(")
            elif isinstance(device, ssd1351):
                source.put("Resetting (Adafruit?) SSD1351 Based SPI OLED Screen, 128x128px.")
                device.cleanup()
                device = ssd1351(spi(device=1, port=0))
                drawing = background.copy()
                device.display(drawing.convert("RGB"))
    return screenState
コード例 #12
0
disp = None

if DSP_SET == "SSD1306":
    disp = ssd1306(serial, rotate=rot)
elif DSP_SET == "SSD1309":
    disp = ssd1309(serial, rotate=rot)
elif DSP_SET == "SSD1322":
    disp = ssd1322(serial, rotate=rot)
elif DSP_SET == "SSD1325":
    disp = ssd1325(serial, rotate=rot)
elif DSP_SET == "SSD1327":
    disp = ssd1327(serial, rotate=rot)
elif DSP_SET == "SSD1331":
    disp = ssd1331(serial, rotate=rot)
elif DSP_SET == "SSD1351":
    disp = ssd1351(serial, rotate=rot)
elif DSP_SET == "SH1106":
    disp = sh1106(serial, rotate=rot)


# disp = sh1106(serial, rotate=2)
# disp = ssd1306(serial, rotate=0)

def getLargeFont():
    return ImageFont.truetype(workDir + "/Fonts/Georgia Bold.ttf", 12)


def getFont():
    return ImageFont.truetype(workDir + "/Fonts/Georgia Bold.ttf", 10)

コード例 #13
0
    def plugin_init(self, enableplugin=None):
        plugin.PluginProto.plugin_init(self, enableplugin)
        if self.enabled:
            try:
                i2cl = self.i2c
            except:
                i2cl = -1
            try:
                i2cport = gpios.HWPorts.geti2clist()
                if i2cl == -1:
                    i2cl = int(i2cport[0])
            except:
                i2cport = []
            if len(i2cport) > 0 and i2cl > -1:
                if self.interval > 2:
                    nextr = self.interval - 2
                else:
                    nextr = self.interval

                self.initialized = False
                serialdev = None
                self.taskdevicepluginconfig[1] = int(
                    float(self.taskdevicepluginconfig[1]))
                if self.taskdevicepluginconfig[1] != 0:  # i2c address
                    serialdev = i2c(port=i2cl,
                                    address=self.taskdevicepluginconfig[1])
                else:
                    return self.initialized
                self.device = None
                try:
                    if "x" in str(self.taskdevicepluginconfig[3]):
                        resstr = str(self.taskdevicepluginconfig[3]).split('x')
                        self.width = int(resstr[0])
                        self.height = int(resstr[1])
                    else:
                        self.width = None
                        self.height = None
                except:
                    self.width = None
                    self.height = None

                if str(self.taskdevicepluginconfig[0]) != "0" and str(
                        self.taskdevicepluginconfig[0]).strip(
                        ) != "":  # display type
                    try:
                        if str(self.taskdevicepluginconfig[0]) == "ssd1306":
                            from luma.oled.device import ssd1306
                            if self.height is None:
                                self.device = ssd1306(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1306(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "sh1106":
                            from luma.oled.device import sh1106
                            if self.height is None:
                                self.device = sh1106(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = sh1106(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1309":
                            from luma.oled.device import ssd1309
                            if self.height is None:
                                self.device = ssd1309(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1309(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1331":
                            from luma.oled.device import ssd1331
                            if self.height is None:
                                self.device = ssd1331(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1331(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1351":
                            from luma.oled.device import ssd1351
                            if self.height is None:
                                self.device = ssd1351(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1351(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1322":
                            from luma.oled.device import ssd1322
                            if self.height is None:
                                self.device = ssd1322(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1322(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1325":
                            from luma.oled.device import ssd1325
                            if self.height is None:
                                self.device = ssd1325(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1325(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1327":
                            from luma.oled.device import ssd1327
                            if self.height is None:
                                self.device = ssd1327(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1327(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                    except Exception as e:
                        misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,
                                    "OLED can not be initialized! " + str(e))
                        self.enabled = False
                        self.device = None
                        return False
                if self.device is not None:
                    try:
                        lc = int(self.taskdevicepluginconfig[4])
                    except:
                        lc = self.P23_Nlines
                    if lc < 1:
                        lc = self.P23_Nlines
                    lineheight = int(
                        self.device.height /
                        lc)  #  lineheight = int(self.device.height / lc)+1
                    self.ufont = ImageFont.truetype('img/UbuntuMono-R.ttf',
                                                    lineheight)
                    try:
                        self.device.show()
                    except:
                        pass
                    with canvas(self.device) as draw:
                        maxcols = int(self.taskdevicepluginconfig[5])
                        if maxcols < 1:
                            maxcols = 1
                        tstr = "X" * maxcols
                        try:
                            sw = draw.textsize(tstr, self.ufont)[0]
                        except:
                            sw = self.device.width
                        while (sw > self.device.width):
                            lineheight -= 1
                            self.ufont = ImageFont.truetype(
                                'img/UbuntuMono-R.ttf', lineheight)
                            sw = draw.textsize(tstr, self.ufont)[0]
                        self.charwidth, self.lineheight = draw.textsize(
                            "X", self.ufont)
                        if lc in [2, 4, 6, 8]:
                            self.lineheight += 1
                    if self.interval > 2:
                        nextr = self.interval - 2
                    else:
                        nextr = 0
                    self._lastdataservetime = rpieTime.millis() - (nextr *
                                                                   1000)
                    self.dispimage = Image.new(
                        '1', (self.device.width, self.device.height), "black")
                else:
                    self.initialized = False
コード例 #14
0
ファイル: _P036_FrameOLED.py プロジェクト: greg2001/rpieasy
    def plugin_init(self, enableplugin=None):
        plugin.PluginProto.plugin_init(self, enableplugin)
        if self.enabled:
            i2cport = -1
            try:
                for i in range(0, 2):
                    if gpios.HWPorts.is_i2c_usable(
                            i) and gpios.HWPorts.is_i2c_enabled(i):
                        i2cport = i
                        break
            except:
                i2cport = -1
            if i2cport > -1:
                if self.interval > 2:
                    nextr = self.interval - 2
                else:
                    nextr = self.interval

                self.initialized = False
                serialdev = None
                self.taskdevicepluginconfig[1] = int(
                    float(self.taskdevicepluginconfig[1]))
                if self.taskdevicepluginconfig[1] != 0:  # i2c address
                    serialdev = i2c(port=i2cport,
                                    address=self.taskdevicepluginconfig[1])
                else:
                    return self.initialized
                self.device = None
                try:
                    if "x" in str(self.taskdevicepluginconfig[3]):
                        resstr = str(self.taskdevicepluginconfig[3]).split('x')
                        self.width = int(resstr[0])
                        self.height = int(resstr[1])
                    else:
                        self.width = None
                        self.height = None
                except:
                    self.width = None
                    self.height = None

                if str(self.taskdevicepluginconfig[0]) != "0" and str(
                        self.taskdevicepluginconfig[0]).strip(
                        ) != "":  # display type
                    try:
                        if str(self.taskdevicepluginconfig[0]) == "ssd1306":
                            from luma.oled.device import ssd1306
                            if self.height is None:
                                self.device = ssd1306(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1306(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "sh1106":
                            from luma.oled.device import sh1106
                            if self.height is None:
                                self.device = sh1106(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = sh1106(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1309":
                            from luma.oled.device import ssd1309
                            if self.height is None:
                                self.device = ssd1309(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1309(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1331":
                            from luma.oled.device import ssd1331
                            if self.height is None:
                                self.device = ssd1331(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1331(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1351":
                            from luma.oled.device import ssd1351
                            if self.height is None:
                                self.device = ssd1351(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1351(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1322":
                            from luma.oled.device import ssd1322
                            if self.height is None:
                                self.device = ssd1322(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1322(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1325":
                            from luma.oled.device import ssd1325
                            if self.height is None:
                                self.device = ssd1325(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1325(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                        elif str(self.taskdevicepluginconfig[0]) == "ssd1327":
                            from luma.oled.device import ssd1327
                            if self.height is None:
                                self.device = ssd1327(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])))
                            else:
                                self.device = ssd1327(
                                    serialdev,
                                    rotate=int(
                                        float(self.taskdevicepluginconfig[2])),
                                    width=self.width,
                                    height=self.height)
                            self.initialized = True
                    except Exception as e:
                        misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,
                                    "OLED can not be initialized! " + str(e))
                        self.enabled = False
                        self.device = None
                        return False
                if self.device is not None:
                    try:
                        lc = int(self.taskdevicepluginconfig[4])
                    except:
                        lc = 1
                    if lc < 1:
                        lc = 1
                    elif lc > 4:
                        lc = 4
                    try:
                        defh = 10
                        if self.height != 64:  # correct y coords
                            defh = int(defh * (self.height / 64))

                        self.hfont = ImageFont.truetype(
                            'img/UbuntuMono-R.ttf', defh)
                        lineheight = 11
                        if lc == 1:
                            lineheight = 24
                            self.ypos = [20, 0, 0, 0]
                        elif lc == 2:
                            lineheight = 16
                            self.ypos = [15, 34, 0, 0]
                        elif lc == 3:
                            lineheight = 12
                            self.ypos = [13, 25, 37, 0]
                        elif lc == 4:
                            lineheight = 10
                            self.ypos = [12, 22, 32, 42]

                        if self.height != 64:  # correct y coords
                            for p in range(len(self.ypos)):
                                self.ypos[p] = int(self.ypos[p] *
                                                   (self.height / 64))
                            lineheight = int(lineheight * (self.height / 64))

                        self.ufont = ImageFont.truetype(
                            'img/UbuntuMono-R.ttf', lineheight)  # use size
                    except Exception as e:
                        print(e)
                    try:
                        self.device.show()
                    except:
                        pass
                    if self.interval > 2:
                        nextr = self.interval - 2
                    else:
                        nextr = 0
                    self._lastdataservetime = rpieTime.millis() - (nextr *
                                                                   1000)
                    try:
                        self.dispimage = Image.new(
                            '1', (self.device.width, self.device.height),
                            "black")
                        self.conty1 = 12
                        if self.height != 64:  # correct y coords
                            self.conty1 = int(self.conty1 * (self.height / 64))
                        self.conty2 = self.device.height - self.conty1
                        self.textbuffer = []
                        self.actualpage = 0
                        self.lastlineindex = self.P36_Nlines
                        for l in reversed(range(self.P36_Nlines)):
                            if (str(self.lines[l]).strip() != "") and (str(
                                    self.lines[l]).strip() != "0"):
                                self.lastlineindex = l
                                break
                        try:
                            self.pages = math.ceil(
                                (self.lastlineindex + 1) /
                                int(self.taskdevicepluginconfig[4]))
                        except:
                            self.pages = 0
                    except Exception as e:
                        self.initialized = False
                    try:
                        cont = int(self.taskdevicepluginconfig[6])
                    except:
                        cont = 0
                    if cont > 0:
                        self.device.contrast(cont)

                    draw = ImageDraw.Draw(self.dispimage)
                    maxcols = int(self.taskdevicepluginconfig[7]
                                  )  # auto decrease font size if needed
                    if maxcols < 1:
                        maxcols = 1
                    tstr = "X" * maxcols
                    try:
                        sw = draw.textsize(tstr, self.ufont)[0]
                    except:
                        sw = self.device.width
                    while (sw > self.device.width):
                        lineheight -= 1
                        self.ufont = ImageFont.truetype(
                            'img/UbuntuMono-R.ttf', lineheight)
                        sw = draw.textsize(tstr, self.ufont)[0]
                    self.writeinprogress = 0
                else:
                    self.initialized = False
        else:
            self.__del__()
コード例 #15
0
import sys
import time
from datetime import datetime

if os.name != 'posix':
    sys.exit('{} platform not supported'.format(os.name))

from luma.core.interface.serial import i2c, spi
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1331, ssd1351

#serial = i2c(port=1, address=0x3C)
#device = ssd1306(serial, rotate=0)

serial = spi(device=0, port=0)
device = ssd1351(serial)

from PIL import ImageFont

try:
    import psutil
except ImportError:
    print(
        "The psutil library was not found. Run 'sudo -H pip install psutil' to install it."
    )
    sys.exit()

# TODO: custom font bitmaps for up/down arrows
# TODO: Load histogram

コード例 #16
0
ファイル: RRFDisplay.py プロジェクト: armel/RRFDisplay
def main(argv):

    # Check and get arguments
    try:
        options, remainder = getopt.getopt(argv, '', ['help', 'interface=', 'i2c-port=', 'i2c-address=', 'display=', 'display-width=', 'display-height=', 'display-theme=', 'follow=', 'refresh=', 'latitude=', 'longitude='])
    except getopt.GetoptError:
        l.usage()
        sys.exit(2)
    for opt, arg in options:
        if opt == '--help':
            l.usage()
            sys.exit()
        elif opt in ('--interface'):
            if arg not in ['i2c', 'spi']:
                print('Unknown interface type (choose between \'i2c\' and \'spi\')')
                sys.exit()
            s.interface = arg
        elif opt in ('--i2c-port'):
            s.i2c_port = int(arg)
        elif opt in ('--i2c-address'):
            s.i2c_address = int(arg, 16)
        elif opt in ('--display'):
            if arg not in ['sh1106', 'ssd1306', 'ssd1327', 'ssd1351', 'st7735']:
                print('Unknown display type (choose between \'sh1106\', \'ssd1306\',  \'ssd1327\', \'ssd1351\' and \'st7735\')')
                sys.exit()
            s.display = arg
        elif opt in ('--display-width'):
            s.display_width = int(arg)
        elif opt in ('--display-height'):
            s.display_height = int(arg)
        elif opt in ('--follow'):
            if arg in ['RRF', 'TECHNIQUE', 'INTERNATIONAL', 'LOCAL', 'BAVARDAGE', 'FON']:
                s.room_current = arg
            else:
                tmp = l.scan(arg)
                if tmp is False:
                    s.room_current = 'RRF'
                else:
                    s.room_current = tmp
                    s.callsign = arg
                    s.scan = True
        elif opt in ('--refresh'):
            s.refresh = float(arg)
        elif opt in ('--latitude'):
            s.latitude = float(arg)
        elif opt in ('--longitude'):
            s.longitude = float(arg)
        elif opt in ('--display-theme'):
            s.display_theme = arg

    # Set serial
    if s.interface == 'i2c':
        serial = i2c(port=s.i2c_port, address=s.i2c_address)
        if s.display == 'sh1106':
            s.device = sh1106(serial, width=s.display_width, height=s.display_height, rotate=0)
        elif s.display == 'ssd1306':
            s.device = ssd1306(serial, width=s.display_width, height=s.display_height, rotate=0)
        elif s.display == 'ssd1327':
            s.device = ssd1327(serial, width=s.display_width, height=s.display_height, rotate=0, mode='RGB')
    else:
        serial = spi(device=0, port=0)
        if s.display == 'ssd1351':        
            s.device = ssd1351(serial, width=s.display_width, height=s.display_height, rotate=1, mode='RGB', bgr=True)
        elif s.display == 'st7735':
            s.device = st7735(serial, width=s.display_width, height=s.display_height, rotate=3, mode='RGB')

    init_message = []

    # Let's go
    init_message.append('RRFDisplay ' + s.version)
    init_message.append('')
    init_message.append('88 et 73 de F4HWN')
    init_message.append('')
    d.display_init(init_message)

    # Lecture du fichier de theme
    init_message.append('Chargement Theme')
    d.display_init(init_message)
    s.theme = cp.ConfigParser()
    s.theme.read('./themes/' + s.display_theme)

    # Lecture initiale de la progation et du cluster
    init_message.append('Requete Propagation')
    d.display_init(init_message)
    l.get_solar()

    init_message.append('Requete Cluster')
    d.display_init(init_message)
    l.get_cluster()

    init_message.append('Let\'s go')
    d.display_init(init_message)

    # Boucle principale
    s.timestamp_start = time.time()

    rrf_data = ''
    rrf_data_old = ''

    #print s.scan
    #print s.callsign
    #print s.room_current

    while(True):
        chrono_start = time.time()

        tmp = datetime.datetime.now()
        s.day = tmp.strftime('%Y-%m-%d')
        s.now = tmp.strftime('%H:%M:%S')
        s.hour = int(tmp.strftime('%H'))
        s.minute = int(s.now[3:-3])
        s.seconde = int(s.now[-2:])

        if s.seconde % 15 == 0 and s.scan == True: # On scan
            tmp = l.scan(s.callsign)
            if tmp is not False:
                #print s.now, tmp
                s.room_current = tmp

        if s.minute == 0: # Update solar propagation
            l.get_solar()

        if s.minute % 4 == 0: # Update cluster
            l.get_cluster()

        url = s.room[s.room_current]['url']

        # Requete HTTP vers le flux json du salon produit par le RRFDisplay 
        try:
            r = requests.get(url, verify=False, timeout=0.5)
        except requests.exceptions.ConnectionError as errc:
            #print ('Error Connecting:', errc)
            pass
        except requests.exceptions.Timeout as errt:
            #print ('Timeout Error:', errt)
            pass

        # Controle de la validité du flux json
        try:
            rrf_data = r.json()
        except:
            pass

        if rrf_data != '' and rrf_data != rrf_data_old: # Si le flux est valide
            rrf_data_old = rrf_data
            data_abstract = rrf_data['abstract'][0]
            data_activity = rrf_data['activity']
            data_transmit = rrf_data['transmit'][0]
            data_last = rrf_data['last']
            data_all = rrf_data['all']

            s.message[1] = l.sanitize_call(data_last[0]['Indicatif'])
            s.message[2] = l.sanitize_call(data_last[1]['Indicatif'])
            s.message[3] = l.sanitize_call(data_last[2]['Indicatif'])

            if s.device.height == 128:      # Only if place...
                try:
                    data_elsewhere = rrf_data['elsewhere'][0]

                    i = 0
                    s.transmit_elsewhere = False
                    for data in rrf_data['elsewhere'][6]:
                        if data in ['RRF', 'TECHNIQUE', 'INTERNATIONAL', 'LOCAL', 'BAVARDAGE', 'FON']:
                            tmp = rrf_data['elsewhere'][6][data]
                            if tmp != 0:
                                s.transmit_elsewhere = True
                                s.raptor[i] = l.convert_second_to_time(tmp) + '/' + data[:3] + '/' + l.sanitize_call(rrf_data['elsewhere'][1][data]) + '/' + str(rrf_data['elsewhere'][5][data])
                            else:
                                s.raptor[i] = l.convert_second_to_time(tmp) + '/' + data[:3] + '/' + l.convert_time_to_string(rrf_data['elsewhere'][3][data]) + '/' + str(rrf_data['elsewhere'][5][data])

                            i += 1
                except:
                    pass

            if data_transmit['Indicatif'] != '':
                if s.transmit is False:      # Wake up screen...
                    s.transmit = l.wake_up_screen(s.device, s.display, s.transmit)

                s.call_current = l.sanitize_call(data_transmit['Indicatif'])
                s.call_type = data_transmit['Type']
                s.call_description = data_transmit['Description']
                s.call_tone = data_transmit['Tone']
                s.call_locator = data_transmit['Locator']
                s.call_sysop = data_transmit['Sysop']
                s.call_prenom = data_transmit['Prenom']
                s.call_latitude = data_transmit['Latitude']
                s.call_longitude = data_transmit['Longitude']

                s.duration = data_transmit['TOT']

            else:
                if s.transmit is True:       # Sleep screen...
                    s.transmit = l.wake_up_screen(s.device, s.display, s.transmit)

                # Load Histogram
                for q in range(0, 24):
                    s.qso_hour[q] = data_activity[q]['TX']

                # Load Last
                limit = len(rrf_data['last'])
                s.call = [''] * 10 
                s.call_time = [''] * 10 

                for q in range(0, limit):
                    s.call[q] = l.sanitize_call(rrf_data['last'][q]['Indicatif'])
                    s.call_time[q] = rrf_data['last'][q]['Heure']

                # Load Best
                limit = len(rrf_data['all'])
                s.best = [''] * 10 
                s.best_time = [0] * 10 

                for q in range(0, limit):
                    s.best[q] = l.sanitize_call(rrf_data['all'][q]['Indicatif'])
                    s.best_time[q] = l.convert_time_to_second(rrf_data['all'][q]['Durée'])

            if(s.seconde < 10):     # TX today
                s.message[0] = 'TX total ' + str(data_abstract['TX total'])

            elif(s.seconde < 20):   # Active node
                s.message[0] = 'Links actifs ' + str(data_abstract['Links actifs'])

            elif(s.seconde < 30):   # Online node
                s.message[0] = 'Links total ' + str(data_abstract['Links connectés'])
                
            elif(s.seconde < 40):   # Total emission
                tmp = l.convert_time_to_string(data_abstract['Emission cumulée'])
                if 'h' in tmp:
                    tmp = tmp[0:6]
                s.message[0] = 'BF total ' + tmp

            elif(s.seconde < 50):   # Last TX
                s.message[0] = 'Dernier ' + data_last[0]['Heure']

            elif(s.seconde < 60):   # Scan
                if s.scan is True:
                    s.message[0] = 'Suivi de ' + s.callsign
                else:
                    s.message[0] = 'Salon ' + s.room_current[:3]

        # Print screen
        if s.device.height == 128:
            d.display_128()
        else:
            d.display_64()

        chrono_stop = time.time()
        chrono_time = chrono_stop - chrono_start
        if chrono_time < s.refresh:
            sleep = s.refresh - chrono_time
        else:
            sleep = 0
        #print "Temps d'execution : %.2f %.2f secondes" % (chrono_time, sleep)
        #sys.stdout.flush()

        time.sleep(sleep)
コード例 #17
0
def connect_oled_i2c_spi(app, cfg):
    """connect to oled I2c SPI"""
    try:
        # OLED DISPLAY 2 SETUP
        app.devices = cfg.get('OLED DISPLAY 2 SETUP', 'oled_devices').strip('"')
        app.i2c_or_spi = cfg.get('OLED DISPLAY 2 SETUP', 'oled_i2c_or_spi').strip('"')
        app.spi_gpio_dc_pin = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_spi_gpio_dc_pin').strip('"'))
        app.spi_gpio_rst_pin = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_spi_gpio_rst_pin'))
        app.port_address = cfg.get('OLED DISPLAY 2 SETUP', 'oled_port_address').strip('"')
        app.spi_device_number = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_spi_device_number'))
        app.port = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_port').strip('"'))
        app.color_mode = cfg.get('OLED DISPLAY 2 SETUP', 'oled_color_mode').strip('"')
        app.screen_width = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_width').strip('"'))
        app.screen_height = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_height').strip('"'))
        app.rotate_screen = int(cfg.get('OLED DISPLAY 2 SETUP', 'oled_rotate').strip('"'))
        # Logo / States Images
        app.showlogo = cfg.get('OLED DISPLAY 2 TEXT', 'oled_showlogo').strip('"')
        app.logos = cfg.get('OLED DISPLAY 2 TEXT', 'oled_logos').strip('"')
        app.logo_path = cfg.get('OLED DISPLAY 2 TEXT', 'oled_logo_path').strip('"')
        app.states_pictures = cfg.get('OLED DISPLAY 2 TEXT', 'oled_states_pictures').strip('"')
        app.state_picture_path = cfg.get('OLED DISPLAY 2 TEXT', 'oled_state_picture_path').strip('"')
        # Text 1, Counter, Date-Time
        app.font_1 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_font_1').strip('"')
        app.counter_1 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_counter_type1').strip('"')
        app.text1_color = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text1_color').strip('"')
        app.text_1 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text_1').strip('"')
        app.size_1 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_size_1').strip('"'))
        app.right_1 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text1_right').strip('"'))
        app.down_1 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text1_down').strip('"'))
        # Text 2, Counter, Date-Time
        app.font_2 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_font_2').strip('"')
        app.counter_2 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_counter_type2').strip('"')
        app.text2_color = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text2_color').strip('"')
        app.text_2 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text_2').strip('"')
        app.size_2 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_size_2').strip('"'))
        app.right_2 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text2_right').strip('"'))
        app.down_2 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text2_down').strip('"'))
        # Text 3, Counter, Date-Time
        app.font_3 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_font_3').strip('"')
        app.counter_3 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_counter_type3').strip('"')
        app.text3_color = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text3_color').strip('"')
        app.text_3 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text_3').strip('"')
        app.size_3 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_size_3').strip('"'))
        app.right_3 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text3_right').strip('"'))
        app.down_3 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text3_down').strip('"'))
        # Text 4, Counter, Date-Time
        app.font_4 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_font_4').strip('"')
        app.counter_4 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_counter_type4').strip('"')
        app.text4_color = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text4_color').strip('"')
        app.text_4 = cfg.get('OLED DISPLAY 2 TEXT', 'oled_text_4').strip('"')
        app.size_4 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_size_4').strip('"'))
        app.right_4 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text4_right').strip('"'))
        app.down_4 = int(cfg.get('OLED DISPLAY 2 TEXT', 'oled_text4_down').strip('"'))
    except OSError:
        pass

    try:
        # Choose I2c or SPI connection
        i = app.i2c_or_spi.split()
        if "SPI" in i:
            app.serial = spi(device=app.spi_device_number, port=app.port, gpio_DC=app.spi_gpio_dc_pin, gpio_RST=app.spi_gpio_rst_pin)
        elif "I2c" in i:
            app.serial = i2c(port=app.port, address=app.port_address)
    except OSError:
        pass
        
    try:  # Connect to screen
        d = app.devices.split()
        if "sh1106" in d:
            app.device = sh1106(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1306" in d:
            app.device = ssd1306(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1309" in d:
            app.device = ssd1309(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1322" in d:
            app.device = ssd1322(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1325" in d:
            app.device = ssd1325(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1327" in d:
            app.device = ssd1327(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1331" in d:
            app.device = ssd1331(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1351" in d:
            app.device = ssd1351(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
        elif "ssd1362" in d:
            app.device = ssd1362(app.serial, rotate=app.rotate_screen, width=app.screen_width, height=app.screen_height)
    except OSError:
        pass      
コード例 #18
0
ファイル: start.py プロジェクト: kecoje/raspnode
  def init(self, args):
    global disp, image, image_hor, image_ver, draw
    driver = args['driver']
    interface = args['interface']
    self.mode = '1'
    self.bits = 1
    
    if interface == 'I2C':
      if driver == 'SSD1306_128_64':
        disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_bus=args['i2c_bus'], i2c_address=args['i2c_address'])
      elif driver == 'SSD1306_128_32':
        disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=args['i2c_bus'], i2c_address=args['i2c_address'])
      elif driver == 'ssd1309_128_64':
        self.backend = 'luma.oled'
        disp = ssd1309(i2c(port=args['i2c_bus'], address=args['i2c_address']))
      #elif driver == 'ssd1322_256_64':
      #  self.backend = 'luma.oled'
      #  disp = ssd1322(i2c(port=args['i2c_bus'], address=args['i2c_address']))
      #elif driver == 'ssd1325_128_64':
      #  self.backend = 'luma.oled'
      #  disp = ssd1325(i2c(port=args['i2c_bus'], address=args['i2c_address']))
      elif driver == 'SSD1327_128_128':
        self.backend = 'luma.oled'
        self.mode = 'RGB'
        self.bits = 8
        disp = ssd1327(i2c(port=args['i2c_bus'], address=args['i2c_address']))
      #elif driver == 'SSD1331_96_64': #
      #  self.backend = 'luma.oled'
      #  self.bits = 16
      #  disp = ssd1331(i2c(port=args['i2c_bus'], address=args['i2c_address']))
      #elif driver == 'SSD1351_128_96': #
      #  self.backend = 'luma.oled'
      #  self.bits = 16
      #  disp = ssd1351(i2c(port=args['i2c_bus'], address=args['i2c_address']))
      elif driver == 'SSH1106_128_64':
        self.backend = 'luma.oled'
        disp = ssh1106(i2c(port=args['i2c_bus'], address=args['i2c_address']))
    elif interface == 'SPI':
      if driver == 'SSD1306_128_64':
        disp = Adafruit_SSD1306.SSD1306_128_64(rst=args['spi_rst_pin'], dc=args['spi_dc_pin'], spi=SPI.SpiDev(args['spi_port'], args['spi_device']), max_speed_hz=args['spi_hz'])
      elif driver == 'SSD1306_128_32':
        disp = Adafruit_SSD1306.SSD1306_128_32(rst=args['spi_rst_pin'], dc=args['spi_dc_pin'], spi=SPI.SpiDev(args['spi_port'], args['spi_device']), max_speed_hz=args['spi_hz'])
      elif driver == 'ssd1309_128_64':
        self.backend = 'luma.oled'
        disp = ssd1309(spi(device=args['spi_device'], port=args['spi_port']))
      elif driver == 'ssd1322_256_64':
        self.backend = 'luma.oled'
        disp = ssd1322(spi(device=args['spi_device'], port=args['spi_port']))
      elif driver == 'ssd1325_128_64':
        self.backend = 'luma.oled'
        disp = ssd1325(spi(device=args['spi_device'], port=args['spi_port']))
      elif driver == 'SSD1327_128_128':
        self.backend = 'luma.oled'
        self.mode = 'RGB'
        self.bits = 8
        disp = ssd1327(spi(device=args['spi_device'], port=args['spi_port']))
      elif driver == 'SSD1331_96_64': #
        self.backend = 'luma.oled'
        self.bits = 16
        disp = ssd1331(spi(device=args['spi_device'], port=args['spi_port']))
      elif driver == 'SSD1351_128_96': #
        self.backend = 'luma.oled'
        self.bits = 16
        disp = ssd1351(spi(device=args['spi_device'], port=args['spi_port']))
      elif driver == 'SSH1106_128_64':
        self.backend = 'luma.oled'
        disp = ssh1106(spi(device=args['spi_device'], port=args['spi_port']))
    
    self.maxValue = 1
    if 'RGB' == self.mode:
      self.maxValue = 255
    
    if 'adafruit' == self.backend:
      disp.begin()
    
    self.rotate({})
    width = self.getOutputWidth()
    height = self.getOutputHeight()
    #image_hor = Image.new('1', (width, height))
    #image_ver = Image.new('1', (width, width))
    image = Image.new(self.mode, (width, width))
    
    images['default'] = image;

    # Get drawing object to draw on image.
    draw = ImageDraw.Draw(image)
    
    #start()
    
    """f = open("out.txt", "a")
コード例 #19
0
    print("Luma is not installed. Install it with 'sudo apt-get install libfreetype6-dev libjpeg-dev build-essential' and 'sudo -H pip3 install --upgrade luma.oled'")
    if not WINDOWS_DEBUG_ON:
        importErrors = True
try:
    from PIL import Image, ImageFont, ImageDraw
except:
    print("Pillow is not installed. Install it with 'pip3 install Pillow'")
    importErrors = True
if importErrors:
    print("Required Libraries not installed. Please install them and try again.")
    junk = getch()
    exit()

#Setup OLED screen
if not WINDOWS_DEBUG_ON:
    device = ssd1351(spi(device=1, port=0))


screenState = True
menuActive = False
buttonsActive = True

#load image stuffs, like backgrounds, diskmasks, fonts, etc.
songBackground = Image.open("background.jpg").convert("RGBA")
menuBackground = Image.open("menu.jpg").convert("RGBA")
infoBackground = Image.open("info.jpg").convert("RGBA")
diskMask = Image.open("diskMask.png").convert("RGBA")
blankDisk = Image.new("RGBA", (67,67), (0,0,0,0))
blankDisplay =  Image.new("RGB", (128,128), (0,0,0))
blankText = Image.new("RGBA", (122,34), (255,255,255,255))
songFont = ImageFont.truetype("roboto/Roboto-Condensed.ttf", 15)
コード例 #20
0
ファイル: clock.py プロジェクト: myonyuntkhine/allaboutRpi
                min_angle = 270 + (6 * now.minute)
                mins = posn(min_angle, cy - margin - 2)

                sec_angle = 270 + (6 * now.second)
                secs = posn(sec_angle, cy - margin - 2)

                draw.ellipse((left + margin, margin, right - margin,
                              min(device.height, 64) - margin),
                             outline="white")
                draw.line((cx, cy, cx + hrs[0], cy + hrs[1]), fill="white")
                draw.line((cx, cy, cx + mins[0], cy + mins[1]), fill="white")
                draw.line((cx, cy, cx + secs[0], cy + secs[1]), fill="red")
                draw.ellipse((cx - 2, cy - 2, cx + 2, cy + 2),
                             fill="white",
                             outline="white")
                draw.text((2 * (cx + margin), cy - 8),
                          today_date,
                          fill="yellow")
                draw.text((2 * (cx + margin), cy), today_time, fill="yellow")

        time.sleep(0.1)


if __name__ == "__main__":
    try:
        device = ssd1351(serial, rotate=0)
        main()
    except KeyboardInterrupt:
        pass
コード例 #21
0
def test_offsets():
    """
    SSD1351 OLED with offsets works correctly.
    """
    recordings = []

    def data(data):
        recordings.append({'data': data})

    def command(*cmd):
        recordings.append({'command': list(cmd)})

    serial.command.side_effect = command
    serial.data.side_effect = data

    ssd1351(serial, width=96, height=96, h_offset=2, v_offset=1)

    assert serial.data.called
    assert serial.command.called

    assert recordings == [{
        'command': [253]
    }, {
        'data': [18]
    }, {
        'command': [253]
    }, {
        'data': [177]
    }, {
        'command': [174]
    }, {
        'command': [179]
    }, {
        'data': [241]
    }, {
        'command': [202]
    }, {
        'data': [127]
    }, {
        'command': [21]
    }, {
        'data': [0, 95]
    }, {
        'command': [117]
    }, {
        'data': [0, 95]
    }, {
        'command': [160]
    }, {
        'data': [112]
    }, {
        'command': [161]
    }, {
        'data': [0]
    }, {
        'command': [162]
    }, {
        'data': [0]
    }, {
        'command': [181]
    }, {
        'data': [0]
    }, {
        'command': [171]
    }, {
        'data': [1]
    }, {
        'command': [177]
    }, {
        'data': [50]
    }, {
        'command': [180]
    }, {
        'data': [160, 181, 85]
    }, {
        'command': [190]
    }, {
        'data': [5]
    }, {
        'command': [199]
    }, {
        'data': [15]
    }, {
        'command': [182]
    }, {
        'data': [1]
    }, {
        'command': [166]
    }, {
        'command': [193]
    }, {
        'data': [255, 255, 255]
    }, {
        'command': [21]
    }, {
        'data': [2, 97]
    }, {
        'command': [117]
    }, {
        'data': [1, 96]
    }, {
        'command': [92]
    }, {
        'data': [0] * (96 * 96 * 2)
    }, {
        'command': [175]
    }]
コード例 #22
0
import sys
import os.path
import PIL
from luma.core.interface.serial import spi
from luma.oled.device import ssd1351
from luma.core.render import canvas
serial = spi(device=0, port=0)
import av
def main():
    video_path = os.path.abspath(os.path.join(os.path.dirname(__file__),'images', 'movie.mp4'))
    print('Loading {}...'.format(video_path))
    clip = av.open(video_path)
    for frame in clip.decode(video=0):
        print('{} ------'.format(frame.index))
        img = frame.to_image()
        if img.width != device.width or img.height != device.height:
            size = device.width, device.height
            img = img.resize(size, PIL.Image.ANTIALIAS)
        device.display(img.convert(device.mode))

if __name__ == "__main__":
    try:
	device = ssd1351(serial, width=128, height=128)
        main()
    except KeyboardInterrupt:
        pass
コード例 #23
0
import sys
#Apps Resources
#TrackBall
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
Trackball = [5, 6, 13, 19]
SW = 26
GPIO.setup(Trackball, GPIO.IN)
GPIO.setup(SW, GPIO.IN)
Trackballindex = 1
TOPINDEX = 0
Array = []

framesize = (128, 128)
Serial = spi(device=0, port=0)
device = ssd1351(Serial, 128, 128, 3, 'diff_to_previous', 0, 0, True)
#ObjectImage = ["Sources", (SizeX,SizeY),(LocationX,LocationY), (SelLoc1X, SelLoc1Y, SelLoc2X, SelLoc2Y), ContextSensitive menu array] If Possible to be selected
#Splash Screen Resources
FramesLogo = ["framesResources/FramesLogo01.png", (70, 27), (30, 90)]
Logo = ["framesResources/CELogo01.jpg", (128, 128), (0, 0), (0, 0, 0, 0)]
#Fillers
Filler = ("framesResources/CELogo01.jpg", (1, 1), (0, 0), (0, 0, 0, 0))
OptionFiller = ()
#Dev Bar Resources
Power = ("framesResources/PowerIcon01.jpg", (10, 10), (114, 6), (113, 5, 124,
                                                                 16))
Wifi = ("framesResources/WifiIcon01.jpg", (12, 12), (97, 5), (96, 4, 109, 17))
Battery = ["framesResources/BatteryIcon01.jpg", (20, 20), (2, 2)]
Bluetooth = ("framesResources/BluetoothIcon01.jpg", (14, 14), (80, 4),
             (79, 3, 94, 18))
#App Screen Resources
コード例 #24
0
ファイル: OledScroll.py プロジェクト: armel/OledScroll
def main(argv):

    # Check and get arguments
    try:
        options, remainder = getopt.getopt(argv, '', [
            'help', 'interface=', 'i2c-port=', 'i2c-address=', 'display=',
            'display-width=', 'display-height='
        ])
    except getopt.GetoptError:
        l.usage()
        sys.exit(2)
    for opt, arg in options:
        if opt == '--help':
            l.usage()
            sys.exit()
        elif opt in ('--interface'):
            if arg not in ['i2c', 'spi']:
                print 'Unknown interface type (choose between \'i2c\' and \'spi\')'
                sys.exit()
            s.interface = arg
        elif opt in ('--i2c-port'):
            s.i2c_port = int(arg)
        elif opt in ('--i2c-address'):
            s.i2c_address = int(arg, 16)
        elif opt in ('--display'):
            if arg not in [
                    'sh1106', 'ssd1306', 'ssd1327', 'ssd1351', 'st7735'
            ]:
                print 'Unknown display type (choose between \'sh1106\', \'ssd1306\',  \'ssd1327\', \'ssd1351\' and \'st7735\')'
                sys.exit()
            s.display = arg
        elif opt in ('--display-width'):
            s.display_width = int(arg)
        elif opt in ('--display-height'):
            s.display_height = int(arg)

    # Set serial
    if s.interface == 'i2c':
        serial = i2c(port=s.i2c_port, address=s.i2c_address)
        if s.display == 'sh1106':
            s.device = sh1106(serial,
                              width=s.display_width,
                              height=s.display_height,
                              rotate=0)
        elif s.display == 'ssd1306':
            s.device = ssd1306(serial,
                               width=s.display_width,
                               height=s.display_height,
                               rotate=0)
        elif s.display == 'ssd1327':
            s.device = ssd1327(serial,
                               width=s.display_width,
                               height=s.display_height,
                               rotate=0,
                               mode='RGB')
    else:
        serial = spi(device=0, port=0)
        if s.display == 'ssd1351':
            s.device = ssd1351(serial,
                               width=s.display_width,
                               height=s.display_height,
                               rotate=1,
                               mode='RGB',
                               bgr=True)
        elif s.display == 'st7735':
            s.device = st7735(serial,
                              width=s.display_width,
                              height=s.display_height,
                              rotate=3,
                              mode='RGB')

    while True:
        print 'Start'
        l.scroll_message("Il etait une fois tout petit chaton.")
        print 'Stop'