def __init__(self, message, version, config): Thread.__init__(self) self.event = Event() self.log = logging.getLogger(self.__class__.__name__) self.reset() self.config = config self.version = version # TODO: gracefully handle exception when OLED absent self.device = sh1106(port=1, address=0x3C) self.font = ImageFont.load_default() self.mode = m_IDLE self.row_index = 0 self.col_index = 0 self.char_space = 6 self.char_size = 4 self.row_height = 12 self.screen_row_size = 5 self.viz_min = 0 self.viz_max = self.screen_row_size self.view_msg_friend = None self.message = message #Show a Msg for x amount of seconds self.dialog_msg = "" self.dialog_msg2 = "" self.dialog_msg3 = "" self.dialog_confirmed = False self.dialog_cmd = 0 self.dialog_task_done = False self.dialog_next_mode = m_MAIN_MENU self.log.info("Initialized Display Thread.")
def __init__( self ): self.sys = SystemStatus() self.metadata = Metadata(self.sys) self.font = ImageFont.truetype( BASE_FONT, STD_FONTSIZE ) self.bigger_font = ImageFont.truetype( BASE_FONT, 22 ) self.status_font = ImageFont.truetype( BASE_FONT, 18 ) self.vd_font = ImageFont.truetype( VD_FONT, VD_FONTSIZE ) self.active_screen = DEFAULT_SCREEN # display this if nothing else self.screensaver_position = (0,0) #time.sleep(10) #Make sure the dependent systems are running at startup try: GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(RST_PIN,GPIO.OUT) GPIO.output(RST_PIN,True) GPIO.output(RST_PIN,False) GPIO.output(RST_PIN,True) self.device = sh1106(port=1, address=0x3C) except Exception, e: print "Failed to initialise Screens class : %s " % (str(e)) raise
def main(): oled = sh1106(port=1, address=0x3C) while (True): try: stats(oled) time.sleep(5) except: time.sleep(5)
def demo(iterations): device = sh1106(dc=25, spi=SPI.SpiDev(0, 0, max_speed_hz=8000000)) screen = (128, 64) for loop in range(iterations): for scale in [2, 3, 4, 3]: sz = map(lambda z: z / scale - 1, screen) with canvas(device) as draw: Maze(sz).render(draw, lambda z: int(z * scale)) time.sleep(5)
def __init__(self, port): context = zmq.Context() self.socket = context.socket(zmq.REP) self.socket.bind("tcp://*:" + port) self.oled = sh1106(port=1, address=0x3C) self.font = ImageFont.load_default() self.font_ra = ImageFont.truetype('fonts/C&C Red Alert [INET].ttf', 10) self.deja_vu_sm = ImageFont.truetype('fonts/DejaVuSansCondensed.ttf', 14) self.deja_vu = ImageFont.truetype('fonts/DejaVuSansCondensed.ttf', 40)
def demo(iterations): device = sh1106(dc=25, spi=SPI.SpiDev(0, 0, max_speed_hz=8000000)) screen = (128, 64) for loop in range(iterations): for scale in [2,3,4,3]: sz = map(lambda z: z/scale-1, screen) with canvas(device) as draw: Maze(sz).render(draw, lambda z: int(z * scale)) time.sleep(5)
def __init__(self, message, version, config, sw_rev, heartbeat): Thread.__init__(self) self.event = Event() self.log = logging.getLogger() self.heartbeat = heartbeat if sw_rev == 1: self.reset() # Needed for V2 self.config = config self.version = version self.sw_rev = sw_rev self.message = message # TODO: gracefully handle exception when OLED absent if self.config.hw_rev == 1: self.device = sh1106(port=1, address=0x3C) else: # self.device = Adafruit_SSD1306.SSD1306_128_64(rst=24) self.device = ssd1306(port=1, address=0x3C) self.font = ImageFont.load_default() # self.font = ImageFont.truetype("5by7.ttf",10) self.mode = m_IDLE self.row_index = 0 self.col_index = 0 self.char_space = 6 self.char_size = 4 self.row_height = 12 self.screen_row_size = 5 self.screen_col_size = 21 self.horiz_min = 0 self.horiz_max = self.screen_col_size self.horiz_index = 0 self.horiz_reset_cnt = 0 self.horiz_start_cnt = 0 self.viz_min = 0 self.viz_max = self.screen_row_size self.dialog_msg = "" self.dialog_msg2 = "" self.dialog_msg3 = "" self.dialog_confirmed = False self.dialog_cmd = 0 self.dialog_task_done = False self.dialog_next_mode = m_MAIN_MENU self.cursor = True self.cursor_x = 0 self.cursor_y = 0 self.key_repeating = False self.log_tail_results = [] self.reg_stage = 1 # WNode Registration Stage. 1/Name,2/NetKey,3/GrpKey self.log.info("Initialized Display Thread.")
def demo(iterations): device = sh1106(port=1, address=0x3C) screen = (128, 64) for loop in range(iterations): for scale in [2, 3, 4, 3]: sz = map(lambda z: z / scale - 1, screen) with canvas(device) as draw: Maze(sz).render(draw, lambda z: int(z * scale)) time.sleep(1)
def __init__(self): try: # self.font = ImageFont.load_default() self.font = ImageFont.truetype("/root/oled/font/arial.ttf", 16) self.device = sh1106(port=1, address=0x3C) self.draw_text("OLED INIT") except: with open("error.txt", "a+") as file: file.write("Failed to init OLED\n")
def __init__(self): self.device = sh1106(port=1, address=0x3C) self.font = ImageFont.truetype( '/usr/share/fonts/truetype/coders_crux.ttf', 32) self.resistance = None self.update_time = 0 self.ohm = Image.new("1", (16, 16), None) self.ohm.putdata(OMEGA) self.resistor = Image.new("1", (25, 10), None) self.resistor.putdata(RESISTOR) self.loading_screen()
def test_diplay(): device = sh1106(bus) bus.reset() # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) assert len(bus.recordings) == 40 for i in range(40): assert bus.recordings[i] == baseline_data.demo_sh1106[i]
def test_init_128x64(): sh1106(serial) serial.command.assert_has_calls([ # Initial burst are initialization commands call(174, 32, 16, 176, 200, 0, 16, 64, 161, 166, 168, 63, 164, 211, 0, 213, 240, 217, 34, 218, 18, 219, 32, 141, 20), # set contrast call(129, 127), # reset the display call(176, 2, 16), call(177, 2, 16), call(178, 2, 16), call(179, 2, 16), call(180, 2, 16), call(181, 2, 16), call(182, 2, 16), call(183, 2, 16) ]) # Next 1024 are all data: zero's to clear the RAM # (1024 = 128 * 64 / 8) serial.data.assert_has_calls([call([0] * 128)] * 8)
def main(): oled = sh1106(dc=25, spi=SPI.SpiDev(0, 0, max_speed_hz=8000000)) i=0 t=False while True: stats(oled,i) time.sleep(0.01) if t==False: i=i-1 if t==True: i=i+1 if i<-100: t=True if i==0: t=False
def main(): qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=2, border=3, ) qr.add_data('http://vincentstudio.info') qr.make(fit=True) img = qr.make_image() img.save('./images/code.png') oled = sh1106(port=0, address=0x3C) font = ImageFont.truetype('./fonts/C&C Red Alert [INET].ttf', 12) with canvas(oled) as draw: logo = Image.open('images/code.png') draw.bitmap((0, 1), logo, fill=1) draw.text((75, 20), 'Vincent', font=font, fill=1) draw.text((90, 32), 'Studio', font=font, fill=1)
def main(): font = ImageFont.load_default() device = sh1106(port=1, address=0x3C) yo = YoBit() with canvas(device) as draw: # Draw some shapes. # First define some constants to allow easy resizing of shapes. padding = 2 spacing = 30 x= padding shape_width = 20 top = padding raw = top bottom = device.height - padding - 1 pair = "btc_usd" last = formated_ticker2(yo,pair) draw.text((x, raw), 'BTC', font=font, fill=255) draw.text((x+spacing , raw), str(last), font=font, fill=255) pair = "dcr_btc" last = formated_ticker2(yo,pair) x = padding raw = raw + 10 draw.text((x, raw), 'DCR', font=font, fill=255) draw.text((x+spacing , raw), str(last), font=font, fill=255) pair = "etc_btc" last = formated_ticker2(yo,pair) x = padding raw = raw + 10 draw.text((x, raw), 'ETC', font=font, fill=255) draw.text((x+spacing , raw), str(last), font=font, fill=255) pair = "cme_btc" last = formated_ticker2(yo,pair) x = padding raw = raw + 10 draw.text((x, raw), 'CME', font=font, fill=255) draw.text((x+spacing , raw), str(last), font=font, fill=255)
def test_display(): device = sh1106(serial) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command = Mock(side_effect=command, unsafe=True) serial.data = Mock(side_effect=data, unsafe=True) # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) serial.data.assert_called() serial.command.assert_called() print(recordings) assert recordings == baseline_data.demo_sh1106
def __init__(self): self.oled = sh1106(port=1, address=0x3C) # create display self.oled.command(const.COMSCANINC, const.SEGREMAP) # invert it self.little_font = ImageFont.truetype("DejaVuSans.ttf", 16) self.big_font = ImageFont.truetype("DejaVuSans.ttf", 32)
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(18, GPIO.OUT) prev_input = 1 LED_on = False from oled.device import ssd1306, sh1106 from oled.render import canvas from PIL import ImageFont font = ImageFont.load_default() device = sh1106(port=1, address=0x3C) gpsd = None #setting the global variable cummDist = 0 old_lati = 0 old_longi = 0 current_distance = 0 button_press = 0 os.system('clear') #clear the terminal (optional) def my_callback(channel): global button_press print "Rising edge detected on port 24" button_press = button_press + 1
def main(): oled = sh1106(port=1, address=0x3C) stats(oled)
def test_init_handle_ioerror(): serial.command.side_effect = IOError(-99, "Test exception") with pytest.raises(IOError) as ex: sh1106(serial) assert "Failed to initialize SH1106 display driver" in str(ex.value)
def run(self): if debug : a = datetime.datetime.now() self.running = True if debug : print("init display") #RST = 24 #disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST) #disp.begin() #disp.clear() #disp.display() # Load default font. font = ImageFont.load_default() font2 = ImageFont.truetype("ARIALN.TTF", 20) #device = ssd1306(port=0, address=0x3C) device = sh1106(port=0, address=0x3C) # Create image buffer. width = device.width height = device.height #image = Image.new('1', (width, height)) # Get drawing object to draw on image. #draw = ImageDraw.Draw(image) rowhight = 12 input = [] inputold = [0,0,0,0,0,0] #input = [126,127,128,129,10,5] # 1=1 2=2 3=1,2 4=3 dvs knapp 3; 5 => knapp 1 och 3 if debug : b = datetime.datetime.now() if debug : delta = b - a if debug : deltatime = delta.total_seconds() if debug : print("Time init=",deltatime) #showimage(image) #print("displaying startimageobject on display") #disp.image(image) #disp.display() #---------------------------------------------------------------------------------------------------------- while (self.running): if debug : a = datetime.datetime.now() #if debug : print("starting loop") repeat = 1 # grabing the last value in queue that differs from inputold and save in variable input while (repeat == 1): inputtemp = queue.get() #if debug : print("comparing inputtemp and inputold: ",inputtemp,inputold) if inputtemp != inputold : #if debug : print("differs, saving in variable input") input = inputtemp #if debug : print(queue.qsize()) if ((queue.qsize() == 0) and (input != inputold)) : repeat = 0 if debug : print("leaving queuehandeling, input determed to: ",input) if inputold != inputtemp : input = inputtemp if input == [] : break # to asure to get out of loop at program termination #if debug : b = datetime.datetime.now() #if debug : delta = b - a #if debug : deltatime = delta.total_seconds() #if debug : print("queuetime: ",deltatime) if debug : a = datetime.datetime.now() with canvas(device) as draw: if input[0] == 999: if debug : print("text is: ", input[1]) twidth,theight = font2.getsize(input[1]) draw.text(((width-twidth)/2,(height-theight)/2), input[1], font=font2, fill=255) time.sleep(2) else: # Draw it all i = 0 while i != 3: draw.line((0,i*rowhight,width,i*rowhight),fill=255) i += 1 i = 0 #print("drawing static lines") while i != 8: draw.line((i*(width//8),0,i*(width//8),2*rowhight),fill=255) i += 1 draw.line((127,0,127,2*rowhight),fill=255) draw.line((0,64,64,2*rowhight),fill=255) draw.line((64,2*rowhight,64,64),fill=255) draw.line((64,64,127,2*rowhight),fill=255) # from left, from top #print("filling boxes") i = 1 while i < 16: ButtonNo = i//2+1 text = str(ButtonNo) twidth,theight = font.getsize("88") x0=(i*(width//16))-(twidth//2) y0=(rowhight-theight)//2+1 x1=(i*(width//16))-(twidth//2)+twidth y1=(rowhight-theight)//2+1+theight-1 if (input[4] & (1 << (ButtonNo-1))) > 0 : draw.rectangle([x0,y0,x1,y1],fill=255, outline=255) else: draw.text(((i*(width//16))-(twidth//2), (rowhight-theight)//2+1),text, font=font, fill=255) i +=2 i = 1 while i < 16: ButtonNo = i//2+9 text = str(ButtonNo) twidth,theight = font.getsize("88") x0=(i*(width//16))-(twidth//2) y0=(rowhight-theight)//2++rowhight+1 x1=(i*(width//16))-(twidth//2)+twidth y1=(rowhight-theight)//2++rowhight+1+theight-1 if (input[5] & (1 << (ButtonNo-9))) > 0 : draw.rectangle([x0,y0,x1,y1],fill=255, outline=255) else: draw.text(((i*(width//16))-(twidth//2), (rowhight-theight)//2+rowhight+1),text, font=font, fill=255) i +=2 draw.text((2,(2*rowhight)), str(input[0]), font=font2, fill=255) draw.text((29,(64-(2*rowhight))//2+(2*rowhight)), str(input[1]), font=font2, fill=255) draw.text((66,(2*rowhight)), str(input[2]), font=font2, fill=255) draw.text((93,(64-(2*rowhight))//2+(2*rowhight)), str(input[3]), font=font2, fill=255) # Display image. if debug : b = datetime.datetime.now() if debug : delta = b - a if debug : deltatime = delta.total_seconds() if debug : print("looptime excl display: ",deltatime) if debug : a = datetime.datetime.now() #self.queue.task_done() if debug : b = datetime.datetime.now() if debug : delta = b - a if debug : deltatime = delta.total_seconds() if debug : print("displaytime: ",deltatime) inputold = input self.running = False
#!/usr/bin/env python # Ported from: # https://github.com/adafruit/Adafruit_Python_SSD1306/blob/master/examples/shapes.py from oled.device import ssd1306, sh1106 from oled.render import canvas from PIL import ImageFont import Adafruit_GPIO as GPIO import Adafruit_GPIO.SPI as SPI font = ImageFont.load_default() device = sh1106(dc=27, spi=SPI.SpiDev(0, 0, max_speed_hz=8000000)) with canvas(device) as draw: # Draw some shapes. # First define some constants to allow easy resizing of shapes. padding = 2 shape_width = 20 top = padding+9 print device.height bottom = device.height - padding - 1 # Draw a rectangle of the same size of screen draw.rectangle((0, 0, device.width-1, device.height-1), outline=255, fill=0) # Move left to right keeping track of the current x position for drawing shapes. x = padding # Draw an ellipse. draw.ellipse((x, top, x+shape_width, bottom), outline=255, fill=0) x += shape_width + padding # Draw a rectangle. draw.rectangle((x, top, x+shape_width, bottom), outline=255, fill=0)
def test_init_invalid_dimensions(): with pytest.raises(oled.error.DeviceDisplayModeError) as ex: sh1106(serial, width=77, height=105) assert "Unsupported display mode: 77 x 105" in str(ex.value)
#!/usr/bin/env python # Ported from: # https://github.com/adafruit/Adafruit_Python_SSD1306/blob/master/examples/shapes.py from oled.device import ssd1306, sh1106 from oled.render import canvas from PIL import ImageFont import Adafruit_GPIO as GPIO import Adafruit_GPIO.SPI as SPI font = ImageFont.load_default() device = sh1106(dc=27, spi=SPI.SpiDev(0, 0, max_speed_hz=8000000)) with canvas(device) as draw: # Draw some shapes. # First define some constants to allow easy resizing of shapes. padding = 2 shape_width = 20 top = padding + 9 print device.height bottom = device.height - padding - 1 # Draw a rectangle of the same size of screen draw.rectangle((0, 0, device.width - 1, device.height - 1), outline=255, fill=0) # Move left to right keeping track of the current x position for drawing shapes. x = padding # Draw an ellipse. draw.ellipse((x, top, x + shape_width, bottom), outline=255, fill=0) x += shape_width + padding
gpio.setcfg(button_vdown, gpio.INPUT) gpio.setcfg(button_pause, gpio.INPUT) #Enable pullup resistor gpio.pullup(button_prev, gpio.PULLUP) gpio.pullup(button_next, gpio.PULLUP) gpio.pullup(button_gsm, gpio.PULLUP) gpio.pullup(button_vup, gpio.PULLUP) gpio.pullup(button_vdown, gpio.PULLUP) gpio.pullup(button_pause, gpio.PULLUP) #------------------------------------------------------------------------------# #------------------------------------------------------------------------------# # Define Device Type , I2C port and padding characters device = sh1106(port=0, address=0x3C) # rev.1 users set port=0 font = ImageFont.load_default() str_pad = " " * 24 #------------------------------------------------------------------------------# def read_switches(): #Reading the switch for inputs sw_prev = 1 sw_next = 1 sw_gsm = 1 sw_vup = 1 sw_vdown = 1 sw_pause = 1 # Initialize
from oled.device import sh1106 from oled.render import canvas from PIL import ImageDraw, Image, ImageFont import time fontSize = 12 font = ImageFont.truetype('/home/pi/fonts/redalert.ttf', fontSize) #font = ImageFont.load_default() device = "null" try: device = sh1106(port=1, address=0x3C) except: print("Ekran Bulunamadi!") bon = "/home/pi/Desktop/Robot/OLED/img/bluetooth/on.png" boff = "/home/pi/Desktop/Robot/OLED/img/bluetooth/off.png" banner = "/home/pi/Desktop/Robot/OLED/img/banner/banner.png" class Pixel: def initScreen(): try: if (device != "null"): img = Image.open(banner).convert('1') with canvas(device) as draw: draw.bitmap((0, 0), img, fill=1) except: print("Banner Error") def printScreen(lines): try: if (device != "null"):
draw.text((0, 40), garage, font=font, fill=255) def clearScreen(oled): font = ImageFont.truetype('font.ttf', 12) with canvas(oled) as draw: draw.rectangle((0,0,oled.width,oled.height),outline=0,fill=0) def main(): oled = sh1106(port=1, address=0x3C) stats(oled) if __name__ == "__main__": main() try: oled = sh1106(port=1, address=0x3C) getTemperature() while count < 1: garage = io.input(btnPin) if garage == False: print('Button Pressed') garageDoor.activateGarage() if io.input(switchPin): isGarageClosed = False else: isGarageClosed = True stats(oled) #count += 1 except KeyboardInterrupt: print("****user exit****")