From 7c841b193c40a3618275c0d59a2314594817dc8f Mon Sep 17 00:00:00 2001 From: kyz Date: Wed, 10 Dec 2025 17:19:20 +0800 Subject: [PATCH] add wifi icon --- .../cpbs-202103-20240423/API/lcdpic.h" | 23 ++++++ .../cpbs-202103-20240423/APP/uishow.c" | 23 +++++- .../cpbs-202103-20240423/APP/wifi.c" | 74 ++++++++++++++++++- 3 files changed, 114 insertions(+), 6 deletions(-) diff --git "a/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/API/lcdpic.h" "b/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/API/lcdpic.h" index 17c68bd..726ee6b 100644 --- "a/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/API/lcdpic.h" +++ "b/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/API/lcdpic.h" @@ -190,3 +190,26 @@ const unsigned char gImage_dusu[200] = { /* 0X00,0X01,0X24,0X00,0X24,0X00, */ 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00 }; + +// WiFiͼ±ê 32*32 +const unsigned char pic_wifi_32x32[128] = { /* 0X00,0X01,0X20,0X00,0X20,0X00, */ +0X00,0X07,0XF0,0X00,0X00,0X3F,0XFE,0X00,0X00,0XFF,0XFF,0X00,0X03,0XFF,0XFF,0XC0, +0X07,0XFF,0XFF,0XE0,0X0F,0XFF,0XFF,0XF8,0X3F,0XE0,0X0F,0XFC,0X7F,0X80,0X01,0XFE, +0XFF,0X00,0X00,0XFF,0X7C,0X00,0X00,0X3E,0X38,0X00,0X00,0X1E,0X30,0X07,0XE0,0X0C, +0X00,0X1F,0XF8,0X00,0X00,0X7F,0XFE,0X00,0X00,0XFF,0XFF,0X00,0X01,0XFF,0XFF,0X80, +0X03,0XFF,0XFF,0XC0,0X03,0XF0,0X0F,0XC0,0X01,0XE0,0X07,0XC0,0X00,0X80,0X01,0X80, +0X00,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC0,0X00,0X00,0X07,0XF0,0X00, +0X00,0X1F,0XF8,0X00,0X00,0X0F,0XF0,0X00,0X00,0X07,0XF0,0X00,0X00,0X07,0XE0,0X00, +0X00,0X03,0XC0,0X00,0X00,0X01,0XC0,0X00,0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00, +}; + +const unsigned char pic_wifi_err_32x32[128] = { /* 0X00,0X01,0X20,0X00,0X20,0X00, */ +0X00,0X07,0XF0,0X04,0X00,0X3F,0XFE,0X0E,0X00,0XFF,0XFF,0X1E,0X03,0XFF,0XFF,0XFC, +0X07,0XFF,0XFF,0XF8,0X0F,0XFF,0XFF,0XF8,0X3F,0XE0,0X0F,0XFC,0X7F,0X80,0X03,0XFE, +0XFF,0X00,0X07,0XFF,0X7C,0X00,0X0F,0X3E,0X38,0X00,0X1E,0X1E,0X30,0X07,0XFC,0X0C, +0X00,0X1F,0XFC,0X00,0X00,0X7F,0XFE,0X00,0X00,0XFF,0XFF,0X00,0X01,0XFF,0XFF,0X80, +0X03,0XFF,0XFF,0XC0,0X03,0XFF,0X0F,0XC0,0X01,0XFE,0X07,0XC0,0X00,0XFC,0X01,0X80, +0X00,0XF8,0X00,0X00,0X00,0XF0,0X00,0X00,0X01,0XE3,0XC0,0X00,0X03,0XC7,0XF0,0X00, +0X07,0X9F,0XF8,0X00,0X0F,0X0F,0XF0,0X00,0X1E,0X07,0XF0,0X00,0X3C,0X07,0XE0,0X00, +0X38,0X03,0XC0,0X00,0X10,0X01,0XC0,0X00,0X00,0X01,0X80,0X00,0X00,0X00,0X00,0X00, +}; diff --git "a/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/APP/uishow.c" "b/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/APP/uishow.c" index a732965..27eb693 100644 --- "a/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/APP/uishow.c" +++ "b/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/APP/uishow.c" @@ -55,12 +55,26 @@ static void Versions_Interface(void); static void TorqueAngle_Interface(SetParameter_t* pdata, InterfaceState_t* InterfaceState); // Ť¾Ø½Ç¶Èģʽ½çÃæ +void wifi_icon_update( int force ) +{ + static int last_wifi_state = -1; + int wifi_state; + wifi_state = Get_Wifi_Status(); + if( !force && last_wifi_state == wifi_state ){ + return; + } + last_wifi_state = wifi_state; - - - + if( wifi_state == -1 ){ + LCD_Picture(204,4,32,32,pic_wifi_err_32x32, GRAY); + }else if( wifi_state == 0 ){ + LCD_Picture(204,4,32,32,pic_wifi_32x32, LIGHTBLUE); + }else{ + LCD_Picture(204,4,32,32,pic_wifi_32x32, 0x0A80); + } +} /******************************************************************************* * Function Name : UiShow_task @@ -1078,7 +1092,10 @@ void Setting_Interface(SetParameter_t* pdata,_calendar_obj* Time,InterfaceState_ LCD_ShowInt_U32(0,48*4,p_UsageCounter,6,BLUE,BACKGROUND); LastInterfaceID = SET_INTERFACE_ID; + + wifi_icon_update( 1 ); } else { + wifi_icon_update( 0 ); if(LastLanguage != p_Language || LastStandard != p_Standard || LastCurPos != I_CursorPosition || LastSelectState != I_SelectedState) { diff --git "a/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/APP/wifi.c" "b/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/APP/wifi.c" index 72ec56c..f872555 100644 --- "a/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/APP/wifi.c" +++ "b/20240801\345\256\214\346\225\264\347\211\210/\346\211\263\346\211\213\344\270\213\344\275\215\346\234\272\350\275\257\344\273\266/cpbs-202103-20240423/APP/wifi.c" @@ -16,10 +16,15 @@ #include "../FreeRTOS/include/FreeRTOS.h" #include "../FreeRTOS/include/task.h" +static int g_wifi_st = -1; TaskHandle_t WifiTask_Handler = NULL; TaskHandle_t AtTask_Handler = NULL; +typedef struct{ + uint8_t data; +}wrench_server_t; + // ÃüÁî½âÎöÏà¹Ø¶¨Òå typedef struct { char mid[5]; // ÃüÁîID£¬ÈçRSVI¡¢RSTSµÈ @@ -310,11 +315,31 @@ void ipd_handler(at_urc_ctx_t *ctx) } } +void connect_handler(at_urc_ctx_t *ctx) +{ + int linkid; + printf("connect handler, ctx:%p\n", ctx); + if( sscanf( ctx->buf, "%d,CONNECT", &linkid ) == 1 ){ + printf( "LINK:%d ---> CONNECT!\n", linkid ); + g_wifi_st = 1; + } +} + +void closed_handler(at_urc_ctx_t *ctx) +{ + int linkid; + printf("closed handler, ctx:%p\n", ctx); + if( sscanf( ctx->buf, "%d,CLOSED", &linkid ) == 1 ){ + printf( "LINK:%d ---> CLOSED!\n", linkid ); + g_wifi_st = 0; + } +} + urc_item_t wifi_utc_tbl[]={ - { + { "+IPD", "\r\n", ipd_handler }, + { "CONNECT", "\r\n", connect_handler }, + { "CLOSED", "\r\n", closed_handler }, - "+IPD", "\r\n", ipd_handler - }, }; @@ -405,6 +430,41 @@ static bool wifi_tcp_send( const void *buf, unsigned int len) return at_do_work(&wifi_at, (at_work)tcp_send_handler, &tx_data); } +int wifi_cipstate( at_obj_t *at ) +{ + int ret = 0; + //AT+CIPSTATE? + //ÏìÓ¦£ºµ±ÓÐÁ¬½Óʱ£¬ AT ·µ»Ø£º + //+CIPSTATE:,<"type">,<"remote IP">,,, + //OK + //µ±Ã»ÓÐÁ¬½Óʱ£¬ AT ·µ»Ø£º + //OK + //return 0: δÁ¬½Ó ´óÓÚ0: Á¬½ÓÊý -1: Ä£¿éͨÐŹÊÕÏ + //½ÓÊÕ»º³åÇø + char *p; + int linkid; + char recvbuf[256]; + //ATÓ¦´ð + at_respond_t r = {"OK", NULL, sizeof(recvbuf), 3000}; + r.recvbuf = recvbuf; + // + if (at_do_cmd(at, &r, "AT+CIPSTATE?") != AT_RET_OK){ + ret = -1; + }else{ + ret = 0; + p = strstr( recvbuf, "+CIPSTATE:"); + while(p){ + if( sscanf(p, "+CIPSTATE:%d", &linkid) == 1){ + printf( "read wifi cipstate, linkid:%d\n", linkid ); + ret++; + } + p = strstr( p+10, "+CIPSTATE:"); + } + } + return ret; + +} + int wifi_init(at_obj_t *at ) { //½ÓÊÕ»º³åÇø @@ -427,6 +487,7 @@ int wifi_init(at_obj_t *at ) else if (at_do_cmd(at, &r, "AT+CIPSERVER=1,8888") != AT_RET_OK) return -1; //AT+CIPSERVER=1 + g_wifi_st = 0; printf( "wifi init ok\n" ); return 0; } @@ -490,8 +551,15 @@ void wifi_task(void *pvParameters) size_t min_free_heap = xPortGetMinimumEverFreeHeapSize(); printf("FreeRTOS Heap Status - Free: %u bytes, Min Free: %u bytes\n", (unsigned int)free_heap, (unsigned int)min_free_heap); + + wifi_cipstate(&wifi_at); //check wifi connection status } vTaskDelay(10); } } + +int Get_Wifi_Status( void ) +{ + return g_wifi_st; +} -- 2.34.1