Exemplo n.º 1
0
/******************************************************************************
 * 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));
#if SAVE_LIGHT_PARAM

    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,0);
#else
    light_set_aim(  0,
	                0,
	                0, 
	                22222,
	                22222,
	                light_param.pwm_period,0);

#endif
    set_pwm_debug_en(0);//disable debug print in pwm driver
    os_printf("PWM version : %08x \r\n",get_pwm_version());
}
void ICACHE_FLASH_ATTR
	light_set_color(uint32 r,uint32 g,uint32 b,uint32 cw,uint32 ww,uint32 period)
{
	os_timer_disarm(&light_hint_t);
	uint32 d_color[] = {r,g,b,cw,ww};
	light_MeshStoreSetParam(&light_param_target,period,d_color);
    light_set_aim(r,g,b,cw,ww,period,0);
}
Exemplo n.º 3
0
void ICACHE_FLASH_ATTR
conect_ap_cb(void*p)
{
	light_set_aim(      
		         		0,
    	                0,
    	                0, 
    	                20000,
    	                20000,
    	                1000);
}
LOCAL void ICACHE_FLASH_ATTR
light_shade(int color)
{
    static bool color_flg = true;
    #if 1
    static uint32 cnt=0;
    if(shade_cnt != 0){	
        if(cnt >= (2*shade_cnt)){
            cnt = 0;
            color_flg = true;
            os_timer_disarm(&light_hint_t);
            LIGHT_INFO("RECOVER LIGHT PARAM; light_shade: \r\n");
			#if ESP_DEBUG_MODE
			if(light_error_flag){
                light_set_aim(light_param_error.pwm_duty[0],light_param_error.pwm_duty[1],light_param_error.pwm_duty[2],
                              light_param_error.pwm_duty[3],light_param_error.pwm_duty[4],light_param_error.pwm_period,0);
			}else{
                light_set_aim(light_param_target.pwm_duty[0],light_param_target.pwm_duty[1],light_param_target.pwm_duty[2],
                              light_param_target.pwm_duty[3],light_param_target.pwm_duty[4],light_param_target.pwm_period,0);
			}
			#else
			light_set_aim(light_param_target.pwm_duty[0],light_param_target.pwm_duty[1],light_param_target.pwm_duty[2],
						  light_param_target.pwm_duty[3],light_param_target.pwm_duty[4],light_param_target.pwm_period,0);
			#endif
            return;
        }else if(cnt==0){
            color_flg = true;
        }
        cnt++;
    }
    #endif
    
    if(color_flg){
		light_show_hint_color(color);      
        color_flg = false;
    }
    else{
        light_set_aim(0,0,0,1000,1000,1000,0);
        color_flg = true;
    }
}
Exemplo n.º 5
0
void ICACHE_FLASH_ATTR
user_light_cancel(void)
{
	os_printf("user_light_cancel\n");
	light_set_aim(      
		         		20000,
    	                0,
    	                0, 
    	                0,
    	                0,
    	                1000);
}
void ICACHE_FLASH_ATTR
	light_ColorRecover()
{

	#if ESP_DEBUG_MODE
    if(light_error_flag){
        light_error_flag = false;
		light_set_aim(light_param_error.pwm_duty[0],light_param_error.pwm_duty[1],light_param_error.pwm_duty[2],
					  light_param_error.pwm_duty[3],light_param_error.pwm_duty[4],light_param_error.pwm_period,0);
		LIGHT_INFO("RECOVER LIGHT PARAM ;light_ColorRecover: \r\n");
		LIGHT_INFO("r: %d ; g: %d ; b: %d ;ww: %d ; cw: %d \r\n",light_param_error.pwm_duty[0],light_param_error.pwm_duty[1],light_param_error.pwm_duty[2],
																light_param_error.pwm_duty[3],light_param_error.pwm_duty[4]);
		return;
    }
	#endif
	
    light_set_aim(light_param_target.pwm_duty[0],light_param_target.pwm_duty[1],light_param_target.pwm_duty[2],
                  light_param_target.pwm_duty[3],light_param_target.pwm_duty[4],light_param_target.pwm_period,0);
    LIGHT_INFO("RECOVER LIGHT PARAM ;light_ColorRecover: \r\n");
    LIGHT_INFO("r: %d ; g: %d ; b: %d ;ww: %d ; cw: %d \r\n",light_param_target.pwm_duty[0],light_param_target.pwm_duty[1],light_param_target.pwm_duty[2],
                                                            light_param_target.pwm_duty[3],light_param_target.pwm_duty[4]);
}
void ICACHE_FLASH_ATTR 
light_show_hint_color(uint32 color)
{
    switch(color){
    	case HINT_GREEN:
    		light_set_aim(0,20000,0,2000,2000,1000,0);
    		break;
    	case HINT_RED:
    		light_set_aim(20000,0,0,2000,2000,1000,0);
    		break;
    	case HINT_BLUE:
    		light_set_aim(0,0,20000,2000,2000,1000,0);
    		break;
    	case HINT_WHITE:
    		light_set_aim(0,0,0,20000,20000,1000,0);
    		break;
    	case HINT_PURE_RED:
    		light_set_aim(22222,0,0,0,0,1000,0);
    		break;
    	case HINT_PURE_GREEN:
    		light_set_aim(0,22222,0,0,0,1000,0);
    		break;
    	case HINT_PURE_BLUE:
    		light_set_aim(0,0,22222,0,0,1000,0);
    		break;
		case HINT_TARGET:
            light_set_aim(light_param_target.pwm_duty[0],light_param_target.pwm_duty[1],light_param_target.pwm_duty[2],
            light_param_target.pwm_duty[3],light_param_target.pwm_duty[4],light_param_target.pwm_period,0);
			break;
		case HINT_YELLOW:
			light_set_aim(22222,22222,0,0,0,1000,0);
			break;
		case HINT_PURPLE:
			light_set_aim(0,22222,22222,0,0,1000,0);
			break;
    }
}
Exemplo n.º 8
0
void ICACHE_FLASH_ATTR
user_light_connect_ap(void)
{
	light_set_aim(      
		         		0,
    	                0,
    	                20000, 
    	                0,
    	                0,
    	                1000);
	os_timer_disarm(&conect_timer);
	os_timer_setfn(&conect_timer, conect_ap_cb, NULL);
	os_timer_arm(&conect_timer,2000,0);
	os_printf("user_light_connect_ap\n");
}
Exemplo n.º 9
0
/******************************************************************************
 * FunctionName : user_light_init
 * Description  : light demo init, mainy init pwm
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_light_init(void)
{

	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};
	os_memcpy(light_param.pwm_duty,pwm_duty_init,sizeof(pwm_duty_init));
	
	light_param.pwm_period = 1000;
	
    /*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(      
		         pwm_duty_init[LIGHT_RED],
    	                pwm_duty_init[LIGHT_GREEN],
    	                pwm_duty_init[LIGHT_BLUE], 
    	                20000,
    	                20000,
    	                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());
}
Exemplo n.º 10
0
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));
    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}};
       uint32 pwm_duty_init[3] = {0,0,0};
pwm_init(light_param.pwm_period,  pwm_duty_init ,PWM_CHANNEL,io_info);

light_set_aim(light_param.pwm_duty[LIGHT_RED],
	                light_param.pwm_duty[LIGHT_GREEN],
	                light_param.pwm_duty[LIGHT_BLUE], 
	                0);
    set_pwm_debug_en(0);
    os_printf("PWM version : %08x \r\n",get_pwm_version());
}
Exemplo n.º 11
0
/******************************************************************************
 * FunctionName : user_light_init
 * Description  : light demo init, mainy init pwm
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void  user_light_init(void)
{
    /*init to off*/
    uint32 pwm_duty_init[PWM_CHANNEL];
    light_param.pwm_period = 1000;
    memset(pwm_duty_init,0,PWM_CHANNEL*sizeof(uint32));
    pwm_init(light_param.pwm_period, pwm_duty_init,PWM_CHANNEL,pwmio_info); 

    /*set target valuve from memory*/
    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;
            light_param.pwm_duty[0]= APP_MAX_PWM;
            light_param.pwm_duty[1]= APP_MAX_PWM;
            light_param.pwm_duty[2]= APP_MAX_PWM;
            light_param.pwm_duty[3]= APP_MAX_PWM;
            light_param.pwm_duty[4]= APP_MAX_PWM;
    }
    printf("LIGHT P:%d",light_param.pwm_period);
    printf(" R:%d",light_param.pwm_duty[LIGHT_RED]);
    printf(" G:%d",light_param.pwm_duty[LIGHT_GREEN]);
    printf(" B:%d",light_param.pwm_duty[LIGHT_BLUE]);
    if(PWM_CHANNEL>LIGHT_COLD_WHITE){
        printf(" CW:%d",light_param.pwm_duty[LIGHT_COLD_WHITE]);
        printf(" WW:%d\r\n",light_param.pwm_duty[LIGHT_WARM_WHITE]);
    }else{
        printf("\r\n");
    }

    light_set_aim(light_param.pwm_duty[LIGHT_RED],
                    light_param.pwm_duty[LIGHT_GREEN],
                    light_param.pwm_duty[LIGHT_BLUE], 
                    light_param.pwm_duty[LIGHT_COLD_WHITE],
                    light_param.pwm_duty[LIGHT_WARM_WHITE],
                    light_param.pwm_period);
        
	return;
}
Exemplo n.º 12
0
void user_esp_pwm_test_task(void *pvParameters)
{
	uint32 r,g,b,cw,ww,period;

	r = 0;
	g = 0;
	b = 0;
	cw = 0;

	period = 1000;

	while(1)   // a demo test pwm
	{
		ESP_DBG(("*****test****r:%d,g:%d,b:%d,cw:%d,ww:%d",r,g,b,cw,ww));
        light_set_aim(r,g,b,cw,ww,period);

		r+=5;
		g+=5;
		b+=5;
		cw+=5;
		ww+=5;
		
		if(r>100)
			r = 0;
		if(g>100)
			g = 0;
		if(b>100)
			b = 0;
		if(cw>100)
			cw = 0;
		if(ww>100)
			ww = 0;
		vTaskDelay(50);
	}
	vTaskDelete(NULL);
	return;
}
Exemplo n.º 13
0
Arquivo: sample.c Projeto: hwwr/test
/*get json cmd from server 服务器下发命令,需要设备端根据具体业务设定去解析处理*/
int ICACHE_FLASH_ATTR main_dev_set_device_status_callback(alink_down_cmd_ptr down_cmd)
{

	json_value *jptr;
	json_value *jstr;
	json_value *jstr_value;
	int value = 0, i = 0;
	char *value_str = NULL;

	wsf_deb("%s %d \n", __FUNCTION__, __LINE__);
	wsf_deb("%s %d\n%s\n", down_cmd->uuid, down_cmd->method, down_cmd->param);

	jptr = json_parse(down_cmd->param, strlen(down_cmd->param));
#if USER_UART_CTRL_DEV_EN
	for (i = 0; i < 5; i++)
	{
		jstr = json_object_object_get_e(jptr, device_attr[i]);
		jstr_value = json_object_object_get_e(jstr, "value");
		value_str = json_object_to_json_string_e(jstr_value);

		if (value_str) {
			value = atoi(value_str);
			cus_wifi_handler_alinkdata2mcu(i, value);

			ESP_DBG(("power:0x%X,temp_value:0x%X,light_value:0x%X,time_delay:0x%X,woke_mode:0x%X", virtual_device.power, \
				virtual_device.temp_value, virtual_device.light_value, virtual_device.time_delay, virtual_device.work_mode));
		}
	}
#endif
#if USER_PWM_LIGHT_EN
	USER_LIGHT_DATA *user_light_data_ptr = zalloc(sizeof(USER_LIGHT_DATA));
	// Set r g b w data,Developers need to parse the real device parameters corresponding to the Json package
	light_set_aim(user_light_data_ptr->light_r, user_light_data_ptr->light_g, user_light_data_ptr->light_b, user_light_data_ptr->light_cw, user_light_data_ptr->light_ww, user_light_data_ptr->light_period);

	free(user_light_data_ptr);
#endif
#if USER_VIRTUAL_DEV_TEST
	for (i = 0; i < 5; i++)
	{
		jstr = json_object_object_get_e(jptr, device_attr[i]);
		jstr_value = json_object_object_get_e(jstr, "value");
		value_str = json_object_to_json_string_e(jstr_value);
		if (value_str) {
			value = atoi(value_str);
			switch (i) {
			case 0:
				if (virtual_device.power != value) {
					virtual_device.power = value;
				}
				break;
			case 1:
				if (virtual_device.temp_value != value) {
					virtual_device.temp_value = value;
				}
				break;
			case 2:
				if (virtual_device.light_value != value) {
					virtual_device.light_value = value;
				}
				break;
			case 3:
				if (virtual_device.time_delay != value) {
					virtual_device.time_delay = value;
				}
				break;
			case 4:
				if (virtual_device.work_mode != value) {
					virtual_device.work_mode = value;
				}
				break;
			default:
				break;
			}
		}
	}
#endif

	json_value_free(jptr);
	device_status_change = 1;   // event send current real device status to the alink server

	return 0;		// alink_device_post_data(down_cmd);
					/* do your job end! */
}