Skip to content

Commit

Permalink
caps_sample:update sample file in apps
Browse files Browse the repository at this point in the history
(cherry-picked from commit 85fc22c)

Signed-off-by: Hyundo Lee <[email protected]>
  • Loading branch information
hdlee27 authored and Kwang-Hui committed Dec 3, 2020
1 parent 452cd53 commit bd1ab52
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 96 deletions.
25 changes: 11 additions & 14 deletions apps/emw3080/light_example/main/caps_activityLightingMode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");
Expand All @@ -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);
}


Expand Down
21 changes: 9 additions & 12 deletions apps/emw3080/light_example/main/caps_colorTemperature.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
42 changes: 18 additions & 24 deletions apps/emw3080/light_example/main/caps_dustSensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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);
}


Expand Down
25 changes: 11 additions & 14 deletions apps/emw3080/light_example/main/caps_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");
Expand All @@ -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);
}


Expand Down
21 changes: 9 additions & 12 deletions apps/emw3080/light_example/main/caps_switchLevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
25 changes: 11 additions & 14 deletions apps/emw3080/switch_example/main/caps_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");
Expand All @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion apps/rtl8720c/light_example/main/caps_colorTemperature.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions apps/rtl8720c/light_example/main/caps_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion apps/rtl8720c/light_example/main/caps_switchLevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion apps/rtl8721c/light_example/main/caps_colorControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
****************************************************************************/

#include "caps/iot_caps_helper_colorControl.h"
#include "JSON.h"
#include "external/JSON.h"

#ifdef __cplusplus
extern "C" {
Expand Down

0 comments on commit bd1ab52

Please sign in to comment.