From d8ebe08ccf724a23818710f616ef6072f570ef9c Mon Sep 17 00:00:00 2001 From: kyz Date: Tue, 30 May 2023 23:03:09 +0800 Subject: [PATCH] =?utf8?q?=E5=B9=B3=E5=8F=B0=E4=BF=AE=E6=94=B9=E5=8F=82?= =?utf8?q?=E6=95=B0=E5=90=8E=E6=9C=AC=E5=9C=B0=E5=AD=98=E5=82=A8=20?= =?utf8?q?=E6=8C=89=E9=94=AE=E5=92=8Cled=E7=9A=84=E6=8E=A5=E5=8F=A3?= =?utf8?q?=E4=BC=98=E5=8C=96=20=E4=B8=AD=E9=97=B4=E4=BB=B6=E6=8E=A5?= =?utf8?q?=E5=8F=A3=E5=AE=9A=E4=B9=89=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...45\345\217\243\345\256\232\344\271\211.md" | 332 ++++++++++++------ app/src/device_button.c | 14 +- app/src/device_config.c | 83 +++-- app/src/device_light.c | 9 +- app/src/iot_dp.c | 2 +- button/inc/button.h | 19 +- button/src/button.c | 122 +++---- button/src/button_scan.c | 51 +-- led/inc/led.h | 7 +- led/src/led.c | 38 +- 10 files changed, 411 insertions(+), 266 deletions(-) diff --git "a/TW8013\344\270\255\351\227\264\344\273\266\346\216\245\345\217\243\345\256\232\344\271\211.md" "b/TW8013\344\270\255\351\227\264\344\273\266\346\216\245\345\217\243\345\256\232\344\271\211.md" index b6477f8..af73e97 100755 --- "a/TW8013\344\270\255\351\227\264\344\273\266\346\216\245\345\217\243\345\256\232\344\271\211.md" +++ "b/TW8013\344\270\255\351\227\264\344\273\266\346\216\245\345\217\243\345\256\232\344\271\211.md" @@ -8,11 +8,8 @@ 5. EIA485 6. 蜂鸣器 --- - ## 1.按键管理 - ### 1.1 数据类型定义 - #### 键值定义 支持8个按键,BUTTON_1 到BUTTON_8 typedef enum{ @@ -26,7 +23,6 @@ BUTTON_8 = (1<<7), BUTTON_ALL = 0xff, }button_code_t; - #### 事件类型定义: 普通按键事件:单击、双击、长按、长按释放 组合按键事件:组合键按下 @@ -34,19 +30,15 @@ EVENT_SINGLE_CLICK = (1<<0), EVENT_DOUBLE_CLICK = (1<<1), EVENT_LONG_PRESS = (1<<2), - EVENT_LONG_PRESS_UP = (1<<3), - EVENT_COMB_PRESS = (1<<4), + EVENT_LONG_PRESS_2S = (1<<3), + EVENT_LONG_PRESS_5S = (1<<4), + EVENT_LONG_PRESS_UP = (1<<5), + EVENT_COMB_PRESS = (1<<6), + EVENT_COMB_PRESS_2S = (1<<7), + EVENT_COMB_PRESS_5S = (1<<8), }button_event_t; - -单击、双击、长按并释放 这三个是互斥的 -“长按”和“长按并释放”是先后关系 -![按键事件]( button_event.png ) - #### 按键控制描述符 - - struct mg_button; - typedef struct mg_button mg_button_t; - + typedef void* btn_ctrl_t; #### 回调函数 typedef void ( * button_event_cb_t )( button_code_t code, button_event_t evt, void * value ); 参数定义: @@ -54,36 +46,36 @@ evt: 按键类型 ,单击 双击 组合键长按等事件 value: 预留参数 返回值: 无 - ### 1.2 控制接口 #### 获取按键控制器 - mg_button_t * mg_button_open( char * button_device_path ); + 默认按键设备: + #define BUTTON_DEVICE_PATH "/dev/input/event2" + + btn_ctrl_t mg_button_open( char * button_device_path ); 参数定义: button_device_path:键盘设备文件, 如/dev/input/event1 + 如果是NULL,则使用默认设备 返回值: - 打开失败,返回 NULL, 成功,返回按键控制器指针。 - + 打开失败,返回 NULL, 成功,返回按键控制器描述符。 #### 关闭按键控制器 - void mg_button_close( mg_button_t * btn_ctrl ); + void mg_button_close( btn_ctrl_t btn_ctrl ); 参数定义: - btn_ctrl: 按键控制器 + btn_ctrl: 按键控制器描述符 返回值: 无 - #### 注册普通按键事件 - int32_t mg_button_event_register( mg_button_t *btn_ctrl, button_code_t code, button_event_t event, button_event_cb_t cb ); + int32_t mg_button_event_register( btn_ctrl_t btn_ctrl, button_code_t code, button_event_t event, button_event_cb_t cb ); 参数定义: - btn_ctrl: 按键控制器 + btn_ctrl: 按键控制器描述符 code: 键值,可以是包含多个按键值 event: 按键事件类型,可以包含多个事件类型 cb: 按键触发时的回调函数 返回值: 0: 成功 -1:失败 - #### 注册组合按键事件 - int32_t mg_button_event_combonation_register( mg_button_t *btn_ctrl, button_code_t code, button_event_t event, uint32_t time_ms, button_event_cb_t cb ); + int32_t mg_button_event_combonation_register( btn_ctrl_t *btn_ctrl, button_code_t code, button_event_t event, uint32_t time_ms, button_event_cb_t cb ); 参数定义: - btn_ctrl: 按键控制器 + btn_ctrl: 按键控制器描述符 code: 键值,包含多个按键值 event: 按键事件类型 time: 组合键按下时间,单位毫秒 @@ -91,94 +83,233 @@ 返回值: 0: 成功 -1:失败 - --- - ## 2 LED显示管理 - ### 2.1 数据类型定义 - #### LED ID定义 - 8个按键灯, 5个装饰灯, 一个灯圈,红外补光灯 - typedef enum{ - KEY_LED_1 = 0, - KEY_LED_2, - KEY_LED_3, - KEY_LED_4, - KEY_LED_5, - KEY_LED_6, - KEY_LED_7, - KEY_LED_8, - FUN_LED_1, - FUN_LED_2, - FUN_LED_3, - FUN_LED_4, - FUN_LED_5, - RING_LED, - IR_LED, - }led_id_t; - -##### LED工作模式 - typedef enum{ - LED_OFF, //关闭 - LED_ON, //常亮 - LED_FLASH_1HZ, - LED_FLASH_2HZ, - LED_FLASH_8HZ, - LED_FLASH_XHZ, - - LED_GRAUAL_ON, //渐变到DP设定亮度后常亮 - LED_GRAUAL_MAX_ON, //渐变到最大亮度后常亮 - LED_GRADUAL_OFF, //渐变到关闭 - - KEYLED_FLASH_FAST = LED_FLASH_8HZ, //快闪 8HZ - KEYLED_FLASH_SLOW_1 = LED_FLASH_1HZ, //慢闪 1HZ - KEYLED_FLASH_SLOW_2 = LED_FLASH_2HZ, //慢闪 2HZ - LED_BREATH_XHZ; //呼吸指示模式 - }led_mode_t; - +8个按键灯 + + #define LED_ID_KEY_1 (1<<0) + #define LED_ID_KEY_2 (1<<1) + #define LED_ID_KEY_3 (1<<2) + #define LED_ID_KEY_4 (1<<3) + #define LED_ID_KEY_5 (1<<4) + #define LED_ID_KEY_6 (1<<5) + #define LED_ID_KEY_7 (1<<6) + #define LED_ID_KEY_8 (1<<7) + #define LED_ID_KEY_ALL (0xff) +5个装饰灯 + + #define LED_ID_ATMOS_1 (1<<0) + #define LED_ID_ATMOS_2 (1<<1) + #define LED_ID_ATMOS_3 (1<<2) + #define LED_ID_ATMOS_4 (1<<3) + #define LED_ID_ATMOS_5 (1<<4) + #define LED_ID_ATMOS_ALL ( 0x1f ) +##### LED状态 + typedef struct{ + uint32_t on; //0:常灭, 1:常亮, 2:闪烁, 3:呼吸 + uint32_t period; //闪烁或呼吸的周期 单位毫秒 + uint32_t br_max; //亮度 + } light_st_t; #### LED控制描述符 - struct mg_led; - typedef struct mg_led mg_led_t; - + typedef void* light_ctrl_t; ### 2.2控制接口 - #### 获取LED控制器 - mg_led_t * mg_led_open( void ); + light_ctrl_t mg_led_open( void ); 参数定义: 无 返回值: 打开失败,返回 NULL; - 成功,返回LED控制器指针。 - + 成功,返回LED控制器描述符。 #### 关闭控制器 - void mg_led_close( mg_led_t * btn_ctrl ); + void mg_led_close( light_ctrl_t light_ctrl ); 参数定义: - btn_ctrl: 按键控制器 + light_ctrl: LED控制器描述符 返回值: 无 -#### LED 显示模式设置 - int32_t mg_led_set( mg_led_t *led_ctrl, led_id_t id, led_mode_t mode, uint32_t keep_ms, void *breath ); - 参数定义: - led_ctrl: LED控制器 - id: LED ID - mode: 显示模式 - keep_ms: 显示模式持续时间,时间到达后关闭,如果是0则保持当前模式不关闭,单位毫秒 - breath: 呼吸指示参数 +#### 按键背光灯控制接口 + +##### 渐变到常亮 + int32_t key_led_on( light_ctrl_t ctrl, uint32_t led_id, uint32_t br_from, uint32_t br_to, uint32_t transition_time ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID,可以是多个LED + br_from: 渐变的起始亮度 + br_to: 渐变的目标亮度 + transition_time: 从0到100亮度渐变时间,单位毫秒 返回值: 0: 成功 -1:失败 - -#### LED 显示模式查询 - int32_t mg_led_get( mg_led_t *led_ctrl, led_id_t id, led_mode_t * mode, uint32_t *brightness ); - 参数定义: - led_ctrl: LED控制器 - id: LED ID - mode: 读取显示模式 - brightness: 当前亮度值 +##### 渐变到常灭 + int32_t key_led_off( light_ctrl_t ctrl, uint32_t led_id, uint32_t br_from, uint32_t br_to, uint32_t transition_time ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID,可以是多个LED + br_from: 渐变的起始亮度 + br_to: 渐变的目标亮度 + transition_time: 从0到100亮度渐变时间,单位毫秒 + 返回值: + 0: 成功 + -1:失败 +##### 闪烁 + int32_t key_led_flash( light_ctrl_t ctrl, uint32_t led_id, uint32_t period_ms, uint32_t duration_ms ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID,可以是多个LED + period_ms: 闪烁周期,单位毫秒 + duration_ms:持续时间,单位毫秒, 为0则一直保持闪烁不退出。 + 返回值: + 0: 成功 + -1:失败 +##### 亮度修改 + int32_t key_led_br_update( light_ctrl_t ctrl, uint32_t led_id, uint32_t br ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID,可以是多个LED + br: 亮度 返回值: 0: 成功 -1:失败 +##### 读取状态 + int32_t key_led_st( light_ctrl_t ctrl, uint32_t led_id, light_st_t *st ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID + st: 状态返回值 + 返回值: + 0: 成功 + -1:失败 +#### 氛围灯控制接口 +##### 渐变到常亮 + int32_t atmos_led_on( light_ctrl_t ctrl, uint32_t led_id, uint32_t br_from, uint32_t br_to, uint32_t transition_time ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID,可以是多个LED + br_from: 渐变的起始亮度 + br_to: 渐变的目标亮度 + transition_time: 从0到100亮度渐变时间,单位毫秒 + 返回值: + 0: 成功 + -1:失败 +##### 渐变到常灭 + int32_t atmos_led_off( light_ctrl_t ctrl, uint32_t led_id, uint32_t br_from, uint32_t br_to, uint32_t transition_time ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID,可以是多个LED + br_from: 渐变的起始亮度 + br_to: 渐变的目标亮度 + transition_time: 从0到100亮度渐变时间,单位毫秒 + 返回值: + 0: 成功 + -1:失败 +##### 闪烁 + int32_t atmos_led_flash( light_ctrl_t ctrl, uint32_t led_id, uint32_t period_ms, uint32_t duration_ms ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID,可以是多个LED + period_ms: 闪烁周期,单位毫秒 + duration_ms:持续时间,单位毫秒, 为0则一直保持闪烁不退出。 + 返回值: + 0: 成功 + -1:失败 +##### 亮度修改 + int32_t atmos_led_br_update( light_ctrl_t ctrl, uint32_t led_id, uint32_t br ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID,可以是多个LED + br: 亮度 + 返回值: + 0: 成功 + -1:失败 +##### 读取状态 + int32_t atmos_led_st( light_ctrl_t ctrl, uint32_t led_id, light_st_t *st ); + 参数定义: + ctrl: LED控制器描述符 + led_id:LED ID + st: 状态返回值 + 返回值: + 0: 成功 + -1:失败 +#### 灯圈控制接口 +##### 渐变到常亮 + int32_t ring_led_on( light_ctrl_t ctrl,uint32_t br_from, uint32_t br_to, uint32_t transition_time ); + 参数定义: + ctrl: LED控制器描述符 + br_from: 渐变的起始亮度 + br_to: 渐变的目标亮度 + transition_time: 从0到100亮度渐变时间,单位毫秒 + 返回值: + 0: 成功 + -1:失败 +##### 渐变到常灭 + int32_t ring_led_off( light_ctrl_t ctrl, uint32_t br_from, uint32_t br_to, uint32_t transition_time ); + 参数定义: + ctrl: LED控制器描述符 + br_from: 渐变的起始亮度 + br_to: 渐变的目标亮度 + transition_time: 从0到100亮度渐变时间,单位毫秒 + 返回值: + 0: 成功 + -1:失败 +##### 呼吸 + int32_t ring_led_breath( light_ctrl_t ctrl, uint32_t period_ms, uint32_t duration_ms ); + 参数定义: + ctrl: LED控制器描述符 + period_ms: 呼吸周期,单位毫秒 + duration_ms:持续时间,单位毫秒, 为0则一直保持呼吸不退出。 + 返回值: + 0: 成功 + -1:失败 +##### 亮度修改 + int32_t ring_led_br_update( light_ctrl_t ctrl, uint32_t br ); + 参数定义: + ctrl: LED控制器描述符 + br: 亮度 + 返回值: + 0: 成功 + -1:失败 +##### 读取状态 + int32_t ring_led_st( light_ctrl_t ctrl, light_st_t *st ); + 参数定义: + ctrl: LED控制器描述符 + st: 状态返回值 + 返回值: + 0: 成功 + -1:失败 +#### 红外补光灯制接口 +##### 打开 + int32_t ir_led_on( light_ctrl_t ctrl, uint32_t br ); + 参数定义: + ctrl: LED控制器描述符 + br: 亮度 + 返回值: + 0: 成功 + -1:失败 +##### 关闭 + int32_t ir_led_off( light_ctrl_t ctrl ); + 参数定义: + ctrl: LED控制器描述符 + 返回值: + 0: 成功 + -1:失败 +##### 亮度修改 + int32_t ring_led_br_update( light_ctrl_t ctrl, uint32_t br ); + 参数定义: + ctrl: LED控制器描述符 + br: 亮度 + 返回值: + 0: 成功 + -1:失败 +##### 读取状态 + int32_t ring_led_st( light_ctrl_t ctrl, light_st_t *st ); + 参数定义: + ctrl: LED控制器描述符 + st: 状态返回值 + 返回值: + 0: 成功 + -1:失败 + --- ## 3 人感TOF ### 3.1 数据类型定义 @@ -311,9 +442,7 @@ --- ## 5 EIA485 ### 5.1 数据类型定义 - #### 串口参数 - 数据位长度 enum{ @@ -342,9 +471,7 @@ #### EIA485控制描述符 struct mg_eia485; typedef struct mg_eia485 mg_eia485_t; - ### 6.2控制接口 - #### 打开EIA485控制器 mg_eia485_t * mg_eia485_open( uint32_t baud, uint32_t data_bits, uint32_t stop_bits, uint32_t parity ); 参数定义: @@ -355,13 +482,11 @@ 返回值: 打开失败,返回 NULL; 成功,返回TOF控制器指针。 - #### 关闭控制器 void mg_eia485_close( mg_eia485_t * eia485_ctrl ); 参数定义: eia485_ctrl: EIA485控制器 返回值: 无 - #### 发送数据 void mg_eia485_write( mg_eia485_t * eia485_ctrl,uint8_t * tx_data, uint32_t tx_size ); 参数定义: @@ -371,7 +496,6 @@ 返回值: 0: 成功 -1:失败 - #### 接收数据 int32_t mg_eia485_read( mg_eia485_t * eia485_ctrl,uint8_t * rx_data, uint32_t rx_size, uint32_t timeout_ms ); 参数定义: @@ -383,16 +507,13 @@ 大于0:读取到的数据长度 0: 无数据 -1: 操作失败失败 - --- ## 6 蜂鸣器 ### 6.1 数据类型定义 #### 传感器控制描述符 struct mg_buzzer; typedef struct mg_buzzer mg_buzzer_t; - ### 6.2控制接口 - #### 获取蜂鸣器控制器 mg_buzzer_t * mg_buzzer_open( void ); 参数定义: @@ -400,13 +521,11 @@ 返回值: 打开失败,返回 NULL; 成功,返回TOF控制器指针。 - #### 关闭控制器 void mg_buzzer_close( mg_buzzer_t * buzzer_ctrl ); 参数定义: buzzer_ctrl: 按键控制器 返回值: 无 - #### 蜂鸣器播放声音 void mg_buzzer_start( mg_bizzer_t * buzzer_ctrl, uint32_t freq_hz, uint32_t time_ms ); 参数定义: @@ -414,5 +533,4 @@ freq_hz: 频率,如果值是0,则立即关闭蜂鸣器 time_ms: 播放时间, 单位毫秒,到达时间后自动关闭,如果值是0 则一直开启 返回值: 无 - --- diff --git a/app/src/device_button.c b/app/src/device_button.c index d212729..bc83e48 100644 --- a/app/src/device_button.c +++ b/app/src/device_button.c @@ -11,7 +11,7 @@ //#include "cQueue.h" #include "device.h" -static mg_button_t *btn_ctrl; +static btn_ctrl_t *g_ctrl; static pthread_mutex_t btn_lock; static cQueue_t *btn_msg_q; @@ -57,12 +57,12 @@ void device_button_init( void ) MG_LOGE( "btn init" ); pthread_mutex_init( &btn_lock, NULL ); btn_msg_q = cQcreate( 100 ); - btn_ctrl = mg_button_open(NULL); //"/dev/input/by-path/platform-gpio_keys-event" ); - if( btn_ctrl ){ - mg_button_event_register( btn_ctrl, 0xFF, EVENT_SINGLE_CLICK|EVENT_DOUBLE_CLICK|EVENT_LONG_PRESS|EVENT_LONG_PRESS_UP, button_single_cb ); - mg_button_event_combonation_register( btn_ctrl, BUTTON_7|BUTTON_8, EVENT_COMB_PRESS_5S, 0, button_comb_cb ); - mg_button_event_combonation_register( btn_ctrl, BUTTON_1|BUTTON_8, EVENT_COMB_PRESS_2S, 0, button_comb_cb ); - mg_button_event_combonation_register( btn_ctrl, BUTTON_2|BUTTON_7, EVENT_COMB_PRESS_2S, 0, button_comb_cb ); + g_ctrl = mg_button_open(NULL); //"/dev/input/by-path/platform-gpio_keys-event" ); + if( g_ctrl ){ + mg_button_event_register( g_ctrl, 0xFF, EVENT_SINGLE_CLICK|EVENT_DOUBLE_CLICK|EVENT_LONG_PRESS|EVENT_LONG_PRESS_UP, button_single_cb ); + mg_button_event_combonation_register( g_ctrl, BUTTON_7|BUTTON_8, EVENT_COMB_PRESS_5S, 0, button_comb_cb ); + mg_button_event_combonation_register( g_ctrl, BUTTON_1|BUTTON_8, EVENT_COMB_PRESS_2S, 0, button_comb_cb ); + mg_button_event_combonation_register( g_ctrl, BUTTON_2|BUTTON_7, EVENT_COMB_PRESS_2S, 0, button_comb_cb ); }else{ MG_LOGE( "mg_button_open fail\n" ); } diff --git a/app/src/device_config.c b/app/src/device_config.c index 64f03dc..6b277c7 100644 --- a/app/src/device_config.c +++ b/app/src/device_config.c @@ -38,11 +38,11 @@ int32_t nv_read( char *path, uint8_t *read_data, uint32_t read_sz ) fp = fopen( path, "r" ); if( fp ){ if( fread( read_data, read_sz, 1, fp )==1 && fread( &read_crc, 4, 1, fp )==1){ - if( read_crc == crc32( 0, read_data, read_sz ) ){ - retval = 0; - }else{ - MG_LOGI( "cfg file[%s] verify fail!", path ); - } + if( read_crc == crc32( 0, read_data, read_sz ) ){ + retval = 0; + }else{ + MG_LOGI( "cfg file[%s] verify fail!", path ); + } }else{ MG_LOGI( "read cfg file[%s] fail!", path ); } @@ -62,7 +62,7 @@ int32_t nv_write( char *path, uint8_t *write_data, uint32_t write_sz ) FILE *fp; uint8_t * wr_buf; - + fp = fopen( path, "w" ); if( fp ){ wr_crc = crc32( 0, (char *)write_data, write_sz ); @@ -82,17 +82,18 @@ int32_t nv_write( char *path, uint8_t *write_data, uint32_t write_sz ) int32_t load_device_cfg( dev_cfg_t *cfg ) { //read file - if( nv_read( DEV_CFG_PATH, (uint8_t*)cfg, sizeof( cfg ) ) != 0 ){ + if( nv_read( DEV_CFG_PATH, (uint8_t*)cfg, sizeof( *cfg ) ) != 0 ){ MG_LOGI( "load cfg file fail, use default cfg!" ); memcpy( cfg, &dev_cfg_default, sizeof( *cfg ) ); } + return 0; } int32_t store_device_cfg( dev_cfg_t *cfg ) { //write file - return nv_write( DEV_CFG_PATH, (uint8_t*)cfg, sizeof(cfg) ); + return nv_write( DEV_CFG_PATH, (uint8_t*)cfg, sizeof(*cfg) ); } @@ -259,7 +260,10 @@ int32_t cfg_key_led_max_write( mg_dev_t *dev, int br ) MG_LOGI( "key_led_max: %d -> %d\n", dev->cfg.key_led_max, br ); } mg_dev_lock( dev ); - dev->cfg.key_led_max = br; + if( br != dev->cfg.key_led_max ){ + dev->cfg.key_led_max = br; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -279,7 +283,10 @@ int32_t cfg_atmos_led_max_write( mg_dev_t *dev, int br ) MG_LOGI( "atmos_led_max: %d -> %d\n", dev->cfg.atmos_led_max, br ); } mg_dev_lock( dev ); - dev->cfg.atmos_led_max = br; + if( br != dev->cfg.atmos_led_max ){ + dev->cfg.atmos_led_max = br; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -299,7 +306,10 @@ int32_t cfg_recognition_level_write( mg_dev_t *dev, int level ) MG_LOGI( ": %d -> %d\n", dev->cfg.recognition_level, level ); } mg_dev_lock( dev ); - dev->cfg.recognition_level= level; + if( level != dev->cfg.recognition_level ){ + dev->cfg.recognition_level= level; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -319,7 +329,10 @@ int32_t cfg_recognition_duration_write( mg_dev_t *dev, int32_t dur_sec ) MG_LOGI( "dur_sec: %d -> %d\n", dev->cfg.recognition_duration, dur_sec ); } mg_dev_lock( dev ); - dev->cfg.recognition_duration = dur_sec; + if( dur_sec != dev->cfg.recognition_duration){ + dev->cfg.recognition_duration = dur_sec; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -339,7 +352,10 @@ int32_t cfg_privacy_mode_write( mg_dev_t *dev, int32_t mode ) MG_LOGI( "privacy_mode: %d -> %d\n", dev->cfg.privacy_mode, mode ); } mg_dev_lock( dev ); - dev->cfg.privacy_mode = mode; + if( mode != dev->cfg.privacy_mode ){ + dev->cfg.privacy_mode = mode; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -359,7 +375,10 @@ int32_t cfg_mg_tof_threshold_write( mg_dev_t *dev, int32_t threshold_cm ) MG_LOGI( ": %d -> %d\n", dev->cfg.mg_tof_threshold, threshold_cm ); } mg_dev_lock( dev ); - dev->cfg.mg_tof_threshold = threshold_cm; + if( threshold_cm != dev->cfg.mg_tof_threshold ){ + dev->cfg.mg_tof_threshold = threshold_cm; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -379,7 +398,10 @@ int32_t cfg_mg_tof_interval_write( mg_dev_t *dev, int32_t interval_sec) MG_LOGI( "mg_tof_interval: %d -> %d\n", dev->cfg.mg_tof_interval, interval_sec ); } mg_dev_lock( dev ); - dev->cfg.mg_tof_interval = interval_sec; + if( interval_sec != dev->cfg.mg_tof_interval ){ + dev->cfg.mg_tof_interval = interval_sec; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -400,7 +422,10 @@ int32_t cfg_mg_disable_row_write( mg_dev_t *dev, int32_t disable ) MG_LOGI( "mg_disable_row: %d -> %d\n", dev->cfg.mg_disable_row, disable ); } mg_dev_lock( dev ); - dev->cfg.mg_disable_row = disable; + if( disable != dev->cfg.mg_disable_row ){ + dev->cfg.mg_disable_row = disable; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -421,7 +446,10 @@ int32_t cfg_mg_key_enable_write( mg_dev_t *dev, int32_t en_mask ) MG_LOGI( "key enable: %02X -> %02X\n", dev->cfg.mg_key_enable, en_mask ); } mg_dev_lock( dev ); - dev->cfg.mg_key_enable = en_mask; + if( en_mask != dev->cfg.mg_key_enable){ + dev->cfg.mg_key_enable = en_mask; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -441,7 +469,10 @@ int32_t cfg_bl_mode_write( mg_dev_t *dev, int32_t mode ) //0:auto, 1-manual MG_LOGI( "bl_mode: %d -> %d\n", dev->cfg.bl_mode, mode ); } mg_dev_lock( dev ); - dev->cfg.bl_mode = mode; + if( mode != dev->cfg.bl_mode){ + dev->cfg.bl_mode = mode; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -461,7 +492,10 @@ int32_t cfg_led_atmos_on_duration_write( mg_dev_t *dev, int32_t dur_sec ) MG_LOGI( "led_atmos_on_duration %d -> %d\n", dev->cfg.led_atmos_on_duration, dur_sec ); } mg_dev_lock( dev ); - dev->cfg.led_atmos_on_duration = dur_sec; + if( dur_sec != dev->cfg.led_atmos_on_duration ){ + dev->cfg.led_atmos_on_duration = dur_sec; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -482,7 +516,10 @@ int32_t cfg_led_atmos_off_duration_write( mg_dev_t *dev, int32_t dur_sec ) MG_LOGI( "led_atmos_off_duration %d -> %d\n", dev->cfg.led_atmos_off_duration, dur_sec ); } mg_dev_lock( dev ); - dev->cfg.led_atmos_off_duration = dur_sec; + if( dur_sec != dev->cfg.led_atmos_off_duration ){ + dev->cfg.led_atmos_off_duration = dur_sec; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); return 0; } @@ -502,8 +539,12 @@ int32_t cfg_mg_tof_sync_write( mg_dev_t *dev, int32_t sync ) MG_LOGI( "mg_tof_sync: %d -> %d\n", dev->cfg.mg_tof_sync, sync); } mg_dev_lock( dev ); - dev->cfg.mg_tof_sync = sync; + if( dev->cfg.mg_tof_sync != sync ){ + dev->cfg.mg_tof_sync = sync; + store_device_cfg( &dev->cfg ); + } mg_dev_unlock( dev ); + return 0; } diff --git a/app/src/device_light.c b/app/src/device_light.c index 7660d14..295e9d9 100644 --- a/app/src/device_light.c +++ b/app/src/device_light.c @@ -100,15 +100,18 @@ void light_mode_set( light_mode_t mode ) break; case LIGHT_MODE_ACTIVE: // - key_led_on( g_led_ctrl, LED_ID_KEY_ALL&key_mask, 0, 100, 0); - atmos_led_on( g_led_ctrl, LED_ID_ATMOS_ALL, 0, 100, 0); + if( cfg_bl_mode_read( &g_mg_dev) ){ + //manual mode + key_led_on( g_led_ctrl, LED_ID_KEY_ALL&key_mask, 0, cfg_key_led_max_read( &g_mg_dev ), 0); + atmos_led_on( g_led_ctrl, LED_ID_ATMOS_ALL, 0, cfg_atmos_led_max_read( &g_mg_dev ), 0); + } break; case LIGHT_MODE_TOF_ACTIVE: // dur_sec = cfg_led_atmos_off_duration_read( &g_mg_dev ); key_led_on( g_led_ctrl, LED_ID_KEY_ALL&key_mask, 0, 100, dur_sec*1000 ); atmos_led_off( g_led_ctrl, LED_ID_ATMOS_ALL, 100, 0, dur_sec*1000 ); - ring_led_breath( g_led_ctrl, 2000, 10*1000 ); + ring_led_breath( g_led_ctrl, 4000, 10*1000 ); break; case LIGHT_MODE_TOF_DEACTIVE: // diff --git a/app/src/iot_dp.c b/app/src/iot_dp.c index a5e65ad..b5e6517 100644 --- a/app/src/iot_dp.c +++ b/app/src/iot_dp.c @@ -167,7 +167,7 @@ int32_t dp_report_all( mg_dev_t *dev ) usleep(50*1000); //dp_property_report_bool( "mg_key_enable", base64_encode(cfg->mg_key_enable) ); //add base64 encode //usleep(50*1000); - dp_property_report_str( "bl_mode", cfg->bl_mode?"auto":"manual"); + dp_property_report_str( "bl_mode", cfg->bl_mode?"manual":"auto"); usleep(50*1000); dp_property_report_int( "led_atmos_off_duration", cfg->led_atmos_off_duration); diff --git a/button/inc/button.h b/button/inc/button.h index 8b870d3..7d4cbdb 100644 --- a/button/inc/button.h +++ b/button/inc/button.h @@ -9,6 +9,7 @@ #include #include +#define BUTTON_DEVICE_PATH "/dev/input/event2" typedef enum{ BUTTON_1 = (1<<0), @@ -34,22 +35,14 @@ typedef enum{ EVENT_COMB_PRESS_5S = (1<<8), }button_event_t; -struct mg_button; -typedef struct mg_button mg_button_t; +typedef void* btn_ctrl_t; typedef void ( * button_event_cb_t )( button_code_t code, button_event_t evt, void * value ); -mg_button_t * mg_button_open( char * button_device_path ); -void mg_button_close( mg_button_t * btn_ctrl ); -int32_t mg_button_event_register( mg_button_t *btn_ctrl, button_code_t code, button_event_t event, button_event_cb_t cb ); -int32_t mg_button_event_combonation_register( mg_button_t *btn_ctrl, button_code_t code, button_event_t event, uint32_t time_ms, button_event_cb_t cb ); - -button_event_cb_t find_single_cb( mg_button_t *btn_ctrl, uint32_t code, uint32_t event ); -button_event_cb_t find_comb_cb( mg_button_t *btn_ctrl, uint32_t code, uint32_t event ); -//-------------------------------------------- -//for test -void button_single_clicked_register( mg_button_t *btn, button_event_cb_t cb ); -//-------------------------------------------- +btn_ctrl_t mg_button_open( char * button_device_path ); +void mg_button_close( btn_ctrl_t btn_ctrl ); +int32_t mg_button_event_register( btn_ctrl_t btn_ctrl, button_code_t code, button_event_t event, button_event_cb_t cb ); +int32_t mg_button_event_combonation_register( btn_ctrl_t btn_ctrl, button_code_t code, button_event_t event, uint32_t time_ms, button_event_cb_t cb ); #endif //__BUTTON__H__ diff --git a/button/src/button.c b/button/src/button.c index f1e2af2..447ed52 100644 --- a/button/src/button.c +++ b/button/src/button.c @@ -15,6 +15,7 @@ #define SINGLE_BTN_CB_MAX 50 #define COMB_BTN_CB_MAX 50 + typedef struct{ uint32_t code; uint32_t event; @@ -29,26 +30,18 @@ typedef struct{ pthread_mutex_t lock; }btn_cb_list_t; -struct mg_button{ +typedef struct mg_button{ char dev_path[100]; int32_t fd; int32_t lock; pthread_t btn_thread; btn_cb_list_t cb_list; -}; - -mg_button_t *g_ptr_button; - -mg_button_t * mg_button_open( char * button_device_path ); -void mg_button_close( mg_button_t * btn_ctrl ); -extern void btn_scan( mg_button_t *btn_ctrl, uint32_t btn_pressed_code ); -static button_event_cb_t g_test_cb = NULL; +} mg_button_t; +static btn_ctrl_t g_btn_ctrl; -static char * button_device_def ="/dev/input/event2"; +extern void btn_scan( btn_ctrl_t btn_ctrl, uint32_t btn_pressed_code ); - -void button_single_clicked_register( mg_button_t *btn, button_event_cb_t cb ); static void* button_task( void* param ); uint32_t button_code( uint32_t key_code ) @@ -93,15 +86,15 @@ void* button_task( void* param ) retval = select(fd + 1, &rdfs, NULL, NULL, &timeout); if( retval == 0 ){ //timeout call btn_scan - btn_scan( p_button, pressed_code ); + btn_scan( (btn_ctrl_t)p_button, pressed_code ); continue; } rd = read(fd, ev, sizeof(ev)); if (rd < (int) sizeof(struct input_event)) { - printf("expected %d bytes, got %d\n", (int) sizeof(struct input_event), rd); - perror("\nevtest: error reading"); + MG_LOGE( "Button read event err!expected %d bytes, got %d\n", (int) sizeof(struct input_event), rd); + //TODO: return NULL; } @@ -111,33 +104,21 @@ void* button_task( void* param ) type = ev[i].type; code = ev[i].code; value = ev[i].value; - - //printf("++++Event: time %ld.%06ld, type:%d", ev[i].input_event_sec, ev[i].input_event_usec, type ); - ///printf("++++Event: ype:%d", type ); - + if( type==EV_KEY ){ if( value == 0 ){ pressed_code &= ~( 1<< (code - KEY_1 ) ); - printf( "btn up...code:%x\n", pressed_code ); + //printf( "btn up...code:%x\n", pressed_code ); }else if( value == 1 ){ - printf( "btn down...code:%x\n", pressed_code ); pressed_code |= ( 1<< (code - KEY_1 ) ); + //printf( "btn down...code:%x\n", pressed_code ); } - if(g_test_cb){ - if( ev[i].value==0){ - g_test_cb( button_code(code), EVENT_SINGLE_CLICK, 0 ); - }else if( ev[i].value==1){ - //g_test_cb( button_code(code), EVENT_SINGLE_CLICK, 0 ); - }else if( ev[i].value==2){ - //ignore key repeate event - } - } - - //printf( "EV_KEY : KEY_%d, value:%d\n", code - KEY_1 +1, ev[i].value ); - continue; - } + + //printf( "EV_KEY : KEY_%d, value:%d\n", code - KEY_1 +1, ev[i].value ); + continue; } - } + } //for + } //while ioctl(fd, EVIOCGRAB, (void*)0); error: @@ -145,15 +126,15 @@ error: } - -mg_button_t * mg_button_open( char * button_device_path ) +btn_ctrl_t mg_button_open( char * button_device_path ) { int32_t fd; pthread_t btn_thread; - mg_button_t *button = g_ptr_button; + mg_button_t *button; - if( button ){ + if( g_btn_ctrl ){ + //busy goto error; } @@ -161,55 +142,52 @@ mg_button_t * mg_button_open( char * button_device_path ) if( !button ){ goto error; } + memset( button, 0, sizeof( mg_button_t ) ); - if( !button_device_path) - button_device_path = button_device_def; - - strcpy( button->dev_path, button_device_path ); + if( button_device_path) + strcpy( button->dev_path, button_device_path ); + else + strcpy( button->dev_path, BUTTON_DEVICE_PATH ); if ((fd = open(button->dev_path, O_RDONLY)) < 0) { - perror("button open"); - fprintf(stderr, "open dev[%s] fail!\n", button->dev_path); + MG_LOGE( "open button device[%s] fail!", button->dev_path ); goto error; } if( pthread_create( &btn_thread, NULL, button_task, (void *)button ) != 0 ){ + MG_LOGE( "create button task fail!" ); perror("create button task!"); goto error; } button->fd = fd; button->btn_thread = btn_thread; - g_ptr_button = button; memset( &button->cb_list, 0, sizeof( button->cb_list ) ); pthread_mutex_init( &button->cb_list.lock, NULL ); - return button; + g_btn_ctrl = (btn_ctrl_t)button; + + return g_btn_ctrl; error: - return NULL; + return 0; } -void mg_button_close( mg_button_t * btn_ctrl ) +void mg_button_close( btn_ctrl_t btn_ctrl ) { - if( btn_ctrl ){ - if( g_ptr_button == btn_ctrl ){ - g_ptr_button = NULL; - }else{ - printf ( "err, button:%p, g_button:%p!\n", btn_ctrl, g_ptr_button ); - } - free( btn_ctrl ); + if( btn_ctrl && btn_ctrl == g_btn_ctrl ){ + g_btn_ctrl = 0; + free( (void *)btn_ctrl ); } - printf ( "tw8013 button close!\n" ); } -int32_t mg_button_event_register( mg_button_t *btn_ctrl, button_code_t code, button_event_t event, button_event_cb_t cb ) +int32_t mg_button_event_register( btn_ctrl_t btn_ctrl, button_code_t code, button_event_t event, button_event_cb_t cb ) { uint32_t found = 0; uint32_t i; - btn_cb_list_t *p_list = &btn_ctrl->cb_list; + btn_cb_list_t *p_list = &((mg_button_t*)btn_ctrl)->cb_list; - MG_LOGI( "regiser single btn, code:%x, event:%x" ); + MG_LOGI( "regiser single btn, code:%x, event:%x", code, event ); pthread_mutex_lock( &p_list->lock ); for( i=0; i < p_list->single_nr; i++ ){ @@ -233,14 +211,14 @@ int32_t mg_button_event_register( mg_button_t *btn_ctrl, button_code_t code, but return 0; } -int32_t mg_button_event_combonation_register( mg_button_t *btn_ctrl, button_code_t code, button_event_t event, uint32_t time_ms, button_event_cb_t cb ) +int32_t mg_button_event_combonation_register( btn_ctrl_t btn_ctrl, button_code_t code, button_event_t event, uint32_t time_ms, button_event_cb_t cb ) { - uint32_t found = 0; uint32_t i; + uint32_t found = 0; int32_t retval = 0; - btn_cb_list_t *p_list = &btn_ctrl->cb_list; + btn_cb_list_t *p_list = &((mg_button_t*)btn_ctrl)->cb_list; - MG_LOGI( "regiser comb btn, code:%x, event:%x" ); + MG_LOGI( "regiser comb btn, code:%x, event:%x", code, event ); pthread_mutex_lock( &p_list->lock ); for( i=0; i < p_list->comb_nr; i++ ){ @@ -264,13 +242,12 @@ int32_t mg_button_event_combonation_register( mg_button_t *btn_ctrl, button_code return retval; } -button_event_cb_t find_single_cb( mg_button_t *btn_ctrl, uint32_t code, uint32_t event ) +button_event_cb_t find_single_cb( btn_ctrl_t btn_ctrl, uint32_t code, uint32_t event ) { int32_t found = 0; uint32_t i; button_event_cb_t cb = NULL; - - btn_cb_list_t *p_list = &btn_ctrl->cb_list; + btn_cb_list_t *p_list = &((mg_button_t*)btn_ctrl)->cb_list; pthread_mutex_lock( &p_list->lock ); for( int i=0; i < p_list->single_nr; i++ ){ @@ -285,13 +262,13 @@ button_event_cb_t find_single_cb( mg_button_t *btn_ctrl, uint32_t code, uint32_t return cb; } -button_event_cb_t find_comb_cb( mg_button_t *btn_ctrl, uint32_t code, uint32_t event ) +button_event_cb_t find_comb_cb( btn_ctrl_t btn_ctrl, uint32_t code, uint32_t event ) { int32_t found = 0; uint32_t i; button_event_cb_t cb = NULL; - btn_cb_list_t *p_list = &btn_ctrl->cb_list; + btn_cb_list_t *p_list = &((mg_button_t*)btn_ctrl)->cb_list; pthread_mutex_lock( &p_list->lock ); for( int i=0; i < p_list->comb_nr; i++ ){ @@ -306,10 +283,5 @@ button_event_cb_t find_comb_cb( mg_button_t *btn_ctrl, uint32_t code, uint32_t e return cb; } -//临时测试用,单击按钮放开时调用 -void button_single_clicked_register( mg_button_t *btn, button_event_cb_t cb ) -{ - //g_test_cb = cb; - //printf( "button regist cb: %p\n", g_test_cb ); -} +//---------------------------------------------------------------------------------- diff --git a/button/src/button_scan.c b/button/src/button_scan.c index 4a8eac7..e74283e 100644 --- a/button/src/button_scan.c +++ b/button/src/button_scan.c @@ -9,8 +9,6 @@ #include "button.h" -//static uint32_t btn_pressed_code = 0x0; //bit0..bit7: 1:key pressed, 0:key released - typedef struct { uint32_t st; //0:up idle, 1: pressed, 2:up wait 250ms for next pressed. 3: double_pressed 8:wait all key released uint32_t code; //btn_code @@ -33,13 +31,14 @@ typedef struct{ uint32_t long_press_5s; }comb_btn_st_t; -extern button_event_cb_t find_single_cb( mg_button_t *btn_ctrl, uint32_t code, uint32_t event ); -extern button_event_cb_t find_comb_cb( mg_button_t *btn_ctrl, uint32_t code, uint32_t event ); + +extern button_event_cb_t find_single_cb( btn_ctrl_t btn_ctrl, uint32_t code, uint32_t event ); +extern button_event_cb_t find_comb_cb( btn_ctrl_t btn_ctrl, uint32_t code, uint32_t event ); static single_btn_st_t single_st; static comb_btn_st_t comb_st; -int32_t is_comb_code( mg_button_t *btn_ctrl, uint32_t code ) +int32_t is_comb_code( btn_ctrl_t btn_ctrl, uint32_t code ) { if( find_comb_cb( btn_ctrl, code, 0 ) ) return 1; @@ -54,7 +53,7 @@ static uint32_t get_systime_ms( void ) return (uint32_t)(tm.tv_sec*1000+tm.tv_usec/1000); } -void single_btn_report( mg_button_t *btn_ctrl, uint32_t code, button_event_t event ) +void single_btn_report( btn_ctrl_t btn_ctrl, uint32_t code, button_event_t event ) { button_event_cb_t cb; @@ -63,7 +62,7 @@ void single_btn_report( mg_button_t *btn_ctrl, uint32_t code, button_event_t eve cb( code, event, NULL ); } -void comb_btn_report( mg_button_t *btn_ctrl, uint32_t code, button_event_t event ) +void comb_btn_report( btn_ctrl_t btn_ctrl, uint32_t code, button_event_t event ) { button_event_cb_t cb; @@ -72,7 +71,7 @@ void comb_btn_report( mg_button_t *btn_ctrl, uint32_t code, button_event_t even cb( code, event, NULL ); } -void comb_btn_scan( mg_button_t *btn_ctrl, comb_btn_st_t *comb, uint32_t pressed_code ) +void comb_btn_scan( btn_ctrl_t btn_ctrl, comb_btn_st_t *comb, uint32_t pressed_code ) { uint32_t curr_time_ms = get_systime_ms(); switch( comb->st ){ @@ -110,23 +109,27 @@ void comb_btn_scan( mg_button_t *btn_ctrl, comb_btn_st_t *comb, uint32_t pressed case 2: if( pressed_code == 0 ){ comb->st = 0; - printf( "comb st -> idle\n" ); + //printf( "comb st -> idle\n" ); } break; } } -void single_btn_scan( mg_button_t *btn_ctrl, single_btn_st_t * btn, uint32_t pressed_code ) +void single_btn_scan( btn_ctrl_t btn_ctrl, single_btn_st_t * btn, uint32_t pressed_code ) { uint32_t curr_time_ms; uint32_t i; curr_time_ms = get_systime_ms(); -static uint32_t code =0; -if( code != pressed_code ){ - printf( "scan pressed code: %02x -> %02x\n", code, pressed_code ); - code = pressed_code; -} + +#if 1 + //for debug + static uint32_t code =0; + if( code != pressed_code ){ + printf( "scan pressed code: %02x -> %02x\n", code, pressed_code ); + code = pressed_code; + } +#endif switch( btn->st ){ case 0: //idle if( pressed_code&0xff ){ @@ -154,15 +157,15 @@ if( code != pressed_code ){ //check long pressed if( !btn->long_press_1s && curr_time_ms - btn->pressed_tick > 1000 ){ btn->long_press_1s = 1; - printf( "------------ long press event ...%x\n", btn->code ); + //printf( "------------ long press event ...%x\n", btn->code ); single_btn_report( btn_ctrl, btn->code, EVENT_LONG_PRESS ); }else if( !btn->long_press_2s && curr_time_ms - btn->pressed_tick > 2000 ){ btn->long_press_2s = 1; - printf( "------------ long press 2s event ...%x\n", btn->code ); + //printf( "------------ long press 2s event ...%x\n", btn->code ); single_btn_report( btn_ctrl, btn->code, EVENT_LONG_PRESS_2S ); }else if( !btn->long_press_5s && curr_time_ms - btn->pressed_tick > 5000 ){ btn->long_press_5s = 1; - printf( "------------ long press 5s event ...%x\n", btn->code ); + //printf( "------------ long press 5s event ...%x\n", btn->code ); single_btn_report( btn_ctrl, btn->code, EVENT_LONG_PRESS_5S ); } @@ -170,7 +173,7 @@ if( code != pressed_code ){ btn->up_tick = curr_time_ms; if( btn->long_press_1s ){ btn->long_press_up = 1; - printf( "------------ long press up event ...%x\n", btn->code ); + //printf( "------------ long press up event ...%x\n", btn->code ); btn->st = 8; //等待全部按键放开 single_btn_report( btn_ctrl, btn->code, EVENT_LONG_PRESS_UP ); }else{ @@ -185,7 +188,7 @@ if( code != pressed_code ){ }else{ if( curr_time_ms - btn->up_tick > 250 ){ btn->single_click = 1; - printf( "------------------sing click event ...%x\n", btn->code ); + //printf( "------------------sing click event ...%x\n", btn->code ); btn->st = 8; //wait all btn released single_btn_report( btn_ctrl, btn->code, EVENT_SINGLE_CLICK ); } @@ -197,7 +200,7 @@ if( code != pressed_code ){ }else{ btn->up_tick = curr_time_ms; btn->double_click = 1; - printf( "------------------double click event ...%x\n", btn->code ); + //printf( "------------------double click event ...%x\n", btn->code ); btn->st = 8; single_btn_report( btn_ctrl, btn->code, EVENT_DOUBLE_CLICK ); } @@ -206,7 +209,7 @@ if( code != pressed_code ){ if( !pressed_code ){ btn->code = 0; btn->st = 0; //idle - printf( "single btn st -> idle\n" ); + //printf( "single btn st -> idle\n" ); } break; } @@ -228,9 +231,9 @@ void btn_scan_init( void ) comb_btn_init(); } -void btn_scan( mg_button_t *btn_ctrl, uint32_t btn_pressed_code ) +void btn_scan( btn_ctrl_t btn_ctrl, uint32_t btn_pressed_code ) { - uint32_t pressed_code = btn_pressed_code; //get_btn_code(); + uint32_t pressed_code = btn_pressed_code; if( single_st.st != 0 && single_st.long_press_1s != 0 ){ //已经产生了长按事件,不检测组合按键 diff --git a/led/inc/led.h b/led/inc/led.h index 60efefd..c107959 100644 --- a/led/inc/led.h +++ b/led/inc/led.h @@ -24,12 +24,7 @@ #define LED_ID_ATMOS_5 (1<<4) #define LED_ID_ATMOS_ALL ( 0x1f ) -#ifdef __x86_64__ -typedef uint64_t light_ctrl_t; -#else - -typedef uint32_t light_ctrl_t; -#endif +typedef void* light_ctrl_t; typedef struct{ uint32_t on; //0:off, 1:on, 2:flash, 3:breath diff --git a/led/src/led.c b/led/src/led.c index 3c6aca2..6c9cf6f 100644 --- a/led/src/led.c +++ b/led/src/led.c @@ -403,7 +403,7 @@ static led_ctrl_t g_light; const struct led_path led_path_info[LED_NR] = { - { LED_KEY_1, "KEY_LED_1", "/sys/class/leds/key_led1" }, + { LED_KEY_1, "KEY_LED_1", "/sys/class/leds/key_led1_d" }, { LED_KEY_2, "KEY_LED_2", "/sys/class/leds/key_led2" }, { LED_KEY_3, "KEY_LED_3", "/sys/class/leds/key_led3" }, { LED_KEY_4, "KEY_LED_4", "/sys/class/leds/key_led4" }, @@ -415,10 +415,9 @@ const struct led_path led_path_info[LED_NR] = { { LED_ATMOS_2, "FUN_LED_2", "/sys/class/leds/fun_led2" }, { LED_ATMOS_3, "FUN_LED_3", "/sys/class/leds/fun_led3" }, { LED_ATMOS_4, "FUN_LED_4", "/sys/class/leds/fun_led4" }, - //{ LED_ATMOS_5, "FUN_LED_5", "/sys/class/leds/fun_led5" }, + { LED_ATMOS_5, "FUN_LED_5", "/sys/class/leds/fun_led5" }, //{ LED_RING, "RING_LED", "/sys/class/leds/ring_led" }, - { LED_ATMOS_5, "FUN_LED_5", "/sys/class/leds/ring_led" }, - { LED_RING, "RING_LED", "/sys/class/leds/fun_led5" }, + { LED_RING, "RING_LED", "/sys/class/leds/key_led1" }, { LED_IR, "IR_LED", "/sys/class/leds/ir_led" }, }; @@ -433,9 +432,23 @@ void hw_led_brignt( led_dev_t * dev, uint32_t br ) } } } +const uint8_t br_gamma[] = { + 0, + 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, + 6, 7 , 8, 10, 12, 14, 16, 18, 20, 22, + 24, 26 ,28, 30, 32, 34, 36, 38, 39, 40, + 41, 42 ,43, 44, 45, 46, 47, 48, 49, 60, + 51, 52 ,53, 54, 55, 56, 57, 58, 59, 60, + 61, 62 ,63, 64, 65, 66, 67, 68, 69, 70, + 71, 72 ,73, 74, 75, 76, 77, 78, 79, 80, + 81, 82 ,83, 84, 85, 86, 87, 88, 89, 90, + 91, 92 ,93, 94, 95, 96, 97, 98, 99, 100, +}; void* led_thread_fun( void *led ) { + uint32_t br; uint32_t curr_br = 0; led_dev_t *dev; uint32_t now_ms; @@ -476,11 +489,14 @@ void* led_thread_fun( void *led ) uint32_t ms = now_ms%dev->period_ms; if( ms*2 < dev->period_ms ){ //up - curr_br = 100 * ms * 2/dev->period_ms; + br = 100 * ms * 2/dev->period_ms; }else{ //down - curr_br = 100 * (dev->period_ms - ms) * 2/dev->period_ms; + br = 100 * (dev->period_ms - ms) * 2/dev->period_ms; } + if( br <1 ) br = 1; + if( br >100 ) br = 100; + curr_br = br_gamma[br]; //printf( "[%d] breath br:%d\n", now_ms%100000, curr_br ); }else if( dev->flash == 0 ){ @@ -491,17 +507,21 @@ void* led_thread_fun( void *led ) || ( dev->on && curr_br >= dev->br_to ) || ( !dev->on&& curr_br <= dev->br_to )){ dev->trans_ms = 0; - curr_br = dev->br_to; + br = dev->br_to; }else{ if( dev->on ){ //trans_ms 是 0-到100 的变化时间, //curr_br = dev->br_from + (now_ms - dev->trans_start_ms)*(dev->br_to - dev->br_from)/dev->trans_ms; - curr_br = dev->br_from + (now_ms - dev->trans_start_ms)*(100 - 0)/dev->trans_ms; + br = dev->br_from + (now_ms - dev->trans_start_ms)*(100 - 0)/dev->trans_ms; }else{ - curr_br = dev->br_from - (now_ms - dev->trans_start_ms)*(100 - 0)/dev->trans_ms; + br = dev->br_from - (now_ms - dev->trans_start_ms)*(100 - 0)/dev->trans_ms; } + //printf( "[%d] LED-%s br trans [ %d -> %d ], now br:%d\n", now_ms%100000, dev->name, dev->br_from, dev->br_to, curr_br ); } + if( br > 100 ) br = 100; + curr_br = br_gamma[ br ]; + }else if( dev->on){ //ON curr_br = dev->br_max; -- 2.34.1