Improve readability of code

more readability
This commit is contained in:
David Lin
2020-02-21 13:09:13 +08:00
committed by GitHub
parent 72042fc89c
commit f1b698bfe7

View File

@@ -15,7 +15,6 @@
#include <stdio.h>
#include <stdlib.h>
// #include <unistd.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
@@ -94,7 +93,6 @@ static void eventPostCheck(void *client)
Log_e("events post failed: %d", rc);
}
}
}
#endif
@@ -131,12 +129,10 @@ static void OnActionCallback(void *pClient, const char *pClientToken, DeviceActi
replyPara.timeout_ms = QCLOUD_IOT_MQTT_COMMAND_TIMEOUT;
strcpy(replyPara.status_msg, "action execute success!"); //add the message about the action resault
DeviceProperty *pActionOutnput = pAction->pOutput;
(void)pActionOutnput; //elimate warning
//TO DO: add your aciont logic here and set output properties which will be reported by action_reply
IOT_ACTION_REPLY(pClient, pClientToken, sg_data_report_buffer, sg_data_report_buffersize, pAction, &replyPara);
}
@@ -303,17 +299,17 @@ __weak void OLED_ShowString(int x, int y, uint8_t *str, int bold)
// handle the light(simulated)
static void light_change_color(const char *color)
{
// <EFBFBD><EFBFBD>Ϊdemo<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>oled<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ʵ<EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵƵ<EFBFBD><EFBFBD><EFBFBD>ɫ
// <EFBFBD>˴<EFBFBD>demo<EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
// 作为demo这里用oled屏字符显示来模拟灯颜色的切换
// 这里应该由用户实现硬件操作代码,来改变智能灯的颜色
// 此处demo,在开发板显示屏上显示具体的颜色
OLED_ShowString(0, 0, (uint8_t *)color, 8);
}
static void light_change_brightness(TYPE_DEF_TEMPLATE_INT brightness)
{
// <EFBFBD><EFBFBD>Ϊdemo<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>oled<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ʵ<EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵƵ<EFBFBD><EFBFBD><EFBFBD>ɫ
// <EFBFBD>˴<EFBFBD>demo<EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
// 作为demo这里用oled屏字符显示来模拟灯颜色的切换
// 这里应该由用户实现硬件操作代码,来改变智能灯的颜色
// 此处demo,在开发板显示屏上显示具体的颜色
char brightness_str[12];
snprintf(brightness_str, sizeof(brightness_str), "%d", brightness);
@@ -323,13 +319,13 @@ static void light_change_brightness(TYPE_DEF_TEMPLATE_INT brightness)
static void light_power_on(void)
{
// <EFBFBD><EFBFBD>Ϊdemo<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>oled<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
// 作为demo这里用oled屏字符显示来模拟灯颜色的切换
OLED_Clear();
}
static void light_power_off(void)
{
// <EFBFBD><EFBFBD>Ϊdemo<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>oled<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
// 作为demo这里用oled屏字符显示来模拟灯颜色的切换
char *info = "light off";
OLED_Clear();
OLED_ShowString(0, 0, (uint8_t *)info, 16);
@@ -345,7 +341,7 @@ void deal_down_stream_user_logic(void *client, ProductDataDefine * pData)
/////////////////////////////////////////////////////////////////////////////////////
char *color_name;
/* <EFBFBD>ƹ<EFBFBD><EFBFBD><EFBFBD>ɫ */
/* 灯光颜色 */
switch (sg_ProductData.m_color) {
case 0:
color_name = " RED ";
@@ -361,12 +357,12 @@ void deal_down_stream_user_logic(void *client, ProductDataDefine * pData)
}
if (sg_ProductData.m_power_switch == 1) {
/* <EFBFBD>ƹ⿪<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>տ<EFBFBD><EFBFBD>Ʋ<EFBFBD><EFBFBD><EFBFBD>չʾ */
/* 灯光开启式,按照控制参数展示 */
light_power_on();
light_change_color(color_name);
light_change_brightness(sg_ProductData.m_brightness);
} else {
/* <EFBFBD>ƹ<EFBFBD><EFBFBD>ر<EFBFBD>չʾ */
/* 灯光关闭展示 */
light_power_off();
}
}
@@ -378,6 +374,7 @@ void first_time_report_construct(DeviceProperty *pReportDataList[], int *pCount)
for (i = 0, j = 0; i < TOTAL_PROPERTY_COUNT; i++) {
pReportDataList[j++] = &(sg_DataTemplate[i].data_property);
}
*pCount = j;
}
/////////////////////////////////////////////////////////////////////////////////////
@@ -487,7 +484,7 @@ int data_template_light_thread(void) {
Log_e("Report system info fail, err: %d", rc);
goto exit;
}
}else{
}else {
Log_e("Get system info fail, err: %d", rc);
}
@@ -496,7 +493,7 @@ int data_template_light_thread(void) {
if (rc != QCLOUD_RET_SUCCESS) {
Log_e("Get data status fail, err: %d", rc);
//goto exit;
}else{
}else {
Log_d("Get data status success");
}
@@ -515,7 +512,6 @@ int data_template_light_thread(void) {
/* handle control msg from server */
if (sg_control_msg_arrived) {
deal_down_stream_user_logic(client, &sg_ProductData);
/* control msg should reply, otherwise server treat device didn't receive and retain the msg which would be get by get status*/
@@ -531,7 +527,7 @@ int data_template_light_thread(void) {
} else {
Log_e("Contol msg reply failed, err: %d", rc);
}
} else{
}else {
Log_d("No control msg received...");
}
@@ -575,7 +571,7 @@ int data_template_light_thread(void) {
Log_e("construct reporte data failed, err: %d", rc);
}
}else{
}else {
//Log_d("no data need to be reported or someting goes wrong");
}
///////////////////////////////////
@@ -587,7 +583,7 @@ int data_template_light_thread(void) {
#endif
HAL_SleepMs(3000);
}
}/*end of while*/
exit:
rc = IOT_Template_Destroy(client);