#define MG_ACTIVE_PATH "mg.active"
#define READ_UUID_CMD "cat cpuinfo | grep Serial"
#define ALS_CFG_PATH "als.cfg"
+#define TOF_CFG_PATH "tof.cfg"
#else
#define IOT_KEY_PATH "/customer/tuya_key"
#define DEV_CFG_PATH "/appconfigs/dev.cfg"
#define ALS_CFG_PATH "/appconfigs/als.cfg"
+#define TOF_CFG_PATH "/appconfigs/tof.cfg"
#define TUYA_AUTH_PATH "/customer/tuya_auth"
#define TUYA_BINDCODE_PATH "/customer/tuya_bindcode"
#define ALS_THRESHOLD_HIGH_DEFAULT 1000
#define ALS_THRESHOLD_LOW_DEFAULT 400
+//人感检测无人判断定时器周期,单位秒
+#define TOF_NOBODY_TIMER_SECS_DEFAULT 1 //默认1秒
+
#define KEY_LED_MAX_DEF 100 //(0-100%)
#define ATMOS_LED_MAX_DEF 100 //(0-100%)
//
int32_t load_als_threshold( uint32_t *ts_high, uint32_t *ts_low);
+uint32_t load_tof_nobody_timer_secs(void);
+
void btn_light_ctrl_init( mg_dev_t *dev );
void btn_light_ctrl_start( mg_dev_t *dev );
return 0;
}
+cJSON * load_json_data_from_file( char *path )
+{
+ FILE *fd;
+ char *json_data;
+ cJSON *root = NULL;
+ size_t file_size;
+
+ fd = fopen( path, "r" );
+ if( fd ){
+ fseek(fd,0,SEEK_END);
+ file_size = ftell(fd);
+ fseek(fd,0,SEEK_SET);
+ json_data = (char *)malloc( file_size+1 );
+ if( json_data ){
+ if(fread( json_data, file_size, 1, fd ) ){
+ json_data[ file_size ] = 0;
+ root = cJSON_Parse((const char *)json_data);
+ if( !root ){
+ printf( "parser json data fail!\r\n" );
+ }
+ }else{
+ MG_LOGE( "read file[%s] fail!\n", path );
+ }
+ free( json_data );
+ }else{
+ MG_LOGE( "out of memory!\n");
+ }
+ fclose( fd );
+ }else{
+ MG_LOGE( "open file [%s] fail\n", path );
+ }
+
+ return root;
+}
+
int32_t load_als_threshold( uint32_t *ts_high, uint32_t *ts_low)
{
FILE *fd;
cJSON *root = NULL;
cJSON *high = NULL;
cJSON *low = NULL;
-
- //printf( "load als thresold...\r\n" );
- //get als.cfg : { "high":1000, "low":400 }
- //1. open file
- fd = fopen( ALS_CFG_PATH, "r" );
- if( !fd ){
- MG_LOGD( "open als_cfg file[%s] fail!\r\n", ALS_CFG_PATH );
- goto err_out;
- }
- //2. read json data
- n = fread( json_data, 1, sizeof(json_data)-1, fd );
- if( n == 0 ){
- MG_LOGD( "read als config file fail!\r\n" );
- goto err_read;
- }
- json_data[n] = 0;
- //( "get json data[%ld]:%s\r\n", n, json_data );
- //3. parse json
- root = cJSON_Parse((const char *)json_data);
- if( !root ){
- MG_LOGD( "parser json data fail!\r\n" );
- goto err_json;
- }
+ root =load_json_data_from_file( ALS_CFG_PATH );
- high =cJSON_GetObjectItem(root, "high");
- low =cJSON_GetObjectItem(root, "low");
+ if( root ){
- if( !cJSON_IsNumber(high) || !cJSON_IsNumber(low) ){
- MG_LOGD( "get threshold high:fail\r\n" );
- goto err_json;
- }
+ high =cJSON_GetObjectItem(root, "high");
+ low =cJSON_GetObjectItem(root, "low");
- if( high )
- *ts_high = high->valueint;
- if( ts_low )
- *ts_low = low->valueint;
+ if( !cJSON_IsNumber(high) || !cJSON_IsNumber(low) ){
+ MG_LOGD( "get threshold high:fail\r\n" );
+ goto err_out;
+ }
+ if( high )
+ *ts_high = high->valueint;
+ if( ts_low )
+ *ts_low = low->valueint;
- cJSON_Delete( root );
- return 0;
+
+ cJSON_Delete( root );
+ return 0;
+ }
-err_json:
+err_out:
if( root ){
cJSON_Delete( root );
}
-err_read:
- if( fd )
- fclose(fd);
-err_out:
if( ts_high )
*ts_high = ALS_THRESHOLD_HIGH_DEFAULT;
if( ts_low )
return -1;
}
-
-cJSON * load_json_data_from_file( char *path )
+//有人到无人判断时间
+uint32_t load_tof_nobody_timer_secs( void )
{
FILE *fd;
- char *json_data;
+ char json_data[200];
+ size_t n;
cJSON *root = NULL;
- size_t file_size;
+ cJSON *nobody_timer = NULL;
+ uint32_t secs;
- fd = fopen( path, "r" );
- if( fd ){
- fseek(fd,0,SEEK_END);
- file_size = ftell(fd);
- fseek(fd,0,SEEK_SET);
- json_data = (char *)malloc( file_size+1 );
- if( json_data ){
- if(fread( json_data, file_size, 1, fd ) ){
- json_data[ file_size ] = 0;
- root = cJSON_Parse((const char *)json_data);
- if( !root ){
- printf( "parser json data fail!\r\n" );
- }
- }else{
- MG_LOGE( "read file[%s] fail!\n", path );
- }
- free( json_data );
+ root =load_json_data_from_file( TOF_CFG_PATH );
+
+ if( root ){
+
+ nobody_timer = cJSON_GetObjectItem(root, "nobody_timer");
+
+ if( !cJSON_IsNumber(nobody_timer ) ){
+ MG_LOGD( "get tof nobody timer :fail\r\n" );
+ secs = TOF_NOBODY_TIMER_SECS_DEFAULT;
}else{
- MG_LOGE( "out of memory!\n");
+ secs = nobody_timer->valueint;
}
- fclose( fd );
+
+ cJSON_Delete( root );
}else{
- MG_LOGE( "open file [%s] fail\n", path );
+ secs = TOF_NOBODY_TIMER_SECS_DEFAULT;
}
+
+ return secs;
- return root;
}
int32_t wifi_config_store( char *ssid, char *passwd )