From d332f08da4babb43ca3e8da67e148f2ab9a78b56 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Thu, 1 Nov 2018 14:31:59 +0100 Subject: [PATCH] Make distinction between channels toggled via GPIO (button) or RPC --- src/channel.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/channel.c b/src/channel.c index 86fb3d4..903c101 100644 --- a/src/channel.c +++ b/src/channel.c @@ -113,7 +113,7 @@ exit: if (s_channels[idx].button_gpio != GPIO_INVALID) { 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_POS, 200, channel_handler, NULL); + mgos_gpio_set_button_handler(s_channels[idx].button_gpio, MGOS_GPIO_PULL_UP, MGOS_GPIO_INT_EDGE_NEG, 20, channel_handler, (void*) 1); } } } @@ -171,6 +171,7 @@ bool channel_get(int idx) { return s_channels[idx].relay_state == 1; } +// Channel handler arg is non-NULL if it was a pushbutton, and NULL if it was an RPC. void channel_handler(int gpio, void *arg) { uint8_t idx; bool state; @@ -181,7 +182,12 @@ void channel_handler(int gpio, void *arg) { return; } - LOG(LL_INFO, ("GPIO %d triggered button %d", gpio, idx)); + if (!arg) { // pushbutton + LOG(LL_INFO, ("RPC triggered channel %d", idx)); + } else { + LOG(LL_INFO, ("Button on GPIO %d triggered channel %d", gpio, idx)); + } + state = channel_get(idx); channel_set(idx, !state);