}light_mode_t;
+typedef struct{
+ uint32_t increase_ms;
+ uint32_t decrease_ms;
+ uint32_t apnea_ms;
+} breath_cfg_t;
typedef struct{
uint8_t br[101]; //0--100亮度值
+ breath_cfg_t breath;
}light_cfg_t;
void light_mode_set( mg_dev_t *dev, light_mode_t mode );
}
-light_cfg_t light_cfg_default = {
+const light_cfg_t light_cfg_default = {
.br = { //亮度0 到100, 对应到sysfs接口的0-255
0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
132, 134, 136, 138, 140, 142, 144, 146, 148, 150,
160, 170, 180, 190, 200, 210, 220, 230, 240, 255,
},
+ .breath={
+ .increase_ms = 1500,
+ .decrease_ms = 1500,
+ .apnea_ms = 0,
+ },
};
//light cfg
size_t n;
cJSON *root = NULL;
cJSON *br = NULL;
+ cJSON *breath = NULL;
cJSON *item= NULL;
light_cfg_t read_cfg;
- int32_t ret = -1;
+ int32_t ret = 0;
int i;
- root =load_json_data_from_file( LIGHT_CFG_PATH );
- if( !root ){
- printf( "load light cfg json:%p\n", root );
- }else{
-
- br = cJSON_GetObjectItem(root, "brightness");
+ memcpy( &read_cfg, &light_cfg_default, sizeof( read_cfg ) );
- if( !br ){
- printf( "load light cfg item br :%p\n", br );
- }else{
- printf( "is_Array:%d\n", cJSON_IsArray(br) );
-
- if( !cJSON_IsArray(br) || cJSON_GetArraySize( br )!= 101 ){
- MG_LOGD( "get array:fail\r\n" );
- }else{
- ret = 0;
+ root =load_json_data_from_file( LIGHT_CFG_PATH );
+ if( root ){
+ if((br = cJSON_GetObjectItem(root, "brightness"))){
+ if( cJSON_IsArray(br) || cJSON_GetArraySize( br ) == 101 ){
for( i=0; i<101; i++ ){
item = cJSON_GetArrayItem( br, i );
if( cJSON_IsNumber( item ) && item->valueint <= 255 ){
}
}
- cJSON_Delete( root );
}
- }
- if( ret == 0 ){
- //printf( "-----------------------------------------------\n" );
- //printf( "load light cfg:\n" );
- //for( i=0; i<101; i++ ){
- // printf( "%4d%s", read_cfg.br[i], (i%10)?" ":"\n" );
- //}
- //printf( "-----------------------------------------------\n" );
- memcpy( cfg, &read_cfg, sizeof( *cfg ) );
- }else{
- memcpy( cfg, &light_cfg_default, sizeof( *cfg ) );
+ if((breath = cJSON_GetObjectItem(root, "breath") ) ){
+
+ if((item = cJSON_GetObjectItem(breath, "increase")) && cJSON_IsNumber( item ) )
+ read_cfg.breath.increase_ms = item->valueint;
+
+ if((item = cJSON_GetObjectItem(breath, "decrease")) && cJSON_IsNumber( item ) )
+ read_cfg.breath.decrease_ms = item->valueint;
+
+ if((item = cJSON_GetObjectItem(breath, "apnea")) && cJSON_IsNumber( item ) )
+ read_cfg.breath.apnea_ms = item->valueint;
+
+ }
+ cJSON_Delete( root );
}
+ memcpy( cfg, &read_cfg, sizeof( *cfg ) );
+
+ //printf( "-----------------------------------------------\n" );
+ //printf( "load light cfg:\n" );
+ //for( i=0; i<101; i++ ){
+ // printf( "%4d%s", read_cfg.br[i], (i%10)?" ":"\n" );
+ //}
+ //printf( "breath:%d, %d, %d\n", read_cfg.breath.increase_ms, read_cfg.breath.decrease_ms, read_cfg.breath.apnea_ms );
+ //printf( "-----------------------------------------------\n" );
return ret;
static void gr_ring_enable(light_ctrl_t led_ctrl,uint32_t index)
{
+ light_cfg_t cfg;
if(index)
{
ring_led_flash(led_ctrl, 1000, 5000);
}
ring_led_flash(led_ctrl, 1000, 5000);
sleep(5);
- ring_led_breath(led_ctrl, 2000, 0);
+ load_light_cfg( &cfg );
+ ring_led_breath(led_ctrl, cfg.breath.increase_ms, cfg.breath.decrease_ms, cfg.breath.apnea_ms, 0);
}
// Report data and turn off gesture mode
int32_t ring_led_on( light_ctrl_t ctrl, uint32_t br_from, uint32_t br_to, uint32_t transition_time );
int32_t ring_led_off( light_ctrl_t ctrl, uint32_t br_from, uint32_t br_to, uint32_t transition_time );
int32_t ring_led_flash( light_ctrl_t ctrl, uint32_t period_ms, uint32_t duration_ms );
-int32_t ring_led_breath( light_ctrl_t ctrl, uint32_t period_ms, uint32_t duration_ms );
+int32_t ring_led_breath( light_ctrl_t ctrl, uint32_t increase_ms, uint32_t decrease_ms, uint32_t apnea_ms, uint32_t duration_ms );
int32_t ring_led_br_update( light_ctrl_t ctrl, uint32_t br );
int32_t ring_led_st( light_ctrl_t ctrl, light_st_t *st );
uint32_t duration_start_ms;
uint32_t duration_stop_ms;
+ uint32_t increase_ms;
+ uint32_t decrease_ms;
+ uint32_t apnea_ms;
+
//----------------------------------
pthread_t led_thread; //LED控制线程
pthread_mutex_t lock;
static int32_t mg_led_on( light_ctrl_t ctrl, uint32_t led_id, uint32_t br_from, uint32_t br_to, uint32_t transition_time );
static int32_t mg_led_off( light_ctrl_t ctrl, uint32_t led_id, uint32_t br_from, uint32_t br_to, uint32_t transition_time );
static int32_t mg_led_flash( light_ctrl_t ctrl, uint32_t led_id, uint32_t period_ms, uint32_t duration_ms );
-static int32_t mg_led_breath( light_ctrl_t ctrl, uint32_t led_id, uint32_t period_ms, uint32_t duration_ms );
+//static int32_t mg_led_breath( light_ctrl_t ctrl, uint32_t led_id, uint32_t period_ms );
+static int32_t mg_led_breath( light_ctrl_t ctrl, uint32_t led_id, uint32_t increas_ms, uint32_t decreas_ms, uint32_t apnea_ms, uint32_t duration_ms );
static int32_t mg_led_br_update( light_ctrl_t ctrl, uint32_t led_id, uint32_t br );
static int32_t mg_led_st( light_ctrl_t ctrl, uint32_t led_id, light_st_t *st );
//--------------------------------------------------------------------------------------------------------------------------------
return mg_led_off( ctrl, LED_RING, br_from, br_to, transition_time );
}
-int32_t ring_led_breath( light_ctrl_t ctrl, uint32_t period_ms, uint32_t duration_ms )
+int32_t ring_led_breath( light_ctrl_t ctrl, uint32_t increase_ms, uint32_t decrease_ms, uint32_t apnea_ms, uint32_t duration_ms )
{
- return mg_led_breath( ctrl, LED_RING, period_ms, duration_ms );
+ return mg_led_breath( ctrl, LED_RING, increase_ms, decrease_ms, apnea_ms, duration_ms );
}
int32_t ring_led_flash( light_ctrl_t ctrl, uint32_t period_ms, uint32_t duration_ms )
return retval;
}
-int32_t mg_led_breath( light_ctrl_t ctrl, uint32_t led_id, uint32_t period_ms, uint32_t duration_ms )
+int32_t mg_led_breath( light_ctrl_t ctrl, uint32_t led_id, uint32_t increase_ms, uint32_t decrease_ms, uint32_t apnea_ms, uint32_t duration_ms )
{
int32_t retval = 0;
led_ctrl_t *led_ctrl;
//lock
dev = &led_ctrl->led[i];
dev->flash = 2;
- dev->period_ms = period_ms;
dev->duration_ms = duration_ms;
if( duration_ms ){
dev->duration_start_ms = now_ms;
dev->duration_stop_ms = now_ms + duration_ms;
}
+ dev->apnea_ms = apnea_ms;
+ dev->increase_ms = increase_ms;
+ dev->decrease_ms = decrease_ms;
+ dev->period_ms = increase_ms+decrease_ms+apnea_ms;
//led_dev_unlock( dev );
}
}
}else if( dev->flash == 2 ){
//breath;
//呼吸周期计算
- uint32_t ms = now_ms%dev->period_ms;
- if( ms*2 < dev->period_ms ){
+ uint32_t ms = now_ms%(dev->increase_ms + dev->decrease_ms + dev->apnea_ms);
+
+ if( ms < dev->increase_ms ){
//up
- br = 100 * ms * 2/dev->period_ms;
- }else{
+ br = 100 * ms /dev->increase_ms;
+ }else if( ms < dev->increase_ms + dev->decrease_ms ){
//down
- br = 100 * (dev->period_ms - ms) * 2/dev->period_ms;
+ br = 100 * (dev->increase_ms + dev->decrease_ms -ms )/dev->decrease_ms;
+ }else{
+ //apnea , led off
+ br = 0;
}
- if( br <1 ) br = 1;
+ //if( br <1 ) br = 1;
if( br >100 ) br = 100;
//curr_br = br_gamma[br];
curr_br = br;
printf( "ring led flash period 1s ...\n" );
ring_led_flash( light, 1000, 5000 );
sleep(5);
-printf( "ring led breath period 1s ...\n" );
- ring_led_breath( light, 5000, 0 );
+printf( "ring led breath period inc 2s, dec 3s, apnea 1s...\n" );
+ ring_led_breath( light, 2000, 3000, 1000, 30000 );
while( 1 ){
key_led_off( light, LED_ID_KEY_ALL, 100, 0, 5000 );