From bd1ab52b5e672f78dea293df05b169853973969c Mon Sep 17 00:00:00 2001 From: Hyundo Lee <54927573+hdlee27@users.noreply.github.com> Date: Tue, 17 Nov 2020 20:50:15 +0900 Subject: [PATCH] caps_sample:update sample file in apps (cherry-picked from commit 85fc22c70258e65f64cd2f3e0310ebb1ca80a13b) Signed-off-by: Hyundo Lee <54927573+hdlee27@users.noreply.github.com> --- .../main/caps_activityLightingMode.c | 25 +++++------ .../main/caps_colorTemperature.c | 21 ++++------ .../light_example/main/caps_dustSensor.c | 42 ++++++++----------- apps/emw3080/light_example/main/caps_switch.c | 25 +++++------ .../light_example/main/caps_switchLevel.c | 21 ++++------ .../emw3080/switch_example/main/caps_switch.c | 25 +++++------ .../main/caps_activityLightingMode.c | 2 +- .../main/caps_colorTemperature.c | 2 +- .../rtl8720c/light_example/main/caps_switch.c | 4 +- .../light_example/main/caps_switchLevel.c | 2 +- .../light_example/main/caps_colorControl.h | 2 +- 11 files changed, 75 insertions(+), 96 deletions(-) diff --git a/apps/emw3080/light_example/main/caps_activityLightingMode.c b/apps/emw3080/light_example/main/caps_activityLightingMode.c index 894a8c50..667dc6c2 100644 --- a/apps/emw3080/light_example/main/caps_activityLightingMode.c +++ b/apps/emw3080/light_example/main/caps_activityLightingMode.c @@ -31,8 +31,8 @@ static int caps_activityLightingMode_attr_lightingMode_str2idx(const char *value if (!strcmp(value, caps_helper_activityLightingMode.attr_lightingMode.values[index])) { return index; } - } - return -1; + } + return -1; } static const char *caps_activityLightingMode_get_lightingMode_value(caps_activityLightingMode_data_t *caps_data) @@ -58,9 +58,7 @@ static void caps_activityLightingMode_set_lightingMode_value(caps_activityLighti static void caps_activityLightingMode_attr_lightingMode_send(caps_activityLightingMode_data_t *caps_data) { - IOT_EVENT *cap_evt; - uint8_t evt_num = 1; - int sequence_no; + int sequence_no = -1; if (!caps_data || !caps_data->handle) { printf("fail to get handle\n"); @@ -71,19 +69,18 @@ static void caps_activityLightingMode_attr_lightingMode_send(caps_activityLighti return; } - cap_evt = st_cap_attr_create_string((char *)caps_helper_activityLightingMode.attr_lightingMode.name, - caps_data->lightingMode_value, NULL); - if (!cap_evt) { - printf("fail to create cap_evt\n"); - return; - } + ST_CAP_SEND_ATTR_STRING(caps_data->handle, + (char *)caps_helper_activityLightingMode.attr_lightingMode.name, + caps_data->lightingMode_value, + NULL, + NULL, + sequence_no); - sequence_no = st_cap_attr_send(caps_data->handle, evt_num, &cap_evt); if (sequence_no < 0) printf("fail to send lightingMode value\n"); + else + printf("Sequence number return : %d\n", sequence_no); - printf("Sequence number return : %d\n", sequence_no); - st_cap_attr_free(cap_evt); } diff --git a/apps/emw3080/light_example/main/caps_colorTemperature.c b/apps/emw3080/light_example/main/caps_colorTemperature.c index df8cad57..fc3f5d0f 100644 --- a/apps/emw3080/light_example/main/caps_colorTemperature.c +++ b/apps/emw3080/light_example/main/caps_colorTemperature.c @@ -61,27 +61,24 @@ static void caps_colorTemperature_set_colorTemperature_unit(caps_colorTemperatur static void caps_colorTemperature_attr_colorTemperature_send(caps_colorTemperature_data_t *caps_data) { - IOT_EVENT *cap_evt; - uint8_t evt_num = 1; - int sequence_no; + int sequence_no = -1; if (!caps_data || !caps_data->handle) { printf("fail to get handle\n"); return; } - cap_evt = st_cap_attr_create_int((char *) caps_helper_colorTemperature.attr_colorTemperature.name, caps_data->colorTemperature_value, caps_data->colorTemperature_unit); - if (!cap_evt) { - printf("fail to create cap_evt\n"); - return; - } + ST_CAP_SEND_ATTR_NUMBER(caps_data->handle, + (char *)caps_helper_colorTemperature.attr_colorTemperature.name, + caps_data->colorTemperature_value, + caps_data->colorTemperature_unit, + NULL, + sequence_no); - sequence_no = st_cap_attr_send(caps_data->handle, evt_num, &cap_evt); if (sequence_no < 0) printf("fail to send colorTemperature value\n"); - - printf("Sequence number return : %d\n", sequence_no); - st_cap_attr_free(cap_evt); + else + printf("Sequence number return : %d\n", sequence_no); } diff --git a/apps/emw3080/light_example/main/caps_dustSensor.c b/apps/emw3080/light_example/main/caps_dustSensor.c index 96c63ee3..8bfeb8f0 100644 --- a/apps/emw3080/light_example/main/caps_dustSensor.c +++ b/apps/emw3080/light_example/main/caps_dustSensor.c @@ -61,27 +61,24 @@ static void caps_dustSensor_set_fineDustLevel_unit(caps_dustSensor_data_t *caps_ static void caps_dustSensor_attr_fineDustLevel_send(caps_dustSensor_data_t *caps_data) { - IOT_EVENT *cap_evt; - uint8_t evt_num = 1; - int sequence_no; + int sequence_no = -1; if (!caps_data || !caps_data->handle) { printf("fail to get handle\n"); return; } - cap_evt = st_cap_attr_create_int((char *) caps_helper_dustSensor.attr_fineDustLevel.name, caps_data->fineDustLevel_value, caps_data->fineDustLevel_unit); - if (!cap_evt) { - printf("fail to create cap_evt\n"); - return; - } + ST_CAP_SEND_ATTR_NUMBER(caps_data->handle, + (char *)caps_helper_dustSensor.attr_fineDustLevel.name, + caps_data->fineDustLevel_value, + caps_data->fineDustLevel_unit, + NULL, + sequence_no); - sequence_no = st_cap_attr_send(caps_data->handle, evt_num, &cap_evt); if (sequence_no < 0) printf("fail to send fineDustLevel value\n"); - - printf("Sequence number return : %d\n", sequence_no); - st_cap_attr_free(cap_evt); + else + printf("Sequence number return : %d\n", sequence_no); } @@ -123,27 +120,24 @@ static void caps_dustSensor_set_dustLevel_unit(caps_dustSensor_data_t *caps_data static void caps_dustSensor_attr_dustLevel_send(caps_dustSensor_data_t *caps_data) { - IOT_EVENT *cap_evt; - uint8_t evt_num = 1; - int sequence_no; + int sequence_no = -1; if (!caps_data || !caps_data->handle) { printf("fail to get handle\n"); return; } - cap_evt = st_cap_attr_create_int((char *) caps_helper_dustSensor.attr_dustLevel.name, caps_data->dustLevel_value, caps_data->dustLevel_unit); - if (!cap_evt) { - printf("fail to create cap_evt\n"); - return; - } + ST_CAP_SEND_ATTR_NUMBER(caps_data->handle, + (char *)caps_helper_dustSensor.attr_dustLevel.name, + caps_data->dustLevel_value, + caps_data->dustLevel_unit, + NULL, + sequence_no); - sequence_no = st_cap_attr_send(caps_data->handle, evt_num, &cap_evt); if (sequence_no < 0) printf("fail to send dustLevel value\n"); - - printf("Sequence number return : %d\n", sequence_no); - st_cap_attr_free(cap_evt); + else + printf("Sequence number return : %d\n", sequence_no); } diff --git a/apps/emw3080/light_example/main/caps_switch.c b/apps/emw3080/light_example/main/caps_switch.c index 2ef1a85d..213c7156 100644 --- a/apps/emw3080/light_example/main/caps_switch.c +++ b/apps/emw3080/light_example/main/caps_switch.c @@ -31,8 +31,8 @@ static int caps_switch_attr_switch_str2idx(const char *value) if (!strcmp(value, caps_helper_switch.attr_switch.values[index])) { return index; } - } - return -1; + } + return -1; } static const char *caps_switch_get_switch_value(caps_switch_data_t *caps_data) @@ -58,9 +58,7 @@ static void caps_switch_set_switch_value(caps_switch_data_t *caps_data, const ch static void caps_switch_attr_switch_send(caps_switch_data_t *caps_data) { - IOT_EVENT *cap_evt; - uint8_t evt_num = 1; - int sequence_no; + int sequence_no = -1; if (!caps_data || !caps_data->handle) { printf("fail to get handle\n"); @@ -71,19 +69,18 @@ static void caps_switch_attr_switch_send(caps_switch_data_t *caps_data) return; } - cap_evt = st_cap_attr_create_string((char *)caps_helper_switch.attr_switch.name, - caps_data->switch_value, NULL); - if (!cap_evt) { - printf("fail to create cap_evt\n"); - return; - } + ST_CAP_SEND_ATTR_STRING(caps_data->handle, + (char *)caps_helper_switch.attr_switch.name, + caps_data->switch_value, + NULL, + NULL, + sequence_no); - sequence_no = st_cap_attr_send(caps_data->handle, evt_num, &cap_evt); if (sequence_no < 0) printf("fail to send switch value\n"); + else + printf("Sequence number return : %d\n", sequence_no); - printf("Sequence number return : %d\n", sequence_no); - st_cap_attr_free(cap_evt); } diff --git a/apps/emw3080/light_example/main/caps_switchLevel.c b/apps/emw3080/light_example/main/caps_switchLevel.c index dbaebec6..f467b2db 100644 --- a/apps/emw3080/light_example/main/caps_switchLevel.c +++ b/apps/emw3080/light_example/main/caps_switchLevel.c @@ -61,27 +61,24 @@ static void caps_switchLevel_set_level_unit(caps_switchLevel_data_t *caps_data, static void caps_switchLevel_attr_level_send(caps_switchLevel_data_t *caps_data) { - IOT_EVENT *cap_evt; - uint8_t evt_num = 1; - int sequence_no; + int sequence_no = -1; if (!caps_data || !caps_data->handle) { printf("fail to get handle\n"); return; } - cap_evt = st_cap_attr_create_int((char *) caps_helper_switchLevel.attr_level.name, caps_data->level_value, caps_data->level_unit); - if (!cap_evt) { - printf("fail to create cap_evt\n"); - return; - } + ST_CAP_SEND_ATTR_NUMBER(caps_data->handle, + (char *)caps_helper_switchLevel.attr_level.name, + caps_data->level_value, + caps_data->level_unit, + NULL, + sequence_no); - sequence_no = st_cap_attr_send(caps_data->handle, evt_num, &cap_evt); if (sequence_no < 0) printf("fail to send level value\n"); - - printf("Sequence number return : %d\n", sequence_no); - st_cap_attr_free(cap_evt); + else + printf("Sequence number return : %d\n", sequence_no); } diff --git a/apps/emw3080/switch_example/main/caps_switch.c b/apps/emw3080/switch_example/main/caps_switch.c index 2ef1a85d..213c7156 100644 --- a/apps/emw3080/switch_example/main/caps_switch.c +++ b/apps/emw3080/switch_example/main/caps_switch.c @@ -31,8 +31,8 @@ static int caps_switch_attr_switch_str2idx(const char *value) if (!strcmp(value, caps_helper_switch.attr_switch.values[index])) { return index; } - } - return -1; + } + return -1; } static const char *caps_switch_get_switch_value(caps_switch_data_t *caps_data) @@ -58,9 +58,7 @@ static void caps_switch_set_switch_value(caps_switch_data_t *caps_data, const ch static void caps_switch_attr_switch_send(caps_switch_data_t *caps_data) { - IOT_EVENT *cap_evt; - uint8_t evt_num = 1; - int sequence_no; + int sequence_no = -1; if (!caps_data || !caps_data->handle) { printf("fail to get handle\n"); @@ -71,19 +69,18 @@ static void caps_switch_attr_switch_send(caps_switch_data_t *caps_data) return; } - cap_evt = st_cap_attr_create_string((char *)caps_helper_switch.attr_switch.name, - caps_data->switch_value, NULL); - if (!cap_evt) { - printf("fail to create cap_evt\n"); - return; - } + ST_CAP_SEND_ATTR_STRING(caps_data->handle, + (char *)caps_helper_switch.attr_switch.name, + caps_data->switch_value, + NULL, + NULL, + sequence_no); - sequence_no = st_cap_attr_send(caps_data->handle, evt_num, &cap_evt); if (sequence_no < 0) printf("fail to send switch value\n"); + else + printf("Sequence number return : %d\n", sequence_no); - printf("Sequence number return : %d\n", sequence_no); - st_cap_attr_free(cap_evt); } diff --git a/apps/rtl8720c/light_example/main/caps_activityLightingMode.c b/apps/rtl8720c/light_example/main/caps_activityLightingMode.c index 5841018c..667dc6c2 100644 --- a/apps/rtl8720c/light_example/main/caps_activityLightingMode.c +++ b/apps/rtl8720c/light_example/main/caps_activityLightingMode.c @@ -140,7 +140,7 @@ caps_activityLightingMode_data_t *caps_activityLightingMode_initialize(IOT_CTX * err = st_cap_cmd_set_cb(caps_data->handle, caps_helper_activityLightingMode.cmd_setLightingMode.name, caps_activityLightingMode_cmd_setLightingMode_cb, caps_data); if (err) { printf("fail to set cmd_cb for setLightingMode of activityLightingMode\n"); - } + } } else { printf("fail to init activityLightingMode handle\n"); } diff --git a/apps/rtl8720c/light_example/main/caps_colorTemperature.c b/apps/rtl8720c/light_example/main/caps_colorTemperature.c index 2868cf5c..fc3f5d0f 100644 --- a/apps/rtl8720c/light_example/main/caps_colorTemperature.c +++ b/apps/rtl8720c/light_example/main/caps_colorTemperature.c @@ -134,7 +134,7 @@ caps_colorTemperature_data_t *caps_colorTemperature_initialize(IOT_CTX *ctx, con err = st_cap_cmd_set_cb(caps_data->handle, caps_helper_colorTemperature.cmd_setColorTemperature.name, caps_colorTemperature_cmd_setColorTemperature_cb, caps_data); if (err) { printf("fail to set cmd_cb for setColorTemperature of colorTemperature\n"); - } + } } else { printf("fail to init colorTemperature handle\n"); } diff --git a/apps/rtl8720c/light_example/main/caps_switch.c b/apps/rtl8720c/light_example/main/caps_switch.c index bdac430c..213c7156 100644 --- a/apps/rtl8720c/light_example/main/caps_switch.c +++ b/apps/rtl8720c/light_example/main/caps_switch.c @@ -145,11 +145,11 @@ caps_switch_data_t *caps_switch_initialize(IOT_CTX *ctx, const char *component, err = st_cap_cmd_set_cb(caps_data->handle, caps_helper_switch.cmd_on.name, caps_switch_cmd_on_cb, caps_data); if (err) { printf("fail to set cmd_cb for on of switch\n"); - } + } err = st_cap_cmd_set_cb(caps_data->handle, caps_helper_switch.cmd_off.name, caps_switch_cmd_off_cb, caps_data); if (err) { printf("fail to set cmd_cb for off of switch\n"); - } + } } else { printf("fail to init switch handle\n"); } diff --git a/apps/rtl8720c/light_example/main/caps_switchLevel.c b/apps/rtl8720c/light_example/main/caps_switchLevel.c index dd7d92b9..f467b2db 100644 --- a/apps/rtl8720c/light_example/main/caps_switchLevel.c +++ b/apps/rtl8720c/light_example/main/caps_switchLevel.c @@ -134,7 +134,7 @@ caps_switchLevel_data_t *caps_switchLevel_initialize(IOT_CTX *ctx, const char *c err = st_cap_cmd_set_cb(caps_data->handle, caps_helper_switchLevel.cmd_setLevel.name, caps_switchLevel_cmd_setLevel_cb, caps_data); if (err) { printf("fail to set cmd_cb for setLevel of switchLevel\n"); - } + } } else { printf("fail to init switchLevel handle\n"); } diff --git a/apps/rtl8721c/light_example/main/caps_colorControl.h b/apps/rtl8721c/light_example/main/caps_colorControl.h index 67820c0f..7918fdd2 100644 --- a/apps/rtl8721c/light_example/main/caps_colorControl.h +++ b/apps/rtl8721c/light_example/main/caps_colorControl.h @@ -17,7 +17,7 @@ ****************************************************************************/ #include "caps/iot_caps_helper_colorControl.h" -#include "JSON.h" +#include "external/JSON.h" #ifdef __cplusplus extern "C" {