Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development gpio not found fix #81

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions ezlopi-core/ezlopi-core-factory-info/ezlopi_core_factory_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,44 @@ extern "C"
\"pullup_ip\": true,\
\"pullup_op\": true,\
\"op_inv\": false\
},\
{\
\"dev_type\": 1,\
\"dev_name\": \"LED\",\
\"id_room\": \"\",\
\"id_item\": 1,\
\"gpio_in\": 0,\
\"gpio_out\": 1,\
\"pullup_ip\": false,\
\"pullup_op\": true,\
\"is_ip\": false,\
\"ip_inv\": false,\
\"op_inv\": false,\
\"val_ip\": false,\
\"val_op\": false\
},\
{\
\"dev_type\":5,\
\"dev_name\":\"RED LED\",\
\"id_room\":\"\",\
\"id_item\":22,\
\"gpio\":5,\
\"pwm_resln\":8,\
\"freq_hz\":10000,\
\"duty_cycle\":0\
},\
{\
\"dev_type\":5,\
\"dev_name\":\"GREEN LED\",\
\"id_room\":\"\",\
\"id_item\":22,\
\"gpio\":13,\
\"pwm_resln\":8,\
\"freq_hz\":10000,\
\"duty_cycle\":0\
}\
],\
\"dev_total\": 1}";
], \
\"dev_total\": 4}";
#endif


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void __setup_item_properties(l_ezlopi_item_t *item, cJSON *cjson_device)

item->interface.gpio.gpio_in.enable = true;
CJSON_GET_VALUE_INT(cjson_device, ezlopi_dev_type_str, item->interface_type);
CJSON_GET_VALUE_GPIO(cjson_device, ezlopi_dev_name_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_GPIO(cjson_device, ezlopi_gpio_str, item->interface.gpio.gpio_in.gpio_num);
CJSON_GET_VALUE_INT(cjson_device, "logic_inv", item->interface.gpio.gpio_in.invert);
CJSON_GET_VALUE_INT(cjson_device, "pull_up", tmp_var);
item->interface.gpio.gpio_in.pull = tmp_var ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ typedef struct s_dimmable_bulb_properties
bool dimmable_bulb_initialized;
uint32_t previous_brightness_value;
uint32_t current_brightness_value;
l_ezlopi_item_t *item_dimmer;
l_ezlopi_item_t *item_dimmer_up;
l_ezlopi_item_t *item_dimmer_down;
l_ezlopi_item_t *item_dimmer_stop;
l_ezlopi_item_t *item_dimmer_switch;
l_ezlopi_item_t* item_dimmer;
l_ezlopi_item_t* item_dimmer_up;
l_ezlopi_item_t* item_dimmer_down;
l_ezlopi_item_t* item_dimmer_stop;
l_ezlopi_item_t* item_dimmer_switch;

} s_dimmable_bulb_properties_t;

static int __prepare(void *arg);
static int __init(l_ezlopi_item_t *item);
static int __list_cjson_value(l_ezlopi_item_t *item, void *arg);
static int __get_cjson_value(l_ezlopi_item_t *item, void *arg);
static int __set_cjson_value(l_ezlopi_item_t *item, void *arg);
static int __prepare(void* arg);
static int __init(l_ezlopi_item_t* item);
static int __list_cjson_value(l_ezlopi_item_t* item, void* arg);
static int __get_cjson_value(l_ezlopi_item_t* item, void* arg);
static int __set_cjson_value(l_ezlopi_item_t* item, void* arg);

