Пример #1
0
    def __init__(self, config, core):
        super(oledScreen, self).__init__()
        self.menu = False
        self.core = core
        self.config = config

        if config['oledScreen']['bus'] and config['oledScreen']['address']:
            self.serial = i2c(bus=SMBus(config['oledScreen']['bus']),
                              address=config['oledScreen']['address'])
        else:
            self.serial = i2c(bus=SMBus(2), address=0x3c)
        self.driver = config['oledScreen']['driver']
        if self.driver == 'ssd1306':
            self.device = ssd1306(self.serial)
        elif self.driver == 'ssd1322':
            self.device = ssd1322(self.serial)
        elif self.driver == 'ssd1325':
            self.device = ssd1325(self.serial)
        elif self.driver == 'ssd1331':
            self.device = ssd1331(self.serial)
        elif self.driver == 'sh1106':
            self.device = sh1106(self.serial)
        else:
            self.device = ssd1306(self.serial)

        self.font = self.make_font('Vera.ttf', 26)
        self.fontSmall = self.make_font('Vera.ttf', 15)
        self.set_image('radio.gif')
Пример #2
0
	def __init__(self, rows=64, cols=128, i2c_address=0x3d, i2c_port=1, devicetype='ssd1306'):

		self.i2c_address = i2c_address
		self.i2c_port = i2c_port

		self.rows = rows
		self.cols = cols

		self.fb = [[]]

		# Initialize the default font
		font = fonts.bmfont.bmfont('latin1_5x8_fixed.fnt')
		self.fp = font.fontpkg

		serial = i2c(port=i2c_port, address=i2c_address)

		if devicetype.lower() == 'ssd1306':
			self.device = ssd1306(serial)
		elif devicetype.lower() == 'sh1106':
			self.device = sh1106(serial)
		elif devicetype.lower() == 'ssd1322':
			self.device = ssd1322(serial)
		elif devicetype.lower() == 'ssd1325':
			self.device = ssd1325(serial)
		elif devicetype.lower() == 'ssd1331':
			self.device = ssd1331(serial)
		else:
			raise ValueError('{0} not a recognized luma device type'.format(devicetype))
Пример #3
0
	def __init__(self, rows=64, cols=128, spi_device=0, spi_port=0, gpio_DC=24, gpio_RST=25,devicetype=u'ssd1306'):

		
		self.spi_port = spi_port
		self.spi_device = spi_device
		self.gpio_DC = gpio_DC
		self.gpio_RST = gpio_RST

		self.rows = rows
		self.cols = cols

		self.fb = [[]]

		# Initialize the default font
		font = fonts.bmfont.bmfont('latin1_5x8_fixed.fnt')
		self.fp = font.fontpkg

		#serial = i2c(port=spi_port, address=spi_device)
		
		serial = spi (port = spi_port, device = spi_device, gpio_DC = gpio_DC, gpio_RST = gpio_RST)

		if devicetype.lower() == u'ssd1306':
			self.device = ssd1306(serial)
		elif devicetype.lower() == u'sh1106':
			self.device = sh1106(serial)
		elif devicetype.lower() == u'ssd1322':
			self.device = ssd1322(serial)
		elif devicetype.lower() == u'ssd1325':
			self.device = ssd1325(serial)
		elif devicetype.lower() == u'ssd1331':
			self.device = ssd1331(serial)
		else:
			raise ValueError('{0} not a recognized luma device type'.format(devicetype))
Пример #4
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()
Пример #5
0
def test_show():
    """
    SSD1331 OLED screen content can be displayed.
    """
    device = ssd1331(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
Пример #6
0
def test_hide():
    """
    SSD1331 OLED screen content can be hidden.
    """
    device = ssd1331(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
Пример #7
0
def test_hide():
    """
    SSD1331 OLED screen content can be hidden.
    """
    device = ssd1331(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
Пример #8
0
def test_show():
    """
    SSD1331 OLED screen content can be displayed.
    """
    device = ssd1331(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
Пример #9
0
def test_init_96x64():
    ssd1331(serial)
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(174, 160, 114, 161, 0, 162, 0, 164, 168, 63, 173, 142, 176, 11,
             177, 116, 179, 208, 138, 128, 139, 128, 140, 128, 187, 62, 190,
             62, 135, 15),
        # set contrast
        call(129, 255, 130, 255, 131, 255),
        # reset the display
        call(21, 0, 95, 117, 0, 63),
        # called last, is a command to show the screen
        call(175)
    ])

    # Next 12288 are all data: zero's to clear the RAM
    # (12288 = 96 * 64 * 2)
    serial.data.assert_called_once_with([0] * 96 * 64 * 2)
Пример #10
0
 def _initOutput(self, spiDevice, rotation):
     # CS on pin 26 (GPIO7; spi0 ce1), DC on pin 18 (GPIO24), RST held at VCC.
     self._dev = ssd1331(spi(device=spiDevice, port=0,
                             # lots of timeouts on the 12288-byte transfer without this
                             #transfer_size=64,
                             #bus_speed_hz=16000000,
                             gpio_RST=None,
                             gpio_DC=24,
                         ),
                         rotation=rotation)
Пример #11
0
def initOLED():

    serial = interface.spi(port=0,
                           device=0,
                           bus_speed_hz=8000000,
                           gpio_DC=24,
                           gpio_RST=25)

    device = oled.ssd1331(serial, width=96, height=64, rotate=3)
    return device
Пример #12
0
def test_init_96x64():
    """
    SSD1331 OLED with a 96 x 64 resolution works correctly.
    """
    ssd1331(serial)
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(174, 160, 114, 161, 0, 162, 0, 164, 168, 63, 173,
             142, 176, 11, 177, 116, 179, 208, 138, 128, 139,
             128, 140, 128, 187, 62, 190, 62, 135, 15),
        # set contrast
        call(129, 255, 130, 255, 131, 255),
        # reset the display
        call(21, 0, 95, 117, 0, 63),
        # called last, is a command to show the screen
        call(175)
    ])

    # Next 12288 are all data: zero's to clear the RAM
    # (12288 = 96 * 64 * 2)
    serial.data.assert_called_once_with([0] * 96 * 64 * 2)
