mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-06 08:32:54 +08:00
remember display mode
This commit is contained in:
@@ -16,6 +16,7 @@ typedef struct
|
||||
uint8_t wakeup_pin;
|
||||
uint8_t led_pin;
|
||||
uint8_t en_pin;
|
||||
uint8_t display_mode;
|
||||
} epd_config_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(),
|
||||
.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_GPIO_Uninit();
|
||||
|
||||
@@ -77,6 +77,14 @@ static void on_disconnect(ble_epd_t * p_epd, ble_evt_t * p_ble_evt)
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
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);
|
||||
break;
|
||||
|
||||
@@ -128,7 +136,7 @@ static void epd_service_on_write(ble_epd_t * p_epd, uint8_t * p_data, uint16_t l
|
||||
break;
|
||||
|
||||
case EPD_CMD_REFRESH:
|
||||
p_epd->display_mode = MODE_NONE;
|
||||
epd_update_display_mode(p_epd, MODE_PICTURE);
|
||||
p_epd->epd->drv->refresh();
|
||||
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];
|
||||
timestamp += (length > 5 ? (int8_t)p_data[5] : 8) * 60 * 60; // timezone
|
||||
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);
|
||||
} break;
|
||||
|
||||
@@ -329,12 +337,14 @@ uint32_t ble_epd_init(ble_epd_t * p_epd)
|
||||
|
||||
epd_config_init(&p_epd->config);
|
||||
epd_config_read(&p_epd->config);
|
||||
|
||||
|
||||
// write default config
|
||||
if (epd_config_empty(&p_epd->config))
|
||||
{
|
||||
uint8_t cfg[] = EPD_CFG_DEFAULT;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
if (force_update ||
|
||||
(p_epd->display_mode == MODE_CALENDAR && timestamp % 86400 == 0) ||
|
||||
(p_epd->display_mode == MODE_CLOCK && timestamp % 60 == 0)) {
|
||||
(p_epd->config.display_mode == MODE_CALENDAR && timestamp % 86400 == 0) ||
|
||||
(p_epd->config.display_mode == MODE_CLOCK && timestamp % 60 == 0)) {
|
||||
epd_gui_update_event_t event = { p_epd, timestamp };
|
||||
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.*/
|
||||
epd_model_t *epd; /**< current EPD model */
|
||||
epd_config_t config; /**< EPD config */
|
||||
display_mode_t display_mode; /**< GUI display mode */
|
||||
} ble_epd_t;
|
||||
|
||||
typedef struct
|
||||
|
||||
Reference in New Issue
Block a user