字符串函数的rt替换
This commit is contained in:
parent
07d3b540f0
commit
157e4d8c51
|
@ -120,24 +120,27 @@ static int example_subscribe(void *handle)
|
||||||
int topic_len = 0;
|
int topic_len = 0;
|
||||||
|
|
||||||
topic_len = strlen(fmt) + strlen(DEMO_PRODUCT_KEY) + strlen(DEMO_DEVICE_NAME) + 1;
|
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)
|
if (topic == NULL)
|
||||||
{
|
{
|
||||||
EXAMPLE_TRACE("memory not enough");
|
EXAMPLE_TRACE("memory not enough");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(topic, 0, topic_len);
|
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);
|
res = IOT_MQTT_Subscribe(handle, topic, IOTX_MQTT_QOS0, example_message_arrive, NULL);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
{
|
{
|
||||||
EXAMPLE_TRACE("subscribe failed");
|
EXAMPLE_TRACE("subscribe failed");
|
||||||
HAL_Free(topic);
|
// HAL_Free(topic);
|
||||||
|
rt_free(topic);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Free(topic);
|
// HAL_Free(topic);
|
||||||
|
rt_free(topic);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int plus_lcd_y(int pls)
|
int plus_lcd_y(int pls)
|
||||||
|
@ -149,7 +152,7 @@ int plus_lcd_y(int pls)
|
||||||
void easy_show_lcd(char *title, float Temp)
|
void easy_show_lcd(char *title, float Temp)
|
||||||
{
|
{
|
||||||
lcd_show_string(10, plus_lcd_y(24), 24, title);
|
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);
|
lcd_show_string(10, plus_lcd_y(32), 32, tmp);
|
||||||
}
|
}
|
||||||
void show_lcd()
|
void show_lcd()
|
||||||
|
@ -160,15 +163,15 @@ void show_lcd()
|
||||||
easy_show_lcd("Brightness:(lux)", brightness);
|
easy_show_lcd("Brightness:(lux)", brightness);
|
||||||
easy_show_lcd("Ps data:", (float)ps_data);
|
easy_show_lcd("Ps data:", (float)ps_data);
|
||||||
// lcd_show_string(10, plus_lcd_y(10), 24, "Temperature:");
|
// 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(24), 32, tmp);
|
||||||
|
|
||||||
// lcd_show_string(10, plus_lcd_y(32), 24, "Humidity:");
|
// 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(24), 32, tmp);
|
||||||
|
|
||||||
// lcd_show_string(10, plus_lcd_y(32), 24, "Brightness:");
|
// 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);
|
// 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)
|
// 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));
|
// 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);
|
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp);
|
||||||
// make_file();
|
// make_file();
|
||||||
if (page_chosen == 2 && !page_stop)
|
if (page_chosen == 2 && !page_stop)
|
||||||
|
@ -271,7 +274,7 @@ void tmp_payload(void)
|
||||||
page_chosen = (page_chosen % PAGE_MAX) + 1;
|
page_chosen = (page_chosen % PAGE_MAX) + 1;
|
||||||
page_first = 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;
|
return;
|
||||||
}
|
}
|
||||||
void test_lcd()
|
void test_lcd()
|
||||||
|
@ -299,24 +302,28 @@ static int example_publish(void *handle)
|
||||||
// strcpy(payload,tmp_payload());
|
// strcpy(payload,tmp_payload());
|
||||||
// rt_kprintf("payload:%s\n",payload);
|
// rt_kprintf("payload:%s\n",payload);
|
||||||
topic_len = strlen(fmt) + strlen(DEMO_PRODUCT_KEY) + strlen(DEMO_DEVICE_NAME) + 1;
|
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)
|
if (topic == NULL)
|
||||||
{
|
{
|
||||||
EXAMPLE_TRACE("memory not enough");
|
EXAMPLE_TRACE("memory not enough");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(topic, 0, topic_len);
|
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));
|
res = IOT_MQTT_Publish_Simple(0, topic, IOTX_MQTT_QOS0, payload, strlen(payload));
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
{
|
{
|
||||||
EXAMPLE_TRACE("publish failed, res = %d", res);
|
EXAMPLE_TRACE("publish failed, res = %d", res);
|
||||||
HAL_Free(topic);
|
// HAL_Free(topic);
|
||||||
|
rt_free(topic);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Free(topic);
|
// HAL_Free(topic);
|
||||||
|
rt_free(topic);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,6 +377,10 @@ static void mqtt_example_main(void *parameter)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ath_init(void)
|
void ath_init(void)
|
||||||
{
|
{
|
||||||
// 初始化设备
|
// 初始化设备
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include <stdio.h>
|
// #include <stdio.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "my_func.h"
|
#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_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);
|
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]);
|
// 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, 20, 16, snake_dirshow[now_direction]);
|
||||||
lcd_show_string(20 + 16 * 4, 20, 16, tmp);
|
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_food[1] = rand() % SNAKE_MAX;
|
||||||
snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
|
snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
|
||||||
snake_len++;
|
snake_len++;
|
||||||
sprintf(tmp, "%d", snake_len);
|
rt_sprintf(tmp, "%d", snake_len);
|
||||||
lcd_show_string(100, 105, 32, tmp);
|
lcd_show_string(100, 105, 32, tmp);
|
||||||
// 防止蛇咬尾出现bug
|
// 防止蛇咬尾出现bug
|
||||||
if (snake_len >= SNAKE_MAX)
|
if (snake_len >= SNAKE_MAX)
|
||||||
|
|
Loading…
Reference in New Issue