示例#1
0
def test_init_128x64():
    ssd1325(serial)
    serial.command.assert_has_calls([
        call(174, 179, 241, 168, 63, 162, 76, 161, 0, 173, 2, 160, 80, 134,
             184, 1, 17, 34, 50, 67, 84, 101, 118),
        call(129, 255),
        call(178, 81, 177, 85, 180, 2, 176, 40, 190, 28, 191, 15, 164),
        call(21, 0, 127, 117, 0, 63),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 64 / 2)
    serial.data.assert_called_once_with([0] * (128 * 64 // 2))
示例#2
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')
示例#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 __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))
    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()
示例#6
0
def test_show():
    """
    SSD1325 OLED screen content can be displayed.
    """
    device = ssd1325(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
示例#7
0
def test_init_128x64():
    """
    SSD1325 OLED with a 128 x 64 resolution works correctly.
    """
    ssd1325(serial)
    serial.command.assert_has_calls([
        call(174, 179, 242, 168, 63, 162, 76, 161, 0, 173, 2, 160, 80, 134, 184,
             1, 17, 34, 50, 67, 84, 101, 118, 178, 81, 177, 85, 180, 3, 176, 40,
             188, 1, 190, 0, 191, 2, 164),
        call(129, 127),
        call(21, 0, 63, 117, 0, 63),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 64 / 2)
    serial.data.assert_called_once_with([0] * (128 * 64 // 2))
示例#8
0
def test_hide():
    """
    SSD1325 OLED screen content can be hidden.
    """
    device = ssd1325(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
示例#9
0
def test_init_128x64():
    """
    SSD1325 OLED with a 128 x 64 resolution works correctly.
    """
    ssd1325(serial)
    serial.command.assert_has_calls([
        call(174, 179, 242, 168, 63, 162, 76, 161, 0, 173, 2, 160, 80, 134,
             184, 1, 17, 34, 50, 67, 84, 101, 118, 178, 81, 177, 85, 180, 3,
             176, 40, 188, 1, 190, 0, 191, 2, 164),
        call(129, 127),
        call(21, 0, 63, 117, 0, 63),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 64 / 2)
    serial.data.assert_called_once_with([0] * (128 * 64 // 2))
示例#10
0
def test_hide():
    """
    SSD1325 OLED screen content can be hidden.
    """
    device = ssd1325(serial)
    serial.reset_mock()
    device.hide()
    serial.command.assert_called_once_with(174)
示例#11
0
def test_show():
    """
    SSD1325 OLED screen content can be displayed.
    """
    device = ssd1325(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
示例#12
0
def test_display():
    device = ssd1325(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, 127, 117, 0, 63)

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(baseline_data.demo_ssd1325)
示例#13
0
def test_monochrome_display():
    """
    SSD1325 OLED screen can draw and display a monochrome image.
    """
    device = ssd1325(serial, mode="1")
    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, 127, 117, 0, 63)

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(baseline_data.demo_ssd1325_monochrome)
示例#14
0
def test_greyscale_display():
    """
    SSD1325 OLED screen can draw and display a greyscale image.
    """
    device = ssd1325(serial, mode="RGB")
    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, 127, 117, 0, 63)

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1325_greyscale'))
示例#15
0
def test_monochrome_display():
    """
    SSD1325 OLED screen can draw and display a monochrome image.
    """
    device = ssd1325(serial, mode="1")
    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, 63, 117, 0, 63)

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_json_data('demo_ssd1325_monochrome'))
示例#16
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")
示例#17
0
def test_monochrome_display():
    """
    SSD1325 OLED screen can draw and display a monochrome image.
    """
    device = ssd1325(serial, mode="1", 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, 63, 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_ssd1325_monochrome", serial.data.call_args.args[0])

    # Next 4096 bytes are data representing the drawn image
    serial.data.assert_called_once_with(get_reference_data('demo_ssd1325_monochrome'))
示例#18
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      
示例#19
0
from osc4py3 import oscmethod as osm
from luma.core.interface.serial import spi
from luma.core.render import canvas
from luma.oled.device import ssd1325
from PIL import ImageFont

# font = ImageFont.truetype("pixelmix.ttf", 20)

font = []  # fonts at every size from 0 to 20
for x in range(21):
    font.append(ImageFont.truetype("/home/pi/Display/FreePixel.ttf", x))
    # print(font[x])

# initialize the oled display
serial = spi(device=0, port=0)
device = ssd1325(serial)

xmarg = 4  # left margin
xoff = 27 + 4  # x offset for four buttons/knobs
yoff = 10  # y offset between text lines (not knob)
toff = 18  # title offset

# Init values:
titleVal = "Noisebox v3"
knobVals = []
buttonVals = []
for x in range(4):
    # each knob has 3 values: numeral, knob pos, label
    knobVals.append([0.555, 0.555, "knob" + str(x)])
    # each button has 2 values: value, label
    # button value can be any string or number
示例#20
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")
示例#21
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__()
示例#22
0
def test_framebuffer_override():
    """
    Reproduce https://github.com/rm-hull/luma.examples/issues/95
    """
    ssd1325(serial, mode="1", framebuffer="diff_to_previous")
示例#23
0
serial = i2c(port=displayConfig["port"], address=displayConfig["address"])

# Get Config Setting and initialize the compatible OLED device
# Compatible devices -> SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331, SSD1351 and SH1106
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)
示例#24
0
def test_show():
    device = ssd1325(serial)
    serial.reset_mock()
    device.show()
    serial.command.assert_called_once_with(175)
示例#25
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
示例#26
0
def test_framebuffer_override():
    """
    Reproduce https://github.com/rm-hull/luma.examples/issues/95
    """
    ssd1325(serial, mode="1", framebuffer="diff_to_previous")
示例#27
0
 def get_device(self):
     return ssd1325(self.spi)
示例#28
0
def test_init_invalid_dimensions():
    with pytest.raises(luma.core.error.DeviceDisplayModeError) as ex:
        ssd1325(serial, width=128, height=77)
    assert "Unsupported display mode: 128 x 77" in str(ex.value)