def render_battery(display, pos_x=140, pos_y=72): v = os.read_battery() c = get_bat_color(v) if not c: return display.rect(pos_x, pos_y, pos_x + 15, pos_y + 7, filled=True, col=c) display.rect(pos_x + 15, pos_y + 2, pos_x + 17, pos_y + 5, filled=True, col=c) if v < 4.0: display.rect(pos_x + 11, pos_y + 1, pos_x + 14, pos_y + 6, filled=True, col=[0, 0, 0]) if v < 3.8: display.rect(pos_x + 6, pos_y + 1, pos_x + 11, pos_y + 6, filled=True, col=[0, 0, 0]) if v < 3.6: display.rect(pos_x + 1, pos_y + 1, pos_x + 6, pos_y + 6, filled=True, col=[0, 0, 0]) render_charging(display, pos_x + 6, pos_y)
def render_battery(display, v): c = get_bat_color(v) if not c: return display.rect(140, 72, 155, 79, filled=True, col=c) display.rect(155, 74, 157, 77, filled=True, col=c) if v < 4.0: display.rect(151, 73, 154, 78, filled=True, col=[0, 0, 0]) if v < 3.8: display.rect(146, 73, 151, 78, filled=True, col=[0, 0, 0]) if v < 3.6: display.rect(141, 73, 146, 78, filled=True, col=[0, 0, 0])
def msg_nosplit(message, title='Loading...', reset=False): global NUM_LINES """Show a terminal style loading screen with title title can be optionaly set when resetting or first call """ global messageHistory try: messageHistory if reset: raise exception except: display.greyscale(False) display.fill(0xFFFFFF) display.textColor(0x000000) display.font(version.font_header) display.cursor(0, 0) display.print(title) messageHistory = [] display.font(version.font_default) lineHeight = display.get_string_height(" ") if len(messageHistory) < NUM_LINES: display.textColor(0x000000) display.cursor(0, 19 + (len(messageHistory) * lineHeight)) display.print(message) messageHistory.append(message) else: messageHistory.pop(0) messageHistory.append(message) display.rect(0, 15, display.width(), display.height() - 15, True, 0xFFFFFF) for i, message in enumerate(messageHistory): display.textColor(0x000000) display.font(version.font_default) display.cursor(0, 19 + (i * lineHeight)) display.print(message) display.flush()
def _draw(self): if self._visible: display.rect(self.x, self.y, self.w, self.h, True, 0xFFFFFF) display.rect(self.x, self.y, self.w, self.h, False, 0x000000) display.font("freesans9") _ = display.textColor(0x000000) display.cursor(self.x + 1, self.y + 1) totalHeight = 0 for i in range(self.offset, len(self.items)): display.cursor(self.x + 1, display.cursor()[1]) item = self.items[i] lineHeight = display.get_string_height(item) totalHeight += lineHeight if totalHeight < self.h: if i == self.selected: display.rect(self.x, display.cursor()[1], self.w, lineHeight, True, 0x000000) _ = display.textColor(0xFFFFFF) else: _ = display.textColor(0x000000) display.cursor(self.x + 1, display.cursor()[1] + 3) display.print(item + "\n") display.cursor(self.x + 1, display.cursor()[1] - 3)
def fill_rounded_box(x, y, w, h, r, color): display.rect(x, y, w, h, True, color)
def rounded_box(x, y, w, h, r, color): display.rect(x, y, w, h, False, color)
def area(x, y, w, h, color): display.rect(x, y, w, h, True, color)