Add lightswitch to this firmware
This commit is contained in:
@ -9,7 +9,7 @@ default: $(TARGET)
|
||||
all: default
|
||||
|
||||
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
|
||||
SRCS = frozen/frozen.c ../src/widget.c ../src/screen.c
|
||||
SRCS = frozen/frozen.c ../src/widget.c ../src/screen.c ../src/helper.c ../src/buttons.c ../src/relays.c ../src/mqtt.c
|
||||
HEADERS = $(wildcard *.h)
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __MGOS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
5
unittest/mgos_config.c
Normal file
5
unittest/mgos_config.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include "mgos_config.h"
|
||||
|
||||
const char *mgos_sys_config_get_device_id() {
|
||||
return "esp8266_ABCDEF";
|
||||
}
|
6
unittest/mgos_config.h
Normal file
6
unittest/mgos_config.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef __MGOS_CONFIG_H
|
||||
#define __MGOS_CONFIG_H
|
||||
|
||||
const char *mgos_sys_config_get_device_id();
|
||||
|
||||
#endif // __MGOS_CONFIG_H
|
31
unittest/mgos_gpio.c
Normal file
31
unittest/mgos_gpio.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include "mgos.h"
|
||||
#include "mgos_gpio.h"
|
||||
|
||||
static mgos_gpio_int_handler_f s_handler_cb;
|
||||
static void *s_handler_cb_arg;
|
||||
|
||||
bool mgos_gpio_set_mode(int pin, enum mgos_gpio_mode mode) {
|
||||
LOG(LL_INFO, ("Setting pin=%d to mode=%d", pin, mode));
|
||||
return true;
|
||||
}
|
||||
|
||||
void mgos_gpio_write(int pin, bool level) {
|
||||
LOG(LL_INFO, ("Setting pin=%d to %s", pin, level?"HIGH":"LOW"));
|
||||
}
|
||||
|
||||
bool mgos_gpio_set_button_handler(int pin, enum mgos_gpio_pull_type pull_type, enum mgos_gpio_int_mode int_mode, int debounce_ms, mgos_gpio_int_handler_f cb, void *arg) {
|
||||
s_handler_cb = cb;
|
||||
s_handler_cb_arg = arg;
|
||||
|
||||
return true;
|
||||
(void) debounce_ms;
|
||||
(void) int_mode;
|
||||
(void) pull_type;
|
||||
(void) pin;
|
||||
}
|
||||
|
||||
void mgos_gpio_inject(int pin) {
|
||||
if (s_handler_cb)
|
||||
s_handler_cb(pin, s_handler_cb_arg);
|
||||
}
|
||||
|
39
unittest/mgos_gpio.h
Normal file
39
unittest/mgos_gpio.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef __MGOS_GPIO_H
|
||||
#define __MGOS_GPIO_H
|
||||
|
||||
#include "mgos.h"
|
||||
|
||||
enum mgos_gpio_mode {
|
||||
MGOS_GPIO_MODE_INPUT = 0, /* input mode */
|
||||
MGOS_GPIO_MODE_OUTPUT = 1 /* output mode */
|
||||
};
|
||||
|
||||
enum mgos_gpio_pull_type {
|
||||
MGOS_GPIO_PULL_NONE = 0,
|
||||
MGOS_GPIO_PULL_UP = 1, /* pin is pilled to the high voltage */
|
||||
MGOS_GPIO_PULL_DOWN = 2 /* pin is pulled to the low voltage */
|
||||
};
|
||||
|
||||
enum mgos_gpio_int_mode {
|
||||
MGOS_GPIO_INT_NONE = 0,
|
||||
MGOS_GPIO_INT_EDGE_POS = 1, /* positive edge */
|
||||
MGOS_GPIO_INT_EDGE_NEG = 2, /* negative edge */
|
||||
MGOS_GPIO_INT_EDGE_ANY = 3, /* any edge - positive or negative */
|
||||
MGOS_GPIO_INT_LEVEL_HI = 4, /* high voltage level */
|
||||
MGOS_GPIO_INT_LEVEL_LO = 5 /* low voltage level */
|
||||
};
|
||||
|
||||
typedef void (*mgos_gpio_int_handler_f)(int pin, void *arg);
|
||||
|
||||
bool mgos_gpio_set_mode(int pin, enum mgos_gpio_mode mode);
|
||||
void mgos_gpio_write(int pin, bool level);
|
||||
|
||||
bool mgos_gpio_set_button_handler(int pin, enum mgos_gpio_pull_type pull_type,
|
||||
enum mgos_gpio_int_mode int_mode,
|
||||
int debounce_ms, mgos_gpio_int_handler_f cb,
|
||||
void *arg);
|
||||
|
||||
void mgos_gpio_inject(int pin);
|
||||
|
||||
|
||||
#endif // __MGOS_GPIO_H
|
@ -49,3 +49,7 @@ void mgos_clear_timer(mgos_timer_id id) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float mg_time() {
|
||||
return (float) time(NULL);
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include "mgos.h"
|
||||
|
||||
#define MGOS_APP "unittest"
|
||||
|
||||
// mgos_log
|
||||
enum cs_log_level {
|
||||
LL_NONE = -1,
|
||||
@ -36,4 +38,6 @@ typedef void (*timer_callback)(void *param);
|
||||
mgos_timer_id mgos_set_timer(int msecs, int flags, timer_callback cb, void *cb_arg);
|
||||
void mgos_clear_timer(mgos_timer_id id);
|
||||
|
||||
float mg_time();
|
||||
|
||||
#endif // __MGOS_MOCK_H
|
||||
|
26
unittest/mgos_mqtt.c
Normal file
26
unittest/mgos_mqtt.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "mgos.h"
|
||||
#include "mgos_mqtt.h"
|
||||
|
||||
uint32_t mqtt_pub_count=0;
|
||||
uint32_t mqtt_sub_count=0;
|
||||
|
||||
static sub_handler_t s_handler;
|
||||
static void *s_handler_ud;
|
||||
|
||||
void mgos_mqtt_pub(char *t, char *m, int m_len, int flags, bool persist) {
|
||||
LOG(LL_INFO, ("Sending topic='%s' msg='%s' persist=%s", t, m, persist?"ON":"OFF"));
|
||||
mqtt_pub_count++;
|
||||
}
|
||||
|
||||
void mgos_mqtt_sub(char *t, sub_handler_t cb, void *ud) {
|
||||
LOG(LL_INFO, ("Subscribing to topic='%s'", t));
|
||||
s_handler = cb;
|
||||
s_handler_ud = ud;
|
||||
}
|
||||
|
||||
void mgos_mqtt_inject(char *topic, char *msg) {
|
||||
LOG(LL_INFO, ("Injecting topic='%s' msg='%s'", topic, msg));
|
||||
mqtt_sub_count++;
|
||||
if (s_handler)
|
||||
s_handler(NULL, topic, strlen(topic), msg, strlen(msg), s_handler_ud);
|
||||
}
|
17
unittest/mgos_mqtt.h
Normal file
17
unittest/mgos_mqtt.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __MGOS_MQTT_H
|
||||
#define __MGOS_MQTT_H
|
||||
|
||||
#include "mgos.h"
|
||||
|
||||
struct mg_connection;
|
||||
|
||||
typedef void (*sub_handler_t)(struct mg_connection *nc, const char *topic,
|
||||
int topic_len, const char *msg, int msg_len,
|
||||
void *ud);
|
||||
|
||||
void mgos_mqtt_pub(char *t, char *m, int m_len, int flags, bool persist);
|
||||
void mgos_mqtt_sub(char *t, sub_handler_t cb, void *ud);
|
||||
|
||||
void mgos_mqtt_inject(char *topic, char *msg);
|
||||
|
||||
#endif // __MGOS_MQTT_H
|
Reference in New Issue
Block a user