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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
// #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
@@ -94,7 +93,6 @@ static void eventPostCheck(void *client)
Log_e("events post failed: %d", rc); Log_e("events post failed: %d", rc);
} }
} }
} }
#endif #endif
@@ -131,12 +129,10 @@ static void OnActionCallback(void *pClient, const char *pClientToken, DeviceActi
replyPara.timeout_ms = QCLOUD_IOT_MQTT_COMMAND_TIMEOUT; replyPara.timeout_ms = QCLOUD_IOT_MQTT_COMMAND_TIMEOUT;
strcpy(replyPara.status_msg, "action execute success!"); //add the message about the action resault strcpy(replyPara.status_msg, "action execute success!"); //add the message about the action resault
DeviceProperty *pActionOutnput = pAction->pOutput; DeviceProperty *pActionOutnput = pAction->pOutput;
(void)pActionOutnput; //elimate warning (void)pActionOutnput; //elimate warning
//TO DO: add your aciont logic here and set output properties which will be reported by action_reply //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); 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) // handle the light(simulated)
static void light_change_color(const char *color) 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> // 作为demo这里用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>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_ShowString(0, 0, (uint8_t *)color, 8); OLED_ShowString(0, 0, (uint8_t *)color, 8);
} }
static void light_change_brightness(TYPE_DEF_TEMPLATE_INT brightness) 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> // 作为demo这里用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>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,在开发板显示屏上显示具体的颜色
char brightness_str[12]; char brightness_str[12];
snprintf(brightness_str, sizeof(brightness_str), "%d", brightness); 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) 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(); OLED_Clear();
} }
static void light_power_off(void) 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"; char *info = "light off";
OLED_Clear(); OLED_Clear();
OLED_ShowString(0, 0, (uint8_t *)info, 16); 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; char *color_name;
/* <EFBFBD>ƹ<EFBFBD><EFBFBD><EFBFBD>ɫ */ /* 灯光颜色 */
switch (sg_ProductData.m_color) { switch (sg_ProductData.m_color) {
case 0: case 0:
color_name = " RED "; color_name = " RED ";
@@ -361,12 +357,12 @@ void deal_down_stream_user_logic(void *client, ProductDataDefine * pData)
} }
if (sg_ProductData.m_power_switch == 1) { if (sg_ProductData.m_power_switch == 1) {
/* <EFBFBD>ƹ⿪<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>տ<EFBFBD><EFBFBD>Ʋ<EFBFBD><EFBFBD><EFBFBD>չʾ */ /* 灯光开启式,按照控制参数展示 */
light_power_on(); light_power_on();
light_change_color(color_name); light_change_color(color_name);
light_change_brightness(sg_ProductData.m_brightness); light_change_brightness(sg_ProductData.m_brightness);
} else { } else {
/* <EFBFBD>ƹ<EFBFBD><EFBFBD>ر<EFBFBD>չʾ */ /* 灯光关闭展示 */
light_power_off(); 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++) { for (i = 0, j = 0; i < TOTAL_PROPERTY_COUNT; i++) {
pReportDataList[j++] = &(sg_DataTemplate[i].data_property); pReportDataList[j++] = &(sg_DataTemplate[i].data_property);
} }
*pCount = j; *pCount = j;
} }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
@@ -515,7 +512,6 @@ int data_template_light_thread(void) {
/* handle control msg from server */ /* handle control msg from server */
if (sg_control_msg_arrived) { if (sg_control_msg_arrived) {
deal_down_stream_user_logic(client, &sg_ProductData); 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*/ /* control msg should reply, otherwise server treat device didn't receive and retain the msg which would be get by get status*/
@@ -587,7 +583,7 @@ int data_template_light_thread(void) {
#endif #endif
HAL_SleepMs(3000); HAL_SleepMs(3000);
} }/*end of while*/
exit: exit:
rc = IOT_Template_Destroy(client); rc = IOT_Template_Destroy(client);