diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 515896e..8df438b 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -32,6 +32,7 @@ list(APPEND srcs "drivers/sertrf/sertrf.c") list(APPEND srcs "drivers/sertrf/device.c") list(APPEND srcs "drivers/sertrf/key.c") list(APPEND srcs "drivers/sertrf/ota_u.c") +list(APPEND srcs "drivers/sertrf/tool.c") list(APPEND srcs "drivers/sertrf/ring_buffer.c") list(APPEND srcs "drivers/sertrf/protocol/MSP.c") list(APPEND srcs "drivers/sertrf/protocol/p_protocol.c") diff --git a/app/drivers/led_strip/led_strip.c b/app/drivers/led_strip/led_strip.c index 50d254c..403af47 100644 --- a/app/drivers/led_strip/led_strip.c +++ b/app/drivers/led_strip/led_strip.c @@ -6,14 +6,18 @@ rmt_transmit_config_t tx_config = { .loop_count = 0, // no transfer loop }; +// 颜色结构体 static rgb_color_t expression[EXAMPLE_LED_NUMBERS]; static rgb_color_t expression_lat[EXAMPLE_LED_NUMBERS] = {0}; +// 延时计数 static uint16_t rgb_toggle_cnt[EXAMPLE_LED_NUMBERS] = {10,10}; -static uint16_t rgb_toggle_cnt_lat[EXAMPLE_LED_NUMBERS] = {0}; +static uint16_t rgb_toggle_cnt_lat[EXAMPLE_LED_NUMBERS] = {2000,2000}; static uint8_t led_strip_pixels[EXAMPLE_LED_NUMBERS * 3]; uint16_t toggle_cycle = 1000; +// 翻转标志位 bool toggle_flag[EXAMPLE_LED_NUMBERS] = {true,true}; +bool toggle_flag_lat[EXAMPLE_LED_NUMBERS] = {true,true}; rgb_color_t rgb_color_rad = {0,255,0,0,0,1,0,RGB_COLOR_RAD}; rgb_color_t rgb_color_orange = {0,255,80,0,0,1,0,RGB_COLOR_ORANGE}; @@ -220,19 +224,26 @@ void rgb_Indicator_light_on(uint8_t index, uint8_t color, uint16_t cyle) memcpy(&expression_lat[index], &expression[index], sizeof(rgb_color_t)); rgb_color_change(index, color); } - if(rgb_toggle_cnt_lat[index] == 0 && rgb_toggle_cnt[index] != cyle) + // 设置较大的时间计数,防止数值被轻易到达 + if(rgb_toggle_cnt_lat[index] == 2000 ) { rgb_toggle_cnt_lat[index] = rgb_toggle_cnt[index]; + printf("rgb_toggle_cnt[index]:%d\n",rgb_toggle_cnt[index]); rgb_update_cyle(index, cyle); } - + if(toggle_flag[index] == false) + { + toggle_flag_lat[index] = !toggle_flag_lat[index]; + toggle_flag[index] = !toggle_flag[index]; + } } void rgb_Indicator_light_off(uint8_t index) { - rgb_color_change(index, expression_lat[index].color_type); rgb_update_cyle(index,(rgb_toggle_cnt_lat[index] + 1) * WORD_TIME_MS ); + + toggle_flag[index] = toggle_flag_lat[index]; memset(&expression_lat[index], 0, sizeof(rgb_color_t)); - rgb_toggle_cnt_lat[index] = 0; + rgb_toggle_cnt_lat[index] = 2000; } diff --git a/app/drivers/sertrf/sertrf.c b/app/drivers/sertrf/sertrf.c index ec315ee..681e667 100644 --- a/app/drivers/sertrf/sertrf.c +++ b/app/drivers/sertrf/sertrf.c @@ -174,7 +174,8 @@ void task_thread(void* arg) switch(get_protocol_status()) { case PROTOCOL_STATUS_OK: - rgb_color_change(1, sertrf.device.last_color); + // rgb_color_change(1, sertrf.device.last_color); + rgb_color_change(1, RGB_COLOR_ORANGE); break; case PROTOCOL_STATUS_NO_DATA: rgb_color_change(1, RGB_COLOR_RAD); @@ -243,45 +244,17 @@ void pc_link_rgb_color(device_t* device) last_connect = device->connect_pc; last_wifi_mode = device->init_device.wifi_mode; - } - if(device->connect_pc == DISCONNECT) - { - rgb_update_cyle(0,50); - } - else if(device->connect_pc){ - rgb_update_cyle(0,888); - }else{ - rgb_update_cyle(0,500); - } -} -void printf_chill_time(uint8_t chill_time, uint16_t type) -{ - static size_t last_time[24] = {0}; - static uint16_t cnt[24] = {0}; - static uint32_t type_cnt_time[24] = {0}; - size_t now_time = os_get_sys_time(); - cnt[chill_time]++; - type_cnt_time[chill_time] += now_time - last_time[chill_time]; - if(cnt[chill_time] % type == 0 && type_cnt_time[chill_time] / type >= now_time - last_time[chill_time] - 1) - { - SYS_LOG_INF("TIME_CHILL%d : %d : %d",chill_time, now_time - last_time[chill_time], type_cnt_time[chill_time]); - cnt[chill_time] = 0; - type_cnt_time[chill_time] = 0; + if(device->connect_pc == DISCONNECT) + { + rgb_update_cyle(0,50); + } + else if(device->connect_pc){ + rgb_update_cyle(0,888); + }else{ + rgb_update_cyle(0,500); + } } - else if(cnt[chill_time] % type == 0) - { - SYS_LOG_WRN("TIME_CHILL%d : %d : %d",chill_time, now_time - last_time[chill_time], type_cnt_time[chill_time]); - cnt[chill_time] = 0; - type_cnt_time[chill_time] = 0; - } - last_time[chill_time] = now_time; -} - -uint32_t parse_hex_or_dec(const char *s) { - if (!s) return 0; - if (s[0] == '0' && (s[1]=='x' || s[1]=='X')) return (uint32_t)strtoul(s+2, NULL, 16); - return (uint32_t)strtoul(s, NULL, 0); } int resend_send(void* data, uint16_t len, int timeout) diff --git a/app/drivers/sertrf/tool.c b/app/drivers/sertrf/tool.c new file mode 100644 index 0000000..113c0c7 --- /dev/null +++ b/app/drivers/sertrf/tool.c @@ -0,0 +1,41 @@ +#include "tool.h" + +int time_out(uint32_t* time_start, uint32_t timeout_ms) +{ + uint32_t time_new = os_get_sys_time(); + if(time_new - *time_start > timeout_ms) + { + *time_start = time_new; + return 1; + } + return 0; +} + +void printf_chill_time(uint8_t chill_time, uint16_t type) +{ + static size_t last_time[24] = {0}; + static uint16_t cnt[24] = {0}; + static uint32_t type_cnt_time[24] = {0}; + size_t now_time = os_get_sys_time(); + cnt[chill_time]++; + type_cnt_time[chill_time] += now_time - last_time[chill_time]; + if(cnt[chill_time] % type == 0 && type_cnt_time[chill_time] / type >= now_time - last_time[chill_time] - 1) + { + SYS_LOG_INF("TIME_CHILL%d : %d : %d\n",chill_time, now_time - last_time[chill_time], type_cnt_time[chill_time]); + cnt[chill_time] = 0; + type_cnt_time[chill_time] = 0; + } + else if(cnt[chill_time] % type == 0) + { + SYS_LOG_WRN("TIME_CHILL%d : %d : %d",chill_time, now_time - last_time[chill_time], type_cnt_time[chill_time]); + cnt[chill_time] = 0; + type_cnt_time[chill_time] = 0; + } + last_time[chill_time] = now_time; +} + +uint32_t parse_hex_or_dec(const char *s) { + if (!s) return 0; + if (s[0] == '0' && (s[1]=='x' || s[1]=='X')) return (uint32_t)strtoul(s+2, NULL, 16); + return (uint32_t)strtoul(s, NULL, 0); +} \ No newline at end of file diff --git a/app/drivers/sertrf/tool.h b/app/drivers/sertrf/tool.h new file mode 100644 index 0000000..bf0a1b8 --- /dev/null +++ b/app/drivers/sertrf/tool.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include "os/os.h" +#include "sys_log.h" + +/** + * @brief 超时判断 + * + */ +int time_out(uint32_t* time_start, uint32_t timeout_ms); +/** + * @brief 打印时间间隔 +*/ +void printf_chill_time(uint8_t chill_time, uint16_t type); +/** + * @brief 字符串转十进制 + */ +uint32_t parse_hex_or_dec(const char *s); \ No newline at end of file