Added the (possibly modified) Espressif SDK to the project to avoid problems with building. This may not be OK license wise, but who cares

This commit is contained in:
2017-05-28 17:39:17 +02:00
parent c04433b7f5
commit 13564727d9
171 changed files with 23154 additions and 1 deletions
+45
View File
@@ -0,0 +1,45 @@
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = libuser.a
endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../../include/ets
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
+120
View File
@@ -0,0 +1,120 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_devicefind.c
*
* Description: Find your hardware's information while working any mode.
*
* Modification history:
* 2014/3/12, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
#include "espconn.h"
#include "user_json.h"
#include "user_devicefind.h"
const char *device_find_request = "Are You Espressif IOT Smart Device?";
#if PLUG_DEVICE
const char *device_find_response_ok = "I'm Plug.";
#elif LIGHT_DEVICE
const char *device_find_response_ok = "I'm Light.";
#elif SENSOR_DEVICE
#if HUMITURE_SUB_DEVICE
const char *device_find_response_ok = "I'm Humiture.";
#elif FLAMMABLE_GAS_SUB_DEVICE
const char *device_find_response_ok = "I'm Flammable Gas.";
#endif
#endif
/*---------------------------------------------------------------------------*/
LOCAL struct espconn ptrespconn;
/******************************************************************************
* FunctionName : user_devicefind_recv
* Description : Processing the received data from the host
* Parameters : arg -- Additional argument to pass to the callback function
* pusrdata -- The received data (or NULL when the connection has been closed!)
* length -- The length of received data
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_devicefind_recv(void *arg, char *pusrdata, unsigned short length)
{
char DeviceBuffer[40] = {0};
char Device_mac_buffer[60] = {0};
char hwaddr[6];
remot_info *premot = NULL;
struct ip_info ipconfig;
if (wifi_get_opmode() != STATION_MODE) {
wifi_get_ip_info(SOFTAP_IF, &ipconfig);
wifi_get_macaddr(SOFTAP_IF, hwaddr);
if (!ip_addr_netcmp((struct ip_addr *)ptrespconn.proto.udp->remote_ip, &ipconfig.ip, &ipconfig.netmask)) {
wifi_get_ip_info(STATION_IF, &ipconfig);
wifi_get_macaddr(STATION_IF, hwaddr);
}
} else {
wifi_get_ip_info(STATION_IF, &ipconfig);
wifi_get_macaddr(STATION_IF, hwaddr);
}
if (pusrdata == NULL) {
return;
}
if (length == os_strlen(device_find_request) &&
os_strncmp(pusrdata, device_find_request, os_strlen(device_find_request)) == 0) {
os_sprintf(DeviceBuffer, "%s" MACSTR " " IPSTR, device_find_response_ok,
MAC2STR(hwaddr), IP2STR(&ipconfig.ip));
os_printf("%s\n", DeviceBuffer);
length = os_strlen(DeviceBuffer);
if (espconn_get_connection_info(&ptrespconn, &premot, 0) != ESPCONN_OK)
return;
os_memcpy(ptrespconn.proto.udp->remote_ip, premot->remote_ip, 4);
ptrespconn.proto.udp->remote_port = premot->remote_port;
espconn_sent(&ptrespconn, DeviceBuffer, length);
} else if (length == (os_strlen(device_find_request) + 18)) {
os_sprintf(Device_mac_buffer, "%s " MACSTR , device_find_request, MAC2STR(hwaddr));
os_printf("%s", Device_mac_buffer);
if (os_strncmp(Device_mac_buffer, pusrdata, os_strlen(device_find_request) + 18) == 0) {
//os_printf("%s\n", Device_mac_buffer);
length = os_strlen(DeviceBuffer);
os_sprintf(DeviceBuffer, "%s" MACSTR " " IPSTR, device_find_response_ok,
MAC2STR(hwaddr), IP2STR(&ipconfig.ip));
os_printf("%s\n", DeviceBuffer);
length = os_strlen(DeviceBuffer);
if (espconn_get_connection_info(&ptrespconn, &premot, 0) != ESPCONN_OK)
return;
os_memcpy(ptrespconn.proto.udp->remote_ip, premot->remote_ip, 4);
ptrespconn.proto.udp->remote_port = premot->remote_port;
espconn_sent(&ptrespconn, DeviceBuffer, length);
} else {
return;
}
}
}
/******************************************************************************
* FunctionName : user_devicefind_init
* Description : the espconn struct parame init
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_devicefind_init(void)
{
ptrespconn.type = ESPCONN_UDP;
ptrespconn.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
ptrespconn.proto.udp->local_port = 1025;
espconn_regist_recvcb(&ptrespconn, user_devicefind_recv);
espconn_create(&ptrespconn);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,344 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: esp_platform_user_timer.c
*
* Description:
*
* Modification history:
* 2014/5/09, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "os_type.h"
#include "mem.h"
#include "osapi.h"
#include "user_interface.h"
#include "espconn.h"
#include "user_esp_platform.h"
#define ESP_DEBUG
#ifdef ESP_DEBUG
#define ESP_DBG os_printf
#else
#define ESP_DBG
#endif
LOCAL os_timer_t device_timer;
uint32 min_wait_second;
char timestamp_str[11];
int timestamp = 0;
char *timer_splits[20] = {NULL};
struct esp_platform_wait_timer_param {
uint8 wait_time_param[11];
uint8 wait_action[15];
int wait_time_second;
};
struct wait_param {
uint8 action[20][15];
uint16 action_number;
uint16 count;
uint32 min_time_backup;
};
void esp_platform_timer_action(struct esp_platform_wait_timer_param *timer_wait_param, uint16 count);
/******************************************************************************
* FunctionName : split
* Description : split string p1 according to sting p2 and save the splits
* Parameters : p1 , p2 ,splits[]
* Returns : the number of splits
*******************************************************************************/
uint16 ICACHE_FLASH_ATTR
split(char *p1, char *p2, char *splits[])
{
int i = 0;
int j = 0;
while (i != -1) {
int start = i;
int end = indexof(p1, p2, start);
if (end == -1) {
end = os_strlen(p1);
}
char *p = (char *) os_zalloc(100);
os_memcpy(p, p1 + start, end - start);
p[end - start] = '\0';
splits[j] = p;
j++;
i = end + 1;
if (i > os_strlen(p1)) {
break;
}
}
return j;
}
/******************************************************************************
* FunctionName : indexof
* Description : calculate the offset of p2 relate to start of p1
* Parameters : p1,p1,start
* Returns : the offset of p2 relate to the start
*******************************************************************************/
int ICACHE_FLASH_ATTR
indexof(char *p1, char *p2, int start)
{
char *find = (char *)os_strstr(p1 + start, p2);
if (find != NULL) {
return (find - p1);
}
return -1;
}
/******************************************************************************
* FunctionName : esp_platform_find_min_time
* Description : find the minimum wait second in timer list
* Parameters : timer_wait_param -- param of timer action and wait time param
* count -- The number of timers given by server
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
esp_platform_find_min_time(struct esp_platform_wait_timer_param *timer_wait_param , uint16 count)
{
uint16 i = 0;
min_wait_second = 0xFFFFFFF;
for (i = 0; i < count ; i++) {
if (timer_wait_param[i].wait_time_second < min_wait_second && timer_wait_param[i].wait_time_second >= 0) {
min_wait_second = timer_wait_param[i].wait_time_second;
}
}
}
/******************************************************************************
* FunctionName : user_platform_timer_first_start
* Description : calculate the wait time of each timer
* Parameters : count -- The number of timers given by server
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_platform_timer_first_start(uint16 count)
{
int i = 0;
struct esp_platform_wait_timer_param timer_wait_param[100] = {0};
ESP_DBG("current timestamp= %ds\n", timestamp);
timestamp = timestamp + min_wait_second;
for (i = 0 ; i < count ; i++) {
char *str = timer_splits[i];
if (indexof(str, "f", 0) == 0) {
char *fixed_wait[2];
ESP_DBG("timer is fixed mode\n");
split(str, "=", fixed_wait);
os_memcpy(timer_wait_param[i].wait_time_param, fixed_wait[0] + 1, os_strlen(fixed_wait[0]) - 1);
os_memcpy(timer_wait_param[i].wait_action, fixed_wait[1], os_strlen(fixed_wait[1]));
timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - timestamp;
os_free(fixed_wait[0]);
os_free(fixed_wait[1]);
}
else if (indexof(str, "l", 0) == 0) {
char *loop_wait[2];
ESP_DBG("timer is loop mode\n");
split(str, "=", loop_wait);
os_memcpy(timer_wait_param[i].wait_time_param, loop_wait[0] + 1, os_strlen(loop_wait[0]) - 1);
os_memcpy(timer_wait_param[i].wait_action, loop_wait[1], os_strlen(loop_wait[1]));
timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - (timestamp % atoi(timer_wait_param[i].wait_time_param));
os_free(loop_wait[0]);
os_free(loop_wait[1]);
} else if (indexof(str, "w", 0) == 0) {
char *week_wait[2];
int monday_wait_time = 0;
ESP_DBG("timer is weekend mode\n");
split(str, "=", week_wait);
os_memcpy(timer_wait_param[i].wait_time_param, week_wait[0] + 1, os_strlen(week_wait[0]) - 1);
os_memcpy(timer_wait_param[i].wait_action, week_wait[1], os_strlen(week_wait[1]));
monday_wait_time = (timestamp - 1388937600) % (7 * 24 * 3600);
ESP_DBG("monday_wait_time == %d", monday_wait_time);
if (atoi(timer_wait_param[i].wait_time_param) > monday_wait_time) {
timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - monday_wait_time;
} else {
timer_wait_param[i].wait_time_second = 7 * 24 * 3600 - monday_wait_time + atoi(timer_wait_param[i].wait_time_param);
}
os_free(week_wait[0]);
os_free(week_wait[1]);
}
}
esp_platform_find_min_time(timer_wait_param, count);
if(min_wait_second == 0) {
return;
}
esp_platform_timer_action(timer_wait_param, count);
}
/******************************************************************************
* FunctionName : user_esp_platform_device_action
* Description : Execute the actions of minimum wait time
* Parameters : pwait_action -- point the list of actions which need execute
*
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_device_action(struct wait_param *pwait_action)
{
uint8 i = 0;
uint16 count = pwait_action->count;
uint16 action_number = pwait_action->action_number;
ESP_DBG("there is %d action at the same time\n", pwait_action->action_number);
#if PLUG_DEVICE
for (i = 0; i < action_number && pwait_action->action[i][0] != '0'; i++) {
ESP_DBG("%s\n",pwait_action->action[i]);
if (os_strcmp(pwait_action->action[i], "on_switch", 9) == 0) {
user_plug_set_status(0x01);
} else if (os_strcmp(pwait_action->action[i], "off_switch", 10) == 0) {
user_plug_set_status(0x00);
} else if (os_strcmp(pwait_action->action[i], "on_off_switch", 13) == 0) {
if (user_plug_get_status() == 0) {
user_plug_set_status(0x01);
} else {
user_plug_set_status(0x00);
}
} else {
return;
}
}
user_platform_timer_first_start(count);
#endif
}
/******************************************************************************
* FunctionName : user_platform_timer_start
* Description : Processing the message about timer from the server
* Parameters : timer_wait_param -- The received data from the server
* count -- the espconn used to connetion with the host
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_wait_time_overflow_check(struct wait_param *pwait_action)
{
ESP_DBG("min_wait_second = %d", min_wait_second);
if (pwait_action->min_time_backup >= 3600) {
os_timer_disarm(&device_timer);
os_timer_setfn(&device_timer, (os_timer_func_t *)user_esp_platform_wait_time_overflow_check, pwait_action);
os_timer_arm(&device_timer, 3600000, 0);
ESP_DBG("min_wait_second is extended\n");
} else {
os_timer_disarm(&device_timer);
os_timer_setfn(&device_timer, (os_timer_func_t *)user_esp_platform_device_action, pwait_action);
os_timer_arm(&device_timer, pwait_action->min_time_backup * 1000, 0);
ESP_DBG("min_wait_second is = %dms\n", pwait_action->min_time_backup * 1000);
}
pwait_action->min_time_backup -= 3600;
}
/******************************************************************************
* FunctionName : user_platform_timer_start
* Description : Processing the message about timer from the server
* Parameters : timer_wait_param -- The received data from the server
* count -- the espconn used to connetion with the host
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
esp_platform_timer_action(struct esp_platform_wait_timer_param *timer_wait_param, uint16 count)
{
uint16 i = 0;
uint16 action_number;
struct wait_param pwait_action = {0};
pwait_action.count = count;
action_number = 0;
for (i = 0; i < count ; i++) {
if (timer_wait_param[i].wait_time_second == min_wait_second) {
os_memcpy(pwait_action.action[action_number], timer_wait_param[i].wait_action, os_strlen(timer_wait_param[i].wait_action));
ESP_DBG("*****%s*****\n", timer_wait_param[i].wait_action);
action_number++;
}
}
pwait_action.action_number = action_number;
pwait_action.min_time_backup = min_wait_second;
user_esp_platform_wait_time_overflow_check(&pwait_action);
}
/******************************************************************************
* FunctionName : user_platform_timer_start
* Description : Processing the message about timer from the server
* Parameters : pbuffer -- The received data from the server
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_platform_timer_start(char *pbuffer)
{
int str_begin = 0;
int str_end = 0;
uint8 i = 0;
char *pstr_start = NULL;
char *pstr_end = NULL;
struct esp_platform_wait_timer_param timer_wait_param[20];
char *pstr = NULL;
min_wait_second = 0;
if ((pstr = (char *)os_strstr(pbuffer, "\"timestamp\":")) != NULL) {
pstr_start = pstr + 13;
pstr_end = (char *)os_strstr(pstr_start, ",");
if (pstr != NULL) {
os_memcpy(timestamp_str, pstr_start, pstr_end - pstr_start);
timestamp = atoi(timestamp_str);
}
}
for (i = 0 ; i < 20 ; i++) {
if (timer_splits[i] != NULL) {
os_free(timer_splits[i]);
timer_splits[i] = NULL;
}
}
if ((pstr_start = (char *)os_strstr(pbuffer, "\"timers\": \"")) != NULL) {
str_begin = 11;
str_end = indexof(pstr_start, "\"", str_begin);
if (str_begin == str_end) {
os_timer_disarm(&device_timer);
return;
}
char *split_buffer = (char *)os_zalloc(str_end - str_begin + 1);
os_memcpy(split_buffer, pstr_start + str_begin, str_end - str_begin);
uint16 count = split(split_buffer , ";" , timer_splits);
os_free(split_buffer);
user_platform_timer_first_start(count);
}
}
+164
View File
@@ -0,0 +1,164 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_json.c
*
* Description: JSON format set up and parse.
* Check your hardware transmation while use this data format.
*
* Modification history:
* 2014/5/09, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "os_type.h"
#include "mem.h"
#include "user_json.h"
LOCAL char *json_buf;
LOCAL int pos;
LOCAL int size;
/******************************************************************************
* FunctionName : find_json_path
* Description : find the JSON format tree's path
* Parameters : json -- A pointer to a JSON set up
* path -- A pointer to the JSON format tree's path
* Returns : A pointer to the JSON format tree
*******************************************************************************/
struct jsontree_value *ICACHE_FLASH_ATTR
find_json_path(struct jsontree_context *json, const char *path)
{
struct jsontree_value *v;
const char *start;
const char *end;
int len;
v = json->values[0];
start = path;
do {
end = (const char *)os_strstr(start, "/");
if (end == start) {
break;
}
if (end != NULL) {
len = end - start;
end++;
} else {
len = os_strlen(start);
}
if (v->type != JSON_TYPE_OBJECT) {
v = NULL;
} else {
struct jsontree_object *o;
int i;
o = (struct jsontree_object *)v;
v = NULL;
for (i = 0; i < o->count; i++) {
if (os_strncmp(start, o->pairs[i].name, len) == 0) {
v = o->pairs[i].value;
json->index[json->depth] = i;
json->depth++;
json->values[json->depth] = v;
json->index[json->depth] = 0;
break;
}
}
}
start = end;
} while (end != NULL && *end != '\0' && v != NULL);
json->callback_state = 0;
return v;
}
/******************************************************************************
* FunctionName : json_putchar
* Description : write the value to the JSON format tree
* Parameters : c -- the value which write the JSON format tree
* Returns : result
*******************************************************************************/
int ICACHE_FLASH_ATTR
json_putchar(int c)
{
if (json_buf != NULL && pos <= size) {
json_buf[pos++] = c;
return c;
}
return 0;
}
/******************************************************************************
* FunctionName : json_ws_send
* Description : set up the JSON format tree for string
* Parameters : tree -- A pointer to the JSON format tree
* path -- A pointer to the JSON format tree's path
* pbuf -- A pointer for the data sent
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
json_ws_send(struct jsontree_value *tree, const char *path, char *pbuf)
{
struct jsontree_context json;
/* maxsize = 128 bytes */
json_buf = (char *)os_malloc(jsonSize);
/* reset state and set max-size */
/* NOTE: packet will be truncated at 512 bytes */
pos = 0;
size = jsonSize;
json.values[0] = (struct jsontree_value *)tree;
jsontree_reset(&json);
find_json_path(&json, path);
json.path = json.depth;
json.putchar = json_putchar;
while (jsontree_print_next(&json) && json.path <= json.depth);
json_buf[pos] = 0;
os_memcpy(pbuf, json_buf, pos);
os_free(json_buf);
}
/******************************************************************************
* FunctionName : json_parse
* Description : parse the data as a JSON format
* Parameters : js_ctx -- A pointer to a JSON set up
* ptrJSONMessage -- A pointer to the data
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
json_parse(struct jsontree_context *json, char *ptrJSONMessage)
{
/* Set value */
struct jsontree_value *v;
struct jsontree_callback *c;
struct jsontree_callback *c_bak = NULL;
while ((v = jsontree_find_next(json, JSON_TYPE_CALLBACK)) != NULL) {
c = (struct jsontree_callback *)v;
if (c == c_bak) {
continue;
}
c_bak = c;
if (c->set != NULL) {
struct jsonparse_state js;
jsonparse_setup(&js, ptrJSONMessage, os_strlen(ptrJSONMessage));
c->set(json, &js);
}
}
}
+141
View File
@@ -0,0 +1,141 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_light.c
*
* Description: light demo's function realization
*
* Modification history:
* 2014/5/1, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "os_type.h"
#include "mem.h"
#include "user_interface.h"
#include "user_light.h"
#include "pwm.h"
#if LIGHT_DEVICE
struct light_saved_param light_param;
/******************************************************************************
* FunctionName : user_light_get_duty
* Description : get duty of each channel
* Parameters : uint8 channel : LIGHT_RED/LIGHT_GREEN/LIGHT_BLUE
* Returns : NONE
*******************************************************************************/
uint32 ICACHE_FLASH_ATTR
user_light_get_duty(uint8 channel)
{
return light_param.pwm_duty[channel];
}
/******************************************************************************
* FunctionName : user_light_set_duty
* Description : set each channel's duty params
* Parameters : uint8 duty : 0 ~ PWM_DEPTH
* uint8 channel : LIGHT_RED/LIGHT_GREEN/LIGHT_BLUE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_light_set_duty(uint32 duty, uint8 channel)
{
if (duty != light_param.pwm_duty[channel]) {
pwm_set_duty(duty, channel);
light_param.pwm_duty[channel] = pwm_get_duty(channel);
}
}
/******************************************************************************
* FunctionName : user_light_get_period
* Description : get pwm period
* Parameters : NONE
* Returns : uint32 : pwm period
*******************************************************************************/
uint32 ICACHE_FLASH_ATTR
user_light_get_period(void)
{
return light_param.pwm_period;
}
/******************************************************************************
* FunctionName : user_light_set_duty
* Description : set pwm frequency
* Parameters : uint16 freq : 100hz typically
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_light_set_period(uint32 period)
{
if (period != light_param.pwm_period) {
pwm_set_period(period);
light_param.pwm_period = pwm_get_period();
}
}
void ICACHE_FLASH_ATTR
user_light_restart(void)
{
spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE);
spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE,
(uint32 *)&light_param, sizeof(struct light_saved_param));
pwm_start();
}
/******************************************************************************
* FunctionName : user_light_init
* Description : light demo init, mainy init pwm
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_light_init(void)
{
spi_flash_read((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE,
(uint32 *)&light_param, sizeof(struct light_saved_param));
if(light_param.pwm_period>10000 || light_param.pwm_period <1000){
light_param.pwm_period = 1000;
}
uint32 io_info[][3] = { {PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM},
{PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM},
{PWM_2_OUT_IO_MUX,PWM_2_OUT_IO_FUNC,PWM_2_OUT_IO_NUM},
{PWM_3_OUT_IO_MUX,PWM_3_OUT_IO_FUNC,PWM_3_OUT_IO_NUM},
{PWM_4_OUT_IO_MUX,PWM_4_OUT_IO_FUNC,PWM_4_OUT_IO_NUM},
};
uint32 pwm_duty_init[PWM_CHANNEL] = {0};
/*PIN FUNCTION INIT FOR PWM OUTPUT*/
pwm_init(light_param.pwm_period, pwm_duty_init ,PWM_CHANNEL,io_info);
os_printf("LIGHT PARAM: R: %d \r\n",light_param.pwm_duty[LIGHT_RED]);
os_printf("LIGHT PARAM: G: %d \r\n",light_param.pwm_duty[LIGHT_GREEN]);
os_printf("LIGHT PARAM: B: %d \r\n",light_param.pwm_duty[LIGHT_BLUE]);
if(PWM_CHANNEL>LIGHT_COLD_WHITE){
os_printf("LIGHT PARAM: CW: %d \r\n",light_param.pwm_duty[LIGHT_COLD_WHITE]);
os_printf("LIGHT PARAM: WW: %d \r\n",light_param.pwm_duty[LIGHT_WARM_WHITE]);
}
os_printf("LIGHT PARAM: P: %d \r\n",light_param.pwm_period);
uint32 light_init_target[8]={0};
os_memcpy(light_init_target,light_param.pwm_duty,sizeof(light_param.pwm_duty));
light_set_aim(
light_init_target[LIGHT_RED],
light_init_target[LIGHT_GREEN],
light_init_target[LIGHT_BLUE],
light_init_target[LIGHT_COLD_WHITE],
light_init_target[LIGHT_WARM_WHITE],
light_param.pwm_period);
set_pwm_debug_en(0);//disable debug print in pwm driver
os_printf("PWM version : %08x \r\n",get_pwm_version());
}
#endif
+334
View File
@@ -0,0 +1,334 @@
#include "ets_sys.h"
#include "osapi.h"
#include "os_type.h"
#include "mem.h"
#include "user_interface.h"
#include "user_light.h"
#include "user_light_adj.h"
#include "pwm.h"
#define ABS_MINUS(x,y) (x<y?(y-x):(x-y))
uint8 light_sleep_flg = 0;
uint16 min_ms = 15;
uint32 current_duty[PWM_CHANNEL] = {0};
bool change_finish=true;
os_timer_t timer_pwm_adj;
static u32 duty_now[PWM_CHANNEL] = {0};
//-----------------------------------Light para storage---------------------------
#define LIGHT_EVT_QNUM (40)
static struct pwm_param LightEvtArr[LIGHT_EVT_QNUM];
static u8 CurFreeLightEvtIdx = 0;
static u8 TotalUsedLightEvtNum = 0;
static u8 CurEvtIdxToBeUse = 0;
static struct pwm_param *LightEvtMalloc(void)
{
struct pwm_param *tmp = NULL;
TotalUsedLightEvtNum++;
if(TotalUsedLightEvtNum > LIGHT_EVT_QNUM ){
TotalUsedLightEvtNum--;
}
else{
tmp = &(LightEvtArr[CurFreeLightEvtIdx]);
CurFreeLightEvtIdx++;
if( CurFreeLightEvtIdx > (LIGHT_EVT_QNUM-1) )
CurFreeLightEvtIdx = 0;
}
os_printf("malloc:%u\n",TotalUsedLightEvtNum);
return tmp;
}
static void ICACHE_FLASH_ATTR LightEvtFree(void)
{
TotalUsedLightEvtNum--;
os_printf("free:%u\n",TotalUsedLightEvtNum);
}
//------------------------------------------------------------------------------------
static void ICACHE_FLASH_ATTR light_pwm_smooth_adj_proc(void);
void ICACHE_FLASH_ATTR
light_save_target_duty()
{
extern struct light_saved_param light_param;
os_memcpy(light_param.pwm_duty,current_duty,sizeof(light_param.pwm_duty));
light_param.pwm_period = pwm_get_period();
#if SAVE_LIGHT_PARAM
spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE);
spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE,
(uint32 *)&light_param, sizeof(struct light_saved_param));
#endif
}
void ICACHE_FLASH_ATTR
light_set_aim_r(uint32 r)
{
current_duty[LIGHT_RED]=r;
light_pwm_smooth_adj_proc();
}
void ICACHE_FLASH_ATTR
light_set_aim_g(uint32 g)
{
current_duty[LIGHT_GREEN]=g;
light_pwm_smooth_adj_proc();
}
void ICACHE_FLASH_ATTR
light_set_aim_b(uint32 b)
{
current_duty[LIGHT_BLUE]=b;
light_pwm_smooth_adj_proc();
}
void ICACHE_FLASH_ATTR
light_set_aim_cw(uint32 cw)
{
current_duty[LIGHT_COLD_WHITE]=cw;
light_pwm_smooth_adj_proc();
}
void ICACHE_FLASH_ATTR
light_set_aim_ww(uint32 ww)
{
current_duty[LIGHT_WARM_WHITE]=ww;
light_pwm_smooth_adj_proc();
}
LOCAL bool ICACHE_FLASH_ATTR
check_pwm_current_duty_diff()
{
int i;
for(i=0;i<PWM_CHANNEL;i++){
if(pwm_get_duty(i) != current_duty[i]){
return true;
}
}
return false;
}
void light_dh_pwm_adj_proc(void *Targ)
{
uint8 i;
for(i=0;i<PWM_CHANNEL;i++){
duty_now[i] = (duty_now[i]*15 + current_duty[i])>>4;
if( ABS_MINUS(duty_now[i],current_duty[i])<20 )
duty_now[i] = current_duty[i];
user_light_set_duty(duty_now[i],i);
}
//os_printf("duty:%u,%u,%u\r\n", pwm.duty[0],pwm.duty[1],pwm.duty[2] );
pwm_start();
if(check_pwm_current_duty_diff()){
change_finish = 0;
os_timer_disarm(&timer_pwm_adj);
os_timer_setfn(&timer_pwm_adj, (os_timer_func_t *)light_dh_pwm_adj_proc, NULL);
os_timer_arm(&timer_pwm_adj, min_ms, 0);
}
else{
os_printf("finish\n");
change_finish = 1;
//light_save_target_duty();
os_timer_disarm(&timer_pwm_adj);
light_pwm_smooth_adj_proc();
}
}
LOCAL bool ICACHE_FLASH_ATTR
check_pwm_duty_zero()
{
int i;
for(i=0;i<PWM_CHANNEL;i++){
if(pwm_get_duty(i) != 0){
return false;
}
}
return true;
}
static void ICACHE_FLASH_ATTR light_pwm_smooth_adj_proc(void)
{
if( TotalUsedLightEvtNum>0 ){
user_light_set_period( LightEvtArr[CurEvtIdxToBeUse].period );
os_memcpy(current_duty,LightEvtArr[CurEvtIdxToBeUse].duty,sizeof(current_duty));
CurEvtIdxToBeUse++;
if(CurEvtIdxToBeUse > (LIGHT_EVT_QNUM-1) ){
CurEvtIdxToBeUse = 0;
}
LightEvtFree();
if(change_finish){
light_dh_pwm_adj_proc(NULL);
}
}
if(change_finish){
light_save_target_duty();
if(check_pwm_duty_zero()){
if(light_sleep_flg==0){
os_printf("light sleep en\r\n");
wifi_set_sleep_type(LIGHT_SLEEP_T);
light_sleep_flg = 1;
}
}
}
}
#if LIGHT_CURRENT_LIMIT
uint32 light_get_cur(uint32 duty , uint8 channel, uint32 period)
{
uint32 duty_max_limit = (period*1000/45);
uint32 duty_mapped = duty*22727/duty_max_limit;
switch(channel){
case LIGHT_RED :
if(duty_mapped>=0 && duty_mapped<23000){
return (duty_mapped*151000/22727);
}
break;
case LIGHT_GREEN:
if(duty_mapped>=0 && duty_mapped<23000){
return (duty_mapped*82000/22727);
}
break;
case LIGHT_BLUE:
if(duty_mapped>=0 && duty_mapped<23000){
return (duty_mapped*70000/22727);
}
break;
case LIGHT_COLD_WHITE:
case LIGHT_WARM_WHITE:
if(duty_mapped>=0 && duty_mapped<23000){
return (duty_mapped*115000/22727);
}
break;
default:
os_printf("CHANNEL ERROR IN GET_CUR\r\n");
break;
}
}
#endif
void ICACHE_FLASH_ATTR
light_set_aim(uint32 r,uint32 g,uint32 b,uint32 cw,uint32 ww,uint32 period)
{
struct pwm_param *tmp = LightEvtMalloc();
if(tmp != NULL){
tmp->period = (period<10000?period:10000);
uint32 duty_max_limit = (period*1000/45);
tmp->duty[LIGHT_RED] = (r<duty_max_limit?r:duty_max_limit);
tmp->duty[LIGHT_GREEN] = (g<duty_max_limit?g:duty_max_limit);
tmp->duty[LIGHT_BLUE] = (b<duty_max_limit?b:duty_max_limit);
tmp->duty[LIGHT_COLD_WHITE] = (cw<duty_max_limit?cw:duty_max_limit);
tmp->duty[LIGHT_WARM_WHITE] = (ww<duty_max_limit?ww:duty_max_limit);//chg
#if LIGHT_CURRENT_LIMIT
uint32 cur_r,cur_g,cur_b,cur_rgb;
//if(cw>0 || ww>0){
cur_r = light_get_cur(tmp->duty[LIGHT_RED] , LIGHT_RED, tmp->period);
cur_g = light_get_cur(tmp->duty[LIGHT_GREEN] , LIGHT_GREEN, tmp->period);
cur_b = light_get_cur(tmp->duty[LIGHT_BLUE] , LIGHT_BLUE, tmp->period);
cur_rgb = (cur_r+cur_g+cur_b);
//}
uint32 cur_cw = light_get_cur( tmp->duty[LIGHT_COLD_WHITE],LIGHT_COLD_WHITE, tmp->period);
uint32 cur_ww = light_get_cur( tmp->duty[LIGHT_WARM_WHITE],LIGHT_WARM_WHITE, tmp->period);
uint32 cur_remain,cur_mar;
cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN);
cur_mar = LIGHT_CURRENT_MARGIN;
/*
if((cur_cw < 50000) || (cur_ww < 50000)){
cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN);
cur_mar = LIGHT_CURRENT_MARGIN;
}else if((cur_cw < 99000) || (cur_ww < 99000)){
cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN_L2);
cur_mar = LIGHT_CURRENT_MARGIN_L2;
}else{
cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN_L3);
cur_mar = LIGHT_CURRENT_MARGIN_L2;
}
*/
/*
if((LIGHT_TOTAL_CURRENT_MAX-cur_rgb)>120){
cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN);
cur_mar = LIGHT_CURRENT_MARGIN;
}else if((LIGHT_TOTAL_CURRENT_MAX-cur_rgb)>100){
cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN_L2);
cur_mar = LIGHT_CURRENT_MARGIN_L2;
}else{
cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN_L3);
cur_mar = LIGHT_CURRENT_MARGIN_L2;
}
*/
os_printf("cur_remain: %d \r\n",cur_remain);
while((cur_cw+cur_ww) > cur_remain){
tmp->duty[LIGHT_COLD_WHITE] = tmp->duty[LIGHT_COLD_WHITE] * 9 / 10;
tmp->duty[LIGHT_WARM_WHITE] = tmp->duty[LIGHT_WARM_WHITE] * 9 / 10;
cur_cw = light_get_cur( tmp->duty[LIGHT_COLD_WHITE],LIGHT_COLD_WHITE, tmp->period);
cur_ww = light_get_cur( tmp->duty[LIGHT_WARM_WHITE],LIGHT_WARM_WHITE, tmp->period);
}
os_printf("debug : %d %d %d %d %d\r\n",cur_r/1000,cur_g/1000,cur_b/1000,cur_cw/1000,cur_ww/1000);
os_printf("debug:total current after adj : %d + %d mA \r\n",(cur_cw+cur_ww+cur_r+cur_g+cur_b)/1000,cur_mar/1000);
#endif
os_printf("prd:%u r : %u g: %u b: %u cw: %u ww: %u \r\n",period,
tmp->duty[0],tmp->duty[1],tmp->duty[2],tmp->duty[3],tmp->duty[4]);
light_pwm_smooth_adj_proc();
}
else{
os_printf("light para full\n");
}
}
+59
View File
@@ -0,0 +1,59 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_main.c
*
* Description: entry file of user application
*
* Modification history:
* 2014/1/1, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "user_interface.h"
#include "user_devicefind.h"
#include "user_webserver.h"
#if ESP_PLATFORM
#include "user_esp_platform.h"
#endif
void user_rf_pre_init(void)
{
}
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void user_init(void)
{
os_printf("SDK version:%s\n", system_get_sdk_version());
#if ESP_PLATFORM
/*Initialization of the peripheral drivers*/
/*For light demo , it is user_light_init();*/
/* Also check whether assigned ip addr by the router.If so, connect to ESP-server */
user_esp_platform_init();
#endif
/*Establish a udp socket to receive local device detect info.*/
/*Listen to the port 1025, as well as udp broadcast.
/*If receive a string of device_find_request, it rely its IP address and MAC.*/
user_devicefind_init();
/*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device.*/
/*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details.*/
/*the JSON command for curl is like:*/
/*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light */
/*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light */
#ifdef SERVER_SSL_ENABLE
user_webserver_init(SERVER_SSL_PORT);
#else
user_webserver_init(SERVER_PORT);
#endif
}
+159
View File
@@ -0,0 +1,159 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_plug.c
*
* Description: plug demo's function realization
*
* Modification history:
* 2014/5/1, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "os_type.h"
#include "mem.h"
#include "user_interface.h"
#include "user_plug.h"
#if PLUG_DEVICE
LOCAL struct plug_saved_param plug_param;
LOCAL struct keys_param keys;
LOCAL struct single_key_param *single_key[PLUG_KEY_NUM];
LOCAL os_timer_t link_led_timer;
LOCAL uint8 link_led_level = 0;
/******************************************************************************
* FunctionName : user_plug_get_status
* Description : get plug's status, 0x00 or 0x01
* Parameters : none
* Returns : uint8 - plug's status
*******************************************************************************/
uint8 ICACHE_FLASH_ATTR
user_plug_get_status(void)
{
return plug_param.status;
}
/******************************************************************************
* FunctionName : user_plug_set_status
* Description : set plug's status, 0x00 or 0x01
* Parameters : uint8 - status
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_plug_set_status(bool status)
{
if (status != plug_param.status) {
if (status > 1) {
os_printf("error status input!\n");
return;
}
plug_param.status = status;
PLUG_STATUS_OUTPUT(PLUG_RELAY_LED_IO_NUM, status);
}
}
/******************************************************************************
* FunctionName : user_plug_short_press
* Description : key's short press function, needed to be installed
* Parameters : none
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_plug_short_press(void)
{
user_plug_set_status((~plug_param.status) & 0x01);
spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE);
spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE,
(uint32 *)&plug_param, sizeof(struct plug_saved_param));
}
/******************************************************************************
* FunctionName : user_plug_long_press
* Description : key's long press function, needed to be installed
* Parameters : none
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_plug_long_press(void)
{
user_esp_platform_set_active(0);
system_restore();
system_restart();
}
LOCAL void ICACHE_FLASH_ATTR
user_link_led_init(void)
{
PIN_FUNC_SELECT(PLUG_LINK_LED_IO_MUX, PLUG_LINK_LED_IO_FUNC);
}
void ICACHE_FLASH_ATTR
user_link_led_output(uint8 level)
{
GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), level);
}
LOCAL void ICACHE_FLASH_ATTR
user_link_led_timer_cb(void)
{
link_led_level = (~link_led_level) & 0x01;
GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), link_led_level);
}
void ICACHE_FLASH_ATTR
user_link_led_timer_init(void)
{
os_timer_disarm(&link_led_timer);
os_timer_setfn(&link_led_timer, (os_timer_func_t *)user_link_led_timer_cb, NULL);
os_timer_arm(&link_led_timer, 50, 1);
link_led_level = 0;
GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), link_led_level);
}
void ICACHE_FLASH_ATTR
user_link_led_timer_done(void)
{
os_timer_disarm(&link_led_timer);
GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), 0);
}
/******************************************************************************
* FunctionName : user_plug_init
* Description : init plug's key function and relay output
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_plug_init(void)
{
user_link_led_init();
wifi_status_led_install(PLUG_WIFI_LED_IO_NUM, PLUG_WIFI_LED_IO_MUX, PLUG_WIFI_LED_IO_FUNC);
single_key[0] = key_init_single(PLUG_KEY_0_IO_NUM, PLUG_KEY_0_IO_MUX, PLUG_KEY_0_IO_FUNC,
user_plug_long_press, user_plug_short_press);
keys.key_num = PLUG_KEY_NUM;
keys.single_key = single_key;
key_init(&keys);
spi_flash_read((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE,
(uint32 *)&plug_param, sizeof(struct plug_saved_param));
PIN_FUNC_SELECT(PLUG_RELAY_LED_IO_MUX, PLUG_RELAY_LED_IO_FUNC);
// no used SPI Flash
if (plug_param.status == 0xff) {
plug_param.status = 1;
}
PLUG_STATUS_OUTPUT(PLUG_RELAY_LED_IO_NUM, plug_param.status);
}
#endif
+230
View File
@@ -0,0 +1,230 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_humiture.c
*
* Description: humiture demo's function realization
*
* Modification history:
* 2014/5/1, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "os_type.h"
#include "user_interface.h"
#if SENSOR_DEVICE
#include "user_sensor.h"
LOCAL struct keys_param keys;
LOCAL struct single_key_param *single_key[SENSOR_KEY_NUM];
LOCAL os_timer_t sensor_sleep_timer;
LOCAL os_timer_t link_led_timer;
LOCAL uint8 link_led_level = 0;
LOCAL uint32 link_start_time;
#if HUMITURE_SUB_DEVICE
#include "driver/i2c_master.h"
#define MVH3004_Addr 0x88
LOCAL uint8 humiture_data[4];
/******************************************************************************
* FunctionName : user_mvh3004_burst_read
* Description : burst read mvh3004's internal data
* Parameters : uint8 addr - mvh3004's address
* uint8 *pData - data point to put read data
* uint16 len - read length
* Returns : bool - true or false
*******************************************************************************/
LOCAL bool ICACHE_FLASH_ATTR
user_mvh3004_burst_read(uint8 addr, uint8 *pData, uint16 len)
{
uint8 ack;
uint16 i;
i2c_master_start();
i2c_master_writeByte(addr);
ack = i2c_master_getAck();
if (ack) {
os_printf("addr not ack when tx write cmd \n");
i2c_master_stop();
return false;
}
i2c_master_stop();
i2c_master_wait(40000);
i2c_master_start();
i2c_master_writeByte(addr + 1);
ack = i2c_master_getAck();
if (ack) {
os_printf("addr not ack when tx write cmd \n");
i2c_master_stop();
return false;
}
for (i = 0; i < len; i++) {
pData[i] = i2c_master_readByte();
i2c_master_setAck((i == (len - 1)) ? 1 : 0);
}
i2c_master_stop();
return true;
}
/******************************************************************************
* FunctionName : user_mvh3004_read_th
* Description : read mvh3004's humiture data
* Parameters : uint8 *data - where data to put
* Returns : bool - ture or false
*******************************************************************************/
bool ICACHE_FLASH_ATTR
user_mvh3004_read_th(uint8 *data)
{
return user_mvh3004_burst_read(MVH3004_Addr, data, 4);
}
/******************************************************************************
* FunctionName : user_mvh3004_init
* Description : init mvh3004, mainly i2c master gpio
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_mvh3004_init(void)
{
i2c_master_gpio_init();
}
uint8 *ICACHE_FLASH_ATTR
user_mvh3004_get_poweron_th(void)
{
return humiture_data;
}
#endif
/******************************************************************************
* FunctionName : user_humiture_long_press
* Description : humiture key's function, needed to be installed
* Parameters : none
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_sensor_long_press(void)
{
user_esp_platform_set_active(0);
system_restore();
system_restart();
}
LOCAL void ICACHE_FLASH_ATTR
user_link_led_init(void)
{
PIN_FUNC_SELECT(SENSOR_LINK_LED_IO_MUX, SENSOR_LINK_LED_IO_FUNC);
PIN_FUNC_SELECT(SENSOR_UNUSED_LED_IO_MUX, SENSOR_UNUSED_LED_IO_FUNC);
GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_UNUSED_LED_IO_NUM), 0);
}
void ICACHE_FLASH_ATTR
user_link_led_output(uint8 level)
{
GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), level);
}
LOCAL void ICACHE_FLASH_ATTR
user_link_led_timer_cb(void)
{
link_led_level = (~link_led_level) & 0x01;
GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), link_led_level);
}
void ICACHE_FLASH_ATTR
user_link_led_timer_init(void)
{
link_start_time = system_get_time();
os_timer_disarm(&link_led_timer);
os_timer_setfn(&link_led_timer, (os_timer_func_t *)user_link_led_timer_cb, NULL);
os_timer_arm(&link_led_timer, 50, 1);
link_led_level = 0;
GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), link_led_level);
}
void ICACHE_FLASH_ATTR
user_link_led_timer_done(void)
{
os_timer_disarm(&link_led_timer);
GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), 0);
}
void ICACHE_FLASH_ATTR
user_sensor_deep_sleep_enter(void)
{
system_deep_sleep(SENSOR_DEEP_SLEEP_TIME > link_start_time \
? SENSOR_DEEP_SLEEP_TIME - link_start_time : 30000000);
}
void ICACHE_FLASH_ATTR
user_sensor_deep_sleep_disable(void)
{
os_timer_disarm(&sensor_sleep_timer);
}
void ICACHE_FLASH_ATTR
user_sensor_deep_sleep_init(uint32 time)
{
os_timer_disarm(&sensor_sleep_timer);
os_timer_setfn(&sensor_sleep_timer, (os_timer_func_t *)user_sensor_deep_sleep_enter, NULL);
os_timer_arm(&sensor_sleep_timer, time, 0);
}
/******************************************************************************
* FunctionName : user_humiture_init
* Description : init humiture function, include key and mvh3004
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_sensor_init(uint8 active)
{
user_link_led_init();
wifi_status_led_install(SENSOR_WIFI_LED_IO_NUM, SENSOR_WIFI_LED_IO_MUX, SENSOR_WIFI_LED_IO_FUNC);
if (wifi_get_opmode() != SOFTAP_MODE) {
single_key[0] = key_init_single(SENSOR_KEY_IO_NUM, SENSOR_KEY_IO_MUX, SENSOR_KEY_IO_FUNC,
user_sensor_long_press, NULL);
keys.key_num = SENSOR_KEY_NUM;
keys.single_key = single_key;
key_init(&keys);
if (GPIO_INPUT_GET(GPIO_ID_PIN(SENSOR_KEY_IO_NUM)) == 0) {
user_sensor_long_press();
}
}
#if HUMITURE_SUB_DEVICE
user_mvh3004_init();
user_mvh3004_read_th(humiture_data);
#endif
#ifdef SENSOR_DEEP_SLEEP
if (wifi_get_opmode() != STATIONAP_MODE) {
if (active == 1) {
user_sensor_deep_sleep_init(SENSOR_DEEP_SLEEP_TIME / 1000 );
} else {
user_sensor_deep_sleep_init(SENSOR_DEEP_SLEEP_TIME / 1000 / 3 * 2);
}
}
#endif
}
#endif
File diff suppressed because it is too large Load Diff