From 157e4d8c5196ff567d91c7150ce6d2b197c36d78 Mon Sep 17 00:00:00 2001 From: james <1943357252@qq.com> Date: Sun, 11 Aug 2024 16:06:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E7=9A=84rt=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- my_pro/myproject.c | 39 +++++++++++++++++++++++++-------------- my_pro/mysnake.c | 6 +++--- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/my_pro/myproject.c b/my_pro/myproject.c index bd7d20b..d464860 100644 --- a/my_pro/myproject.c +++ b/my_pro/myproject.c @@ -120,24 +120,27 @@ static int example_subscribe(void *handle) int topic_len = 0; topic_len = strlen(fmt) + strlen(DEMO_PRODUCT_KEY) + strlen(DEMO_DEVICE_NAME) + 1; - topic = HAL_Malloc(topic_len); + topic = rt_malloc(topic_len); if (topic == NULL) { EXAMPLE_TRACE("memory not enough"); return -1; } memset(topic, 0, topic_len); - HAL_Snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME); + // HAL_Snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME); + rt_snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME); res = IOT_MQTT_Subscribe(handle, topic, IOTX_MQTT_QOS0, example_message_arrive, NULL); if (res < 0) { EXAMPLE_TRACE("subscribe failed"); - HAL_Free(topic); + // HAL_Free(topic); + rt_free(topic); return -1; } - HAL_Free(topic); + // HAL_Free(topic); + rt_free(topic); return 0; } int plus_lcd_y(int pls) @@ -149,7 +152,7 @@ int plus_lcd_y(int pls) void easy_show_lcd(char *title, float Temp) { lcd_show_string(10, plus_lcd_y(24), 24, title); - sprintf(tmp, "%f", Temp); + rt_sprintf(tmp, "%f", Temp); lcd_show_string(10, plus_lcd_y(32), 32, tmp); } void show_lcd() @@ -160,15 +163,15 @@ void show_lcd() easy_show_lcd("Brightness:(lux)", brightness); easy_show_lcd("Ps data:", (float)ps_data); // lcd_show_string(10, plus_lcd_y(10), 24, "Temperature:"); - // sprintf(tmp, "%f", Temp); + // rt_sprintf(tmp, "%f", Temp); // lcd_show_string(10, plus_lcd_y(24), 32, tmp); // lcd_show_string(10, plus_lcd_y(32), 24, "Humidity:"); - // sprintf(tmp, "%f", Humi); + // rt_sprintf(tmp, "%f", Humi); // lcd_show_string(10, plus_lcd_y(24), 32, tmp); // lcd_show_string(10, plus_lcd_y(32), 24, "Brightness:"); - // sprintf(tmp, "%f(lux)", brightness); + // rt_sprintf(tmp, "%f(lux)", brightness); // lcd_show_string(10, plus_lcd_y(24), 32, tmp); } @@ -211,7 +214,7 @@ void tmp_payload(void) // } // icm20608_get_accel(icm20608_device_t dev, rt_int16_t *accel_x, rt_int16_t *accel_y, rt_int16_t *accel_z) // memset(tmp, 0, sizeof(tmp)); - // sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt); + // rt_sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt); // rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp); // make_file(); if (page_chosen == 2 && !page_stop) @@ -271,7 +274,7 @@ void tmp_payload(void) page_chosen = (page_chosen % PAGE_MAX) + 1; page_first = 1; } - sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f,\"LightLux\":%.2f,\"Psdata\":%d,\"Snakelen\":%d}}", Temp, Humi, brightness, ps_data, snake_len); + rt_sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f,\"LightLux\":%.2f,\"Psdata\":%d,\"Snakelen\":%d}}", Temp, Humi, brightness, ps_data, snake_len); return; } void test_lcd() @@ -299,24 +302,28 @@ static int example_publish(void *handle) // strcpy(payload,tmp_payload()); // rt_kprintf("payload:%s\n",payload); topic_len = strlen(fmt) + strlen(DEMO_PRODUCT_KEY) + strlen(DEMO_DEVICE_NAME) + 1; - topic = HAL_Malloc(topic_len); + // topic = HAL_Malloc(topic_len); + topic = rt_malloc(topic_len); if (topic == NULL) { EXAMPLE_TRACE("memory not enough"); return -1; } memset(topic, 0, topic_len); - HAL_Snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME); + // HAL_Snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME); + rt_snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME); res = IOT_MQTT_Publish_Simple(0, topic, IOTX_MQTT_QOS0, payload, strlen(payload)); if (res < 0) { EXAMPLE_TRACE("publish failed, res = %d", res); - HAL_Free(topic); + // HAL_Free(topic); + rt_free(topic); return -1; } - HAL_Free(topic); + // HAL_Free(topic); + rt_free(topic); return 0; } @@ -370,6 +377,10 @@ static void mqtt_example_main(void *parameter) return; } + + + + void ath_init(void) { // 初始化设备 diff --git a/my_pro/mysnake.c b/my_pro/mysnake.c index a4491ef..f514faf 100644 --- a/my_pro/mysnake.c +++ b/my_pro/mysnake.c @@ -1,4 +1,4 @@ -#include +// #include #include #include #include "my_func.h" @@ -92,7 +92,7 @@ void snake_entry(void *parameter) new_head_x = (snake_list[snake_head][0] + snake_direction[now_direction][0] + SNAKE_MAX) % (SNAKE_MAX); new_head_y = (snake_list[snake_head][1] + snake_direction[now_direction][1] + SNAKE_MAX) % (SNAKE_MAX); - sprintf(tmp, "(%d,%d)", new_head_x, new_head_y); + rt_sprintf(tmp, "(%d,%d)", new_head_x, new_head_y); // rt_kprintf("head:%d,%d\n", snake_list[snake_head][0], snake_list[snake_head][1]); lcd_show_string(20, 20, 16, snake_dirshow[now_direction]); lcd_show_string(20 + 16 * 4, 20, 16, tmp); @@ -104,7 +104,7 @@ void snake_entry(void *parameter) snake_food[1] = rand() % SNAKE_MAX; snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN); snake_len++; - sprintf(tmp, "%d", snake_len); + rt_sprintf(tmp, "%d", snake_len); lcd_show_string(100, 105, 32, tmp); // 防止蛇咬尾出现bug if (snake_len >= SNAKE_MAX)