format with uncrustify
This commit is contained in:
@ -85,10 +85,10 @@ bool channel_init(const char *fn) {
|
|||||||
LOG(LL_ERROR, ("Too many channels (max is %d)", CHANNEL_MAX));
|
LOG(LL_ERROR, ("Too many channels (max is %d)", CHANNEL_MAX));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
LOG(LL_INFO, ("Channel[%d]: led=%d%s relay=%d%s button=%d ", idx, led, led_invert?"(inverted)":"", relay, relay_invert?"(inverted)":"", button));
|
LOG(LL_INFO, ("Channel[%d]: led=%d%s relay=%d%s button=%d ", idx, led, led_invert ? "(inverted)" : "", relay, relay_invert ? "(inverted)" : "", button));
|
||||||
s_channels[idx].button_gpio = button;
|
s_channels[idx].button_gpio = button;
|
||||||
s_channels[idx].relay_gpio = relay;
|
s_channels[idx].relay_gpio = relay;
|
||||||
s_channels[idx].relay_invert= relay_invert;
|
s_channels[idx].relay_invert = relay_invert;
|
||||||
s_channels[idx].led_gpio = led;
|
s_channels[idx].led_gpio = led;
|
||||||
s_channels[idx].led_invert = led_invert;
|
s_channels[idx].led_invert = led_invert;
|
||||||
}
|
}
|
||||||
@ -108,17 +108,17 @@ exit:
|
|||||||
|
|
||||||
if (s_channels[idx].relay_gpio != GPIO_INVALID) {
|
if (s_channels[idx].relay_gpio != GPIO_INVALID) {
|
||||||
mgos_gpio_set_mode(s_channels[idx].relay_gpio, MGOS_GPIO_MODE_OUTPUT);
|
mgos_gpio_set_mode(s_channels[idx].relay_gpio, MGOS_GPIO_MODE_OUTPUT);
|
||||||
mgos_gpio_write(s_channels[idx].relay_gpio, (s_channels[idx].relay_state + s_channels[idx].relay_invert)%2);
|
mgos_gpio_write(s_channels[idx].relay_gpio, (s_channels[idx].relay_state + s_channels[idx].relay_invert) % 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_channels[idx].led_gpio != GPIO_INVALID) {
|
if (s_channels[idx].led_gpio != GPIO_INVALID) {
|
||||||
mgos_gpio_set_mode(s_channels[idx].led_gpio, MGOS_GPIO_MODE_OUTPUT);
|
mgos_gpio_set_mode(s_channels[idx].led_gpio, MGOS_GPIO_MODE_OUTPUT);
|
||||||
mgos_gpio_write(s_channels[idx].led_gpio, (s_channels[idx].relay_state + s_channels[idx].led_invert)%2);
|
mgos_gpio_write(s_channels[idx].led_gpio, (s_channels[idx].relay_state + s_channels[idx].led_invert) % 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_channels[idx].button_gpio != GPIO_INVALID) {
|
if (s_channels[idx].button_gpio != GPIO_INVALID) {
|
||||||
mgos_gpio_set_mode(s_channels[idx].button_gpio, MGOS_GPIO_MODE_INPUT);
|
mgos_gpio_set_mode(s_channels[idx].button_gpio, MGOS_GPIO_MODE_INPUT);
|
||||||
mgos_gpio_set_button_handler(s_channels[idx].button_gpio, MGOS_GPIO_PULL_UP, MGOS_GPIO_INT_EDGE_NEG, 20, channel_handler, (void*) 1);
|
mgos_gpio_set_button_handler(s_channels[idx].button_gpio, MGOS_GPIO_PULL_UP, MGOS_GPIO_INT_EDGE_NEG, 20, channel_handler, (void *)1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,6 +156,7 @@ struct channel_set_cb_args {
|
|||||||
|
|
||||||
static void channel_set_cb(void *arg) {
|
static void channel_set_cb(void *arg) {
|
||||||
struct channel_set_cb_args *cb_args = (struct channel_set_cb_args *)arg;
|
struct channel_set_cb_args *cb_args = (struct channel_set_cb_args *)arg;
|
||||||
|
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
LOG(LL_ERROR, ("Callback arg is NULL"));
|
LOG(LL_ERROR, ("Callback arg is NULL"));
|
||||||
return;
|
return;
|
||||||
@ -179,7 +180,7 @@ void channel_set_duration(int idx, bool state, uint16_t seconds) {
|
|||||||
cb_args->value = !state;
|
cb_args->value = !state;
|
||||||
cb_args->idx = idx;
|
cb_args->idx = idx;
|
||||||
LOG(LL_INFO, ("Setting timer for %d seconds on channel %d with future value %d", seconds, cb_args->idx, cb_args->value));
|
LOG(LL_INFO, ("Setting timer for %d seconds on channel %d with future value %d", seconds, cb_args->idx, cb_args->value));
|
||||||
mgos_set_timer (1000 * seconds, false /* oneshot */, channel_set_cb, cb_args);
|
mgos_set_timer(1000 * seconds, false /* oneshot */, channel_set_cb, cb_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void channel_set(int idx, bool state) {
|
void channel_set(int idx, bool state) {
|
||||||
@ -192,10 +193,10 @@ void channel_set(int idx, bool state) {
|
|||||||
s_channels[idx].button_last_change = now;
|
s_channels[idx].button_last_change = now;
|
||||||
s_channels[idx].relay_state = state;
|
s_channels[idx].relay_state = state;
|
||||||
if (s_channels[idx].relay_gpio != GPIO_INVALID) {
|
if (s_channels[idx].relay_gpio != GPIO_INVALID) {
|
||||||
mgos_gpio_write(s_channels[idx].relay_gpio, (s_channels[idx].relay_state + s_channels[idx].relay_invert)%2);
|
mgos_gpio_write(s_channels[idx].relay_gpio, (s_channels[idx].relay_state + s_channels[idx].relay_invert) % 2);
|
||||||
}
|
}
|
||||||
if (s_channels[idx].led_gpio != GPIO_INVALID) {
|
if (s_channels[idx].led_gpio != GPIO_INVALID) {
|
||||||
mgos_gpio_write(s_channels[idx].led_gpio, (s_channels[idx].relay_state + s_channels[idx].led_invert)%2);
|
mgos_gpio_write(s_channels[idx].led_gpio, (s_channels[idx].relay_state + s_channels[idx].led_invert) % 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
mqtt_publish_stat("channel", "{idx: %d, relay_state: %d}", idx, channel_get(idx));
|
mqtt_publish_stat("channel", "{idx: %d, relay_state: %d}", idx, channel_get(idx));
|
||||||
@ -233,13 +234,13 @@ void channel_handler(int gpio, void *arg) {
|
|||||||
LOG(LL_INFO, ("Button on GPIO %d triggered channel %d", gpio, idx));
|
LOG(LL_INFO, ("Button on GPIO %d triggered channel %d", gpio, idx));
|
||||||
// Scan the button for 100ms to ensure it is still pressed. This is to avoid
|
// Scan the button for 100ms to ensure it is still pressed. This is to avoid
|
||||||
// RFI noise from triggering GPIO pins.
|
// RFI noise from triggering GPIO pins.
|
||||||
for (int i=0; i<10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
bool value;
|
bool value;
|
||||||
|
|
||||||
mgos_msleep(10);
|
mgos_msleep(10);
|
||||||
value=mgos_gpio_read(gpio);
|
value = mgos_gpio_read(gpio);
|
||||||
if (value) {
|
if (value) {
|
||||||
LOG(LL_WARN, ("Button on GPIO %d no longer pressed after %d ms, skipping", gpio, 10*i));
|
LOG(LL_WARN, ("Button on GPIO %d no longer pressed after %d ms, skipping", gpio, 10 * i));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ static bool timespec_spec_parse(const char *spec, struct mgos_timespec_spec *out
|
|||||||
LOG(LL_ERROR, ("spec cannot be NULL or empty"));
|
LOG(LL_ERROR, ("spec cannot be NULL or empty"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (i = 1; i < (int) strlen(spec); i++) {
|
for (i = 1; i < (int)strlen(spec); i++) {
|
||||||
if (spec[i] != ':' && spec[i] != '-' && !(spec[i] >= '0' && spec[i] <= '9')) {
|
if (spec[i] != ':' && spec[i] != '-' && !(spec[i] >= '0' && spec[i] <= '9')) {
|
||||||
LOG(LL_ERROR, ("spec='%s': illegal chars, only want [:\\-0-9]", spec));
|
LOG(LL_ERROR, ("spec='%s': illegal chars, only want [:\\-0-9]", spec));
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user