def draw_pixel(self, pos_x, pos_y, color=None): """draw a pixel at x,y""" if self.rotation == 90: pos_x, pos_y = self.height - pos_y - 1, pos_x if self.rotation == 180: pos_x, pos_y = self.width - pos_x - 1, self.height - pos_y - 1 if self.rotation == 270: pos_x, pos_y = pos_y, self.width - pos_x - 1 Page.draw_pixel(self, pos_x, pos_y, color)
def __init__(self, width, height, driver, auto_flush=True): Chip.__init__(self, width, height, driver, auto_flush) Page.__init__(self, driver) self.rotation = 0 self.buffer = [] self.area = { 'start_x': 0, 'start_y': 0, 'end_x': width - 1, 'end_y': height - 1 }
def init(self): """initialize display""" self.driver.init() Page.init(self) Chip.init(self) self.driver.reset() init_sequence = [0xae, 0xa4, 0xa9, 0xe2, 0xa0, 0xaf] for cmd in init_sequence: self.driver.cmd(cmd, 0) self.driver.cmd(cmd, 1)
def fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw a filled rectangle""" if self.rotation == 90: pos_x1, pos_y1 = self.height - pos_y1 - 1, pos_x1 pos_x2, pos_y2 = self.height - pos_y2 - 1, pos_x2 if self.rotation == 180: pos_x1, pos_y1 = self.width - pos_x1 - 1, self.height - pos_y1 - 1 pos_x2, pos_y2 = self.width - pos_x2 - 1, self.height - pos_y2 - 1 if self.rotation == 270: pos_x1, pos_y1 = pos_y1, self.width - pos_x1 - 1 pos_x2, pos_y2 = pos_y2, self.width - pos_x2 - 1 Page.fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2)
def init(self): """inits a device""" self.driver.init() Page.init(self) Chip.init(self) self.driver.reset() self.driver.cmd(0xae) # turn off panel self.driver.cmd(0x00) # set low column address self.driver.cmd(0x10) # set high column address self.driver.cmd(0x40) # set start line address self.driver.cmd(0x20) # addr mode self.driver.cmd(0x02) # horizontal self.driver.cmd(0xb0) # set page address self.driver.cmd(0x81) # set contrast control register self.driver.cmd(0xff) # a0/a1, a1 = segment 127 to 0, a0:0 to seg127 self.driver.cmd(self.rotations[self.rotation]['sgmt']) # c8/c0 set com(N-1)to com0 c0:com0 to com(N-1) self.driver.cmd(self.rotations[self.rotation]['com']) self.driver.cmd(0xa6) # set normal display, a6 - normal, a7 - inverted self.driver.cmd(0xa8) # set multiplex ratio(16to63) self.driver.cmd(0x3f) # 1/64 duty self.driver.cmd(0xd3) # set display offset self.driver.cmd(0x00) # not offset # set display clock divide ratio/oscillator frequency self.driver.cmd(0xd5) self.driver.cmd(0x80) # set divide ratio self.driver.cmd(0xd9) # set pre-charge period self.driver.cmd(0xf1) self.driver.cmd(0xda) # set com pins hardware configuration self.driver.cmd(0x12) self.driver.cmd(0xdb) # set vcomh self.driver.cmd(0x40) self.driver.cmd(0x8d) # charge pump self.driver.cmd(0x14) # enable charge pump self.driver.cmd(0xaf) # turn on panel
def init(self): """inits a device""" Page.init(self) Chip.init(self)
def __init__(self, width, height, driver, auto_flush=False): Chip.__init__(self, width, height, driver, auto_flush) Page.__init__(self, driver) self.rotation = 0
def draw_pixel(self, pos_x, pos_y, color=None): """draw a pixel at x,y""" if self.rotation == 90 or self.rotation == 270: pos_x, pos_y = pos_y, pos_x Page.draw_pixel(self, pos_x, pos_y, color)