int device_0022_PWM_dimmable_lamp(e_ezlopi_actions_t action, l_ezlopi_item_t *item, void *arg, void *user_arg)
int device_0022_PWM_dimmable_lamp(e_ezlopi_actions_t action, l_ezlopi_item_t* item, void* arg, void* user_arg)
{
int ret = 0;

Expand Down Expand Up @@ -71,14 +71,14 @@ int device_0022_PWM_dimmable_lamp(e_ezlopi_actions_t action, l_ezlopi_item_t *it
return ret;
}

static int __set_cjson_value(l_ezlopi_item_t *item, void *arg)
static int __set_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;

cJSON *device_details = (cJSON *)arg;
cJSON* device_details = (cJSON*)arg;
if (device_details)
{
s_dimmable_bulb_properties_t *dimmable_bulb_arg = (s_dimmable_bulb_properties_t *)item->user_arg;
s_dimmable_bulb_properties_t* dimmable_bulb_arg = (s_dimmable_bulb_properties_t*)item->user_arg;
if (dimmable_bulb_arg)
{
if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
Expand Down Expand Up @@ -108,19 +108,19 @@ static int __set_cjson_value(l_ezlopi_item_t *item, void *arg)
return ret;
}

static int __list_cjson_value(l_ezlopi_item_t *item, void *arg)
static int __list_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;

cJSON *param = (cJSON *)arg;
cJSON* param = (cJSON*)arg;
if (param && item && item->user_arg)
{
s_dimmable_bulb_properties_t *dimmable_bulb_arg = (s_dimmable_bulb_properties_t *)item->user_arg;
s_dimmable_bulb_properties_t* dimmable_bulb_arg = (s_dimmable_bulb_properties_t*)item->user_arg;
if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
{
int dimmable_value_percentage = (int)floor(((dimmable_bulb_arg->current_brightness_value * 100.0) / 4095.0));
cJSON_AddNumberToObject(param, ezlopi_value_str, dimmable_value_percentage);
char *formatted_val = ezlopi_valueformatter_int(dimmable_value_percentage);
char* formatted_val = ezlopi_valueformatter_int(dimmable_value_percentage);
if (formatted_val)
{
cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
Expand All @@ -132,7 +132,7 @@ static int __list_cjson_value(l_ezlopi_item_t *item, void *arg)
else if (ezlopi_item_name_dimmer_up == item->cloud_properties.item_name)
{
cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
char* formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
Expand All @@ -142,7 +142,7 @@ static int __list_cjson_value(l_ezlopi_item_t *item, void *arg)
else if (ezlopi_item_name_dimmer_down == item->cloud_properties.item_name)
{
cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
char* formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
Expand All @@ -152,7 +152,7 @@ static int __list_cjson_value(l_ezlopi_item_t *item, void *arg)
else if (ezlopi_item_name_dimmer_stop == item->cloud_properties.item_name)
{
cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
char* formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
Expand All @@ -170,26 +170,26 @@ static int __list_cjson_value(l_ezlopi_item_t *item, void *arg)
return ret;
}

static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
static int __get_cjson_value(l_ezlopi_item_t* item, void* arg)
{
int ret = 0;

cJSON *param = (cJSON *)arg;
cJSON* param = (cJSON*)arg;
if (param && item && item->user_arg)
{
s_dimmable_bulb_properties_t *dimmable_bulb_arg = (s_dimmable_bulb_properties_t *)item->user_arg;
s_dimmable_bulb_properties_t* dimmable_bulb_arg = (s_dimmable_bulb_properties_t*)item->user_arg;
if (ezlopi_item_name_dimmer == item->cloud_properties.item_name)
{
int dimmable_value_percentage = (int)floor(((dimmable_bulb_arg->current_brightness_value * 100.0) / 4095.0));
cJSON_AddNumberToObject(param, ezlopi_value_str, dimmable_value_percentage);
char *formatted_val = ezlopi_valueformatter_int(dimmable_value_percentage);
char* formatted_val = ezlopi_valueformatter_int(dimmable_value_percentage);
cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
free(formatted_val);
}
else if (ezlopi_item_name_dimmer_up == item->cloud_properties.item_name)
{
cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
char* formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
Expand All @@ -199,7 +199,7 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
else if (ezlopi_item_name_dimmer_down == item->cloud_properties.item_name)
{
cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
char* formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
Expand All @@ -209,7 +209,7 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
else if (ezlopi_item_name_dimmer_stop == item->cloud_properties.item_name)
{
cJSON_AddNumberToObject(param, ezlopi_value_str, 0);
char *formatted_val = ezlopi_valueformatter_int(0);
char* formatted_val = ezlopi_valueformatter_int(0);
if (formatted_val)
{
cJSON_AddStringToObject(param, ezlopi_valueFormatted_str, formatted_val);
Expand All @@ -227,20 +227,20 @@ static int __get_cjson_value(l_ezlopi_item_t *item, void *arg)
return ret;
}

static int __init(l_ezlopi_item_t *item)
static int __init(l_ezlopi_item_t* item)
{
int ret = 0;
if (item)
{
if (GPIO_IS_VALID_GPIO(item->interface.pwm.gpio_num))
{
s_dimmable_bulb_properties_t *dimmable_bulb_arg = (s_dimmable_bulb_properties_t *)item->user_arg;
s_dimmable_bulb_properties_t* dimmable_bulb_arg = (s_dimmable_bulb_properties_t*)item->user_arg;
if (dimmable_bulb_arg)
{
if (0 == dimmable_bulb_arg->dimmable_bulb_initialized)
{
s_ezlopi_channel_speed_t *ezlopi_dimmable_channel_speed = ezlopi_pwm_init(item->interface.pwm.gpio_num, item->interface.pwm.pwm_resln,
item->interface.pwm.freq_hz, item->interface.pwm.duty_cycle);
s_ezlopi_channel_speed_t* ezlopi_dimmable_channel_speed = ezlopi_pwm_init(item->interface.pwm.gpio_num, item->interface.pwm.pwm_resln,
item->interface.pwm.freq_hz, item->interface.pwm.duty_cycle);
if (ezlopi_dimmable_channel_speed)
{
item->interface.pwm.channel = ezlopi_dimmable_channel_speed->channel;
Expand Down Expand Up @@ -277,7 +277,7 @@ static int __init(l_ezlopi_item_t *item)
return ret;
}

static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *cj_device)
static void __prepare_device_cloud_properties(l_ezlopi_device_t* device, cJSON* cj_device)
{
// char *device_name = NULL;
// CJSON_GET_VALUE_STRING(cj_device, ezlopi_dev_name_str, device_name);
Expand All @@ -291,7 +291,7 @@ static void __prepare_device_cloud_properties(l_ezlopi_device_t *device, cJSON *
device->cloud_properties.device_type_id = NULL;
}

static void __prepare_dimmer_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
static void __prepare_dimmer_item_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.has_getter = true;
Expand All @@ -308,7 +308,7 @@ static void __prepare_dimmer_item_properties(l_ezlopi_item_t *item, cJSON *cj_de
item->interface.pwm.pwm_resln = 12;
}

static void __prepare_dimmer_up_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
static void __prepare_dimmer_up_item_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.has_getter = true;
Expand All @@ -325,7 +325,7 @@ static void __prepare_dimmer_up_item_properties(l_ezlopi_item_t *item, cJSON *cj
item->interface.pwm.pwm_resln = 12;
}

static void __prepare_dimmer_down_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
static void __prepare_dimmer_down_item_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.has_getter = true;
Expand All @@ -342,7 +342,7 @@ static void __prepare_dimmer_down_item_properties(l_ezlopi_item_t *item, cJSON *
item->interface.pwm.pwm_resln = 12;
}

static void __prepare_dimmer_stop_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
static void __prepare_dimmer_stop_item_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
CJSON_GET_VALUE_INT(cj_device, ezlopi_dev_type_str, item->interface_type);
item->cloud_properties.has_getter = true;
Expand All @@ -359,7 +359,7 @@ static void __prepare_dimmer_stop_item_properties(l_ezlopi_item_t *item, cJSON *
item->interface.pwm.pwm_resln = 12;
}

static void __prepare_dimmer_switch_item_properties(l_ezlopi_item_t *item, cJSON *cj_device)
static void __prepare_dimmer_switch_item_properties(l_ezlopi_item_t* item, cJSON* cj_device)
{
item->interface_type = EZLOPI_DEVICE_INTERFACE_DIGITAL_OUTPUT;
item->cloud_properties.has_getter = true;
Expand All @@ -370,7 +370,7 @@ static void __prepare_dimmer_switch_item_properties(l_ezlopi_item_t *item, cJSON
item->cloud_properties.item_id = ezlopi_cloud_generate_item_id();
item->cloud_properties.scale = NULL;

CJSON_GET_VALUE_GPIO(cj_device, ezlopi_dev_name_str, item->interface.gpio.gpio_out.gpio_num);
CJSON_GET_VALUE_GPIO(cj_device, ezlopi_gpio_str, item->interface.gpio.gpio_out.gpio_num);
item->interface.gpio.gpio_in.enable = false;
item->interface.gpio.gpio_out.enable = true;
item->interface.gpio.gpio_out.interrupt = false;
Expand All @@ -380,19 +380,19 @@ static void __prepare_dimmer_switch_item_properties(l_ezlopi_item_t *item, cJSON
item->interface.gpio.gpio_out.value = true;
}

static int __prepare(void *arg)
static int __prepare(void* arg)
{
int ret = 0;

s_ezlopi_prep_arg_t *prep_arg = (s_ezlopi_prep_arg_t *)arg;
s_ezlopi_prep_arg_t* prep_arg = (s_ezlopi_prep_arg_t*)arg;
if (prep_arg && prep_arg->cjson_device)
{
l_ezlopi_device_t *device = ezlopi_device_add_device(prep_arg->cjson_device);
l_ezlopi_device_t* device = ezlopi_device_add_device(prep_arg->cjson_device);
if (device)
{
__prepare_device_cloud_properties(device, prep_arg->cjson_device);

s_dimmable_bulb_properties_t *dimmable_bulb_arg = malloc(sizeof(s_dimmable_bulb_properties_t));
s_dimmable_bulb_properties_t* dimmable_bulb_arg = malloc(sizeof(s_dimmable_bulb_properties_t));
if (dimmable_bulb_arg)
{
dimmable_bulb_arg->current_brightness_value = 0;
Expand Down
Loading