6 Star 29 Fork 15

cot软件包 / cotLed

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cot_led.c 21.56 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
/**
**********************************************************************************************************************
* @file cot_led.c
* @brief 该文件提供LED灯控制功能
* @author const_zpc any question please send mail to const_zpc@163.com
* @version V1.0.0
* @date 2023-11-05
*
**********************************************************************************************************************
* 源码路径:https://gitee.com/cot_package/cot_led.git 具体问题及建议可在该网址填写 Issue
*
*
**********************************************************************************************************************
*/
/* Includes ----------------------------------------------------------------------------------------------------------*/
#include "cot_led.h"
#include <string.h>
#include <stdarg.h>
// 呼吸灯软件模拟PWM频率(HZ)
#define BREATHE_PWM_RATE 50
/* Private typedef ---------------------------------------------------------------------------------------------------*/
/* Private define ----------------------------------------------------------------------------------------------------*/
#define BREATHE_PWM_PERIOD (1000 / BREATHE_PWM_RATE)
/* Private macro -----------------------------------------------------------------------------------------------------*/
#define TIME_MAX_VAL (uint32_t)0xffff
#define TIME_ADD(tic, time) (TIME_MAX_VAL - (tic) < (time) ? ((tic) = 0xffff) : (tic += time))
#define LED_ABS(a) ((a) > 0 ? (a) : -(a))
#define FILL_STATE_BITS(state, sbit, ebit) {int bit; for (bit = (sbit); bit < (ebit); bit++) (state)[bit / 8] |= (0x01 << (bit % 8));}
#define SET_STATE_BITS(state, bit) {(state)[bit / 8] |= (0x01 << (bit % 8));}
/* Private variables -------------------------------------------------------------------------------------------------*/
static cotLedCfg_t *sg_pLedTable = NULL;
static size_t sg_ledNum = 0;
/* Private function prototypes ---------------------------------------------------------------------------------------*/
/* Private function --------------------------------------------------------------------------------------------------*/
/**
* @brief 按键初始化
*
* @param[in] pCfgTable 指示灯数组表指针
* @param[in] num 指示灯数组元素数目
* @return 0,成功; -1,失败
*/
int cotLed_Init(cotLedCfg_t pCfgTable[], size_t num)
{
uint8_t led;
sg_pLedTable = pCfgTable;
sg_ledNum = num;
for (led = 0; led < num; led++)
{
memset(&sg_pLedTable[led].proc, 0, sizeof(cotLedProc_t));
}
return 0;
}
/**
* @brief 设置LED的亮灭状态
*
* @param[in] led 指定指示灯
* @param[in] state 亮灭状态
* @return 0,成功; -1,失败
*/
int cotLed_SetState(led_t led, cotLedState_e state)
{
if (sg_pLedTable == NULL || sg_ledNum == 0 || led >= sg_ledNum)
{
return -1;
}
sg_pLedTable[led].proc.interval = 100;
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.data.state[0] = (state == COT_LED_ON ? 0x01 : 0x00);
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = 1;
sg_pLedTable[led].proc.count = 0;
sg_pLedTable[led].proc.isSetCount = 0;
sg_pLedTable[led].proc.defState = 0;
sg_pLedTable[led].proc.isPwm = 0;
return 0;
}
/**
* @brief 设置LED的亮灭状态及持续时间
*
* @attention 时间应为控制任务调度周期的倍数
* @param[in] led 指定指示灯
* @param[in] state 亮灭状态
* @param[in] time 持续时间, 单位毫秒
* @return 0,成功; -1,失败
*/
int cotLed_SetStateWithTime(led_t led, cotLedState_e state, uint16_t time)
{
if (sg_pLedTable == NULL || sg_ledNum == 0 || led >= sg_ledNum)
{
return -1;
}
sg_pLedTable[led].proc.interval = time;
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.data.state[0] = (state == COT_LED_ON ? 0x01 : 0x00);
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = 1;
sg_pLedTable[led].proc.count = 1;
sg_pLedTable[led].proc.isSetCount = 1;
sg_pLedTable[led].proc.defState = (state == COT_LED_ON ? 0 : 1);
sg_pLedTable[led].proc.isPwm = 0;
return 0;
}
/**
* @brief 点亮LED
*
* @param[in] led 指定指示灯
* @return 0,成功; -1,失败
*/
int cotLed_ON(led_t led)
{
return cotLed_SetState(led, COT_LED_ON);
}
/**
* @brief 熄灭LED
*
* @param[in] led 指定指示灯
* @return 0,成功; -1,失败
*/
int cotLed_OFF(led_t led)
{
return cotLed_SetState(led, COT_LED_OFF);
}
/**
* @brief 翻转指定LED亮灭状态
*
* @param led 指定指示灯
* @return 0,成功; -1,失败
*/
int cotLed_Toggle(led_t led)
{
if (sg_pLedTable == NULL || sg_ledNum == 0 || led >= sg_ledNum)
{
return -1;
}
sg_pLedTable[led].proc.interval = 100;
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.data.state[0] = sg_pLedTable[led].proc.data.state[0] == 0 ? 0x01 : 0x00;
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = 1;
sg_pLedTable[led].proc.count = 0;
sg_pLedTable[led].proc.isSetCount = 0;
sg_pLedTable[led].proc.defState = 0;
sg_pLedTable[led].proc.isPwm = 0;
return 0;
}
/**
* @brief 设置LED为闪烁状态
*
* @attention 时间应为控制任务调度周期的倍数
* @param[in] led 指定指示灯
* @param[in] time 闪烁亮灭间隔时间, 单位毫秒
* @return 0,成功; -1,失败
*/
int cotLed_Twinkle(led_t led, uint16_t time)
{
if (sg_pLedTable == NULL || sg_ledNum == 0 || led >= sg_ledNum)
{
return -1;
}
sg_pLedTable[led].proc.interval = time;
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.data.state[0] = 0x01;
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = 2;
sg_pLedTable[led].proc.count = 0;
sg_pLedTable[led].proc.isSetCount = 0;
sg_pLedTable[led].proc.defState = 0;
sg_pLedTable[led].proc.isPwm = 0;
return 0;
}
/**
* @brief 设置LED为闪烁状态及次数, 最后次数完成后的亮灭状态
*
* @note 一亮一灭为一次闪烁
* @attention 时间应为控制任务调度周期的倍数
* @param[in] led 指定指示灯
* @param[in] time 闪烁亮灭间隔时间, 单位毫秒
* @param[in] count 闪烁次数
* @param[in] defState 闪烁次数完成后的亮灭状态
* @return 0,成功; -1,失败
*/
int cotLed_TwinkleWithCount(led_t led, uint16_t time, uint8_t count, cotLedState_e defState)
{
if (sg_pLedTable == NULL || sg_ledNum == 0 || led >= sg_ledNum)
{
return -1;
}
sg_pLedTable[led].proc.interval = time;
sg_pLedTable[led].proc.tic = 0;
// 根据默认状态最后一次闪烁时状态设置相反状态达到较好的闪烁效果
sg_pLedTable[led].proc.data.state[0] = defState == COT_LED_ON ? 0x01 : 0x02;
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = 2;
sg_pLedTable[led].proc.count = count;
sg_pLedTable[led].proc.isSetCount = 1;
sg_pLedTable[led].proc.defState = defState == COT_LED_ON ? 1 : 0;
sg_pLedTable[led].proc.isPwm = 0;
return 0;
}
/**
* @brief 为多个LED设置为跑马灯
*
* @note
* @param[in] led LED组
* @param[in] ledNum LED数目
* @param[in] time LED亮时间
* @return 0,成功; -1,失败
*/
int cotLed_Marquee(led_t led[], uint8_t ledNum, int32_t time)
{
if (sg_pLedTable == NULL || sg_ledNum == 0)
{
return -1;
}
for (uint8_t i = 0; i < ledNum; i++)
{
if (led[i] < sg_ledNum)
{
memset(sg_pLedTable[led[i]].proc.data.state, 0, LED_STATE_BYTE_NUM);
sg_pLedTable[led[i]].proc.interval = time;
sg_pLedTable[led[i]].proc.tic = 0;
SET_STATE_BITS(sg_pLedTable[led[i]].proc.data.state, i);
sg_pLedTable[led[i]].proc.offset = 0;
sg_pLedTable[led[i]].proc.validBits = ledNum;
sg_pLedTable[led[i]].proc.count = 0;
sg_pLedTable[led[i]].proc.isSetCount = 0;
sg_pLedTable[led[i]].proc.defState = 0;
sg_pLedTable[led[i]].proc.isPwm = 0;
}
}
return 0;
}
/**
* @brief 为多个LED设置为跑马灯及次数, 最后次数完成后的亮灭状态
*
* @note
* @param[in] led LED组
* @param[in] ledNum LED数目
* @param[in] time LED亮时间
* @param[in] count 跑马灯次数
* @param[in] defState 跑马灯次数完成后的亮灭状态
* @return 0,成功; -1,失败
*/
int cotLed_MarqueeWithCount(led_t led[], uint8_t ledNum, int32_t time, uint8_t count, cotLedState_e defState)
{
if (sg_pLedTable == NULL || sg_ledNum == 0)
{
return -1;
}
for (uint8_t i = 0; i < ledNum; i++)
{
if (led[i] < sg_ledNum)
{
memset(sg_pLedTable[led[i]].proc.data.state, 0, LED_STATE_BYTE_NUM);
sg_pLedTable[led[i]].proc.interval = time;
sg_pLedTable[led[i]].proc.tic = 0;
SET_STATE_BITS(sg_pLedTable[led[i]].proc.data.state, i);
sg_pLedTable[led[i]].proc.offset = 0;
sg_pLedTable[led[i]].proc.validBits = ledNum;
sg_pLedTable[led[i]].proc.count = count;
sg_pLedTable[led[i]].proc.isSetCount = 1;
sg_pLedTable[led[i]].proc.defState = defState == COT_LED_ON ? 1 : 0;
sg_pLedTable[led[i]].proc.isPwm = 0;
}
}
return 0;
}
/**
* @brief 为多个LED设置为流水灯
*
* @note
* @param[in] led LED组
* @param[in] ledNum LED数目
* @param[in] time LED亮时间
* @return 0,成功; -1,失败
*/
int cotLed_Waterfall(led_t led[], uint8_t ledNum, int32_t time)
{
if (sg_pLedTable == NULL || sg_ledNum == 0)
{
return -1;
}
for (uint8_t i = 0; i < ledNum; i++)
{
if (led[i] < sg_ledNum)
{
memset(sg_pLedTable[led[i]].proc.data.state, 0, LED_STATE_BYTE_NUM);
sg_pLedTable[led[i]].proc.interval = time;
sg_pLedTable[led[i]].proc.tic = 0;
FILL_STATE_BITS(sg_pLedTable[led[i]].proc.data.state, i, ledNum);
sg_pLedTable[led[i]].proc.offset = 0;
sg_pLedTable[led[i]].proc.validBits = ledNum + 1;
sg_pLedTable[led[i]].proc.count = 0;
sg_pLedTable[led[i]].proc.isSetCount = 0;
sg_pLedTable[led[i]].proc.defState = 0;
sg_pLedTable[led[i]].proc.isPwm = 0;
}
}
return 0;
}
/**
* @brief 为多个LED设置为流水灯及次数, 最后次数完成后的亮灭状态
*
* @note
* @param[in] led LED组
* @param[in] ledNum LED数目
* @param[in] time LED亮时间
* @param[in] count 流水灯次数
* @param[in] defState 流水灯次数完成后的亮灭状态
* @return 0,成功; -1,失败
*/
int cotLed_WaterfallWithCount(led_t led[], uint8_t ledNum, int32_t time, uint8_t count, cotLedState_e defState)
{
if (sg_pLedTable == NULL || sg_ledNum == 0)
{
return -1;
}
for (uint8_t i = 0; i < ledNum; i++)
{
if (led[i] < sg_ledNum)
{
memset(sg_pLedTable[led[i]].proc.data.state, 0, LED_STATE_BYTE_NUM);
sg_pLedTable[led[i]].proc.interval = time;
sg_pLedTable[led[i]].proc.tic = 0;
FILL_STATE_BITS(sg_pLedTable[led[i]].proc.data.state, i, ledNum);
sg_pLedTable[led[i]].proc.offset = 0;
sg_pLedTable[led[i]].proc.validBits = ledNum + 1;
sg_pLedTable[led[i]].proc.count = count;
sg_pLedTable[led[i]].proc.isSetCount = 1;
sg_pLedTable[led[i]].proc.defState = defState == COT_LED_ON ? 1 : 0;
sg_pLedTable[led[i]].proc.isPwm = 0;
}
}
return 0;
}
/**
* @brief 设置指定LED为呼吸灯模式
*
* @attention LED控制任务必须为1ms周期
* @param[in] led 指定指示灯
* @param[in] period 呼吸周期,即多久完成一次呼吸;单位毫秒
* @return 0,成功; -1,失败
*/
int cotLed_Breathe(led_t led, uint16_t period)
{
if (sg_pLedTable == NULL || sg_ledNum == 0)
{
return -1;
}
if (led < sg_ledNum)
{
sg_pLedTable[led].proc.interval = period / 2 / BREATHE_PWM_PERIOD;
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.data.state[0] = 0; // 根据默认状态最后一次闪烁时状态设置相反状态达到较好的闪烁效果
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = 2;
sg_pLedTable[led].proc.count = 0;
sg_pLedTable[led].proc.isSetCount = 0;
sg_pLedTable[led].proc.defState = 0;
sg_pLedTable[led].proc.isPwm = 1;
sg_pLedTable[led].proc.data.pwm.onTime = 0;
sg_pLedTable[led].proc.data.pwm.tic = 0;
sg_pLedTable[led].proc.pwmDir = 1;
}
return 0;
}
/**
* @brief 设置指定LED为呼吸灯模式及次数, 最后次数完成后的亮灭状态
*
* @attention LED控制任务必须为1ms周期
* @param[in] led 指定指示灯
* @param[in] period 呼吸周期,即多久完成一次呼吸;单位毫秒
* @param[in] count 次数
* @param[in] defState 次数完成后的亮灭状态
* @return 0,成功; -1,失败
*/
int cotLed_BreatheWithCount(led_t led, uint16_t period, uint8_t count, cotLedState_e defState)
{
if (sg_pLedTable == NULL || sg_ledNum == 0)
{
return -1;
}
if (led < sg_ledNum)
{
sg_pLedTable[led].proc.interval = period / 2 / BREATHE_PWM_PERIOD;
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.data.state[0] = 0; // 根据默认状态最后一次闪烁时状态设置相反状态达到较好的闪烁效果
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = 2;
sg_pLedTable[led].proc.count = count;
sg_pLedTable[led].proc.isSetCount = 1;
sg_pLedTable[led].proc.defState = defState == COT_LED_ON ? 1 : 0;
sg_pLedTable[led].proc.isPwm = 1;
sg_pLedTable[led].proc.data.pwm.onTime = 0;
sg_pLedTable[led].proc.data.pwm.tic = 0;
sg_pLedTable[led].proc.pwmDir = 1;
}
return 0;
}
/**
* @brief 设置LED的自定义状态
*
* @attention 时间应为控制任务调度周期的倍数
* @param[in] led 指定指示灯
* @param[in] ... 亮灭时间参数:
* > 0, 亮的持续时间
* < 0, 灭的持续时间
* = 0, 可变参数设置结束
* @return 0,成功; -1,失败
*/
int cotLed_Custom(led_t led, ...)
{
uint8_t bits;
uint8_t offset = 0;
uint8_t validBits = 0;
va_list timeList;
int32_t time;
uint16_t interval = 0xffff;
if (sg_pLedTable == NULL || sg_ledNum == 0 || led >= sg_ledNum)
{
return -1;
}
va_start(timeList, led);
do
{
time = va_arg(timeList, int32_t);
if (time != 0 && LED_ABS(time) < interval)
{
interval = (uint16_t)LED_ABS(time);
}
} while (time != 0);
va_end(timeList);
validBits = 0;
offset = 0;
memset(sg_pLedTable[led].proc.data.state, 0, sizeof(sg_pLedTable[led].proc.data.state));
va_start(timeList, led);
do
{
time = va_arg(timeList, int32_t);
if (LED_ABS(time) != 0)
{
bits = (uint16_t)LED_ABS(time) / interval;
if (time > 0)
{
for (int i = 0; i < bits; i++)
{
sg_pLedTable[led].proc.data.state[offset / 8] |= 0x01 << (offset % 8);
offset++;
}
}
else
{
for (int i = 0; i < bits; i++)
{
sg_pLedTable[led].proc.data.state[offset / 8] |= 0x00 << (offset % 8);
offset++;
}
}
validBits += bits;
}
} while (time != 0);
va_end(timeList);
sg_pLedTable[led].proc.interval = interval;
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = validBits;
sg_pLedTable[led].proc.count = 0;
sg_pLedTable[led].proc.isSetCount = 0;
sg_pLedTable[led].proc.defState = 0;
sg_pLedTable[led].proc.isPwm = 0;
return 0;
}
/**
* @brief 设置LED的自定义状态及次数, 最后次数完成后的亮灭状态
*
* @attention 时间应为控制任务调度周期的倍数
* @param[in] led 指定指示灯
* @param[in] count 自定义状态次数,0表示无次数限制
* @param[in] defState 自定义状态次数完成后的亮灭状态
* @param[in] ... 亮灭时间参数:
* > 0, 亮的持续时间
* < 0, 灭的持续时间
* = 0, 可变参数设置结束
* @return 0,成功; -1,失败
*/
int cotLed_CustomWithCount(led_t led, uint8_t count, cotLedState_e defState, ...)
{
uint8_t bits;
uint8_t offset = 0;
uint8_t validBits = 0;
va_list timeList;
int32_t time;
uint16_t interval = 0xffff;
if (sg_pLedTable == NULL || sg_ledNum == 0 || led >= sg_ledNum)
{
return -1;
}
va_start(timeList, defState);
do
{
time = va_arg(timeList, int32_t);
if (time != 0 && LED_ABS(time) < interval)
{
interval = (uint16_t)LED_ABS(time);
}
} while (time != 0);
va_end(timeList);
validBits = 0;
offset = 0;
memset(sg_pLedTable[led].proc.data.state, 0, sizeof(sg_pLedTable[led].proc.data.state));
va_start(timeList, defState);
do
{
time = va_arg(timeList, int32_t);
if (LED_ABS(time) != 0)
{
bits = (uint16_t)LED_ABS(time) / interval;
if (time > 0)
{
for (int i = 0; i < bits; i++)
{
sg_pLedTable[led].proc.data.state[offset / 8] |= 0x01 << (offset % 8);
offset++;
}
}
else
{
for (int i = 0; i < bits; i++)
{
sg_pLedTable[led].proc.data.state[offset / 8] |= 0x00 << (offset % 8);
offset++;
}
}
validBits += bits;
}
} while (time != 0);
va_end(timeList);
sg_pLedTable[led].proc.interval = interval;
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.offset = 0;
sg_pLedTable[led].proc.validBits = validBits;
sg_pLedTable[led].proc.count = count;
sg_pLedTable[led].proc.isSetCount = count == 0 ? 0 : 1;
sg_pLedTable[led].proc.defState = defState == COT_LED_ON ? 1 : 0;
sg_pLedTable[led].proc.isPwm = 0;
return 0;
}
static cotLedState_e ReadPwmLedState(cotLedProc_t *pLed)
{
cotLedState_e eLedState;
if (pLed->data.pwm.tic < pLed->data.pwm.onTime)
{
eLedState = COT_LED_ON;
}
else
{
eLedState = COT_LED_OFF;
}
if (pLed->data.pwm.tic >= BREATHE_PWM_PERIOD)
{
pLed->data.pwm.tic = 0;
}
return eLedState;
}
static void CtrlPwmLedState(cotLedProc_t *pLed)
{
if (pLed->tic > pLed->interval)
{
pLed->tic = 0;
if (pLed->pwmDir)
{
pLed->data.pwm.onTime++;
if (pLed->data.pwm.onTime >= BREATHE_PWM_PERIOD)
{
pLed->pwmDir = 0;
}
}
else
{
pLed->data.pwm.onTime--;
if (pLed->data.pwm.onTime == 0)
{
pLed->pwmDir = 1;
if (pLed->count > 0)
{
pLed->count--;
}
}
}
}
}
/**
* @brief LED控制周期任务
*
* @param[in] sysTime 系统运行时间, 单位毫秒
* @return 0,成功; -1,失败
*/
int cotLed_Ctrl(uint32_t sysTime)
{
uint16_t led;
static uint32_t s_sysTimeBak = 0;
if (sg_pLedTable == NULL || sg_ledNum == 0)
{
return -1;
}
if (s_sysTimeBak == 0)
{
s_sysTimeBak = sysTime;
}
for (led = 0; led < sg_ledNum; led++)
{
TIME_ADD(sg_pLedTable[led].proc.tic, (sysTime - s_sysTimeBak));
if (sg_pLedTable[led].proc.isSetCount)
{
if (sg_pLedTable[led].proc.count == 0)
{
sg_pLedTable[led].proc.curState = sg_pLedTable[led].proc.defState ? COT_LED_ON : COT_LED_OFF;
}
else
{
if (sg_pLedTable[led].proc.isPwm)
{
sg_pLedTable[led].proc.curState = ReadPwmLedState(&sg_pLedTable[led].proc);
}
else
{
sg_pLedTable[led].proc.curState = (cotLedState_e)((sg_pLedTable[led].proc.data.state[sg_pLedTable[led].proc.offset / 8] >> (sg_pLedTable[led].proc.offset % 8)) & 0X01);
}
}
}
else
{
if (sg_pLedTable[led].proc.isPwm)
{
sg_pLedTable[led].proc.curState = ReadPwmLedState(&sg_pLedTable[led].proc);
}
else
{
sg_pLedTable[led].proc.curState = (cotLedState_e)((sg_pLedTable[led].proc.data.state[sg_pLedTable[led].proc.offset / 8] >> (sg_pLedTable[led].proc.offset % 8)) & 0X01);
}
}
if (sg_pLedTable[led].proc.isPwm)
{
TIME_ADD(sg_pLedTable[led].proc.data.pwm.tic, (sysTime - s_sysTimeBak));
CtrlPwmLedState(&sg_pLedTable[led].proc);
}
else
{
if (sg_pLedTable[led].proc.tic >= sg_pLedTable[led].proc.interval)
{
sg_pLedTable[led].proc.tic = 0;
sg_pLedTable[led].proc.offset++;
if (sg_pLedTable[led].proc.offset >= sg_pLedTable[led].proc.validBits)
{
sg_pLedTable[led].proc.offset = 0;
if (sg_pLedTable[led].proc.count > 0)
{
sg_pLedTable[led].proc.count--;
}
}
}
}
}
for (led = 0; led < sg_ledNum; led++)
{
sg_pLedTable[led].pfnLedCtrl(sg_pLedTable[led].proc.curState ? COT_LED_ON : COT_LED_OFF);
}
s_sysTimeBak = sysTime;
return 0;
}
C
1
https://gitee.com/cot_package/cot_led.git
git@gitee.com:cot_package/cot_led.git
cot_package
cot_led
cotLed
master

搜索帮助