Make distinction between channels toggled via GPIO (button) or RPC
This commit is contained in:
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user