mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 05:28:14 +08:00
power
This commit is contained in:
50
TC1/main.c
50
TC1/main.c
@@ -27,7 +27,7 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
|
|||||||
{
|
{
|
||||||
UNUSED_PARAMETER(size);
|
UNUSED_PARAMETER(size);
|
||||||
|
|
||||||
mico_system_context_get()->micoSystemConfig.name[0] = 1; //在下次重启时使用默认名称
|
mico_system_context_get()->micoSystemConfig.name[0] = 1; //在下次重启时使用默认名称
|
||||||
mico_system_context_get()->micoSystemConfig.name[1] = 0;
|
mico_system_context_get()->micoSystemConfig.name[1] = 0;
|
||||||
|
|
||||||
user_config_t* userConfigDefault = user_config_data;
|
user_config_t* userConfigDefault = user_config_data;
|
||||||
@@ -51,8 +51,8 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
|
|||||||
userConfigDefault->socket[i].name[5] = 0xa3;
|
userConfigDefault->socket[i].name[5] = 0xa3;
|
||||||
userConfigDefault->socket[i].name[6] = i + '1';
|
userConfigDefault->socket[i].name[6] = i + '1';
|
||||||
userConfigDefault->socket[i].name[7] = 0;
|
userConfigDefault->socket[i].name[7] = 0;
|
||||||
|
//sprintf(userConfigDefault->socket[i].name, "插座%d", i);//编码异常
|
||||||
|
|
||||||
// sprintf(userConfigDefault->socket[i].name, "插座%d", i);//编码异常
|
|
||||||
for (j = 0; j < SOCKET_TIME_TASK_NUM; j++)
|
for (j = 0; j < SOCKET_TIME_TASK_NUM; j++)
|
||||||
{
|
{
|
||||||
userConfigDefault->socket[i].task[j].hour = 0;
|
userConfigDefault->socket[i].task[j].hour = 0;
|
||||||
@@ -62,7 +62,7 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
|
|||||||
userConfigDefault->socket[i].task[j].action = 1;
|
userConfigDefault->socket[i].task[j].action = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// mico_system_context_update(sys_config);
|
//mico_system_context_update(sys_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
int application_start(void)
|
int application_start(void)
|
||||||
@@ -71,10 +71,9 @@ int application_start(void)
|
|||||||
os_log("Start %s",VERSION);
|
os_log("Start %s",VERSION);
|
||||||
|
|
||||||
char main_num=0;
|
char main_num=0;
|
||||||
uint32_t power_last = 0xffffffff;
|
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
/* Create mico system context and read application's config data from flash */
|
// Create mico system context and read application's config data from flash
|
||||||
sys_config = mico_system_context_init(sizeof(user_config_t));
|
sys_config = mico_system_context_init(sizeof(user_config_t));
|
||||||
user_config = ((system_context_t*)sys_config)->user_config_data;
|
user_config = ((system_context_t*)sys_config)->user_config_data;
|
||||||
require_action(user_config, exit, err = kNoMemoryErr);
|
require_action(user_config, exit, err = kNoMemoryErr);
|
||||||
@@ -99,7 +98,9 @@ int application_start(void)
|
|||||||
}
|
}
|
||||||
MicoSysLed(0);
|
MicoSysLed(0);
|
||||||
|
|
||||||
if (user_config->version != USER_CONFIG_VERSION || user_config->socket[0].task[0].hour < 0 || user_config->socket[0].task[0].hour > 23)
|
if (user_config->version != USER_CONFIG_VERSION
|
||||||
|
|| user_config->socket[0].task[0].hour < 0
|
||||||
|
|| user_config->socket[0].task[0].hour > 23)
|
||||||
{
|
{
|
||||||
os_log("WARNGIN: user params restored!");
|
os_log("WARNGIN: user params restored!");
|
||||||
err = mico_system_context_restore(sys_config);
|
err = mico_system_context_restore(sys_config);
|
||||||
@@ -109,8 +110,8 @@ int application_start(void)
|
|||||||
if (sys_config->micoSystemConfig.name[0] == 1)
|
if (sys_config->micoSystemConfig.name[0] == 1)
|
||||||
{
|
{
|
||||||
IPStatusTypedef para;
|
IPStatusTypedef para;
|
||||||
os_log("micoWlanGetIPStatus:%d", micoWlanGetIPStatus(¶, Station)); //mac读出来全部是0??!!!
|
os_log("micoWlanGetIPStatus:%d", micoWlanGetIPStatus(¶, Station));
|
||||||
strcpy(strMac, para.mac);
|
strcpy(strMac, para.mac); //mac读出来全部是0??!!!
|
||||||
os_log("result:%s",strMac);
|
os_log("result:%s",strMac);
|
||||||
os_log("result:%s",para.mac);
|
os_log("result:%s",para.mac);
|
||||||
|
|
||||||
@@ -132,8 +133,15 @@ int application_start(void)
|
|||||||
WifiInit();
|
WifiInit();
|
||||||
if (!open_ap)
|
if (!open_ap)
|
||||||
{
|
{
|
||||||
if (sys_config->micoSystemConfig.reserved != NOTIFY_STATION_UP) ApInit();
|
if (sys_config->micoSystemConfig.reserved != NOTIFY_STATION_UP)
|
||||||
else WifiConnect(sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key);
|
{
|
||||||
|
ApInit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WifiConnect(sys_config->micoSystemConfig.ssid,
|
||||||
|
sys_config->micoSystemConfig.user_key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
user_udp_init();
|
user_udp_init();
|
||||||
KeyInit();
|
KeyInit();
|
||||||
@@ -141,26 +149,23 @@ int application_start(void)
|
|||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
err = user_rtc_init();
|
err = user_rtc_init();
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
user_power_init();
|
PowerInit();
|
||||||
|
|
||||||
/* start http server thread */
|
uint32_t power_last = 0xffffffff;
|
||||||
AppHttpdStart();
|
AppHttpdStart(); // start http server thread
|
||||||
|
char* power_buf = malloc(128);
|
||||||
|
if (!power_buf) goto exit;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
main_num++;
|
main_num++;
|
||||||
//发送功率数据
|
//发送功率数据
|
||||||
if (power_last != power || main_num>4)
|
if (power_last != power || main_num > 4)
|
||||||
{
|
{
|
||||||
power_last = power;
|
power_last = power;
|
||||||
main_num =0;
|
main_num =0;
|
||||||
char* power_buf = malloc(128);
|
sprintf(power_buf, "{\"mac\":\"%s\",\"power\":\"%u.%u\",\"total_time\":%u}",
|
||||||
if (power_buf != NULL)
|
strMac, (unsigned int)(power / 10), (unsigned int)(power % 10), (unsigned int)total_time);
|
||||||
{
|
user_send(0, power_buf);
|
||||||
sprintf(power_buf, "{\"mac\":\"%s\",\"power\":\"%u.%u\",\"total_time\":%u}",
|
|
||||||
strMac, (unsigned int)(power/10), (unsigned int)(power%10), (unsigned int)total_time);
|
|
||||||
user_send(0, power_buf);
|
|
||||||
free(power_buf);
|
|
||||||
}
|
|
||||||
user_mqtt_hass_power();
|
user_mqtt_hass_power();
|
||||||
}
|
}
|
||||||
mico_thread_msleep(1000);
|
mico_thread_msleep(1000);
|
||||||
@@ -168,6 +173,7 @@ int application_start(void)
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
os_log("application_start ERROR!");
|
os_log("application_start ERROR!");
|
||||||
|
if (power_buf) free(power_buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ static uint32_t clock_count = 0;
|
|||||||
static uint32_t timer_count = 0;
|
static uint32_t timer_count = 0;
|
||||||
static uint32_t timer_irq_count = 0;
|
static uint32_t timer_irq_count = 0;
|
||||||
|
|
||||||
static void power_timer_handler(void* arg)
|
static void PowerTimerHandler(void* arg)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t timer = 0;
|
uint32_t timer = 0;
|
||||||
|
|
||||||
if (timer_irq_count > 1)
|
if (timer_irq_count > 1)
|
||||||
@@ -47,21 +46,21 @@ static void power_timer_handler(void* arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void power_irq_handler(void* arg)
|
static void PowerIrqHandler(void* arg)
|
||||||
{
|
{
|
||||||
clock_count = mico_nanosecond_clock_value();
|
clock_count = mico_nanosecond_clock_value();
|
||||||
if (timer_irq_count == 0) clock_count_last = clock_count;
|
if (timer_irq_count == 0) clock_count_last = clock_count;
|
||||||
timer_irq_count++;
|
timer_irq_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void user_power_init(void)
|
void PowerInit(void)
|
||||||
{
|
{
|
||||||
os_log("user_power_init");
|
os_log("user_power_init");
|
||||||
|
|
||||||
MicoGpioInitialize(POWER, INPUT_PULL_UP);
|
MicoGpioInitialize(POWER, INPUT_PULL_UP);
|
||||||
mico_rtos_init_timer(&power_timer, 1000, power_timer_handler, NULL);
|
mico_rtos_init_timer(&power_timer, 1000, PowerTimerHandler, NULL);
|
||||||
mico_rtos_start_timer(&power_timer);
|
mico_rtos_start_timer(&power_timer);
|
||||||
|
|
||||||
MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, power_irq_handler, NULL);
|
MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, PowerIrqHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef __USER_POWER_H_
|
#ifndef __USER_POWER_H_
|
||||||
#define __USER_POWER_H_
|
#define __USER_POWER_H_
|
||||||
|
|
||||||
void user_power_init(void);
|
void PowerInit(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user