初步完善时钟功能

This commit is contained in:
tpu
2025-05-14 17:23:41 +08:00
parent 89203f5b7a
commit 3ff35ffed1
6 changed files with 94 additions and 73 deletions

View File

@@ -77,6 +77,7 @@
/* It allows developer to hot attach debugger and get debug information */
/****************************************************************************************************************/
#define CFG_DEVELOPMENT_DEBUG
#undef CFG_DEVELOPMENT_DEBUG
/****************************************************************************************************************/
/* UART Console Print. If CFG_PRINTF is defined, serial interface logging mechanism will be enabled. */

View File

@@ -55,7 +55,7 @@
****************************************************************************************
*/
#define EPD_VERSION 0xA50f0005
#define EPD_VERSION 0xA50f0001
/*

View File

@@ -224,11 +224,8 @@ int epd_lut_size(void)
void epd_init(void)
{
epd_hw_open();
//printk("epd_init: %dx%d\n", scr_w, scr_h);
printk("epd_init: %dx%d\n", scr_w, scr_h);
update_mode = UPDATE_FULL;
epd_power(1);
epd_reset(1);

View File

@@ -88,6 +88,7 @@ void fb_test(void);
#define UPDATE_FAST 1
#define UPDATE_FLY 2
#define DRAW_BT 0x80
extern int scr_w;
extern int scr_h;

View File

@@ -110,6 +110,12 @@ void date_inc(void)
}
}
// 0: 状态不变
// 1: 分钟改变
// 2: 分钟改变10分钟
// 3: 小时改变
// 4: 天数改变
int clock_update(int inc)
{
int retv = 0;
@@ -178,6 +184,11 @@ void clock_print(void)
/****************************************************************************************/
static char *wday_str[] = {"", "", "", "", "", "", ""};
static int epd_wait_state;
static timer_hnd epd_wait_hnd;
static uint8_t batt_cal(uint16_t adc_sample)
{
uint8_t batt_lvl;
@@ -196,15 +207,15 @@ static uint8_t batt_cal(uint16_t adc_sample)
return batt_lvl;
}
static void draw_batt(void)
static void draw_batt(int x, int y)
{
int p = batt_cal(adcval);
p /= 10;
draw_rect(190, 8, 202, 14, BLACK);
draw_box(188, 10, 189, 12, BLACK);
draw_rect(x, y-4, x+14, y+4, BLACK);
draw_box(x-2, y-1, x-1, y+1, BLACK);
draw_box(201-p, 9, 201, 13, BLACK);
draw_box(x+12-p, y-2, x+12, y+2, BLACK);
}
static void draw_bt(int x, int y)
@@ -222,41 +233,52 @@ static void draw_bt(int x, int y)
}
char *wday_str[] = {"", "", "", "", "", "", ""};
static void epd_wait_timer(void)
{
if(epd_busy()){
epd_wait_hnd = app_easy_timer(40, epd_wait_timer);
}else{
epd_wait_hnd = EASY_TIMER_INVALID_TIMER;
epd_cmd1(0x10, 0x01);
epd_power(0);
epd_hw_close();
arch_set_sleep_mode(ARCH_EXT_SLEEP_ON);
}
}
void clock_draw(int full)
void clock_draw(int flags)
{
char tbuf[64];
epd_init();
epd_hw_open();
epd_update_mode(flags&3);
memset(fb_bw, 0xff, scr_h*line_bytes);
memset(fb_rr, 0x00, scr_h*line_bytes);
draw_batt();
draw_bt(180, 11);
draw_batt(190, 13);
if(flags&DRAW_BT){
draw_bt(180, 13);
}
select_font(1);
sprintf(tbuf, "%02d:%02d", hour, minute);
draw_text(12, 20, tbuf, BLACK);
draw_text(12, 25, tbuf, BLACK);
sprintf(tbuf, "%4d年%2d月%2d日 星期%s", year, month+1, date+1, wday_str[wday]);
sprintf(tbuf, "%4d年%2d月%2d日 星期%s", year, month+1, date+1, wday_str[wday]);
select_font(0);
draw_text(15, 85, tbuf, BLACK);
epd_screen_update();
draw_text(15, 8, tbuf, BLACK);
if(full){
epd_update_mode(UPDATE_FULL);
}else{
epd_update_mode(UPDATE_FLY);
}
epd_update();
epd_wait();
draw_text(12, 85, "十二月初二", BLACK);
epd_cmd1(0x10, 0x01);
epd_power(0);
epd_hw_close();
epd_init();
epd_screen_update();
epd_update();
arch_set_sleep_mode(ARCH_SLEEP_OFF);
epd_wait_hnd = app_easy_timer(40, epd_wait_timer);
}
@@ -274,7 +296,7 @@ void user_svc1_long_val_wr_ind_handler(ke_msg_id_t const msgid, struct custs1_va
printk("Long value: %d\n", param->length);
if(param->value[0]==0x91){
clock_set((uint8_t*)param->value);
// clock_draw(1);
clock_draw(DRAW_BT|UPDATE_FAST);
clock_print();
}
}

View File

