SumProject/my_pro/myinfrared.c
2024-08-06 15:04:31 +08:00

56 lines
1.4 KiB
C

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include "infrared.h"
#include <drv_gpio.h>
#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#include <ulog.h>
/* 配置 LED 灯引脚 */
#define PIN_LED_B GET_PIN(F, 11) // PF11 : LED_B --> LED
#define PIN_LED_R GET_PIN(F, 12) // PF12 : LED_R --> LED
void myir_entry(void *parameter)
{
rt_kprintf("myir_entry\n");
unsigned int count = 1;
rt_int16_t key;
struct infrared_decoder_data infrared_data;
/* 选择 NEC 解码器 */
ir_select_decoder("nec");
/* 设置 RGB 引脚为输出模式*/
rt_pin_mode(PIN_LED_R, PIN_MODE_OUTPUT);
rt_pin_mode(PIN_LED_B, PIN_MODE_OUTPUT);
rt_pin_write(PIN_LED_R, PIN_HIGH);
rt_pin_write(PIN_LED_B, PIN_HIGH);
while (count > 0)
{
if (infrared_read("nec", &infrared_data) == RT_EOK)
{
/* 读取到红外数据,红灯亮起 */
rt_pin_write(PIN_LED_R, PIN_LOW);
LOG_I("RECEIVE OK: addr:0x%02X key:0x%02X repeat:%d", infrared_data.data.nec.addr,
infrared_data.data.nec.key, infrared_data.data.nec.repeat);
}
rt_thread_mdelay(10);
/* 熄灭蓝灯 */
rt_pin_write(PIN_LED_B, PIN_HIGH);
/* 熄灭红灯 */
rt_pin_write(PIN_LED_R, PIN_HIGH);
count++;
// if( count % 100 == 0)
// rt_kprintf("count = %d\n", count);
}
}