def _draw_once(self): '''最初に一度だけ描画する処理''' # 枠を表示 (デバッグ用) #lcd.rect(0, 0, self.width + 1, self.height + 1, lcd.BLACK) # 温度計の液溜め部分(正式には「球部」)の円を描画 lcd.circle(self.circle_x, self.circle_y, self.circle_radius, self.color, self.color) # 目盛りの間隔 (摂氏度) tick = 10 # 目盛りとグラフの隙間のピクセル数 m = 2 # 目盛りの長さ (ピクセル) l = 8 # 目盛りと軸の数字の隙間のピクセル数 m2 = 4 # フォントの設定 lcd.font(lcd.FONT_Default, color=self.axis_color, transparent=True) # TODO: ラベルを描画 label_x = self.bar_x - m - l - m2 - lcd.textWidth(self.label) label_y = self.y lcd.text(label_x, label_y, self.label) # フォントの設定 lcd.font(lcd.FONT_Default, color=self.axis_color, transparent=True) # フォントサイズ font_width, font_height = lcd.fontSize() half_font_height = int(round(font_height / 2)) min_ylabel = int(math.ceil(self.min_value / 10)) * 10 for i in range(min_ylabel, self.max_value + 1, tick): y1 = self._calc_y(i) # 目盛り (左) lcd.line(self.bar_x - m - l, y1, self.bar_x - m, y1, self.axis_color) # 目盛り (右) lcd.line(self.bar_x + self.bar_width + m, y1, self.bar_x + self.bar_width + m + l, y1, self.axis_color) # 目盛りラベル tick_label = '{}'.format(i) lcd.print(tick_label, self.bar_x - m - l - m2 - lcd.textWidth(tick_label), y1 - half_font_height, self.axis_color)
def printToLcd(self): if self._coord == None: self._coord = lcd.getCursor() oldTxt = self._format.format(self._oldValue) + self._suffix oldTxtWidth = lcd.textWidth(oldTxt) txt = self._format.format(self.value) + self._suffix txtWidth = lcd.textWidth(txt) # erase lcd.textClear(self._coord[0], self._coord[1], oldTxt, lcd.WHITE) lcd.line(self._coord[0], self._coord[1] + 25, self._coord[0] + oldTxtWidth, self._coord[1] + 25, lcd.WHITE) # write lcd.setCursor(self._coord[0], self._coord[1]) lcd.print(txt) if self._editingActive: lcd.line(self._coord[0], self._coord[1] + 25, self._coord[0] + txtWidth, self._coord[1] + 25)
def printToLcd(self): if self._coord == None: self._coord = lcd.getCursor() oldTxt = self._oldValue oldTxtWith = lcd.textWidth(oldTxt) txt = self.value txtWidth = lcd.textWidth(txt) # erase lcd.textClear(self._coord[0], self._coord[1], oldTxt, lcd.WHITE) lcd.line(self._coord[0], self._coord[1] + 25, self._coord[0] + oldTxtWith, self._coord[1] + 25, lcd.WHITE) # write x = (320 - (lcd.textWidth(self.value))) / 2 lcd.setCursor(int(x), self._coord[1]) self._coord = lcd.getCursor() lcd.print(txt) if self._editingActive: lcd.line(self._coord[0], self._coord[1] + 25, self._coord[0] + txtWidth, self._coord[1] + 25)
def update(self, value): # 取得値をテキストでも表示 if self.w == win_w: lcd.font(lcd.FONT_DejaVu24, transparent=False) else: lcd.font(lcd.FONT_DejaVu18, transparent=False) fw, fh = lcd.fontSize() if value is not None: angle = int((value - self.tick_s) / (self.tick_e - self.tick_s) * 100 - 50) if angle != self.prev_angle: # 前回取得値の針を消去 if self.prev_angle is not None: for i in range(-1, 2): lcd.lineByAngle(self.center_x + i, self.center_y, int(self.h * 0.15), int(self.h * 0.42), self.prev_angle, lcd.WHITE) # 今回取得値の針を表示 for i in range(-1, 2): lcd.lineByAngle(self.center_x + i, self.center_y, int(self.h * 0.15), int(self.h * 0.42), angle, lcd.RED) if self.title != '': lcd.print(self.title, self.center_x - lcd.textWidth(self.title) // 2, self.y + self.h - int(fh * 2.4), lcd.BLACK) self.prev_angle = angle if value != self.prev_value: text = self.value_format.format(value) lcd.print(text, self.center_x - lcd.textWidth(text) // 2, self.y + self.h - int(fh * 1.2), lcd.BLACK) self.prev_value = value else: text = self.value_format.format(self.prev_value) lcd.print(text, self.center_x - lcd.textWidth(text) // 2, self.y + self.h - int(fh * 1.2), lcd.RED)
def __init__(self, x, y, w, h, tick_s, tick_e, color, title, value_format): self.x = x # メーターの表示位置 self.y = y # メーターの表示位置 self.w = w # メーターの表示幅 self.h = h # メーターの表示高 self.tick_s = tick_s # 目盛の最小値 self.tick_e = tick_e # 目盛の最大値 self.title = title self.value_format = value_format # 値をテキスト表示する際のフォーマット self.center_x = x + w // 2 # 針の原点 self.center_y = y + int(h * 0.9) # 針の原点 self.prev_value = tick_s self.prev_angle = None lcd.roundrect(x, y, w, h, h // 10, lcd.BLACK, lcd.WHITE) lcd.arc(self.center_x, self.center_y, int(h * 0.67), int(h * 0.07), -50, 50, color, color) lcd.arc(self.center_x, self.center_y, int(h * 0.6), 2, -50, 50, lcd.BLACK) # 目盛の値表示用フォント設定 if self.w == win_w: lcd.font(lcd.FONT_Default, transparent=False) else: lcd.font(lcd.FONT_DefaultSmall, transparent=True) fw, fh = lcd.fontSize() tick = tick_s tick_i = (tick_e - tick_s) // 4 for r in range(-50, 51, 5): if r % 25 == 0: # 目盛の最小値から最大値を4分割して目盛値を表示 lcd.lineByAngle(self.center_x - 1, self.center_y, int(h * 0.6), int(h * 0.1), r, lcd.BLACK) lcd.lineByAngle(self.center_x, self.center_y, int(h * 0.6), int(h * 0.1), r, lcd.BLACK) tick_text = str(tick) text_width = lcd.textWidth(tick_text) lcd.print( tick_text, self.center_x + int(math.sin(math.radians(r)) * h * 0.7) - text_width // 2, self.center_y - int(math.cos(math.radians(r)) * h * 0.7) - fh, lcd.BLACK) tick += tick_i else: # 細かい目盛線を表示 lcd.lineByAngle(self.center_x, self.center_y, int(h * 0.6), int(h * 0.05), r, lcd.BLACK)
def __init__(self, x, y, w, h, color): self.x = x # 時計の表示位置 self.y = y # 時計の表示位置 self.w = w # 時計の表示幅 self.h = h # 時計の表示高 self.center_x = x + w // 2 # 針の中心 self.center_y = y + h // 2 # 針の中心 self.hour_deg = 0 self.minute_deg = 0 self.second_deg = 0 lcd.roundrect(x, y, w, h, h // 10, lcd.BLACK, lcd.WHITE) # 0 から 360 とは書けないので、半分の円弧を合わせる lcd.arc(self.center_x, self.center_y, int(h * 0.39), int(h * 0.08), 0, 180, color, color) lcd.arc(self.center_x, self.center_y, int(h * 0.39), int(h * 0.08), 180, 360, color, color) if self.w == win_w: lcd.font(lcd.FONT_Default, transparent=False) else: lcd.font(lcd.FONT_DefaultSmall, transparent=True) fw, fh = lcd.fontSize() hour = 12 for r in range(0, 360, 360 // 60): if r % (360 // 12) == 0: # 1〜12の位置に黒点および数字を表示 lcd.circle( self.center_x + int(math.sin(math.radians(r)) * h / 2 * 0.7), self.center_y - int(math.cos(math.radians(r)) * h / 2 * 0.7), 2, lcd.BLACK, lcd.BLACK) hour_text = str(hour) text_width = lcd.textWidth(hour_text) lcd.print( hour_text, self.center_x + int(math.sin(math.radians(r)) * h / 2 * 0.85) - text_width // 2, self.center_y - int(math.cos(math.radians(r)) * h / 2 * 0.85) - fh // 2, lcd.BLACK) hour = (hour + 1) % 12 else: lcd.pixel( self.center_x + int(math.sin(math.radians(r)) * h / 2 * 0.7), self.center_y - int(math.cos(math.radians(r)) * h / 2 * 0.7), lcd.BLACK)
def drawBanner(self): lcd.rect(0, 0, self.W, self.h_banner, lcd.BLUE, lcd.BLUE) lcd.setCursor(self.W - lcd.textWidth(self.title) - 5, 5) lcd.print(self.title) th_m = _thread.start_new_thread('monitor', self.__th_statusMonitor, ())
self.draw(self.index) elif argument == 2: return self.index elif argument == 3: if self.index == len(self.applist)-1: self.index = 0 else: self.index +=1 self.draw(self.index) return -1 lcd.image(0,0,'m5stack.jpg') utime.sleep(3) lcd.clear(lcd.BLACK) lcd.font('/flash/font/ep60.fon', fixedwidth=0) lcd.setColor(lcd.RED,lcd.BLACK) lcd.text(int((320-lcd.textWidth('APP'))/2),1,'APP') appchose=List(applist) while True: if buttonA.wasPressed(): temp = appchose.event(1) if temp == -1: pass else: if applist[temp][0] == '/flash': exec(open(applist[temp][0] + "/" + applist[temp][1]).read()) else: exec(open(applist[temp][0] + "/" + applist[temp][1] + "/" + "main.py").read()) if buttonB.wasPressed():
def printToLcdCenter(self, y): x = ( 320 - (lcd.textWidth(self._format.format(self._max) + self._suffix))) / 2 lcd.setCursor(int(x), y) self.printToLcd()