add week start setting

This commit is contained in:
Shuanglei Tao
2025-07-03 11:51:37 +08:00
parent 714adab127
commit f821b56c0b
6 changed files with 60 additions and 32 deletions

View File

@@ -208,34 +208,39 @@ static void DrawDateHeader(Adafruit_GFX *gfx, int16_t x, int16_t y, tm_t *tm, st
GFX_printf(gfx, "%s", data->ssid);
}
static void DrawWeekHeader(Adafruit_GFX *gfx, int16_t x, int16_t y)
static void DrawWeekHeader(Adafruit_GFX *gfx, int16_t x, int16_t y, gui_data_t *data)
{
GFX_fillRect(gfx, x, y, 380, 24, GFX_RED);
GFX_fillRect(gfx, x + 50, y, 280, 24, GFX_BLACK);
GFX_setFont(gfx, u8g2_font_wqy9_t_lunar);
uint8_t w = (data->width - 2 * x) / 7;
uint8_t r = (data->width - 2 * x) % 7;
for (int i = 0; i < 7; i++) {
GFX_setTextColor(gfx, GFX_WHITE, (i > 0 && i < 6) ? GFX_BLACK : GFX_RED);
GFX_setCursor(gfx, x + 15 + i * 55, y + 16);
GFX_printf(gfx, "%s", Lunar_DayString[i]);
uint8_t day = (data->week_start + i) % 7;
uint16_t bg = (day == 0 || day == 6) ? GFX_RED : GFX_BLACK;
GFX_fillRect(gfx, x + i * w, y, i == 6 ? (w + r) : w, 24, bg);
GFX_setTextColor(gfx, GFX_WHITE, bg);
GFX_setCursor(gfx, x + 18 + i * w, y + 16);
GFX_printf(gfx, "%s", Lunar_DayString[day]);
}
}
static void DrawMonthDays(Adafruit_GFX *gfx, tm_t *tm, struct Lunar_Date *Lunar)
static void DrawMonthDays(Adafruit_GFX *gfx, tm_t *tm, struct Lunar_Date *Lunar, gui_data_t *data)
{
uint8_t firstDayWeek = get_first_day_week(tm->tm_year + YEAR0, tm->tm_mon + 1);
int8_t adjustedFirstDay = (firstDayWeek - data->week_start + 7) % 7;
uint8_t monthMaxDays = thisMonthMaxDays(tm->tm_year + YEAR0, tm->tm_mon + 1);
uint8_t monthDayRows = 1 + (monthMaxDays - (7 - firstDayWeek) + 6) / 7;
uint8_t monthDayRows = 1 + (monthMaxDays - (7 - adjustedFirstDay) + 6) / 7;
for (uint8_t i = 0; i < monthMaxDays; i++) {
uint16_t year = tm->tm_year + YEAR0;
uint8_t month = tm->tm_mon + 1;
uint8_t day = i + 1;
int16_t week = (firstDayWeek + i) % 7;
bool weekend = (week == 0) || (week == 6);
int16_t actualWeek = (firstDayWeek + i) % 7;
int16_t displayWeek = (adjustedFirstDay + i) % 7;
bool weekend = (actualWeek == 0) || (actualWeek == 6);
int16_t x = 22 + week * 55;
int16_t y = (monthDayRows > 5 ? 69 : 72) + (firstDayWeek + i) / 7 * (monthDayRows > 5 ? 39 : 48);
int16_t x = 22 + displayWeek * 55;
int16_t y = (monthDayRows > 5 ? 69 : 72) + (adjustedFirstDay + i) / 7 * (monthDayRows > 5 ? 39 : 48);
if (day == tm->tm_mday) {
GFX_fillCircle(gfx, x + 11, y + (monthDayRows > 5 ? 10 : 12), 22, GFX_RED);
@@ -252,7 +257,7 @@ static void DrawMonthDays(Adafruit_GFX *gfx, tm_t *tm, struct Lunar_Date *Lunar)
LUNAR_SolarToLunar(Lunar, year, month, day);
char festival[10] = {0};
if (GetFestival(year, month, day, week, Lunar, festival)) {
if (GetFestival(year, month, day, actualWeek, Lunar, festival)) {
if (day != tm->tm_mday) GFX_setTextColor(gfx, GFX_RED, GFX_WHITE);
GFX_setCursor(gfx, strlen(festival) > 6 ? x - 6 : x, y + 24);
GFX_printf(gfx, "%s", festival);
@@ -281,8 +286,8 @@ static void DrawMonthDays(Adafruit_GFX *gfx, tm_t *tm, struct Lunar_Date *Lunar)
static void DrawCalendar(Adafruit_GFX *gfx, tm_t *tm, struct Lunar_Date *Lunar, gui_data_t *data)
{
DrawDateHeader(gfx, 10, 28, tm, Lunar, data);
DrawWeekHeader(gfx, 10, 32);
DrawMonthDays(gfx, tm, Lunar);
DrawWeekHeader(gfx, 10, 32, data);
DrawMonthDays(gfx, tm, Lunar, data);
}
/* Routine to Draw Large 7-Segment formated number
@@ -369,6 +374,8 @@ static void DrawClock(Adafruit_GFX *gfx, tm_t *tm, struct Lunar_Date *Lunar, gui
void DrawGUI(gui_data_t *data, buffer_callback draw, display_mode_t mode)
{
if (data->week_start > 6 || data->week_start < 0) data->week_start = 0;
tm_t tm = {0};
struct Lunar_Date Lunar;