@@ -60,14 +60,6 @@
****************************************************************************************
*/
// Manufacturer Specific Data ADV structure type
struct mnf_specific_data_ad_structure
{
uint8_t ad_structure_size;
uint8_t ad_structure_type;
uint8_t company_id[APP_AD_MSD_COMPANY_ID_LEN];
uint8_t proprietary_data[APP_AD_MSD_DATA_LEN];
};
/*
* GLOBAL VARIABLE DEFINITIONS
@@ -78,6 +70,13 @@ uint8_t app_connection_idx __SECTION_ZERO("retention_mem_ar
timer_hnd app_clock_timer_used __SECTION_ZERO("retention_mem_area0"); //@RETENTION MEMORY
timer_hnd app_param_update_request_timer_used __SECTION_ZERO("retention_mem_area0");
static int adv_state;
static int otp_btaddr[2];
static int otp_boot;
static char adv_name[20];
int clock_interval;
/*
* FUNCTION DEFINITIONS
****************************************************************************************
@@ -135,10 +134,6 @@ static void param_update_request_timer_cb()
app_param_update_request_timer_used = EASY_TIMER_INVALID_TIMER;
}
static int adv_count;
int otp_btaddr[2];
int otp_boot;
char adv_name[20];
static void read_otp_value(void)
{
@@ -181,7 +176,8 @@ void user_app_init(void)
app_param_update_request_timer_used = EASY_TIMER_INVALID_TIMER;
app_clock_timer_used = EASY_TIMER_INVALID_TIMER;
adv_count = 0;
clock_interval = 60; // 60s
adv_state = 0;
fspi_config(0x00030605);
epd_hw_init(0x23200700, 0x05210006, 104, 212, ROTATE_3); // for 2.13 board BW
@@ -190,44 +186,38 @@ void user_app_init(void)
default_app_on_init();
}
void user_app_before_sleep(void)
{
epd_hw_close();
}
void epd_test(void);
void epd_test2(void);
static void app_clock_timer_cb(void)
{
app_clock_timer_used = app_easy_timer(1000, app_clock_timer_cb);
app_clock_timer_used = app_easy_timer(clock_interval*100, app_clock_timer_cb);
int stat = clock_update(10);
int stat = clock_update(clock_interval);
clock_print();
if(stat>0){
int full = (stat>1)? 1:0;
clock_draw(full);
int flags = UPDATE_FLY;
if(stat>=3){
flags = DRAW_BT | UPDATE_FULL;
}else if(stat>=2){
flags = DRAW_BT | UPDATE_FAST;
}
if(adv_count<20){
if(adv_count>=12){
adv_count = 0;
user_app_adv_start();
}else{
adv_count += 1;
}
if(flags==4){
adc1_update();
}
if(flags&DRAW_BT){
user_app_adv_start();
}
if(stat>0 || flags&DRAW_BT){
clock_draw(flags);
}
}
void user_app_on_db_init_complete( void )
{
app_clock_timer_used = app_easy_timer(1000, app_clock_timer_cb);
printk("\nuser_app_on_db_init_complete! %08x\n", app_clock_timer_used);
printk("\nuser_app_on_db_init_complete!\n");
int adcval = adc1_update();
printk("Voltage: %d\n", adcval);
@@ -235,13 +225,19 @@ void user_app_on_db_init_complete( void )
clock_print();
clock_push();
clock_draw(1);
clock_draw(DRAW_BT|UPDATE_FULL);
user_app_adv_start();
app_clock_timer_used = app_easy_timer(clock_interval*100, app_clock_timer_cb);
}
void user_app_adv_start(void)
{
if(adv_state)
return;
adv_state = 1;
struct gapm_start_advertise_cmd* cmd = app_easy_gap_undirected_advertise_get_active();
app_add_ad_struct(cmd, adv_name, adv_name[0]+1, 1);
@@ -258,7 +254,6 @@ void user_app_connection(uint8_t connection_idx, struct gapc_connection_req_ind
if (app_env[connection_idx].conidx != GAP_INVALID_CONIDX)
{
adv_count = 20;
app_connection_idx = connection_idx;
printk(" interval: %d\n", param->con_interval);
@@ -277,9 +272,7 @@ void user_app_connection(uint8_t connection_idx, struct gapc_connection_req_ind
clock_push();
} else {
// No connection has been established, restart advertising
//user_app_adv_start();
adv_count = 0;
adv_state = 0;
}
default_app_on_connection(connection_idx, param);
@@ -288,6 +281,10 @@ void user_app_connection(uint8_t connection_idx, struct gapc_connection_req_ind
void user_app_adv_undirect_complete(uint8_t status)
{
printk("user_app_adv_undirect_complete: %02x\n", status);
if(status!=0){
adv_state = 0;
clock_draw(UPDATE_FLY);
}
}
@@ -302,12 +299,15 @@ void user_app_disconnect(struct gapc_disconnect_ind const *param)
app_param_update_request_timer_used = EASY_TIMER_INVALID_TIMER;
}
adv_state = 0;
if(param->reason!=CO_ERROR_REMOTE_USER_TERM_CON){
// 非主动断开连接时, 重新广播.
user_app_adv_start();
}else{
clock_draw(UPDATE_FLY);
}
adv_count = 0;
}