Added relay handler

This commit is contained in:
Dirk Jahnke 2018-01-27 17:18:20 +01:00
parent 85cdbbf42d
commit 922420a6fd
4 changed files with 48 additions and 2 deletions

View File

@ -9,11 +9,13 @@
"${workspaceRoot}/../modules/mongoose-os/fw/include", "${workspaceRoot}/../modules/mongoose-os/fw/include",
"${workspaceRoot}/../modules/mongoose-os/common", "${workspaceRoot}/../modules/mongoose-os/common",
"${workspaceRoot}/../modules/mongoose-os/src", "${workspaceRoot}/../modules/mongoose-os/src",
"${workspaceRoot}/../modules/mjs", "${workspaceRoot}/../modules/libs/mjs",
"${workspaceRoot}/../modules/libs/http-server/include", "${workspaceRoot}/../modules/libs/http-server/include",
"${workspaceRoot}/../modules/libs/http-i2c/include", "${workspaceRoot}/../modules/libs/http-i2c/include",
"${workspaceRoot}/../modules/libs/mqtt/include", "${workspaceRoot}/../modules/libs/mqtt/include",
"${workspaceRoot}/../modules/libs/cron/include" "${workspaceRoot}/../modules/libs/cron/include",
"${workspaceRoot}/../modules/libs/crontab/include",
"${workspaceRoot}/../modules/libs/wifi/include"
], ],
"defines": [], "defines": [],
"intelliSenseMode": "clang-x64", "intelliSenseMode": "clang-x64",

View File

@ -12,6 +12,7 @@
#include "buttonHandler.h" #include "buttonHandler.h"
#include "ledHandler.h" #include "ledHandler.h"
#include "relayHandler.h"
#define RELAY_PIN 12 #define RELAY_PIN 12
@ -52,6 +53,7 @@ static void mqtt_ev_handler(struct mg_connection *c, int ev, void *p, void *user
static void buttonPressOne(int pressCount) { static void buttonPressOne(int pressCount) {
LOG(LL_DEBUG, ("buttonPressOne called with pressCount=%d", pressCount)); LOG(LL_DEBUG, ("buttonPressOne called with pressCount=%d", pressCount));
set_relay(RELAY_TOGGLE);
} }
static void buttonPressTwo(int pressCount) { static void buttonPressTwo(int pressCount) {

29
src/relayHandler.c Normal file
View File

@ -0,0 +1,29 @@
#include "mgos.h"
#include "mgos_gpio.h"
#include "relayHandler.h"
#define ON_BOARD_RELAY_PIN 8
void set_relay(enum RelayAction rm) {
switch (rm) {
case RELAY_ON:
mgos_gpio_write(ON_BOARD_RELAY_PIN, false);
break;
case RELAY_OFF:
mgos_gpio_write(ON_BOARD_RELAY_PIN, true);
break;
case RELAY_TOGGLE:
mgos_gpio_toggle(ON_BOARD_RELAY_PIN);
break;
default:
LOG(LL_ERROR, ("ERROR: Unknown relay mode %d -- ignored", rm));
break;
}
LOG(LL_DEBUG, ("set_relay mode=%d", rm));
}
void init_relay_handler() {
mgos_gpio_set_mode(ON_BOARD_RELAY_PIN, MGOS_GPIO_MODE_OUTPUT);
mgos_gpio_write(ON_BOARD_RELAY_PIN, true);
}

13
src/relayHandler.h Normal file
View File

@ -0,0 +1,13 @@
// relayHandler.h
#ifndef _relayHandler_h_included_
#define _relayHandler_h_included_
enum RelayAction {
RELAY_ON = 0,
RELAY_OFF,
RELAY_TOGGLE
};
extern void set_relay(enum RelayAction newStatus);
extern void init_relay_handler();
#endif