From b0cec8579e3f27f13931a7bd01939b329da63b73 Mon Sep 17 00:00:00 2001 From: kyz Date: Mon, 7 Aug 2023 12:15:26 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E5=91=BC=E5=90=B8=E7=81=AF?= =?utf8?q?=E6=97=B6=E9=97=B4=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0?= 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" | 14 ++++++-- ...57\344\273\266\350\257\264\346\230\216.md" | 34 +++++++++++-------- app/inc/mg_version.h | 2 +- app/src/device_config.c | 6 ++-- led/src/led.c | 15 ++++++-- 5 files changed, 49 insertions(+), 22 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 5195251..7028127 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" @@ -83,6 +83,14 @@ 返回值: 0: 成功 -1:失败 +#### 读取按键状态 + uint32_t mg_button_pressed_code( btn_ctrl_t btn_ctrl ); //读取button按下状态, + 参数定义: + btn_ctrl: 按键控制器描述符 + 返回值: + 返回值bit0到bit7,其每个bit为1对应一个按键按下,例如 + 0x00: 当前8个键全部释放 + 0xff: 当前8个键全部按下 --- ## 2 LED显示管理 ### 2.1 数据类型定义 @@ -263,10 +271,12 @@ 0: 成功 -1:失败 ##### 呼吸 - 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 ); 参数定义: ctrl: LED控制器描述符 - period_ms: 呼吸周期,单位毫秒 + increase_ms: 呼吸灯渐亮时间,单位毫秒 + increase_ms: 呼吸灯渐暗时间,单位毫秒 + apnea_ms: 呼吸灯关闭时间,单位毫秒 duration_ms:持续时间,单位毫秒, 为0则一直保持呼吸不退出。 返回值: 0: 成功 diff --git "a/TW8013\350\275\257\344\273\266\350\257\264\346\230\216.md" "b/TW8013\350\275\257\344\273\266\350\257\264\346\230\216.md" index 79de6cc..244d9b2 100755 --- "a/TW8013\350\275\257\344\273\266\350\257\264\346\230\216.md" +++ "b/TW8013\350\275\257\344\273\266\350\257\264\346\230\216.md" @@ -142,22 +142,28 @@ /appconfigs/light.cfg 文件内容: { - "brightness" : [ - 0, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 32, 34, 36, 38, 40, 42, 34, 36, 38, 50, - 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, - 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, - 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, - 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, - 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, - 160, 170, 180, 190, 200, 210, 220, 230, 240, 255 - ] + "brightness" : [ + 0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 32, 34, 36, 38, 40, 42, 34, 36, 38, 50, + 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, + 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, + 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, + 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, + 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, + 160, 170, 180, 190, 200, 210, 220, 230, 240, 255 + ], + "breath" : { + "increase":600, + "decrease":600, + "apnea":300 + } } - 对应0--100各级亮度的值, 亮度取值范围是0-255,0:关闭, 255:最大亮度 + brightness 对应0--100各级亮度的值, 亮度取值范围是0-255,0:关闭, 255:最大亮度 应用启动时加载,如果文件不存在,则使用默认值 + breath 呼吸灯时间参数,分别为渐亮,渐暗,关闭的时间,单位毫秒. ### 1.13 守护进程 mgd 文件路径 diff --git a/app/inc/mg_version.h b/app/inc/mg_version.h index 5d1f0a3..bf6add7 100644 --- a/app/inc/mg_version.h +++ b/app/inc/mg_version.h @@ -1,7 +1,7 @@ #ifndef __MG_VERSION_H__ #define __MG_VERSION_H__ -#define SW_VERSION "0.0.9" +#define SW_VERSION "0.0.10" #endif //__MG_VERION_H__ diff --git a/app/src/device_config.c b/app/src/device_config.c index abc8bdd..03bbdcc 100644 --- a/app/src/device_config.c +++ b/app/src/device_config.c @@ -859,9 +859,9 @@ const light_cfg_t light_cfg_default = { 160, 170, 180, 190, 200, 210, 220, 230, 240, 255, }, .breath={ - .increase_ms = 1500, - .decrease_ms = 1500, - .apnea_ms = 0, + .increase_ms = 600, + .decrease_ms = 600, + .apnea_ms = 300, }, }; diff --git a/led/src/led.c b/led/src/led.c index c507a33..78ee97e 100644 --- a/led/src/led.c +++ b/led/src/led.c @@ -517,16 +517,27 @@ void* led_thread_fun( void *led ) //breath; //呼吸周期计算 uint32_t ms = now_ms%(dev->increase_ms + dev->decrease_ms + dev->apnea_ms); + //static int8_t dir = 0; if( ms < dev->increase_ms ){ //up - br = 100 * ms /dev->increase_ms; + br = ( 5 + 10 *100 * ms /dev->increase_ms)/10; + if( br < curr_br ) + br = curr_br; + //if( dir <= 0 ) printf( "[%s]breath inc: dir %d -> 1 , time_ms:%d/%d\n", dev->name, dir, ms, now_ms ); + //dir = 1; }else if( ms < dev->increase_ms + dev->decrease_ms ){ //down - br = 100 * (dev->increase_ms + dev->decrease_ms -ms )/dev->decrease_ms; + br = ( 5 + 10 *100 * (dev->increase_ms + dev->decrease_ms -ms )/dev->decrease_ms)/10; + if( br > curr_br ) + br = curr_br; + //if( dir >= 0 ) printf( "[%s]breath dec: dir %d -> -1 , time_ms:%d/%d\n", dev->name, dir, ms, now_ms ); + //dir = -1; }else{ //apnea , led off br = 0; + //if( dir != 0 ) printf( "[%s]breath apnea: %d -> 0, time_ms:%d/%d\n", dev->name, dir, ms, now_ms ); + //dir = 0; } //if( br <1 ) br = 1; if( br >100 ) br = 100; -- 2.34.1