mg_sonoff/src/main.c

41 lines
1.2 KiB
C

#include "mgos.h"
#include "mgos_app.h"
#include "mgos_sys_config.h"
#include "mgos_timers.h"
#include "buttonHandler.h"
#include "ledHandler.h"
#include "relayHandler.h"
#include "mqttHandler.h"
static void buttonPressOne(int pressCount) {
LOG(LL_DEBUG, ("buttonPressOne called with pressCount=%d", pressCount));
set_relay(RELAY_TOGGLE);
set_led_status(LED_ONCE);
}
static void buttonPressTwo(int pressCount) {
LOG(LL_DEBUG, ("buttonPressTwo called with pressCount=%d", pressCount));
}
static void buttonPressThree(int pressCount) {
LOG(LL_DEBUG, ("buttonPressThree called with pressCount=%d", pressCount));
}
static void on_board_led_off_cb(void *arg) {
(void) arg;
set_led_status(LED_OFF);
}
enum mgos_app_init_result mgos_app_init(void) {
init_led_handler();
set_led_status(LED_BLINK_FAST);
init_button_handler();
add_button_press_callback(1, buttonPressOne);
add_button_press_callback(2, buttonPressTwo);
add_button_press_callback(3, buttonPressThree);
init_mqtt_handler();
LOG(LL_INFO, ("SONOFF app initialized"));
mgos_set_timer(5000, 0, on_board_led_off_cb, NULL);
return MGOS_APP_INIT_SUCCESS;
}