From fea76c91f4e287da44bb820ac81137cc2330cc24 Mon Sep 17 00:00:00 2001 From: james <1943357252@qq.com> Date: Tue, 6 Aug 2024 10:00:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E4=BA=86=E7=BA=A2=E5=A4=96=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E5=8F=88=E4=B8=8D=E8=A1=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config | 4 +- README.md | 4 +- my_error/README.md | 12 +++- .../660c6c04fddc1bd3ccbe4255df5d449.jpg | Bin {my_pro => my_picture}/image-1.png | Bin {my_pro => my_picture}/image-2.png | Bin {my_pro => my_picture}/image-3.png | Bin {my_pro => my_picture}/image.png | Bin {my_pro => my_picture}/lcdtemp.jpg | Bin {my_pro => my_picture}/note.md | 0 my_pro/myirfrared.c | 56 ++++++++++++++++++ my_pro/myproject.c | 22 +++++++ rtconfig.h | 3 + 13 files changed, 97 insertions(+), 4 deletions(-) rename {my_pro => my_picture}/660c6c04fddc1bd3ccbe4255df5d449.jpg (100%) rename {my_pro => my_picture}/image-1.png (100%) rename {my_pro => my_picture}/image-2.png (100%) rename {my_pro => my_picture}/image-3.png (100%) rename {my_pro => my_picture}/image.png (100%) rename {my_pro => my_picture}/lcdtemp.jpg (100%) rename {my_pro => my_picture}/note.md (100%) create mode 100644 my_pro/myirfrared.c diff --git a/.config b/.config index 09a8b6a..7424769 100644 --- a/.config +++ b/.config @@ -1147,7 +1147,9 @@ CONFIG_NEC_DEVIATION=100 CONFIG_PKG_USING_DRV_INFRARED=y # CONFIG_INFRARED_SEND is not set -# CONFIG_INFRARED_RECEIVE is not set +CONFIG_INFRARED_RECEIVE=y +CONFIG_INFRARED_RECEIVE_PIN=17 +CONFIG_INFRARED_RECEIVE_HWTIMER="timer16" # CONFIG_PKG_USING_INFRARED_V010 is not set CONFIG_PKG_USING_INFRARED_V011=y # CONFIG_PKG_USING_INFRARED_LATEST_VERSION is not set diff --git a/README.md b/README.md index 1ef6e91..b7c7fe4 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # My_project #### LCD 显示温湿度 -![LCD温湿度](/my_pro/lcdtemp.jpg) +![LCD温湿度](/my_picture/lcdtemp.jpg) 左上角是(0,0) →x,↓y ### 简易贪吃蛇 -![alt text](/my_pro/660c6c04fddc1bd3ccbe4255df5d449.jpg) +![alt text](/my_picture/660c6c04fddc1bd3ccbe4255df5d449.jpg) # STM32F407 星火一号开发板 BSP 说明 ## 简介 diff --git a/my_error/README.md b/my_error/README.md index a486641..f44ae2a 100644 --- a/my_error/README.md +++ b/my_error/README.md @@ -1,4 +1,6 @@ ![语法错误图](syntax_env1.5.png) + + 换了env2就可以? ![alt text](image-1.png) @@ -6,4 +8,12 @@ 但 ![alt text](image.png) 对照示例0.1.1版什么都不用做,也不会报错什么没定义 -.config/rtconfig.h \ No newline at end of file +.config/rtconfig.h +### GET_PIN(F, 11) 的头文件 + +``` c +#include +/* 配置 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 +``` \ No newline at end of file diff --git a/my_pro/660c6c04fddc1bd3ccbe4255df5d449.jpg b/my_picture/660c6c04fddc1bd3ccbe4255df5d449.jpg similarity index 100% rename from my_pro/660c6c04fddc1bd3ccbe4255df5d449.jpg rename to my_picture/660c6c04fddc1bd3ccbe4255df5d449.jpg diff --git a/my_pro/image-1.png b/my_picture/image-1.png similarity index 100% rename from my_pro/image-1.png rename to my_picture/image-1.png diff --git a/my_pro/image-2.png b/my_picture/image-2.png similarity index 100% rename from my_pro/image-2.png rename to my_picture/image-2.png diff --git a/my_pro/image-3.png b/my_picture/image-3.png similarity index 100% rename from my_pro/image-3.png rename to my_picture/image-3.png diff --git a/my_pro/image.png b/my_picture/image.png similarity index 100% rename from my_pro/image.png rename to my_picture/image.png diff --git a/my_pro/lcdtemp.jpg b/my_picture/lcdtemp.jpg similarity index 100% rename from my_pro/lcdtemp.jpg rename to my_picture/lcdtemp.jpg diff --git a/my_pro/note.md b/my_picture/note.md similarity index 100% rename from my_pro/note.md rename to my_picture/note.md diff --git a/my_pro/myirfrared.c b/my_pro/myirfrared.c new file mode 100644 index 0000000..dea023d --- /dev/null +++ b/my_pro/myirfrared.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include "infrared.h" +#include + +#define DBG_TAG "main" +#define DBG_LVL DBG_LOG +#include +#include + +/* 配置 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_kprintf("RECEIVE OK\n"); + } + 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); + } +} + + diff --git a/my_pro/myproject.c b/my_pro/myproject.c index 1aeea22..215b12f 100644 --- a/my_pro/myproject.c +++ b/my_pro/myproject.c @@ -11,6 +11,7 @@ #include #include "mysnake.h" + char DEMO_PRODUCT_KEY[IOTX_PRODUCT_KEY_LEN + 1] = {0}; char DEMO_DEVICE_NAME[IOTX_DEVICE_NAME_LEN + 1] = {0}; char DEMO_DEVICE_SECRET[IOTX_DEVICE_SECRET_LEN + 1] = {0}; @@ -49,9 +50,13 @@ float brightness; int lcd_y; int int_tmp; +extern void myir_entry(void *parameter); + void ath_init(void); void mqt_init(void); int ap3_init(void); +void irf_init(void); + #define EXAMPLE_TRACE(fmt, ...) \ do \ @@ -300,6 +305,7 @@ static void mqtt_example_main(void *parameter) rt_thread_t MQTT_Thread = RT_NULL; rt_thread_t Snake_Thread = RT_NULL; +rt_thread_t Irfrared_Thread = RT_NULL; void ath_init(void) { @@ -355,6 +361,20 @@ MSH_CMD_EXPORT_ALIAS(snk_init, snake, "snake game"); // return 0; // } +void irf_init(void) +{ + Irfrared_Thread = rt_thread_create("Irfrared_Thread", myir_entry, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); + + if (Irfrared_Thread != RT_NULL) + { + rt_thread_startup(Irfrared_Thread); + } + else + { + rt_kprintf("Irfrared Thread Create Failed!\n"); + } +} +MSH_CMD_EXPORT_ALIAS(irf_init, irf, "Irfrared"); void my_project(void) { ath_init(); @@ -362,5 +382,7 @@ void my_project(void) mqt_init(); ap3_init(); + + irf_init(); } MSH_CMD_EXPORT_ALIAS(my_project, myproject, run my project); \ No newline at end of file diff --git a/rtconfig.h b/rtconfig.h index 929b998..27d9fe0 100644 --- a/rtconfig.h +++ b/rtconfig.h @@ -498,6 +498,9 @@ #define NEC_DEVIATION 100 /* end of Select infrared decoder */ #define PKG_USING_DRV_INFRARED +#define INFRARED_RECEIVE +#define INFRARED_RECEIVE_PIN 17 +#define INFRARED_RECEIVE_HWTIMER "timer16" #define PKG_USING_INFRARED_V011 /* end of peripheral libraries and drivers */