Пример #13
0
def test_display():
    device = ssd1331(serial)
    serial.reset_mock()

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

    # Initial command to reset the display
    serial.command.assert_called_once_with(21, 0, 95, 117, 0, 63)

    # Next 12288 bytes are data representing the drawn image
    serial.data.assert_called_once_with(baseline_data.demo_ssd1331)
Пример #14
0
 def _initOutput(self, spiDevice, rotation):
     # CS on pin 26 (GPIO7; spi0 ce1), DC on pin 18 (GPIO24), RST held at VCC.
     self._dev = ssd1331(
         spi(
             device=spiDevice,
             port=0,
             # lots of timeouts on the 12288-byte transfer without this
             #transfer_size=64,
             #bus_speed_hz=16000000,
             gpio_RST=None,
             gpio_DC=24,
         ),
         rotation=rotation)
Пример #15
0
 def __init__(self, rotate=0, debug_output=False):
     self.padding = 2
     self.top = self.padding
     self.bottom = 64 - self.padding - 1
     self.rotate = rotate
     self.debug_output = debug_output
     self.ser = interface.serial.spi(port=0, device=0)
     self.device = ssd1331(serial_interface=self.ser,
                           width=96,
                           height=64,
                           rotate=self.rotate)
     self.device.contrast(150)
     if debug_output == True:
         print("[OK]\t waveshare 0.96\" oled initilizaed successully")
Пример #16
0
def test_display():
    """
    SSD1331 OLED screen can draw and display an image.
    """
    device = ssd1331(serial)
    serial.reset_mock()

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

    # Initial command to reset the display
    serial.command.assert_called_once_with(21, 0, 95, 117, 0, 63)

    # Next 12288 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1331'))
Пример #17
0
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 = ssd1331(serial)
    serial.reset_mock()

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

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

    serial.data.assert_called_once_with(expected)
Пример #18
0
def test_display():
    """
    SSD1331 OLED screen can draw and display an image.
    """
    device = ssd1331(serial)
    serial.reset_mock()

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

    # Initial command to reset the display
    serial.command.assert_called_once_with(21, 0, 95, 117, 0, 63)

    # Next 12288 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1331'))
Пример #19
0
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 = ssd1331(serial)
    serial.reset_mock()

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

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

    serial.data.assert_called_once_with(expected)
Пример #20
0
    def __init__(self, config, core):
        super(serialRFID, self).__init__()
        self.menu = False
        self.core = core
        self.config = config
        self.deviceName = config['serialRFID']['device']
        self.rate = config['serialRFID']['rate']
        self.oledEnabled = config['serialRFID']['oled_enabled']
        #if screen is used
        if self.oledEnabled:
            if config['serialRFID']['oled_bus'] and config['serialRFID'][
                    'oled_address']:
                self.serial = i2c(bus=SMBus(config['serialRFID']['oled_bus']),
                                  address=config['serialRFID']['oled_address'])
            self.driver = config['serialRFID']['oled_driver']
            if self.driver == 'ssd1306':
                self.device = ssd1306(self.serial)
            elif self.driver == 'ssd1322':
                self.device = ssd1322(self.serial)
            elif self.driver == 'ssd1325':
                self.device = ssd1325(self.serial)
            elif self.driver == 'ssd1331':
                self.device = ssd1331(self.serial)
            elif self.driver == 'sh1106':
                self.device = sh1106(self.serial)
            else:
                self.device = ssd1306(self.serial)

        GPIO.setmode(GPIO.BOARD)

        #register buttons
        if config['serialRFID']['button']:
            GPIO.setup(config['serialRFID']['button'],
                       GPIO.IN,
                       pull_up_down=GPIO.PUD_UP)
            GPIO.add_event_detect(config['serialRFID']['button'],
                                  GPIO.RISING,
                                  bouncetime=600)
            GPIO.add_event_callback(config['serialRFID']['button'],
                                    self.eventDetected)

        if self.oledEnabled:
            self.set_image("radio.gif")
