mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-07 00:52:49 +08:00
remember display mode
This commit is contained in:
@@ -16,6 +16,7 @@ typedef struct
|
|||||||
uint8_t wakeup_pin;
|
uint8_t wakeup_pin;
|
||||||
uint8_t led_pin;
|
uint8_t led_pin;
|
||||||
uint8_t en_pin;
|
uint8_t en_pin;
|
||||||
|
uint8_t display_mode;
|
||||||
} epd_config_t;
|
} epd_config_t;
|
||||||
|
|
||||||
#define EPD_CONFIG_SIZE (sizeof(epd_config_t) / sizeof(uint8_t))
|
#define EPD_CONFIG_SIZE (sizeof(epd_config_t) / sizeof(uint8_t))
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ static void epd_gui_update(void * p_event_data, uint16_t event_size)
|
|||||||
.temperature = epd->drv->read_temp(),
|
.temperature = epd->drv->read_temp(),
|
||||||
.voltage = EPD_ReadVoltage(),
|
.voltage = EPD_ReadVoltage(),
|
||||||
};
|
};
|
||||||
DrawGUI(&data, epd->drv->write_image, p_epd->display_mode);
|
DrawGUI(&data, epd->drv->write_image, (display_mode_t)p_epd->config.display_mode);
|
||||||
epd->drv->refresh();
|
epd->drv->refresh();
|
||||||
EPD_GPIO_Uninit();
|
EPD_GPIO_Uninit();
|
||||||
|
|
||||||
@@ -77,6 +77,14 @@ static void on_disconnect(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
|
|||||||
EPD_GPIO_Uninit();
|
EPD_GPIO_Uninit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void epd_update_display_mode(ble_epd_t * p_epd, display_mode_t mode)
|
||||||
|
{
|
||||||
|
if (p_epd->config.display_mode != mode) {
|
||||||
|
p_epd->config.display_mode = mode;
|
||||||
|
epd_config_write(&p_epd->config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void epd_service_on_write(ble_epd_t * p_epd, uint8_t * p_data, uint16_t length)
|
static void epd_service_on_write(ble_epd_t * p_epd, uint8_t * p_data, uint16_t length)
|
||||||
{
|
{
|
||||||
NRF_LOG_DEBUG("[EPD]: on_write LEN=%d\n", length);
|
NRF_LOG_DEBUG("[EPD]: on_write LEN=%d\n", length);
|
||||||
@@ -114,7 +122,7 @@ static void epd_service_on_write(ble_epd_t * p_epd, uint8_t * p_data, uint16_t l
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case EPD_CMD_CLEAR:
|
case EPD_CMD_CLEAR:
|
||||||
p_epd->display_mode = MODE_NONE;
|
epd_update_display_mode(p_epd, MODE_PICTURE);
|
||||||
p_epd->epd->drv->clear(length > 1 ? p_data[1] : true);
|
p_epd->epd->drv->clear(length > 1 ? p_data[1] : true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -128,7 +136,7 @@ static void epd_service_on_write(ble_epd_t * p_epd, uint8_t * p_data, uint16_t l
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case EPD_CMD_REFRESH:
|
case EPD_CMD_REFRESH:
|
||||||
p_epd->display_mode = MODE_NONE;
|
epd_update_display_mode(p_epd, MODE_PICTURE);
|
||||||
p_epd->epd->drv->refresh();
|
p_epd->epd->drv->refresh();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -145,7 +153,7 @@ static void epd_service_on_write(ble_epd_t * p_epd, uint8_t * p_data, uint16_t l
|
|||||||
uint32_t timestamp = (p_data[1] << 24) | (p_data[2] << 16) | (p_data[3] << 8) | p_data[4];
|
uint32_t timestamp = (p_data[1] << 24) | (p_data[2] << 16) | (p_data[3] << 8) | p_data[4];
|
||||||
timestamp += (length > 5 ? (int8_t)p_data[5] : 8) * 60 * 60; // timezone
|
timestamp += (length > 5 ? (int8_t)p_data[5] : 8) * 60 * 60; // timezone
|
||||||
set_timestamp(timestamp);
|
set_timestamp(timestamp);
|
||||||
p_epd->display_mode = length > 6 ? (display_mode_t)p_data[6] : MODE_CALENDAR;
|
epd_update_display_mode(p_epd, length > 6 ? (display_mode_t)p_data[6] : MODE_CALENDAR);
|
||||||
ble_epd_on_timer(p_epd, timestamp, true);
|
ble_epd_on_timer(p_epd, timestamp, true);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@@ -329,12 +337,14 @@ uint32_t ble_epd_init(ble_epd_t * p_epd)
|
|||||||
|
|
||||||
epd_config_init(&p_epd->config);
|
epd_config_init(&p_epd->config);
|
||||||
epd_config_read(&p_epd->config);
|
epd_config_read(&p_epd->config);
|
||||||
|
|
||||||
// write default config
|
// write default config
|
||||||
if (epd_config_empty(&p_epd->config))
|
if (epd_config_empty(&p_epd->config))
|
||||||
{
|
{
|
||||||
uint8_t cfg[] = EPD_CFG_DEFAULT;
|
uint8_t cfg[] = EPD_CFG_DEFAULT;
|
||||||
memcpy(&p_epd->config, cfg, sizeof(cfg));
|
memcpy(&p_epd->config, cfg, sizeof(cfg));
|
||||||
|
if (p_epd->config.display_mode == 0xFF)
|
||||||
|
p_epd->config.display_mode = MODE_CALENDAR;
|
||||||
epd_config_write(&p_epd->config);
|
epd_config_write(&p_epd->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,8 +381,8 @@ void ble_epd_on_timer(ble_epd_t * p_epd, uint32_t timestamp, bool force_update)
|
|||||||
{
|
{
|
||||||
// Update calendar on 00:00:00, clock on every minute
|
// Update calendar on 00:00:00, clock on every minute
|
||||||
if (force_update ||
|
if (force_update ||
|
||||||
(p_epd->display_mode == MODE_CALENDAR && timestamp % 86400 == 0) ||
|
(p_epd->config.display_mode == MODE_CALENDAR && timestamp % 86400 == 0) ||
|
||||||
(p_epd->display_mode == MODE_CLOCK && timestamp % 60 == 0)) {
|
(p_epd->config.display_mode == MODE_CLOCK && timestamp % 60 == 0)) {
|
||||||
epd_gui_update_event_t event = { p_epd, timestamp };
|
epd_gui_update_event_t event = { p_epd, timestamp };
|
||||||
app_sched_event_put(&event, sizeof(epd_gui_update_event_t), epd_gui_update);
|
app_sched_event_put(&event, sizeof(epd_gui_update_event_t), epd_gui_update);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ typedef struct
|
|||||||
bool is_notification_enabled; /**< Variable to indicate if the peer has enabled notification of the RX characteristic.*/
|
bool is_notification_enabled; /**< Variable to indicate if the peer has enabled notification of the RX characteristic.*/
|
||||||
epd_model_t *epd; /**< current EPD model */
|
epd_model_t *epd; /**< current EPD model */
|
||||||
epd_config_t config; /**< EPD config */
|
epd_config_t config; /**< EPD config */
|
||||||
display_mode_t display_mode; /**< GUI display mode */
|
|
||||||
} ble_epd_t;
|
} ble_epd_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|||||||
26
GUI/GUI.c
26
GUI/GUI.c
@@ -119,16 +119,30 @@ static bool GetFestival(uint16_t year, uint8_t mon, uint8_t day, uint8_t week,
|
|||||||
if (GetJieQi(year, mon, day, &JQdate) && JQdate == day) {
|
if (GetJieQi(year, mon, day, &JQdate) && JQdate == day) {
|
||||||
uint8_t JQ = (mon - 1) * 2;
|
uint8_t JQ = (mon - 1) * 2;
|
||||||
if (day >= 15) JQ++;
|
if (day >= 15) JQ++;
|
||||||
|
strcpy(festival, JieQiStr[JQ]);
|
||||||
if (JQ == 6) // 清明
|
if (JQ == 6) // 清明
|
||||||
sprintf(festival, "%s节", JieQiStr[JQ]);
|
strcat(festival, "节");
|
||||||
else
|
|
||||||
strcpy(festival, JieQiStr[JQ]);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DrawTimeSyncTip(Adafruit_GFX *gfx)
|
||||||
|
{
|
||||||
|
GFX_setFont(gfx, u8g2_font_wqy12_t_lunar);
|
||||||
|
GFX_fillRect(gfx, gfx->_width / 2 - 100, gfx->_height / 2 - 25, 200, 50, GFX_WHITE);
|
||||||
|
GFX_drawRoundRect(gfx, gfx->_width / 2 - 100, gfx->_height / 2 - 25, 200, 50, 5, GFX_BLACK);
|
||||||
|
GFX_setTextColor(gfx, GFX_RED, GFX_WHITE);
|
||||||
|
GFX_setCursor(gfx, 149, 145);
|
||||||
|
GFX_printf(gfx, "SYNC TIME!");
|
||||||
|
GFX_setTextColor(gfx, GFX_BLACK, GFX_WHITE);
|
||||||
|
GFX_setCursor(gfx, 110, 164);
|
||||||
|
GFX_setFont(gfx, u8g2_font_wqy9_t_lunar);
|
||||||
|
GFX_printf(gfx, "https://tsl0922.github.io/EPD-nRF5");
|
||||||
|
}
|
||||||
|
|
||||||
static void DrawBattery(Adafruit_GFX *gfx, int16_t x, int16_t y, float voltage)
|
static void DrawBattery(Adafruit_GFX *gfx, int16_t x, int16_t y, float voltage)
|
||||||
{
|
{
|
||||||
uint8_t level = (uint8_t)(voltage * 100 / 4.2);
|
uint8_t level = (uint8_t)(voltage * 100 / 4.2);
|
||||||
@@ -165,7 +179,7 @@ static void DrawDateHeader(Adafruit_GFX *gfx, int16_t x, int16_t y, tm_t *tm, st
|
|||||||
GFX_setFont(gfx, u8g2_font_wqy9_t_lunar);
|
GFX_setFont(gfx, u8g2_font_wqy9_t_lunar);
|
||||||
GFX_printf(gfx, "星期%s", Lunar_DayString[tm->tm_wday]);
|
GFX_printf(gfx, "星期%s", Lunar_DayString[tm->tm_wday]);
|
||||||
|
|
||||||
DrawBattery(gfx, 365, 4, data->voltage);
|
DrawBattery(gfx, 365, 6, data->voltage);
|
||||||
|
|
||||||
GFX_setCursor(gfx, x + 270, y);
|
GFX_setCursor(gfx, x + 270, y);
|
||||||
GFX_printf(gfx, "%s%s%s %s%s", Lunar_MonthLeapString[Lunar->IsLeap], Lunar_MonthString[Lunar->Month],
|
GFX_printf(gfx, "%s%s%s %s%s", Lunar_MonthLeapString[Lunar->IsLeap], Lunar_MonthString[Lunar->Month],
|
||||||
@@ -357,6 +371,10 @@ void DrawGUI(gui_data_t *data, buffer_callback draw, display_mode_t mode)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if ((mode == MODE_CALENDAR || mode == MODE_CLOCK) &&
|
||||||
|
(tm.tm_year + YEAR0 == 2025 && tm.tm_mon + 1 == 1)) {
|
||||||
|
DrawTimeSyncTip(&gfx);
|
||||||
|
}
|
||||||
} while(GFX_nextPage(&gfx, draw));
|
} while(GFX_nextPage(&gfx, draw));
|
||||||
|
|
||||||
GFX_end(&gfx);
|
GFX_end(&gfx);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MODE_NONE = 0,
|
MODE_PICTURE = 0,
|
||||||
MODE_CALENDAR = 1,
|
MODE_CALENDAR = 1,
|
||||||
MODE_CLOCK = 2,
|
MODE_CLOCK = 2,
|
||||||
} display_mode_t;
|
} display_mode_t;
|
||||||
|
|||||||
13
main.c
13
main.c
@@ -417,6 +417,9 @@ void gpiote_evt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
|
|||||||
nrf_drv_gpiote_in_uninit(pin);
|
nrf_drv_gpiote_in_uninit(pin);
|
||||||
nrf_drv_gpiote_uninit();
|
nrf_drv_gpiote_uninit();
|
||||||
|
|
||||||
|
// blink LED on wakeup
|
||||||
|
EPD_LED_BLINK();
|
||||||
|
|
||||||
advertising_start();
|
advertising_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,10 +448,10 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
|
|||||||
case BLE_ADV_EVT_IDLE:
|
case BLE_ADV_EVT_IDLE:
|
||||||
NRF_LOG_INFO("advertising timeout\n");
|
NRF_LOG_INFO("advertising timeout\n");
|
||||||
if (m_epd.config.wakeup_pin != 0xFF) {
|
if (m_epd.config.wakeup_pin != 0xFF) {
|
||||||
if (m_epd.display_mode != MODE_NONE)
|
if (m_epd.config.display_mode == MODE_PICTURE)
|
||||||
setup_wakeup_pin(m_epd.config.wakeup_pin);
|
|
||||||
else
|
|
||||||
sleep_mode_enter();
|
sleep_mode_enter();
|
||||||
|
else
|
||||||
|
setup_wakeup_pin(m_epd.config.wakeup_pin);
|
||||||
} else {
|
} else {
|
||||||
advertising_start();
|
advertising_start();
|
||||||
}
|
}
|
||||||
@@ -788,8 +791,10 @@ int main(void)
|
|||||||
NRF_LOG_DEBUG("done.\n");
|
NRF_LOG_DEBUG("done.\n");
|
||||||
|
|
||||||
if (m_resetreas & NRF_POWER_RESETREAS_DOG_MASK) {
|
if (m_resetreas & NRF_POWER_RESETREAS_DOG_MASK) {
|
||||||
m_epd.display_mode = MODE_CALENDAR;
|
m_epd.config.display_mode = MODE_CALENDAR;
|
||||||
ble_epd_on_timer(&m_epd, 0, true);
|
ble_epd_on_timer(&m_epd, 0, true);
|
||||||
|
} else {
|
||||||
|
ble_epd_on_timer(&m_epd, m_timestamp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
|
|||||||
Reference in New Issue
Block a user