gbmanager/src/relais.cpp

36 lines
1.2 KiB
C++
Raw Normal View History

2022-05-31 13:53:19 +02:00
#include "relais.h"
Relais::Relais(uint gpio, gpio_irq_callback_t callback)
: gpio{gpio}, callback{callback} {
2022-05-31 13:53:19 +02:00
gpio_init(gpio);
2022-05-31 15:59:22 +02:00
gpio_set_dir(gpio, GPIO_OUT);
2022-05-31 13:53:19 +02:00
off();
}
void Relais::activate(bool active) {
if (active == lastState) {
return;
}
lastState = active;
gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, false,
callback);
gpio_set_irq_enabled_with_callback(BUTTON_2_PIN, GPIO_IRQ_EDGE_FALL, false,
callback);
gpio_set_irq_enabled_with_callback(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, false,
callback);
gpio_put(gpio, !active);
sleep_ms(100);
gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, true,
callback);
gpio_set_irq_enabled_with_callback(BUTTON_2_PIN, GPIO_IRQ_EDGE_FALL, true,
callback);
gpio_set_irq_enabled_with_callback(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, true,
callback);
}
2022-05-31 13:53:19 +02:00
2022-05-31 14:28:15 +02:00
void Relais::on() { activate(true); }
2022-05-31 13:53:19 +02:00
void Relais::off() { activate(false); }