From ccd1b683bf67b4030c69f178c6ce865c3649fe87 Mon Sep 17 00:00:00 2001 From: helloyifa Date: Thu, 10 Apr 2025 20:23:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=85=E7=94=B5=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20LED=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BC=A0=E6=84=9F=E5=99=A8=E6=A6=82=E7=8E=87?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E4=B8=8D=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/spp_and_le/app_temperature.c | 154 ++++++++++++++---- 1 file changed, 123 insertions(+), 31 deletions(-) diff --git a/fw-AC63_BT_SDK/apps/spp_and_le/app_temperature.c b/fw-AC63_BT_SDK/apps/spp_and_le/app_temperature.c index 1ea885a..0a6e9a9 100644 --- a/fw-AC63_BT_SDK/apps/spp_and_le/app_temperature.c +++ b/fw-AC63_BT_SDK/apps/spp_and_le/app_temperature.c @@ -20,18 +20,18 @@ #include "examples/trans_data/ble_trans_profile.h" //#include "ble_trans_profile.h" static int led_state = 0; - +static u16 temer_temperature_detect = 0; void temperature_blink_led() { if (led_state) { - gpio_direction_output(IO_PORTA_07, 0); + gpio_direction_output(BLE_TEMPERATURE_WORK_LED, 0); led_state = 0; } else { led_state = 1; - gpio_direction_output(IO_PORTA_07, 1); + gpio_direction_output(BLE_TEMPERATURE_WORK_LED, 1); } } @@ -210,10 +210,10 @@ static uint8_t reversal(uint8_t data) //--------------send start convert ----------------------------- gpio_direction_output(DQ_PIN, 0);//pin_write(DQ_PIN, PIN_LOW); // DQ low //printf("send start convert out 0\r\n"); - delay_ms(5); + delay_us_by_timer0(300); gpio_direction_output(DQ_PIN, 1);//pin_write(DQ_PIN, PIN_HIGH); //printf("send start convert out 1\r\n"); - udelay(20); + delay_us_by_timer0(20); //-----------------check DQ pin status should be high--------------------------------------- gpio_set_direction(DQ_PIN,1); @@ -236,9 +236,9 @@ static uint8_t reversal(uint8_t data) do { bit0 = pin_read(DQ_PIN); - delay_us(2); + delay_us_by_timer0(2); retry++; - if (retry > 20000) // time out 40ms + if (retry > 30000) // time out 40ms { *pcal = (uint16_t)(ERR_DONE * 128); printf("wait for done pulse fail \r\n"); @@ -246,7 +246,7 @@ static uint8_t reversal(uint8_t data) } } while (bit0); printf("wait for done pulse succ \r\n"); - delay_us(10); + delay_us_by_timer0(10); //--------------read 24bit data--------------- gpio_set_direction(DQ_PIN,0); gpio_direction_output(DQ_PIN, 1);//pin_write(DQ_PIN, PIN_HIGH); @@ -281,7 +281,8 @@ static uint8_t reversal(uint8_t data) gpio_direction_output(DQ_PIN, 1);//pin_write(DQ_PIN, PIN_HIGH); // DQ low //pin_mode(DQ_PIN, PIN_MODE_OUTPUT_OD); - delay_us(60); + //delay_us(60); + delay_us_by_timer0(60); } //------------------- NST1002 Big Endian,but mcu Little Endian swap[0] = data[1]; @@ -313,7 +314,7 @@ static uint8_t reversal(uint8_t data) { if (ei < 4) ei = -1 - err; - printf("NST1002 err %s\r\n", err_code[ei]); + printf("NST1002 err code :%d err %s\r\n", err,err_code[ei]); return; } @@ -332,6 +333,88 @@ void temperature_detect(void) } #endif +u16 charge_led_hander = 0; +void temperature_charge_led(u8 on){ + if(charge_led_hander){ + sys_timer_del(charge_led_hander); + } + if(on){ + charge_led_hander = sys_timer_add(NULL, temperature_blink_led, 500); + }else{ + sys_timer_del(charge_led_hander); + } +} + +void temperature_work_led(u8 on){ + if(on){ + gpio_direction_output(BLE_TEMPERATURE_WORK_LED, 1); + }else{ + gpio_direction_output(BLE_TEMPERATURE_WORK_LED, 0); + } +} + +void temperature_poweron_led_timeout(){ + temperature_work_led(0); +} + +void temperature_set_soft_poweroff(void) +{ + printf("temperature_set_soft_poweroff\n"); + //VCM_DET_EN(0);//关闭VCM复位 + //gpio_shortpress_reset_config(0);//1--enable 0--disable + + //P33_CON_SET(P3_PINR_CON, 0, 1, 0);//关闭长按复位 + //P33_CON_SET(P3_PINR_CON, 0, 1, 1);//打开长按复位 + gpio_longpress_pin0_reset_config(IO_PORTA_09, 0, 0); + + //必须先主动断开蓝牙链路,否则要等链路超时断开 +#if TCFG_USER_BLE_ENABLE + btstack_ble_exit(0); + //延时300ms,确保BT退出链路断开 + sys_timeout_add(NULL, power_set_soft_poweroff, 300); +#else + power_set_soft_poweroff(); +#endif +} + +void temperature_charge_state(int state){ + switch (state) + { + //接入充电 + case BLE_TEMPERATURE_CHARGE_STATE_CHARGING : + printf("BLE_TEMPERATURE_CHARGE_STATE_CHARGING\n"); + sys_timer_del(temer_temperature_detect); + //体温计指标灯闪烁3次后转灭 + for(int i = 0; i< 3 ; i++){ + temperature_work_led(1); + delay_ms_by_timer0(150); + temperature_work_led(0); + delay_ms_by_timer0(150); + } + //spple_power_event_to_user(POWER_EVENT_POWER_SOFTOFF); + //printf("!!!!!!!!!!!!!! CHARGING POWER OFF!!!!!!!!!!!!!!!!\n"); + //printf("BLE_TEMPERATURE_CHARGE_STATE_CHARGING 2\n"); + + break; + //充电完成 + case BLE_TEMPERATURE_CHARGE_STATE_FULL : + //printf("BLE_TEMPERATURE_CHARGE_STATE_FULL\n"); + //spple_power_event_to_user(POWER_EVENT_POWER_SOFTOFF); + //printf("!!!!!!!!!!!!!! POWER OFF!!!!!!!!!!!!!!!!\n"); + temperature_set_soft_poweroff(); + break; + //拔出充电 + case BLE_TEMPERATURE_CHARGE_STATE_IDLE : + printf("BLE_TEMPERATURE_CHARGE_STATE_IDLE\n"); + temer_temperature_detect = sys_timer_add(NULL, temperature_detect, 300); + temperature_charge_led(0); + temperature_work_led(1); + sys_s_hi_timerout_add(NULL,temperature_poweron_led_timeout,2000); + break; + default: + break; + } +} void temperature_ble_init(){ printf(">>>>>>>>>>>>>>>>> temperature_ble_init ...\n"); @@ -350,41 +433,50 @@ void temperature_ble_init(){ } + + + void temperature_init(void) { printf(">>>>>>>>>>>>>>>>> temperature_init ...\n"); - - udelay(20); + delay_us(60); printf(">>>>>>>>>>>>>>>>> temperature_init2 ...\n"); - udelay(1000*200); - printf("mdelay 200ms s...\n"); - delay_ms(200); - printf("mdelay 200ms e...\n"); - + extern u16 get_vbat_trim(); extern u16 get_vbg_trim(); printf("vbat_trim:%d...vbg_trim:%d", get_vbat_trim(), get_vbg_trim()); // 添加以上代码,看打印值,如果为15跟63,那就要用烧录器先烧录一遍。 - - sys_s_hi_timer_add(NULL, temperature_blink_led, 200); - //sys_s_hi_timer_add(NULL, temperature_detect, 2000); + //从收纳仓取出时自动开机(指示灯亮2S后灭) + temperature_work_led(1); + sys_s_hi_timerout_add(NULL,temperature_poweron_led_timeout,2000); - sys_timer_add(NULL, temperature_detect, 200); + //sys_s_hi_timer_add(NULL, temperature_blink_led, 200); + //sys_s_hi_timer_add(NULL, temperature_detect, 2000); + //sys_timer_add 方式添加定时任务 任务里边可以使用udelay delay_ms 等延时 sys_s_hi_timer_add 则延时无效 + temer_temperature_detect = sys_timer_add(NULL, temperature_detect, 300); // NTC VDD - gpio_set_direction(IO_PORTB_05,0); - gpio_direction_output(IO_PORTB_05, 1); + //gpio_set_direction(IO_PORTB_05,0); + //gpio_direction_output(IO_PORTB_05, 1); + /* - delay_ms(100); - gpio_set_direction(IO_PORTB_04,1); - gpio_set_die(IO_PORTB_04,1); - delay_ms(100); - printf("check DQ pin status cur dq:%d:\r\n" ,pin_read(IO_PORTB_04)); - gpio_set_pull_up(IO_PORTB_04, 1); - delay_ms(100); - printf("check DQ pin status cur dq:%d:\r\n" ,pin_read(IO_PORTB_04)); + //test delay + gpio_set_direction(DQ_PIN,0); + gpio_direction_output(DQ_PIN, 1); + delay_us_by_timer0(20); + gpio_direction_output(DQ_PIN, 0); + delay_us_by_timer0(20); + gpio_direction_output(DQ_PIN, 1); + delay_us_by_timer0(20); + gpio_direction_output(DQ_PIN, 0); + delay_ms(200); + gpio_direction_output(DQ_PIN, 1); + delay_ms(200); + gpio_direction_output(DQ_PIN, 0); + delay_ms(200); + gpio_direction_output(DQ_PIN, 1); */ }