def get_device(): # rev.1 users set port=0 # substitute spi(device=0, port=0) below if using that interface serial = spi(device=0, port=0) # substitute ssd1331(...) or sh1106(...) below if using that device device = ssd1309(serial) return device
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()
def initialize_variables(self): from luma.core.interface.serial import i2c from luma.core.render import canvas from luma.oled.device import ssd1309 self.canvas = canvas try: function_channels = db_retrieve_table_daemon( FunctionChannel).filter( FunctionChannel.function_id == self.unique_id).all() self.options_channels = self.setup_custom_channel_options_json( FUNCTION_INFORMATION['custom_channel_options'], function_channels) for each_set in range(self.number_line_sets): self.line_sets.append([]) for each_line in range(lcd_lines): self.line_sets[each_set].append(each_line) self.logger.debug("Line sets: {}".format(self.line_sets)) self.device = ssd1309( i2c(port=self.i2c_bus, address=int(str(self.i2c_address), 16))) self.logger.debug("LCD Function started") except: self.logger.exception("Starting LCD Function")
def test_hide(): """ SSD1309 OLED screen content can be hidden. """ device = ssd1309(serial) serial.reset_mock() device.hide() serial.command.assert_called_once_with(174)
def test_show(): """ SSD1309 OLED screen content can be displayed. """ device = ssd1309(serial) serial.reset_mock() device.show() serial.command.assert_called_once_with(175)
def __init__(self): # OLED Reset pin GPIO.setup(RESET, GPIO.OUT) self._reset() serial = i2c(port=1, address=0x3C) self.device = ssd1309(serial)
def get_device(args): if 'emulator' in args and args.emulator: import luma.emulator.device Device = getattr(luma.emulator.device, args.emulator) return Device(**vars(args)) else: from luma.oled.device import ssd1309 from luma.core.interface.serial import ftdi_spi return ssd1309(ftdi_spi(), **vars(args))
def get_device(): # rev.1 users set port=0 # substitute spi(device=0, port=0) below if using that interface serial = spi( device=0, port=0, cs_high=True ) #cs_high = True is a workaround to this isseu https://github.com/raspberrypi/linux/issues/3355 #s erial = spi(device=0, port=0) # substitute ssd1331(...) or sh1106(...) below if using that device device = ssd1309(serial) return device
def test_init_128x64(): """ SSD1309 OLED with a 128 x 64 resolution works correctly. """ ssd1309(serial) serial.command.assert_has_calls([ # Initial burst are initialization commands call(174, 213, 128, 168, 63, 211, 0, 64, 141, 20, 32, 0, 161, 200, 218, 18, 217, 241, 219, 64, 164, 166), # set contrast call(129, 207), # reset the display call(33, 0, 127, 34, 0, 7), # called last, is a command to show the screen call(175) ]) # Next are all data: zero's to clear the RAM serial.data.assert_called_once_with([0] * (128 * 64 // 8))
def test_display(): """ SSD1309 OLED screen can draw and display an image. """ device = ssd1309(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(33, 0, 127, 34, 0, 7) # Next 1024 bytes are data representing the drawn image serial.data.assert_called_once_with(get_json_data('demo_ssd1309'))
def test_display(): """ SSD1309 OLED screen can draw and display an image. """ device = ssd1309(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(33, 0, 127, 34, 0, 7) # To regenerate test data, uncomment the following (remember not to commit though) # ================================================================================ # from baseline_data import save_reference_data # save_reference_data("demo_ssd1309", serial.data.call_args.args[0]) # Next 1024 bytes are data representing the drawn image serial.data.assert_called_once_with(get_reference_data('demo_ssd1309'))
def main(): # rev.1 users set port=0 # substitute spi(device=0, port=0) below if using that interface serial = spi(device=0, port=0) # substitute ssd1331(...) or sh1106(...) below if using that device device = ssd1309(serial) font = make_font("fontawesome-webfont.ttf", device.height - 10) with canvas(device) as draw: w, h = draw.textsize("\uf027", font=font) left = (device.width - 50) / 2 top = (device.height - 50) / 2 draw.text((left, top), "\uf027", font=font, fill="white") print(f"left: {left}, top: {top}") with canvas(device) as draw: w, h = draw.textsize("\uf027", font=font) left = (device.width - w) / 2 top = (device.height - h) / 2 draw.text((left, top), "\uf028", font=font, fill="white") print(f"left: {left}, top: {top}")
def init(): global Oled_Device, Effects_Data GPIO.setwarnings(True) GPIO.setmode(GPIO.BOARD) # Use Board mode # define the Encoder switch inputs GPIO.setup(Enc_A, GPIO.IN) GPIO.setup(Enc_B, GPIO.IN) GPIO.setup(Enc_SW, GPIO.IN) # setup callback thread for the A and B encoder # use interrupts for all inputs GPIO.add_event_detect(Enc_A, GPIO.RISING, callback=rotary_interrupt) # NO bouncetime GPIO.add_event_detect(Enc_B, GPIO.RISING, callback=rotary_interrupt) # NO bouncetime GPIO.add_event_detect(Enc_SW, GPIO.FALLING, callback=rotary_click_interrupt) # get effects URL = "http://127.0.0.1/effect/list" r = requests.get(url=URL) Effects_Data = r.json() # OLED Reset GPIO.setup(RESET, GPIO.OUT) # rest low then high GPIO.output(RESET, GPIO.LOW) sleep(0.100) GPIO.output(RESET, GPIO.HIGH) serial = i2c(port=1, address=0x3C) Oled_Device = ssd1309(serial) # Draw initial menu with canvas(Oled_Device) as draw: draw_menu(Oled_Device, draw, Effects_Data, 0) return
return "nope" print("Wifi: ", get_ip_address('wlan0')) ssid = os.popen("iwconfig wlan0 \ | grep 'ESSID' \ | awk '{print $4}' \ | awk -F\\\" '{print $2}'").read() print("ssid: " + ssid) fp = open("logger.txt", "a") fp.write("\n" + str(currentDT) + "start logging") fp.close() device = get_device() serial = spi(device=0, port=0) device = ssd1309(serial) status = "Not connected" try: url = "https://www.google.com" urllib.urlopen(url) status = "connected" except: status = "Not connected" #print("hi") with canvas(device) as draw: draw.text((10, 20), ssid, fill="white") draw.text((10, 30), get_ip_address('wlan0'), fill="white") draw.text((10, 40), status, fill="white")
from luma.core.interface.serial import i2c from luma.core.render import canvas from luma.oled.device import ssd1309 import RPi.GPIO as GPIO # Import the GPIO module as 'GPIO' from hcsr04sensor import sensor import time serial = i2c(port=1, address=0x3C) # Set I2C interface device = ssd1309(serial) # load the display reference GPIO.setmode(GPIO.BCM) # Set the GPIO mode to BCM numbering trig4 = 23 # mid right echo4 = 24 trig5 = 13 # far right echo5 = 19 trig3 = 5 # behind echo3 = 6 trig2 = 8 # mid left echo2 = 7 trig1 = 21 # far left echo1 = 20 configFill = "black" def draw_display(dist1, dist2, dist3, dist4, dist5): try: with canvas(device) as draw: # First we check for 9-12 ft range, then 6-9, then 0-6. #print("sensor 1 is: ", dist1) #print("sensor 2 is: ", dist2)
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
} # Open i2c address port 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)
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__()
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
from luma.core.interface.serial import i2c, spi from luma.core.render import canvas from luma.oled.device import ssd1306, ssd1309, ssd1325, ssd1331, sh1106 # rev.1 users set port=0 # substitute spi(device=0, port=0) below if using that interface serial = i2c(port=1, address=0x3C) # substitute ssd1331(...) or sh1106(...) below if using that device device = ssd1309(serial, rotate=2) with canvas(device) as draw: draw.rectangle((-50, 100, 00, 50), outline="white", fill="black") draw.text((-50, -40), "Hello World", fill="white")
crl = pycurl.Curl() STATE_NONE = -1 STATE_PLAYER = 0 STATE_PLAYLIST_MENU = 1 STATE_QUEUE_MENU = 2 STATE_VOLUME = 3 STATE_SHOW_INFO = 4 STATE_LIBRARY_MENU = 5 STATE_LIBRARY_INFO = 6 UPDATE_INTERVAL = 0.034 PIXEL_SHIFT_TIME = 120 #time between picture position shifts in sec. interface = spi(device=0, port=0) oled = ssd1309(interface) #without rotate display is 0 degrees, with rotate=2 its 180 degrees oled.WIDTH = 128 oled.HEIGHT = 64 oled.state = 'stop' oled.stateTimeout = 0 oled.timeOutRunning = False oled.activeSong = '' oled.activeArtist = 'VOLuMIO' oled.playState = 'unknown' oled.playPosition = 0 oled.modal = False oled.playlistoptions = [] oled.queue = [] oled.libraryFull = []
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")