Formatting

This commit is contained in:
Pim van Pelt
2018-04-17 15:00:29 +02:00
parent 8bf7b919cc
commit 491ba88d1a
25 changed files with 2290 additions and 1956 deletions

View File

@ -21,8 +21,8 @@ static bool rpc_args_to_idx_and_gpio(struct mg_rpc_request_info *ri, struct mg_s
return false;
}
if (idx<0 || idx>=channel_get_total()) {
mg_rpc_send_errorf(ri, 400, "idx must be between 0 and %d", channel_get_total()-1);
if (idx < 0 || idx >= channel_get_total()) {
mg_rpc_send_errorf(ri, 400, "idx must be between 0 and %d", channel_get_total() - 1);
ri = NULL;
return false;
}
@ -35,51 +35,53 @@ static bool rpc_args_to_idx_and_gpio(struct mg_rpc_request_info *ri, struct mg_s
}
*return_gpio = gpio;
*return_idx = idx;
*return_idx = idx;
return true;
}
static void rpc_channel_toggle_handler(struct mg_rpc_request_info *ri, void *cb_arg, struct mg_rpc_frame_info *fi, struct mg_str args) {
uint8_t gpio;
int idx;
int idx;
rpc_log(ri, args);
if (!rpc_args_to_idx_and_gpio(ri, args, &idx, &gpio))
if (!rpc_args_to_idx_and_gpio(ri, args, &idx, &gpio)) {
return;
}
channel_handler(gpio, NULL);
mg_rpc_send_responsef(ri, "{idx: %d, relay_state: %d}", idx, channel_get(idx));
ri = NULL;
(void) ri;
(void) cb_arg;
(void) fi;
(void) args;
(void)ri;
(void)cb_arg;
(void)fi;
(void)args;
}
static void rpc_channel_get_handler(struct mg_rpc_request_info *ri, void *cb_arg, struct mg_rpc_frame_info *fi, struct mg_str args) {
uint8_t gpio;
int idx;
int idx;
rpc_log(ri, args);
if (!rpc_args_to_idx_and_gpio(ri, args, &idx, &gpio))
if (!rpc_args_to_idx_and_gpio(ri, args, &idx, &gpio)) {
return;
}
mg_rpc_send_responsef(ri, "{idx: %d, relay_state: %d}", idx, channel_get(idx));
ri = NULL;
(void) ri;
(void) cb_arg;
(void) fi;
(void) args;
(void)ri;
(void)cb_arg;
(void)fi;
(void)args;
}
static void rpc_channel_set_handler(struct mg_rpc_request_info *ri, void *cb_arg, struct mg_rpc_frame_info *fi, struct mg_str args) {
uint8_t gpio;
int idx;
int value;
int idx;
int value;
rpc_log(ri, args);
@ -89,8 +91,8 @@ static void rpc_channel_set_handler(struct mg_rpc_request_info *ri, void *cb_arg
return;
}
if (idx<0 || idx>=channel_get_total()) {
mg_rpc_send_errorf(ri, 400, "idx must be between 0 and %d", channel_get_total()-1);
if (idx < 0 || idx >= channel_get_total()) {
mg_rpc_send_errorf(ri, 400, "idx must be between 0 and %d", channel_get_total() - 1);
ri = NULL;
return;
}
@ -102,18 +104,19 @@ static void rpc_channel_set_handler(struct mg_rpc_request_info *ri, void *cb_arg
return;
}
channel_set(idx, (bool) value);
channel_set(idx, (bool)value);
mg_rpc_send_responsef(ri, "{idx: %d, relay_state: %d}", idx, channel_get(idx));
ri = NULL;
(void) ri;
(void) cb_arg;
(void) fi;
(void) args;
(void)ri;
(void)cb_arg;
(void)fi;
(void)args;
}
void rpc_init() {
struct mg_rpc *c = mgos_rpc_get_global();
mg_rpc_add_handler(c, "Channel.Toggle", "{idx: %d}", rpc_channel_toggle_handler, NULL);
mg_rpc_add_handler(c, "Channel.Get", "{idx: %d}", rpc_channel_get_handler, NULL);
mg_rpc_add_handler(c, "Channel.Set", "{idx: %d, value: %d}", rpc_channel_set_handler, NULL);