1 Star 0 Fork 8

Anderson/vtor_elec_module

forked from vtor3478/vtor_elec_module 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vtor_led.c 2.59 KB
一键复制 编辑 原始数据 按行查看 历史
#include "vtor_led.h"
//#include "vtor_string.h"
#ifdef __VTOR_LED__
void VtorLed_SetMode(VtorLed* led, int8_t mode)
{
led->mode = mode;
// 预设几种模式
int16_t defaultVtorLedParamArray[][3] =
{
0,0,0,
100,100,100,
3000,1500,3000,
200,100,200,
200,100,400,
200,100,600,
500,400,500,
500,400,1000,
500,400,1500,
200,100,3000,
500,200,3000,
1000,900,3000,
24,0,3000,
24,0,1000,
24,0,300,
};
// 配置参数
VtorLed_SetParams(led,
defaultVtorLedParamArray[mode][0],
defaultVtorLedParamArray[mode][1],
defaultVtorLedParamArray[mode][2]);
}
void VtorLed_SetParams(VtorLed* led, int16_t arr, int16_t ccr, int16_t cycleTime)
{
// int8_t str[128];
// VtorString_Clear(str);
// VtorString_AppendString(str, "VtorLed_SetParams(");
// VtorString_AppendInt(str, arr);
// VtorString_AppendString(str, ", ");
// VtorString_AppendInt(str, ccr);
// VtorString_AppendString(str, ", ");
// VtorString_AppendInt(str, cycleTime);
// VtorString_AppendString(str, ")\r\n");
// VtorString_Print(str);
led->pwmCnt = 0;
led->holdCnt = 0;
led->pwmArr = arr;
led->pwmCcr = ccr;
if(led->mode < 12)
{
// 闪烁灯情况下,根据cycleTime计算3000ms内有多少个arr
led->holdCcr = cycleTime;
}
else
{
// 呼吸灯情况下,cycleTime代表总呼吸时长,
// 根据cycleTime计算每一级亮度持续时间
led->holdCcr = cycleTime / ((led->pwmArr - VTOR_LED_CONFIG_BREATH_MAX_BRIGHTNESS_DIFF) * 2 + 1) - 1;
}
}
void VtorLed_Run(VtorLed* led, int8_t tickInc)
{
// 呼吸灯模式
// 更新模拟定时器cnt
led->pwmCnt += tickInc;
led->pwmCnt %= led->pwmArr;
if(led->mode < 12)
{
// 单闪,双闪等模式
// holdCcr 决定单周期内总有效控制时长
// 非常建议holdCcr刚好 小于等于 整数倍pwmArr
led->holdCnt += tickInc;
if(led->holdCnt < led->holdCcr)
{
led->curState = led->pwmCnt < led->pwmCcr;
}
if(led->holdCnt >= VTOR_LED_CONFIG_BLINK_TOTAL_TIME)
{
led->holdCnt = 0;
led->pwmCnt = 0;
}
}
else
{
// 每级亮度维持时间
led->holdCnt += tickInc;
if(led->holdCnt >= led->holdCcr) // ccr当arr用,达到时就清零
{
led->holdCnt = 0;
// 更新pwm期望占空比
led->pwmCcr += led->pwmCcrInc;
if(led->pwmCcr >= led->pwmArr - VTOR_LED_CONFIG_BREATH_MAX_BRIGHTNESS_DIFF)
{
led->pwmCcrInc = -1;
}
else if(led->pwmCcr <= 0)
{
led->pwmCcrInc = 1;
}
}
led->curState = led->pwmCnt < led->pwmCcr;
}
// 亮灯 灭灯
if(led->lastState != led->curState)
{
led->lastState = led->curState;
if(led->setState)
{
led->setState(led->curState);
}
}
}
#endif // __VTOR_LED__
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Thomas_Ti/vtor_elec_module.git
git@gitee.com:Thomas_Ti/vtor_elec_module.git
Thomas_Ti
vtor_elec_module
vtor_elec_module
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385