声明:本资料归公司同事提供。
1.定义控制每一路灯的标志
#define LED_OFF 0x0000
#define LED_0 0x8000
#define LED_1 0x4000
#define LED_2 0x2000
#define LED_3 0x1000
#define LED_4 0x0800
#define LED_5 0x0400
#define LED_6 0x0200
#define LED_7 0x0100
#define LED_8 0x0080
#define LED_9 0x0040
#define LED_10 0x0020
#define LED_11 0x0010
#define LED_12 0x0008
#define LED_13 0x0004
#define LED_14 0x0002
#define LED_15 0x0001
#define LED_ALL_ON 0xffff
#define LED_1_10 0x4020
#define LED_2_9 0x2040
#define LED_3_8 0x1080
#define LED_4_7 0x0900
#define LED_5_6 0x0600
#define LED_END_FLAG 0xffff
#define LED_0 0x8000
#define LED_1 0x4000
#define LED_2 0x2000
#define LED_3 0x1000
#define LED_4 0x0800
#define LED_5 0x0400
#define LED_6 0x0200
#define LED_7 0x0100
#define LED_8 0x0080
#define LED_9 0x0040
#define LED_10 0x0020
#define LED_11 0x0010
#define LED_12 0x0008
#define LED_13 0x0004
#define LED_14 0x0002
#define LED_15 0x0001
#define LED_ALL_ON 0xffff
#define LED_1_10 0x4020
#define LED_2_9 0x2040
#define LED_3_8 0x1080
#define LED_4_7 0x0900
#define LED_5_6 0x0600
#define LED_END_FLAG 0xffff
2.定义一个结构体,记录要点亮的灯和这些灯持续的时间(单位为ticks)
typedef struct {
kal_uint16 data;
kal_uint16 ticks;
}neonlight_led_mode_type;
kal_uint16 data;
kal_uint16 ticks;
}neonlight_led_mode_type;
3.添加灯效
1) enum AUD_SYN_LIGHT_MODE 加一个成员,便于代码可读性强,比如加来电灯效
typedef enum{
AUD_SYN_LIGHT_OFF,
AUD_SYN_LIGHT_MODE1,
AUD_SYN_LIGHT_MODE2,
AUD_SYN_LIGHT_MODE3,
AUD_SYN_LIGHT_MODE4,
AUD_SYN_LIGHT_MODE5,
AUD_SYN_LIGHT_MODE6,
AUD_SYN_LIGHT_MAX,
POWER_ON_MODE,
POWER_OFF_MODE,
INCOMING_CALL_MODE,
FLASH_LIGHT_MODE_MAX,
}AUD_SYN_LIGHT_MODE;
AUD_SYN_LIGHT_OFF,
AUD_SYN_LIGHT_MODE1,
AUD_SYN_LIGHT_MODE2,
AUD_SYN_LIGHT_MODE3,
AUD_SYN_LIGHT_MODE4,
AUD_SYN_LIGHT_MODE5,
AUD_SYN_LIGHT_MODE6,
AUD_SYN_LIGHT_MAX,
POWER_ON_MODE,
POWER_OFF_MODE,
INCOMING_CALL_MODE,
FLASH_LIGHT_MODE_MAX,
}AUD_SYN_LIGHT_MODE;
2)加灯效数组,如下:
const neonlight_led_mode_type mode_data_incoming[] = {
{LED_OFF,10},
{LED_3|LED_4|LED_5,40},
{LED_0|LED_1|LED_2,40},
{LED_9|LED_10|LED_0,40},
{LED_6|LED_7|LED_8,40},
{LED_3|LED_4|LED_5,40},
{LED_0|LED_1|LED_2,40},
{LED_ALL_ON,60},
{LED_OFF,LED_END_FLAG}
};
3)将新加入的灯效添加到支持灯效的list里
const neonlight_led_mode_type * data_array[FLASH_LIGHT_MODE_MAX] =
{
NULL , /*AUD_SYN_LIGHT_OFF*/
mode_data1, /*AUD_SYN_LIGHT_MODE1*/
mode_data2, /*AUD_SYN_LIGHT_MODE2*/
mode_data3, /*AUD_SYN_LIGHT_MODE3*/
mode_data4, /*AUD_SYN_LIGHT_MODE4*/
mode_data5, /*AUD_SYN_LIGHT_MODE5*/
mode_data6, /*AUD_SYN_LIGHT_MODE6*/
NULL, /*AUD_SYN_LIGHT_MAX*/
mode_data_on,/*POWER_ON_MODE*/
mode_data_off,/*POWER_OFF_MODE*/
mode_data_incoming/*INCOMING_CALL_MODE*/
};
const neonlight_led_mode_type * data_array[FLASH_LIGHT_MODE_MAX] =
{
NULL , /*AUD_SYN_LIGHT_OFF*/
mode_data1, /*AUD_SYN_LIGHT_MODE1*/
mode_data2, /*AUD_SYN_LIGHT_MODE2*/
mode_data3, /*AUD_SYN_LIGHT_MODE3*/
mode_data4, /*AUD_SYN_LIGHT_MODE4*/
mode_data5, /*AUD_SYN_LIGHT_MODE5*/
mode_data6, /*AUD_SYN_LIGHT_MODE6*/
NULL, /*AUD_SYN_LIGHT_MAX*/
mode_data_on,/*POWER_ON_MODE*/
mode_data_off,/*POWER_OFF_MODE*/
mode_data_incoming/*INCOMING_CALL_MODE*/
};
4.跑马灯开始,停止,循环持续机制如下:
如来电跑马灯效就可以在mmi_ucm_entry_incoming_call中调用start_neonlight_led(INCOMING_CALL_MODE);
在mmi_ucm_exit_incoming_call中调用stop_neonlight_led
不管是用gpio,或IC控制的led,只要在以下TODO语句下调用对应led驱动函数即可
void neonlight_callback(void *dummy_para)
{
if( data_array[cur_syn_mode][cur_step].ticks == LED_END_FLAG)
{
cur_step = 0;
}
//此时data_array[cur_syn_mode][cur_step].data里面存储的是要亮哪些led
//TODO:此处调用点亮led的函数
//TODO:此处调用点亮led的函数
//此处根据当前led需要持续的时间置timer
kal_set_timer(led_syn_timer_id,neonlight_callback, NULL,data_array[cur_syn_mode][cur_step].ticks, 0);
cur_step++;
}
void start_neonlight_led(kal_uint8 cur_mode)
{
if(0x0 == led_syn_timer_id )
{
led_syn_timer_id = kal_create_timer("LED_SYN_TIMER");
}
cur_syn_mode = cur_mode;
if(data_array[cur_syn_mode] != NULL )
{
cur_step = 0;
neonlight_callback(NULL);
}
{
if(0x0 == led_syn_timer_id )
{
led_syn_timer_id = kal_create_timer("LED_SYN_TIMER");
}
cur_syn_mode = cur_mode;
if(data_array[cur_syn_mode] != NULL )
{
cur_step = 0;
neonlight_callback(NULL);
}
}
void stop_neonlight_led(void)
{
if(led_syn_timer_id)
{
kal_cancel_timer(led_syn_timer_id);
//TODO:此处调用关闭所有灯的函数
}
}
{
if(led_syn_timer_id)
{
kal_cancel_timer(led_syn_timer_id);
//TODO:此处调用关闭所有灯的函数
}
}