mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 21:18:13 +08:00
add:增加user_config版本,不同时初始化user_config
add:定时开关功能(未测试)
This commit is contained in:
@@ -22,7 +22,7 @@ void appRestoreDefault_callback( void * const user_config_data, uint32_t size )
|
|||||||
sprintf( mico_system_context_get( )->micoSystemConfig.name, ZTC1_NAME );
|
sprintf( mico_system_context_get( )->micoSystemConfig.name, ZTC1_NAME );
|
||||||
user_config_t* userConfigDefault = user_config_data;
|
user_config_t* userConfigDefault = user_config_data;
|
||||||
userConfigDefault->idx = -1;
|
userConfigDefault->idx = -1;
|
||||||
|
userConfigDefault->version=USER_CONFIG_VERSION;
|
||||||
for(i=0;i<PLUG_NUM;i++)
|
for(i=0;i<PLUG_NUM;i++)
|
||||||
{
|
{
|
||||||
userConfigDefault->plug[i].idx=-1;
|
userConfigDefault->plug[i].idx=-1;
|
||||||
@@ -37,6 +37,8 @@ void appRestoreDefault_callback( void * const user_config_data, uint32_t size )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mico_system_context_update( sys_config );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int application_start( void )
|
int application_start( void )
|
||||||
@@ -70,12 +72,13 @@ int application_start( void )
|
|||||||
MicoGpioInitialize( (mico_gpio_t) MICO_GPIO_5, OUTPUT_PUSH_PULL );
|
MicoGpioInitialize( (mico_gpio_t) MICO_GPIO_5, OUTPUT_PUSH_PULL );
|
||||||
user_led_set( 0 );
|
user_led_set( 0 );
|
||||||
|
|
||||||
if ( user_config->plug[0].task[0].hour < 0 || user_config->plug[0].task[0].hour > 23 )
|
if (user_config->version!=USER_CONFIG_VERSION || user_config->plug[0].task[0].hour < 0 || user_config->plug[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 );
|
||||||
require_noerr( err, exit );
|
require_noerr( err, exit );
|
||||||
}
|
}
|
||||||
|
os_log( "version:%d",user_config->version );
|
||||||
os_log( "idx:%d",user_config->idx );
|
os_log( "idx:%d",user_config->idx );
|
||||||
for ( i = 0; i < PLUG_NUM; i++ )
|
for ( i = 0; i < PLUG_NUM; i++ )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "MiCOKit_EXT.h"
|
#include "MiCOKit_EXT.h"
|
||||||
|
|
||||||
#define ZTC1_NAME "zTC1"
|
#define ZTC1_NAME "zTC1"
|
||||||
|
#define USER_CONFIG_VERSION 1
|
||||||
|
|
||||||
|
|
||||||
#define PLUG_NAME_LENGTH 32
|
#define PLUG_NAME_LENGTH 32
|
||||||
#define PLUG_NUM 6 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
#define PLUG_NUM 6 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
@@ -47,6 +49,7 @@ typedef struct {
|
|||||||
|
|
||||||
//<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
//<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
char version;
|
||||||
char idx;
|
char idx;
|
||||||
user_plug_config_t plug[PLUG_NUM];
|
user_plug_config_t plug[PLUG_NUM];
|
||||||
} user_config_t;
|
} user_config_t;
|
||||||
|
|||||||
@@ -28,15 +28,17 @@ void user_relay_set( char x, char y )
|
|||||||
else
|
else
|
||||||
Gpiosetfunction = MicoGpioOutputLow;
|
Gpiosetfunction = MicoGpioOutputLow;
|
||||||
|
|
||||||
|
|
||||||
if ( x >= 0 && x < Relay_NUM )
|
if ( x >= 0 && x < Relay_NUM )
|
||||||
{
|
{
|
||||||
(*Gpiosetfunction)( relay[x] );
|
(*Gpiosetfunction)( relay[x] );
|
||||||
|
os_log("set relay %d:%d",x,y);
|
||||||
} else if ( x == Relay_NUM )
|
} else if ( x == Relay_NUM )
|
||||||
{
|
{
|
||||||
OSStatus *setgpiofunction = MicoGpioOutputTrigger;
|
|
||||||
for ( int i = 0; i < Relay_NUM; i++ )
|
for ( int i = 0; i < Relay_NUM; i++ )
|
||||||
{
|
{
|
||||||
(*Gpiosetfunction)( relay[i] );
|
(*Gpiosetfunction)( relay[i] );
|
||||||
|
os_log("set relay %d:%d",i,y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
extern void user_led_set(char x);
|
extern void user_led_set(char x);
|
||||||
extern void key_init(void);
|
extern void key_init(void);
|
||||||
|
extern void user_relay_set( char x, char y );
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,8 +24,26 @@ OSStatus user_sntp_get_time( )
|
|||||||
err = sntp_get_time( &ipp, ¤t_time );
|
err = sntp_get_time( &ipp, ¤t_time );
|
||||||
if ( err != kNoErr )
|
if ( err != kNoErr )
|
||||||
{
|
{
|
||||||
os_log("sntp_get_time1 err = %d.retry", err);
|
os_log("sntp_get_time1 err = %d.", err);
|
||||||
ipp.s_addr = 0xd248912c;
|
hostent_content = gethostbyname( "cn.pool.ntp.org" );
|
||||||
|
pptr = hostent_content->h_addr_list;
|
||||||
|
ipp.s_addr = *(uint32_t *) (*pptr);
|
||||||
|
err = sntp_get_time( &ipp, ¤t_time );
|
||||||
|
}
|
||||||
|
if ( err != kNoErr )
|
||||||
|
{
|
||||||
|
os_log("sntp_get_time2 err = %d.", err);
|
||||||
|
hostent_content = gethostbyname( "s1a.time.edu.cn" );
|
||||||
|
pptr = hostent_content->h_addr_list;
|
||||||
|
ipp.s_addr = *(uint32_t *) (*pptr);
|
||||||
|
err = sntp_get_time( &ipp, ¤t_time );
|
||||||
|
}
|
||||||
|
if ( err != kNoErr )
|
||||||
|
{
|
||||||
|
os_log("sntp_get_time3 err = %d.", err);
|
||||||
|
hostent_content = gethostbyname( "ntp.sjtu.edu.cn" );
|
||||||
|
pptr = hostent_content->h_addr_list;
|
||||||
|
ipp.s_addr = *(uint32_t *) (*pptr);
|
||||||
err = sntp_get_time( &ipp, ¤t_time );
|
err = sntp_get_time( &ipp, ¤t_time );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +65,7 @@ OSStatus user_sntp_get_time( )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
os_log("sntp_get_time2 err = %d.", err);
|
os_log("sntp_get_time4 err = %d.", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +106,7 @@ OSStatus user_rtc_init( void )
|
|||||||
|
|
||||||
void rtc_thread( mico_thread_arg_t arg )
|
void rtc_thread( mico_thread_arg_t arg )
|
||||||
{
|
{
|
||||||
iso8601_time_t iso8601_time;
|
int i, j;
|
||||||
OSStatus err = kUnknownErr;
|
OSStatus err = kUnknownErr;
|
||||||
LinkStatusTypeDef LinkStatus;
|
LinkStatusTypeDef LinkStatus;
|
||||||
mico_rtc_time_t rtc_time;
|
mico_rtc_time_t rtc_time;
|
||||||
@@ -129,6 +147,37 @@ void rtc_thread( mico_thread_arg_t arg )
|
|||||||
// MicoRtcSetTime( &rtc_time ); //MicoRtc<74><63><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ʱ!
|
// MicoRtcSetTime( &rtc_time ); //MicoRtc<74><63><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ʱ!
|
||||||
os_log("time:20%02d/%02d/%02d %d %02d:%02d:%02d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec);
|
os_log("time:20%02d/%02d/%02d %d %02d:%02d:%02d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec);
|
||||||
|
|
||||||
|
char update_user_config_flag = 0;
|
||||||
|
for ( i = 0; i < PLUG_NUM; i++ )
|
||||||
|
{
|
||||||
|
for ( j = 0; j < PLUG_TIME_TASK_NUM; j++ )
|
||||||
|
{
|
||||||
|
if ( user_config->plug[i].task[j].on != 0 )
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t repeat = user_config->plug[i].task[j].repeat;
|
||||||
|
if ( //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>̵<EFBFBD><CCB5><EFBFBD>״̬: <20><>Ϊ0 ʱ<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>趨ֵ, <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>趨ֵ
|
||||||
|
rtc_time.sec == 0 && rtc_time.min == user_config->plug[i].task[j].minute
|
||||||
|
&& rtc_time.hr == user_config->plug[i].task[j].hour
|
||||||
|
&& ((repeat == 0x80) || repeat & (1 << (rtc_time.weekday - 1)))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
user_relay_set( i, user_config->plug[i].task[j].action );
|
||||||
|
if ( repeat == 0x80 )
|
||||||
|
{
|
||||||
|
user_config->plug[i].task[j].on = 0;
|
||||||
|
update_user_config_flag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( update_user_config_flag == 1 )
|
||||||
|
{
|
||||||
|
mico_system_context_update( sys_config ); //<2F><><EFBFBD>¶<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
update_user_config_flag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ( rtc_init != 1 || (rtc_time.sec == 0 && rtc_time.min == 0) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿСʱУһ<D7BC><D2BB>
|
if ( rtc_init != 1 || (rtc_time.sec == 0 && rtc_time.min == 0) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿСʱУһ<D7BC><D2BB>
|
||||||
{
|
{
|
||||||
micoWlanGetLinkStatus( &LinkStatus );
|
micoWlanGetLinkStatus( &LinkStatus );
|
||||||
|
|||||||
Reference in New Issue
Block a user