Add channel_get_total()

This commit is contained in:
Pim van Pelt
2018-01-22 22:23:48 +01:00
parent b78e79223a
commit 3327a561f9
3 changed files with 13 additions and 8 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>2) {
mg_rpc_send_errorf(ri, 400, "idx must be 0, 1, 2");
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;
}
@ -95,8 +95,8 @@ static void rpc_channel_set_handler(struct mg_rpc_request_info *ri, void *cb_arg
return;
}
if (idx<0 || idx>2) {
mg_rpc_send_errorf(ri, 400, "idx must be 0, 1, 2");
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;
}