from m5stack import *
from m5stack_ui import *
from uiflow import *
import wifiCfg
import urequests
import time
import json
screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0x2f2f2f)
jsonData = None
target_month = None
target_year = None
monthDataList = None
pos_week = None
day = None
pos_day = None
api_url = None
weekDataList = None
count = None
color_gray = None
color_deepskyblue = None
dayData = None
color_lime = None
color_hotpink = None
labelTitle = M5Label('Medication Calendar', x=86, y=7, color=0x00ff00, font=FONT_MONT_14, parent=None)
labelMo = M5Label('Mo', x=13, y=30, color=0xfcf9f9, font=FONT_MONT_18, parent=None)
labelTu = M5Label('Tu', x=60, y=30, color=0xffffff, font=FONT_MONT_18, parent=None)
labelWe = M5Label('We', x=102, y=30, color=0xffffff, font=FONT_MONT_18, parent=None)
labelTh = M5Label('Th', x=150, y=30, color=0xffffff, font=FONT_MONT_18, parent=None)
labelFr = M5Label('Fr', x=196, y=30, color=0xffffff, font=FONT_MONT_18, parent=None)
labelSa = M5Label('Sa', x=238, y=30, color=0x1e90ff, font=FONT_MONT_18, parent=None)
labelSu = M5Label('Su', x=282, y=30, color=0xdc143c, font=FONT_MONT_18, parent=None)
line0 = M5Line(x1=7, y1=50, x2=312, y2=50, color=0xf5f5f5, width=1, parent=None)
line1 = M5Line(x1=7, y1=78, x2=312, y2=78, color=0xf5f5f5, width=1, parent=None)
line2 = M5Line(x1=7, y1=106, x2=312, y2=106, color=0xf5f5f5, width=1, parent=None)
line3 = M5Line(x1=7, y1=134, x2=312, y2=134, color=0xf5f5f5, width=1, parent=None)
line4 = M5Line(x1=7, y1=162, x2=312, y2=162, color=0xf5f5f5, width=1, parent=None)
line5 = M5Line(x1=7, y1=190, x2=312, y2=190, color=0xf5f5f5, width=1, parent=None)
line6 = M5Line(x1=7, y1=218, x2=312, y2=218, color=0xf5f5f5, width=1, parent=None)
line7 = M5Line(x1=47, y1=28, x2=47, y2=218, color=0xc0c0c0, width=1, parent=None)
line8 = M5Line(x1=92, y1=28, x2=92, y2=218, color=0xc0c0c0, width=1, parent=None)
line9 = M5Line(x1=137, y1=28, x2=137, y2=218, color=0xc0c0c0, width=1, parent=None)
line10 = M5Line(x1=182, y1=28, x2=182, y2=218, color=0xc0c0c0, width=1, parent=None)
line11 = M5Line(x1=227, y1=28, x2=227, y2=218, color=0xc0c0c0, width=1, parent=None)
line12 = M5Line(x1=272, y1=28, x2=272, y2=218, color=0xc0c0c0, width=1, parent=None)
label1_1 = M5Label('X', x=20, y=58, color=0x808080, font=FONT_MONT_14, parent=None)
label1_2 = M5Label('X', x=65, y=58, color=0x808080, font=FONT_MONT_14, parent=None)
label1_3 = M5Label('X', x=110, y=58, color=0x808080, font=FONT_MONT_14, parent=None)
label1_4 = M5Label('X', x=155, y=58, color=0x808080, font=FONT_MONT_14, parent=None)
label1_5 = M5Label('X', x=200, y=58, color=0x808080, font=FONT_MONT_14, parent=None)
label1_6 = M5Label('X', x=245, y=58, color=0x808080, font=FONT_MONT_14, parent=None)
label1_7 = M5Label('X', x=290, y=58, color=0x808080, font=FONT_MONT_14, parent=None)
label2_1 = M5Label('X', x=20, y=86, color=0x808080, font=FONT_MONT_14, parent=None)
label2_2 = M5Label('X', x=65, y=86, color=0x808080, font=FONT_MONT_14, parent=None)
label2_3 = M5Label('X', x=110, y=86, color=0x808080, font=FONT_MONT_14, parent=None)
label2_4 = M5Label('X', x=155, y=86, color=0x808080, font=FONT_MONT_14, parent=None)
label2_5 = M5Label('X', x=200, y=86, color=0x808080, font=FONT_MONT_14, parent=None)
label2_6 = M5Label('X', x=245, y=86, color=0x808080, font=FONT_MONT_14, parent=None)
label2_7 = M5Label('X', x=290, y=86, color=0x808080, font=FONT_MONT_14, parent=None)
label3_1 = M5Label('X', x=20, y=114, color=0x808080, font=FONT_MONT_14, parent=None)
label3_2 = M5Label('X', x=65, y=114, color=0x808080, font=FONT_MONT_14, parent=None)
label3_3 = M5Label('X', x=110, y=114, color=0x808080, font=FONT_MONT_14, parent=None)
label3_4 = M5Label('X', x=155, y=114, color=0x808080, font=FONT_MONT_14, parent=None)
label3_5 = M5Label('X', x=200, y=113, color=0x808080, font=FONT_MONT_14, parent=None)
label3_6 = M5Label('X', x=245, y=114, color=0x808080, font=FONT_MONT_14, parent=None)
label3_7 = M5Label('X', x=290, y=114, color=0x808080, font=FONT_MONT_14, parent=None)
label4_1 = M5Label('X', x=20, y=142, color=0x808080, font=FONT_MONT_14, parent=None)
label4_2 = M5Label('X', x=65, y=142, color=0x808080, font=FONT_MONT_14, parent=None)
label4_3 = M5Label('X', x=110, y=142, color=0x808080, font=FONT_MONT_14, parent=None)
label4_4 = M5Label('X', x=155, y=142, color=0x808080, font=FONT_MONT_14, parent=None)
label4_5 = M5Label('X', x=200, y=142, color=0x808080, font=FONT_MONT_14, parent=None)
label4_6 = M5Label('X', x=245, y=142, color=0x808080, font=FONT_MONT_14, parent=None)
label4_7 = M5Label('X', x=290, y=142, color=0x808080, font=FONT_MONT_14, parent=None)
label5_1 = M5Label('X', x=20, y=170, color=0x808080, font=FONT_MONT_14, parent=None)
label5_2 = M5Label('X', x=65, y=170, color=0x808080, font=FONT_MONT_14, parent=None)
label5_3 = M5Label('X', x=110, y=170, color=0x808080, font=FONT_MONT_14, parent=None)
label5_4 = M5Label('X', x=155, y=170, color=0x808080, font=FONT_MONT_14, parent=None)
label5_5 = M5Label('X', x=200, y=170, color=0x808080, font=FONT_MONT_14, parent=None)
label5_6 = M5Label('X', x=245, y=170, color=0x808080, font=FONT_MONT_14, parent=None)
label5_7 = M5Label('X', x=290, y=170, color=0x808080, font=FONT_MONT_14, parent=None)
label6_1 = M5Label('X', x=20, y=198, color=0x808080, font=FONT_MONT_14, parent=None)
label6_2 = M5Label('X', x=65, y=198, color=0x808080, font=FONT_MONT_14, parent=None)
label6_3 = M5Label('X', x=110, y=198, color=0x808080, font=FONT_MONT_14, parent=None)
label6_4 = M5Label('X', x=155, y=198, color=0x808080, font=FONT_MONT_14, parent=None)
label6_5 = M5Label('X', x=200, y=198, color=0x808080, font=FONT_MONT_14, parent=None)
label6_6 = M5Label('X', x=245, y=198, color=0x808080, font=FONT_MONT_14, parent=None)
label6_7 = M5Label('X', x=290, y=198, color=0x808080, font=FONT_MONT_14, parent=None)
labelYYYYMM = M5Label('YYYY/MM', x=125, y=220, color=0xffd700, font=FONT_MONT_18, parent=None)
labelPrev = M5Label('<<', x=45, y=224, color=0xdaa520, font=FONT_MONT_14, parent=None)
labelNext = M5Label('>>', x=255, y=224, color=0xdaa520, font=FONT_MONT_14, parent=None)
from numbers import Number
# 関数定義:カレンダー情報取得
# - 服薬カレンダー情報をWebAPIから取得する
def getCalenderData():
global jsonData, target_month, target_year, monthDataList, pos_week, day, pos_day, api_url, weekDataList, count, color_gray, color_deepskyblue, dayData, color_lime, color_hotpink
rgb.setColorAll(0x3366ff)
rgb.setBrightness(10)
# GET APIにHTTPリクエストする
# GET /calendar/{year}/{month}
try:
req = urequests.request(method='GET', url=(str(api_url) + str(((str('/calendar/') + str(((str(target_year) + str(((str('/') + str(target_month))))))))))), headers={})
# 関数コール:カレンダー情報表示
# 引数: jsonData(WebAPIから受信したJSONデータ)
displayCalendarData(json.loads((req.text)))
rgb.setColorAll(0x33ff33)
wait(2)
rgb.setBrightness(0)
gc.collect()
req.close()
except:
labelYYYYMM.set_text('error')
rgb.setColorAll(0xff0000)
wait(2)
rgb.setBrightness(0)
# 関数定義:カレンダー情報表示
# - JSONデータからカレンダー情報を表示する
# 引数: jsonData(WebAPIから受信したJSONデータ)
def displayCalendarData(jsonData):
global target_month, target_year, monthDataList, pos_week, day, pos_day, api_url, weekDataList, count, color_gray, color_deepskyblue, dayData, color_lime, color_hotpink
# 関数コール:全日付ラベル非表示
all_days_displayHide()
# 表示月をラベルに表示
labelYYYYMM.set_text(str(jsonData['yyyymm']))
# 「1か月分データリスト」を変数にセットする
monthDataList = jsonData['data']
# 変数「週の位置」を初期化
pos_week = 0
# 「1か月分データリスト」をループして「1週間分データリスト」を取得
for weekDataList in monthDataList:
# 「週の位置」をカウントアップ
pos_week = (pos_week if isinstance(pos_week, Number) else 0) + 1
# 変数「曜日の位置」を初期化
pos_day = 0
# 「1週間分データリスト」をループして「日別件数データ」を取得
for dayData in weekDataList:
# 「曜日の位置」をカウントアップ
pos_day = (pos_day if isinstance(pos_day, Number) else 0) + 1
# 「日別件数データ」から「日」を取得し変数にセットする
day = dayData['day']
# 「日別件数データ」から「件数」を取得し変数にセットする
count = dayData['count']
# 関数コール:日情報表示
displayDay()
# 関数定義:全日付ラベル非表示
# - 42マス分の日付ラベルを全て非表示にする
def all_days_displayHide():
global jsonData, target_month, target_year, monthDataList, pos_week, day, pos_day, api_url, weekDataList, count, color_gray, color_deepskyblue, dayData, color_lime, color_hotpink
label1_1.set_hidden(True)
label1_2.set_hidden(True)
label1_3.set_hidden(True)
label1_4.set_hidden(True)
label1_5.set_hidden(True)
label1_6.set_hidden(True)
label1_7.set_hidden(True)
label2_1.set_hidden(True)
label2_2.set_hidden(True)
label2_3.set_hidden(True)
label2_4.set_hidden(True)
label2_5.set_hidden(True)
label2_6.set_hidden(True)
label2_7.set_hidden(True)
label3_1.set_hidden(True)
label3_2.set_hidden(True)
label3_3.set_hidden(True)
label3_4.set_hidden(True)
label3_5.set_hidden(True)
label3_6.set_hidden(True)
label3_7.set_hidden(True)
label4_1.set_hidden(True)
label4_2.set_hidden(True)
label4_3.set_hidden(True)
label4_4.set_hidden(True)
label4_5.set_hidden(True)
label4_6.set_hidden(True)
label4_7.set_hidden(True)
label5_1.set_hidden(True)
label5_2.set_hidden(True)
label5_3.set_hidden(True)
label5_4.set_hidden(True)
label5_5.set_hidden(True)
label5_6.set_hidden(True)
label5_7.set_hidden(True)
label6_1.set_hidden(True)
label6_2.set_hidden(True)
label6_3.set_hidden(True)
label6_4.set_hidden(True)
label6_5.set_hidden(True)
label6_6.set_hidden(True)
label6_7.set_hidden(True)
# 関数定義:日情報表示
# - カレンダーに日付を表示し、件数に応じて色をつける
def displayDay():
global jsonData, target_month, target_year, monthDataList, pos_week, day, pos_day, api_url, weekDataList, count, color_gray, color_deepskyblue, dayData, color_lime, color_hotpink
if pos_week == 1 and pos_day == 1:
if day > 0:
label1_1.set_text(str(day))
if count == 0:
label1_1.set_text_color(color_gray)
if count == 1:
label1_1.set_text_color(color_deepskyblue)
if count == 2:
label1_1.set_text_color(color_lime)
if count >= 3:
label1_1.set_text_color(color_hotpink)
label1_1.set_hidden(False)
if pos_week == 1 and pos_day == 2:
if day > 0:
label1_2.set_text(str(day))
if count == 0:
label1_2.set_text_color(color_gray)
if count == 1:
label1_2.set_text_color(color_deepskyblue)
if count == 2:
label1_2.set_text_color(color_lime)
if count >= 3:
label1_2.set_text_color(color_hotpink)
label1_2.set_hidden(False)
if pos_week == 1 and pos_day == 3:
if day > 0:
label1_3.set_text(str(day))
if count == 0:
label1_3.set_text_color(color_gray)
if count == 1:
label1_3.set_text_color(color_deepskyblue)
if count == 2:
label1_3.set_text_color(color_lime)
if count >= 3:
label1_3.set_text_color(color_hotpink)
label1_3.set_hidden(False)
if pos_week == 1 and pos_day == 4:
if day > 0:
label1_4.set_text(str(day))
if count == 0:
label1_4.set_text_color(color_gray)
if count == 1:
label1_4.set_text_color(color_deepskyblue)
if count == 2:
label1_4.set_text_color(color_lime)
if count >= 3:
label1_4.set_text_color(color_hotpink)
label1_4.set_hidden(False)
if pos_week == 1 and pos_day == 5:
if day > 0:
label1_5.set_text(str(day))
if count == 0:
label1_5.set_text_color(color_gray)
if count == 1:
label1_5.set_text_color(color_deepskyblue)
if count == 2:
label1_5.set_text_color(color_lime)
if count >= 3:
label1_5.set_text_color(color_hotpink)
label1_5.set_hidden(False)
if pos_week == 1 and pos_day == 6:
if day > 0:
label1_6.set_text(str(day))
if count == 0:
label1_6.set_text_color(color_gray)
if count == 1:
label1_6.set_text_color(color_deepskyblue)
if count == 2:
label1_6.set_text_color(color_lime)
if count >= 3:
label1_6.set_text_color(color_hotpink)
label1_6.set_hidden(False)
if pos_week == 1 and pos_day == 7:
if day > 0:
label1_7.set_text(str(day))
if count == 0:
label1_7.set_text_color(color_gray)
if count == 1:
label1_7.set_text_color(color_deepskyblue)
if count == 2:
label1_7.set_text_color(color_lime)
if count >= 3:
label1_7.set_text_color(color_hotpink)
label1_7.set_hidden(False)
if pos_week == 2 and pos_day == 1:
if day > 0:
label2_1.set_text(str(day))
if count == 0:
label2_1.set_text_color(color_gray)
if count == 1:
label2_1.set_text_color(color_deepskyblue)
if count == 2:
label2_1.set_text_color(color_lime)
if count >= 3:
label2_1.set_text_color(color_hotpink)
label2_1.set_hidden(False)
if pos_week == 2 and pos_day == 2:
if day > 0:
label2_2.set_text(str(day))
if count == 0:
label2_2.set_text_color(color_gray)
if count == 1:
label2_2.set_text_color(color_deepskyblue)
if count == 2:
label2_2.set_text_color(color_lime)
if count >= 3:
label2_2.set_text_color(color_hotpink)
label2_2.set_hidden(False)
if pos_week == 2 and pos_day == 3:
if day > 0:
label2_3.set_text(str(day))
if count == 0:
label2_3.set_text_color(color_gray)
if count == 1:
label2_3.set_text_color(color_deepskyblue)
if count == 2:
label2_3.set_text_color(color_lime)
if count >= 3:
label2_3.set_text_color(color_hotpink)
label2_3.set_hidden(False)
if pos_week == 2 and pos_day == 4:
if day > 0:
label2_4.set_text(str(day))
if count == 0:
label2_4.set_text_color(color_gray)
if count == 1:
label2_4.set_text_color(color_deepskyblue)
if count == 2:
label2_4.set_text_color(color_lime)
if count >= 3:
label2_4.set_text_color(color_hotpink)
label2_4.set_hidden(False)
if pos_week == 2 and pos_day == 5:
if day > 0:
label2_5.set_text(str(day))
if count == 0:
label2_5.set_text_color(color_gray)
if count == 1:
label2_5.set_text_color(color_deepskyblue)
if count == 2:
label2_5.set_text_color(color_lime)
if count >= 3:
label2_5.set_text_color(color_hotpink)
label2_5.set_hidden(False)
if pos_week == 2 and pos_day == 6:
if day > 0:
label2_6.set_text(str(day))
if count == 0:
label2_6.set_text_color(color_gray)
if count == 1:
label2_6.set_text_color(color_deepskyblue)
if count == 2:
label2_6.set_text_color(color_lime)
if count >= 3:
label2_6.set_text_color(color_hotpink)
label2_6.set_hidden(False)
if pos_week == 2 and pos_day == 7:
if day > 0:
label2_7.set_text(str(day))
if count == 0:
label2_7.set_text_color(color_gray)
if count == 1:
label2_7.set_text_color(color_deepskyblue)
if count == 2:
label2_7.set_text_color(color_lime)
if count >= 3:
label2_7.set_text_color(color_hotpink)
label2_7.set_hidden(False)
if pos_week == 3 and pos_day == 1:
if day > 0:
label3_1.set_text(str(day))
if count == 0:
label3_1.set_text_color(color_gray)
if count == 1:
label3_1.set_text_color(color_deepskyblue)
if count == 2:
label3_1.set_text_color(color_lime)
if count >= 3:
label3_1.set_text_color(color_hotpink)
label3_1.set_hidden(False)
if pos_week == 3 and pos_day == 2:
if day > 0:
label3_2.set_text(str(day))
if count == 0:
label3_2.set_text_color(color_gray)
if count == 1:
label3_2.set_text_color(color_deepskyblue)
if count == 2:
label3_2.set_text_color(color_lime)
if count >= 3:
label3_2.set_text_color(color_hotpink)
label3_2.set_hidden(False)
if pos_week == 3 and pos_day == 3:
if day > 0:
label3_3.set_text(str(day))
if count == 0:
label3_3.set_text_color(color_gray)
if count == 1:
label3_3.set_text_color(color_deepskyblue)
if count == 2:
label3_3.set_text_color(color_lime)
if count >= 3:
label3_3.set_text_color(color_hotpink)
label3_3.set_hidden(False)
if pos_week == 3 and pos_day == 4:
if day > 0:
label3_4.set_text(str(day))
if count == 0:
label3_4.set_text_color(color_gray)
if count == 1:
label3_4.set_text_color(color_deepskyblue)
if count == 2:
label3_4.set_text_color(color_lime)
if count >= 3:
label3_4.set_text_color(color_hotpink)
label3_4.set_hidden(False)
if pos_week == 3 and pos_day == 5:
if day > 0:
label3_5.set_text(str(day))
if count == 0:
label3_5.set_text_color(color_gray)
if count == 1:
label3_5.set_text_color(color_deepskyblue)
if count == 2:
label3_5.set_text_color(color_lime)
if count >= 3:
label3_5.set_text_color(color_hotpink)
label3_5.set_hidden(False)
if pos_week == 3 and pos_day == 6:
if day > 0:
label3_6.set_text(str(day))
if count == 0:
label3_6.set_text_color(color_gray)
if count == 1:
label3_6.set_text_color(color_deepskyblue)
if count == 2:
label3_6.set_text_color(color_lime)
if count >= 3:
label3_6.set_text_color(color_hotpink)
label3_6.set_hidden(False)
if pos_week == 3 and pos_day == 7:
if day > 0:
label3_7.set_text(str(day))
if count == 0:
label3_7.set_text_color(color_gray)
if count == 1:
label3_7.set_text_color(color_deepskyblue)
if count == 2:
label3_7.set_text_color(color_lime)
if count >= 3:
label3_7.set_text_color(color_hotpink)
label3_7.set_hidden(False)
if pos_week == 4 and pos_day == 1:
if day > 0:
label4_1.set_text(str(day))
if count == 0:
label4_1.set_text_color(color_gray)
if count == 1:
label4_1.set_text_color(color_deepskyblue)
if count == 2:
label4_1.set_text_color(color_lime)
if count >= 3:
label4_1.set_text_color(color_hotpink)
label4_1.set_hidden(False)
if pos_week == 4 and pos_day == 2:
if day > 0:
label4_2.set_text(str(day))
if count == 0:
label4_2.set_text_color(color_gray)
if count == 1:
label4_2.set_text_color(color_deepskyblue)
if count == 2:
label4_2.set_text_color(color_lime)
if count >= 3:
label4_2.set_text_color(color_hotpink)
label4_2.set_hidden(False)
if pos_week == 4 and pos_day == 3:
if day > 0:
label4_3.set_text(str(day))
if count == 0:
label4_3.set_text_color(color_gray)
if count == 1:
label4_3.set_text_color(color_deepskyblue)
if count == 2:
label4_3.set_text_color(color_lime)
if count >= 3:
label4_3.set_text_color(color_hotpink)
label4_3.set_hidden(False)
if pos_week == 4 and pos_day == 4:
if day > 0:
label4_4.set_text(str(day))
if count == 0:
label4_4.set_text_color(color_gray)
if count == 1:
label4_4.set_text_color(color_deepskyblue)
if count == 2:
label4_4.set_text_color(color_lime)
if count >= 3:
label4_4.set_text_color(color_hotpink)
label4_4.set_hidden(False)
if pos_week == 4 and pos_day == 5:
if day > 0:
label4_5.set_text(str(day))
if count == 0:
label4_5.set_text_color(color_gray)
if count == 1:
label4_5.set_text_color(color_deepskyblue)
if count == 2:
label4_5.set_text_color(color_lime)
if count >= 3:
label4_5.set_text_color(color_hotpink)
label4_5.set_hidden(False)
if pos_week == 4 and pos_day == 6:
if day > 0:
label4_6.set_text(str(day))
if count == 0:
label4_6.set_text_color(color_gray)
if count == 1:
label4_6.set_text_color(color_deepskyblue)
if count == 2:
label4_6.set_text_color(color_lime)
if count >= 3:
label4_6.set_text_color(color_hotpink)
label4_6.set_hidden(False)
if pos_week == 4 and pos_day == 7:
if day > 0:
label4_7.set_text(str(day))
if count == 0:
label4_7.set_text_color(color_gray)
if count == 1:
label4_7.set_text_color(color_deepskyblue)
if count == 2:
label4_7.set_text_color(color_lime)
if count >= 3:
label4_7.set_text_color(color_hotpink)
label4_7.set_hidden(False)
if pos_week == 5 and pos_day == 1:
if day > 0:
label5_1.set_text(str(day))
if count == 0:
label5_1.set_text_color(color_gray)
if count == 1:
label5_1.set_text_color(color_deepskyblue)
if count == 2:
label5_1.set_text_color(color_lime)
if count >= 3:
label5_1.set_text_color(color_hotpink)
label5_1.set_hidden(False)
if pos_week == 5 and pos_day == 2:
if day > 0:
label5_2.set_text(str(day))
if count == 0:
label5_2.set_text_color(color_gray)
if count == 1:
label5_2.set_text_color(color_deepskyblue)
if count == 2:
label5_2.set_text_color(color_lime)
if count >= 3:
label5_2.set_text_color(color_hotpink)
label5_2.set_hidden(False)
if pos_week == 5 and pos_day == 3:
if day > 0:
label5_3.set_text(str(day))
if count == 0:
label5_3.set_text_color(color_gray)
if count == 1:
label5_3.set_text_color(color_deepskyblue)
if count == 2:
label5_3.set_text_color(color_lime)
if count >= 3:
label5_3.set_text_color(color_hotpink)
label5_3.set_hidden(False)
if pos_week == 5 and pos_day == 4:
if day > 0:
label5_4.set_text(str(day))
if count == 0:
label5_4.set_text_color(color_gray)
if count == 1:
label5_4.set_text_color(color_deepskyblue)
if count == 2:
label5_4.set_text_color(color_lime)
if count >= 3:
label5_4.set_text_color(color_hotpink)
label5_4.set_hidden(False)
if pos_week == 5 and pos_day == 5:
if day > 0:
label5_5.set_text(str(day))
if count == 0:
label5_5.set_text_color(color_gray)
if count == 1:
label5_5.set_text_color(color_deepskyblue)
if count == 2:
label5_5.set_text_color(color_lime)
if count >= 3:
label5_5.set_text_color(color_hotpink)
label5_5.set_hidden(False)
if pos_week == 5 and pos_day == 6:
if day > 0:
label5_6.set_text(str(day))
if count == 0:
label5_6.set_text_color(color_gray)
if count == 1:
label5_6.set_text_color(color_deepskyblue)
if count == 2:
label5_6.set_text_color(color_lime)
if count >= 3:
label5_6.set_text_color(color_hotpink)
label5_6.set_hidden(False)
if pos_week == 5 and pos_day == 7:
if day > 0:
label5_7.set_text(str(day))
if count == 0:
label5_7.set_text_color(color_gray)
if count == 1:
label5_7.set_text_color(color_deepskyblue)
if count == 2:
label5_7.set_text_color(color_lime)
if count >= 3:
label5_7.set_text_color(color_hotpink)
label5_7.set_hidden(False)
if pos_week == 6 and pos_day == 1:
if day > 0:
label6_1.set_text(str(day))
if count == 0:
label6_1.set_text_color(color_gray)
if count == 1:
label6_1.set_text_color(color_deepskyblue)
if count == 2:
label6_1.set_text_color(color_lime)
if count >= 3:
label6_1.set_text_color(color_hotpink)
label6_1.set_hidden(False)
if pos_week == 6 and pos_day == 2:
if day > 0:
label6_2.set_text(str(day))
if count == 0:
label6_2.set_text_color(color_gray)
if count == 1:
label6_2.set_text_color(color_deepskyblue)
if count == 2:
label6_2.set_text_color(color_lime)
if count >= 3:
label6_2.set_text_color(color_hotpink)
label6_2.set_hidden(False)
if pos_week == 6 and pos_day == 3:
if day > 0:
label6_3.set_text(str(day))
if count == 0:
label6_3.set_text_color(color_gray)
if count == 1:
label6_3.set_text_color(color_deepskyblue)
if count == 2:
label6_3.set_text_color(color_lime)
if count >= 3:
label6_3.set_text_color(color_hotpink)
label6_3.set_hidden(False)
if pos_week == 6 and pos_day == 4:
if day > 0:
label6_4.set_text(str(day))
if count == 0:
label6_4.set_text_color(color_gray)
if count == 1:
label6_4.set_text_color(color_deepskyblue)
if count == 2:
label6_4.set_text_color(color_lime)
if count >= 3:
label6_4.set_text_color(color_hotpink)
label6_4.set_hidden(False)
if pos_week == 6 and pos_day == 5:
if day > 0:
label6_5.set_text(str(day))
if count == 0:
label6_5.set_text_color(color_gray)
if count == 1:
label6_5.set_text_color(color_deepskyblue)
if count == 2:
label6_5.set_text_color(color_lime)
if count >= 3:
label6_5.set_text_color(color_hotpink)
label6_5.set_hidden(False)
if pos_week == 6 and pos_day == 6:
if day > 0:
label6_6.set_text(str(day))
if count == 0:
label6_6.set_text_color(color_gray)
if count == 1:
label6_6.set_text_color(color_deepskyblue)
if count == 2:
label6_6.set_text_color(color_lime)
if count >= 3:
label6_6.set_text_color(color_hotpink)
label6_6.set_hidden(False)
if pos_week == 6 and pos_day == 7:
if day > 0:
label6_7.set_text(str(day))
if count == 0:
label6_7.set_text_color(color_gray)
if count == 1:
label6_7.set_text_color(color_deepskyblue)
if count == 2:
label6_7.set_text_color(color_lime)
if count >= 3:
label6_7.set_text_color(color_hotpink)
label6_7.set_hidden(False)
# 本体のAボタン(左)が押された時のイベント
def buttonA_wasPressed():
global target_month, target_year, monthDataList, jsonData, pos_week, day, pos_day, api_url, count, color_gray, color_deepskyblue, color_lime, weekDataList, color_hotpink, dayData
power.setVibrationEnable(True)
wait(0.2)
power.setVibrationEnable(False)
target_month = (target_month if isinstance(target_month, Number) else 0) + -1
if target_month < 1:
target_year = (target_year if isinstance(target_year, Number) else 0) + -1
target_month = 12
# 関数コール:カレンダー情報取得
getCalenderData()
pass
btnA.wasPressed(buttonA_wasPressed)
# 本体のBボタン(真ん中)が押された時のイベント
def buttonB_wasPressed():
global target_month, target_year, monthDataList, jsonData, pos_week, day, pos_day, api_url, count, color_gray, color_deepskyblue, color_lime, weekDataList, color_hotpink, dayData
power.setVibrationEnable(True)
wait(0.2)
power.setVibrationEnable(False)
target_year = rtc.datetime()[0]
target_month = rtc.datetime()[1]
# 関数コール:カレンダー情報取得
getCalenderData()
pass
btnB.wasPressed(buttonB_wasPressed)
# 本体のCボタン(右)が押された時のイベント
def buttonC_wasPressed():
global target_month, target_year, monthDataList, jsonData, pos_week, day, pos_day, api_url, count, color_gray, color_deepskyblue, color_lime, weekDataList, color_hotpink, dayData
power.setVibrationEnable(True)
wait(0.2)
power.setVibrationEnable(False)
target_month = (target_month if isinstance(target_month, Number) else 0) + 1
if target_month > 12:
target_year = (target_year if isinstance(target_year, Number) else 0) + 1
target_month = 1
# 関数コール:カレンダー情報取得
getCalenderData()
pass
btnC.wasPressed(buttonC_wasPressed)
# ここから起動スタート
# 初期状態の画面を見せないように画面を暗くする
screen.set_screen_brightness(0)
# Wifiと接続する
wifiCfg.doConnect('wifi-ssid', 'wifi-password')
# Wifiの接続が完了するまで待機する
while not (wifiCfg.wlan_sta.isconnected()):
wait(1)
# NTPで時刻合わせ
rtc.settime('ntp', host='jp.pool.ntp.org', tzone=9)
# 対象年を変数にセット
target_year = rtc.datetime()[0]
# 対象月を変数にセット
target_month = rtc.datetime()[1]
# WebAPIのURLを変数にセット
api_url = 'https://xxx.execute-api.ap-northeast-1.amazonaws.com'
# 灰色のRBGを変数にセット
color_gray = 0x808080
# 水色のRGBを変数にセット
color_deepskyblue = 0x00bfff
# 黄緑色のRGBを変数にセット
color_lime = 0x00ff00
# ピンク色のRGBを変数にセット
color_hotpink = 0xe169b4
# 関数コール:カレンダー情報取得
getCalenderData()
# 画面表示が完了したら画面の明るさを戻す
screen.set_screen_brightness(100)