修复RGB在按键提示的时候导致的RGB指示问题,以及将功能性函数分离开来
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,7 +244,7 @@ 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);
|
||||
@@ -253,35 +254,7 @@ void pc_link_rgb_color(device_t* device)
|
||||
}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;
|
||||
}
|
||||
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)
|
||||
|
||||
41
app/drivers/sertrf/tool.c
Normal file
41
app/drivers/sertrf/tool.c
Normal file
@@ -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);
|
||||
}
|
||||
24
app/drivers/sertrf/tool.h
Normal file
24
app/drivers/sertrf/tool.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#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);
|
||||
Reference in New Issue
Block a user