Пример #21
0
def test_display():
    """
    SSD1331 OLED screen can draw and display an image.
    """
    device = ssd1331(serial, framebuffer=full_frame())
    serial.reset_mock()

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

    # Initial command to reset the display
    serial.command.assert_called_once_with(21, 0, 95, 117, 0, 63)

    # To regenerate test data, uncomment the following (remember not to commit though)
    # ================================================================================
    # from baseline_data import save_reference_data
    # save_reference_data("demo_ssd1331", serial.data.call_args.args[0])

    # Next 12288 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_reference_data('demo_ssd1331'))
Пример #22
0
    def __init__(self, DSPMod12):
        self.port = DSPMod12

        self.cs = self.port.pin1
        self.mosi = self.port.pin2
        self.nc = self.port.pin3
        self.sclk = self.port.pin4

        self.dc = self.port.pin7
        self.rst = self.port.pin8
        self.vccen = self.port.pin9
        self.pmoden = self.port.pin10
        self.powerf = True

        #
        if self.cs == 7:  #CE1
            self.serial = spi(device=1,
                              port=0,
                              gpio_DC=self.dc,
                              gpio_RST=self.rst)
        elif self.cs == 8:  #CE0
            self.serial = spi(device=0,
                              port=0,
                              gpio_DC=self.dc,
                              gpio_RST=self.rst)
        else:
            #throw exception
            pass

        # Setup GPIO.
        gpio.setmode(gpio.BCM)
        gpio.setup(self.vccen, gpio.OUT)
        gpio.output(self.vccen, gpio.HIGH)
        gpio.setup(self.pmoden, gpio.OUT)
        gpio.output(self.pmoden, gpio.HIGH)

        self.device = ssd1331(self.serial)
Пример #23
0
DSP_SET = displayConfig["DisplayType"]
rot = displayConfig["Rotation"]
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)
Пример #24
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
Пример #25
0
    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__()
Пример #26
0
def test_init_invalid_dimensions():
    with pytest.raises(luma.core.error.DeviceDisplayModeError) as ex:
        ssd1331(serial, width=23, height=57)
    assert "Unsupported display mode: 23 x 57" in str(ex.value)
Пример #27
0
def test_show():
    device = ssd1331(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
Пример #28
0
import time

from luma.core.interface.serial import spi
from luma.core.render import canvas
from luma.oled.device import ssd1331
import os

serial = spi(device=0, port=1, gpio_DC=24, gpio_RST=23)
device = ssd1331(serial)


def parser():
    read_txt = []
    with open('/home/pi/SWAW_Project/data.txt', 'r') as reader:
        read_txt = reader.readlines()
    print(read_txt)
    read_txt_parsed = []
    for x in range(len(read_txt)):
        if (x == 0):
            continue
        read_txt_parsed.append(read_txt[x].split(' '))
    read_txt_parsed[0][0] = 'T:'
    read_txt_parsed[1][0] = 'H:'
    read_txt_parsed[2][0] = 'P:'
    read_txt_parsed[3][0] = 'I:'
    returned = read_txt_parsed[0][0] + ' ' + read_txt_parsed[0][1][:-1] + ' ' + u'\N{DEGREE SIGN}' + 'C\n' + read_txt_parsed[1][0] + ' ' + read_txt_parsed[1][1][:-1] \
    + ' %\n' + read_txt_parsed[2][0] + ' ' + read_txt_parsed[2][1][:-1] + ' hPa\n' +  read_txt_parsed[3][0] + ' ' + read_txt_parsed[3][1][:-1] + ' Lx'
    print(returned)
    print(read_txt_parsed)
    return returned
Пример #29
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      
Пример #30
0
  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")
Пример #31
0
import os
ni.ifaddresses('wlan0')
ip = ni.ifaddresses('wlan0')[ni.AF_INET][0]['addr']
print(ip)

ssid = os.popen("/sbin/iwconfig wlan0 \
                | grep 'ESSID' \
                | awk '{print $4}' \
                | awk -F\\\" '{print $2}'").read()
print(ssid)

GPIO.setwarnings(False)

#device.clear()
serial = luma.core.interface.serial.spi(port=0, device=0)
device = ssd1331(serial_interface=serial, width=96, height=64, persist=True)
device.persist = True

#print(device.persist)i

device.clear()

font1 = ImageFont.truetype(
    os.path.abspath(
        os.path.join(os.path.dirname(__file__), "Orbitron-Regular.ttf")), 10)
font2 = ImageFont.truetype(
    os.path.abspath(
        os.path.join(os.path.dirname(__file__), "FjallaOne-Regular.ttf")), 11)
font3 = ImageFont.truetype(
    os.path.abspath(os.path.join(os.path.dirname(__file__),
                                 "Oswald-Light.ttf")), 10)