Add lightswitch to this firmware

This commit is contained in:
Pim van Pelt
2017-12-20 17:04:51 +01:00
parent 7ba19c8372
commit 1cbd2130db
24 changed files with 749 additions and 13 deletions

26
include/buttons.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef __BUTTONS_H
#define __BUTTONS_H
#include "mgos.h"
#include <string.h>
#define MAX_BUTTONS 8
struct button_t {
uint8_t gpio;
float last_change;
};
int buttons_init(const char *flag);
uint8_t buttons_find_by_gpio(uint8_t gpio);
bool buttons_touch_by_gpio(uint8_t gpio);
float buttons_get_last_change_by_gpio(uint8_t gpio);
bool buttons_touch_by_idx(uint8_t idx);
float buttons_get_last_change_by_idx(uint8_t idx);
uint8_t buttons_get_gpio_by_idx(uint8_t idx);
void buttons_cb(int gpio, void *args);
#endif // __BUTTONS_H

19
include/helper.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef __HELPER_H
#define __HELPER_H
#include "mgos.h"
#include <ctype.h>
#include <fnmatch.h>
#define MIN_GPIO 0
#define MAX_GPIO 16
#define MQTT_TOPIC_PREFIX ""
#define MQTT_TOPIC_BROADCAST_CMD "/mongoose/broadcast"
#define MQTT_TOPIC_BROADCAST_STAT "/mongoose/broadcast/stat"
#define ERR_GPIO_INVALID 255
bool is_button_flag_valid(const char *flag);
bool is_relay_flag_valid(const char *flag);
#endif // __HELPER_H

10
include/lightswitch.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __LIGHTSWITCH_H
#define __LIGHTSWITCH_h
#include <string.h>
#include "mgos.h"
#include "helper.h"
#include "buttons.h"
#include "relays.h"
#endif // __LIGHTSWITCH_h

10
include/mqtt.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __MQTT_H
#define __MQTT_H
#include "mgos.h"
#include "mgos_mqtt.h"
void mqtt_init();
void mqtt_publish_stat(const char *stat, const char *msg);
#endif // __MQTT_H

26
include/relays.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef __RELAYS_H
#define __RELAYS_H
#include "mgos.h"
#include <string.h>
#define MAX_RELAYS 8
struct relay_t {
uint8_t gpio;
float last_change;
bool state;
};
int relays_init(const char *flag);
uint8_t relays_find_by_gpio(uint8_t gpio);
bool relays_set_by_gpio(uint8_t gpio, bool state);
bool relays_get_by_gpio(uint8_t gpio);
float relays_get_last_change_by_gpio(uint8_t gpio);
bool relays_set_by_idx(uint8_t idx, bool state);
bool relays_get_by_idx(uint8_t idx);
float relays_get_last_change_by_idx(uint8_t idx);
uint8_t relays_get_gpio_by_idx(uint8_t idx);
#endif // __RELAYS_H

10
include/rpc.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __RPC_H
#define __RPC_H
#include "mgos.h"
#include "mgos_rpc.h"
#include "common/mg_str.h"
void rpc_init();
#endif // __RPC_H