调整文件夹,调整md
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 857 KiB |
@@ -1,66 +0,0 @@
|
||||
#include <board.h>
|
||||
#include <rtthread.h>
|
||||
#include <drv_gpio.h>
|
||||
#include "aht10.h"
|
||||
|
||||
// AHT挂载的总线名字
|
||||
#define AHT10_I2C_BUS "i2c3"
|
||||
|
||||
// 创建AHT线程时待用
|
||||
#define THREAD_PRIORITY 25
|
||||
#define THREAD_STACK_SIZE 2048
|
||||
#define THREAD_TIMESLICE 5
|
||||
|
||||
// AHT线程指针
|
||||
rt_thread_t AHT10 = RT_NULL;
|
||||
|
||||
// AHT测试样例
|
||||
void AHT10_Test(void *parameter)
|
||||
{
|
||||
// AHT设备指针
|
||||
aht10_device_t Dev = RT_NULL;
|
||||
|
||||
// Humi:湿度值,Temp:温度值
|
||||
float Humi, Temp;
|
||||
|
||||
// 初始化设备
|
||||
Dev = aht10_init(AHT10_I2C_BUS);
|
||||
if (Dev == RT_NULL)
|
||||
{
|
||||
rt_kprintf("AHT10_init Fail");
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
// 读取温湿度值
|
||||
Humi = aht10_read_humidity(Dev);
|
||||
Temp = aht10_read_temperature(Dev);
|
||||
|
||||
// 没有下载rt_vsprintf_full软件包的时候
|
||||
rt_kprintf("Humi: %d.%d\n", (int)Humi, (int)(Humi * 10) % 10);
|
||||
rt_kprintf("Temp: %d.%d\n", (int)Temp, (int)(Temp * 10) % 10);
|
||||
|
||||
// 配合rt_vsnprintf_full软件包使用
|
||||
// rt_kprintf("Humi: %f, Temp: %f\n", Humi, Temp);
|
||||
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void AHT10_Creat_Thread(void)
|
||||
{
|
||||
// 创建线程
|
||||
AHT10 = rt_thread_create("AHT10", AHT10_Test, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
// 创建成功就启动
|
||||
if (AHT10 != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(AHT10);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("AHT10_Thread Create Fail");
|
||||
}
|
||||
}
|
||||
// 导出Shell命令
|
||||
MSH_CMD_EXPORT(AHT10_Creat_Thread, This Function will creat a AHT10 thread.);
|
@@ -1,6 +0,0 @@
|
||||
#### LCD 显示温湿度
|
||||

|
||||
左上角是(0,0) →x,↓y
|
||||
|
||||
### 简易贪吃蛇
|
||||

|
@@ -1,15 +0,0 @@
|
||||
from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd]
|
||||
src = Glob('*.c')
|
||||
|
||||
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
for item in list:
|
||||
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||
|
||||
Return('group')
|
@@ -1,99 +0,0 @@
|
||||
//记得在menuconfig中开启支持旧版本功能(Support legacy version)
|
||||
#include <board.h>
|
||||
#include <rtthread.h>
|
||||
#include <drv_gpio.h>
|
||||
#include <dfs_posix.h>//需要添加软件包进这里
|
||||
|
||||
//定义要写入的内容
|
||||
char String[] = "Hello, RT-Thread.Welcom to RSOC!\n temp: 123, humi: 789";
|
||||
|
||||
//定义接受文件内容的缓冲区
|
||||
char buffer[100] = {};
|
||||
|
||||
void FileSystem_Test(void *parameter)
|
||||
{
|
||||
//文件描述符
|
||||
int fd;
|
||||
|
||||
//用只写方式打开文件,如果没有该文件,则创建一个文件
|
||||
fd = open("/fal/FileTest.txt", O_WRONLY | O_CREAT);
|
||||
|
||||
//如果打开成功
|
||||
if (fd >= 0)
|
||||
{
|
||||
//写入文件
|
||||
write(fd, String, sizeof(String));
|
||||
|
||||
rt_kprintf("Write done.\n");
|
||||
|
||||
//关闭文件
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("File Open Fail.\n");
|
||||
}
|
||||
|
||||
//用只读方式打开文件
|
||||
fd = open("/fal/FileTest.txt", O_RDONLY);
|
||||
|
||||
if (fd>= 0)
|
||||
{
|
||||
//读取文件内容
|
||||
rt_uint32_t size = read(fd, buffer, sizeof(buffer));
|
||||
|
||||
if (size < 0)
|
||||
{
|
||||
rt_kprintf("Read File Fail.\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
//输出文件内容
|
||||
rt_kprintf("Read from file test.txt : %s \n", buffer);
|
||||
|
||||
//关闭文件
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("File Open Fail.\n");
|
||||
}
|
||||
}
|
||||
//导出命令
|
||||
MSH_CMD_EXPORT(FileSystem_Test, FileSystem_Test);
|
||||
|
||||
static void readdir_sample(void)
|
||||
{
|
||||
DIR *dirp;
|
||||
struct dirent *d;
|
||||
|
||||
/* 打开 / dir_test 目录 */
|
||||
dirp = opendir("/fal");
|
||||
if (dirp == RT_NULL)
|
||||
{
|
||||
rt_kprintf("open directory error!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 读取目录 */
|
||||
while ((d = readdir(dirp)) != RT_NULL)
|
||||
{
|
||||
rt_kprintf("found %s\n", d->d_name);
|
||||
}
|
||||
|
||||
/* 关闭目录 */
|
||||
closedir(dirp);
|
||||
}
|
||||
}
|
||||
/* 导出到 msh 命令列表中 */
|
||||
MSH_CMD_EXPORT(readdir_sample, readdir sample);
|
||||
|
||||
/*
|
||||
#define WIFI_CS GET_PIN(F, 10)
|
||||
void WIFI_CS_PULL_DOWM(void)
|
||||
{
|
||||
rt_pin_mode(WIFI_CS, PIN_MODE_OUTPUT);
|
||||
rt_pin_write(WIFI_CS, PIN_LOW);
|
||||
}
|
||||
INIT_BOARD_EXPORT(WIFI_CS GET_PIN);
|
||||
*/
|
@@ -1,85 +0,0 @@
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
#include <icm20608.h>
|
||||
|
||||
#define LOG_TAG "icm.app"
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
#include <ulog.h>
|
||||
|
||||
static void icm_thread_entry(void *parameter)
|
||||
{
|
||||
icm20608_device_t dev = RT_NULL;
|
||||
const char *i2c_bus_name = "i2c2";
|
||||
int count = 0;
|
||||
rt_err_t result;
|
||||
|
||||
/* 初始化 icm20608 传感器 */
|
||||
dev = icm20608_init(i2c_bus_name);
|
||||
if (dev == RT_NULL)
|
||||
{
|
||||
LOG_E("The sensor initializes failure");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D("The sensor initializes success");
|
||||
}
|
||||
|
||||
/* 对 icm20608 进行零值校准:采样 10 次,求取平均值作为零值 */
|
||||
result = icm20608_calib_level(dev, 10);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
LOG_D("The sensor calibrates success");
|
||||
LOG_D("accel_offset: X%6d Y%6d Z%6d", dev->accel_offset.x, dev->accel_offset.y, dev->accel_offset.z);
|
||||
LOG_D("gyro_offset : X%6d Y%6d Z%6d", dev->gyro_offset.x, dev->gyro_offset.y, dev->gyro_offset.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("The sensor calibrates failure");
|
||||
icm20608_deinit(dev);
|
||||
}
|
||||
|
||||
while (count++ < 100)
|
||||
{
|
||||
rt_int16_t accel_x, accel_y, accel_z;
|
||||
rt_int16_t gyros_x, gyros_y, gyros_z;
|
||||
|
||||
/* 读取三轴加速度 */
|
||||
result = icm20608_get_accel(dev, &accel_x, &accel_y, &accel_z);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
LOG_D("current accelerometer: accel_x%6d, accel_y%6d, accel_z%6d", accel_x, accel_y, accel_z);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("The sensor does not work");
|
||||
}
|
||||
|
||||
/* 读取三轴陀螺仪 */
|
||||
result = icm20608_get_gyro(dev, &gyros_x, &gyros_y, &gyros_z);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
LOG_D("current gyroscope : gyros_x%6d, gyros_y%6d, gyros_z%6d", gyros_x, gyros_y, gyros_z);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("The sensor does not work");
|
||||
break;
|
||||
}
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
static int icm_app(void)
|
||||
{
|
||||
rt_thread_t res = rt_thread_create("icm", icm_thread_entry, RT_NULL, 1024, 20, 50);
|
||||
if(res == RT_NULL)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
rt_thread_startup(res);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT(icm_app, icm_app);
|
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
Before Width: | Height: | Size: 26 KiB |
Binary file not shown.
Before Width: | Height: | Size: 31 KiB |
Binary file not shown.
Before Width: | Height: | Size: 222 KiB |
@@ -1,255 +0,0 @@
|
||||
#include "rtthread.h"
|
||||
#include "dev_sign_api.h"
|
||||
#include "mqtt_api.h"
|
||||
#include <board.h>
|
||||
#include <drv_gpio.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "aht10.h"
|
||||
#include <dfs_posix.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};
|
||||
|
||||
void *HAL_Malloc(uint32_t size);
|
||||
void HAL_Free(void *ptr);
|
||||
void HAL_Printf(const char *fmt, ...);
|
||||
int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN + 1]);
|
||||
int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN + 1]);
|
||||
int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN]);
|
||||
uint64_t HAL_UptimeMs(void);
|
||||
int HAL_Snprintf(char *str, const int len, const char *fmt, ...);
|
||||
|
||||
//定义接受文件内容的缓冲区
|
||||
char buffer[1026] = {};
|
||||
char tmp[1026];
|
||||
|
||||
#define GPIO_LED_B GET_PIN(F,11)
|
||||
#define GPIO_LED_R GET_PIN(F,12)
|
||||
|
||||
// AHT挂载的总线名字
|
||||
#define AHT10_I2C_BUS "i2c3"
|
||||
|
||||
// AHT设备指针
|
||||
aht10_device_t Dev = RT_NULL;
|
||||
|
||||
// Humi:湿度值,Temp:温度值
|
||||
float Humi, Temp;
|
||||
|
||||
|
||||
#define EXAMPLE_TRACE(fmt, ...) \
|
||||
do { \
|
||||
HAL_Printf("%s|%03d :: ", __func__, __LINE__); \
|
||||
HAL_Printf(fmt, ##__VA_ARGS__); \
|
||||
HAL_Printf("%s", "\r\n"); \
|
||||
} while(0)
|
||||
|
||||
static void example_message_arrive(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt msg)
|
||||
{
|
||||
iotx_mqtt_topic_info_t *topic_info = (iotx_mqtt_topic_info_pt) msg->msg;
|
||||
|
||||
switch (msg->event_type) {
|
||||
case IOTX_MQTT_EVENT_PUBLISH_RECEIVED:
|
||||
/* print topic name and topic message */
|
||||
EXAMPLE_TRACE("Message Arrived:");
|
||||
rt_pin_mode(GPIO_LED_R, PIN_MODE_OUTPUT);
|
||||
//topic_info->payload 为发送的内容,可以据此设置命令
|
||||
if(rt_pin_read(GPIO_LED_R) == PIN_HIGH)
|
||||
{
|
||||
// rt_kprintf("LED_R should be ON\n");
|
||||
rt_pin_write(GPIO_LED_R, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
// rt_kprintf("LED_R should be OFF\n");
|
||||
rt_pin_write(GPIO_LED_R, PIN_HIGH);
|
||||
}
|
||||
EXAMPLE_TRACE("Topic : %.*s", topic_info->topic_len, topic_info->ptopic);
|
||||
EXAMPLE_TRACE("Payload: %.*s", topic_info->payload_len, topic_info->payload);
|
||||
EXAMPLE_TRACE("\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int example_subscribe(void *handle)
|
||||
{
|
||||
int res = 0;
|
||||
const char *fmt = "/%s/%s/user/get";
|
||||
char *topic = NULL;
|
||||
int topic_len = 0;
|
||||
|
||||
topic_len = strlen(fmt) + strlen(DEMO_PRODUCT_KEY) + strlen(DEMO_DEVICE_NAME) + 1;
|
||||
topic = HAL_Malloc(topic_len);
|
||||
if (topic == NULL) {
|
||||
EXAMPLE_TRACE("memory not enough");
|
||||
return -1;
|
||||
}
|
||||
memset(topic, 0, topic_len);
|
||||
HAL_Snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME);
|
||||
|
||||
res = IOT_MQTT_Subscribe(handle, topic, IOTX_MQTT_QOS0, example_message_arrive, NULL);
|
||||
if (res < 0) {
|
||||
EXAMPLE_TRACE("subscribe failed");
|
||||
HAL_Free(topic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAL_Free(topic);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void make_file()
|
||||
{
|
||||
//文件描述符
|
||||
int fd;
|
||||
|
||||
//用只写方式打开文件,如果没有该文件,则创建一个文件
|
||||
fd = open("/fal/test/Data.txt", O_WRONLY | O_CREAT | O_APPEND); //和原来相比,只是把O_TRUNC参数更改为O_APPEND,即更改为打开后,如果再进行写入,将从文件的末尾位置开始写。
|
||||
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,String);
|
||||
//如果打开成功
|
||||
if (fd >= 0)
|
||||
{
|
||||
//写入文件
|
||||
write(fd, tmp, sizeof(tmp));
|
||||
|
||||
// rt_kprintf("Write done.\n");
|
||||
|
||||
//关闭文件
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("File Open Fail.\n");
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
int cnt = 0;
|
||||
void tmp_payload(void)
|
||||
{
|
||||
// 读取温湿度值
|
||||
Humi = aht10_read_humidity(Dev);
|
||||
Temp = aht10_read_temperature(Dev);
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt);
|
||||
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp);
|
||||
make_file();
|
||||
sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f}}", Temp, Humi);
|
||||
return;
|
||||
}
|
||||
static int example_publish(void *handle)
|
||||
{
|
||||
|
||||
|
||||
tmp_payload();
|
||||
int res = 0;
|
||||
const char *fmt = "/sys/%s/%s/thing/event/property/post";
|
||||
// /k1lyriw1yGj/${deviceName}/user/get
|
||||
char *topic = NULL;
|
||||
int topic_len = 0;
|
||||
char *payload = tmp;
|
||||
// strcpy(payload,tmp_payload());
|
||||
// rt_kprintf("payload:%s\n",payload);
|
||||
topic_len = strlen(fmt) + strlen(DEMO_PRODUCT_KEY) + strlen(DEMO_DEVICE_NAME) + 1;
|
||||
topic = HAL_Malloc(topic_len);
|
||||
if (topic == NULL) {
|
||||
EXAMPLE_TRACE("memory not enough");
|
||||
return -1;
|
||||
}
|
||||
memset(topic, 0, topic_len);
|
||||
HAL_Snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME);
|
||||
|
||||
res = IOT_MQTT_Publish_Simple(0, topic, IOTX_MQTT_QOS0, payload, strlen(payload));
|
||||
if (res < 0) {
|
||||
EXAMPLE_TRACE("publish failed, res = %d", res);
|
||||
HAL_Free(topic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAL_Free(topic);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void example_event_handle(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt msg)
|
||||
{
|
||||
EXAMPLE_TRACE("msg->event_type : %d", msg->event_type);
|
||||
}
|
||||
|
||||
static void mqtt_example_main(void *parameter)
|
||||
{
|
||||
void *pclient = NULL;
|
||||
int res = 0;
|
||||
int loop_cnt = 0;
|
||||
iotx_mqtt_param_t mqtt_params;
|
||||
|
||||
HAL_GetProductKey(DEMO_PRODUCT_KEY);
|
||||
HAL_GetDeviceName(DEMO_DEVICE_NAME);
|
||||
HAL_GetDeviceSecret(DEMO_DEVICE_SECRET);
|
||||
|
||||
EXAMPLE_TRACE("mqtt example");
|
||||
|
||||
|
||||
memset(&mqtt_params, 0x0, sizeof(mqtt_params));
|
||||
|
||||
mqtt_params.handle_event.h_fp = example_event_handle;
|
||||
|
||||
pclient = IOT_MQTT_Construct(&mqtt_params);
|
||||
if (NULL == pclient) {
|
||||
EXAMPLE_TRACE("MQTT construct failed");
|
||||
return ;
|
||||
}
|
||||
|
||||
res = example_subscribe(pclient);
|
||||
if (res < 0) {
|
||||
IOT_MQTT_Destroy(&pclient);
|
||||
return ;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (0 == loop_cnt % 20) {
|
||||
example_publish(pclient);
|
||||
}
|
||||
|
||||
IOT_MQTT_Yield(pclient, 200);
|
||||
|
||||
loop_cnt += 1;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
#define THREAD_PRIORITY 25
|
||||
#define THREAD_STACK_SIZE 4096
|
||||
#define THREAD_TIMESLICE 5
|
||||
|
||||
rt_thread_t MQTT_Thread = RT_NULL;
|
||||
|
||||
void MQTT_Creat_Thread(void)
|
||||
{
|
||||
|
||||
// 初始化设备
|
||||
Dev = aht10_init(AHT10_I2C_BUS);
|
||||
if (Dev == RT_NULL)
|
||||
{
|
||||
rt_kprintf("AHT10_init Fail");
|
||||
return;
|
||||
}
|
||||
|
||||
MQTT_Thread = rt_thread_create("MTQQ_Thread", mqtt_example_main, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
|
||||
if (MQTT_Thread != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(MQTT_Thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("MQTT Thread Create Failed!\n");
|
||||
}
|
||||
|
||||
}
|
||||
MSH_CMD_EXPORT(MQTT_Creat_Thread, create a MQTT_Thread);
|
@@ -1,108 +0,0 @@
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
#include <stdlib.h>
|
||||
#include <drv_lcd.h>
|
||||
#include <ntp.h>
|
||||
|
||||
#define LCD_MAX 240
|
||||
void lcd_black(int x, int y)
|
||||
{
|
||||
lcd_address_set(x, y, x, y);
|
||||
lcd_write_half_word(BLACK);
|
||||
}
|
||||
|
||||
void lcd_white(int x, int y)
|
||||
{
|
||||
lcd_address_set(x, y, x, y);
|
||||
lcd_write_half_word(WHITE);
|
||||
}
|
||||
int roundxy[4][2] = {
|
||||
{0, 0},
|
||||
{0, LCD_MAX},
|
||||
{LCD_MAX, 0},
|
||||
{LCD_MAX, LCD_MAX},
|
||||
};
|
||||
int xymove[4][2] = {
|
||||
{1, 1},
|
||||
{1, -1},
|
||||
{-1, 1},
|
||||
{-1, -1},
|
||||
};
|
||||
void mytime()
|
||||
{
|
||||
rt_thread_mdelay(10000);
|
||||
time_t cur_time;
|
||||
|
||||
cur_time = ntp_get_time(RT_NULL);
|
||||
if (cur_time)
|
||||
{
|
||||
rt_kprintf("NTP Server Time: %s", ctime((const time_t *)&cur_time));
|
||||
}
|
||||
lcd_show_string(20, 2, 16, ctime((const time_t *)&cur_time));
|
||||
}
|
||||
|
||||
void xy_round(int x, int y, int x2, int y2, int r, int ii)
|
||||
{
|
||||
// rt_kprintf("x:%d,y:%d,x2:%d,y2:%d,r:%d\n", x, y, x2, y2, r);
|
||||
for (int i = x; i != x2; i += xymove[ii][0])
|
||||
{
|
||||
for (int j = y; j != y2; j += xymove[ii][1])
|
||||
{
|
||||
int newi = x2 - i;
|
||||
int newj = y2 - j;
|
||||
// rt_kprintf("(%d,%d,%d)",(newi * newi + newj * newj), newi, newj);
|
||||
if ((newi * newi + newj * newj) > (r * r))
|
||||
{
|
||||
// rt_kprintf("x:%d,y:%d\n", i, j);
|
||||
lcd_black(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void my_round(int r)
|
||||
{
|
||||
// 这个范围涂黑
|
||||
lcd_fill(0, 0, roundxy[2][0], roundxy[2][1], BLACK);
|
||||
lcd_write_half_word(BLACK);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
xy_round(roundxy[i][0], roundxy[i][1], roundxy[i][0] + r * xymove[i][0], roundxy[i][1] + r * xymove[i][1], r, i);
|
||||
}
|
||||
}
|
||||
void xy_sink()
|
||||
{
|
||||
for (int i = 0; i < 240; i++)
|
||||
{
|
||||
for (int j = 0; j <= 240; j++)
|
||||
{
|
||||
lcd_black(j, 240 - i);
|
||||
rt_thread_mdelay(1);
|
||||
}
|
||||
// rt_kprintf("(%d,...) Blacked\n", i);
|
||||
}
|
||||
}
|
||||
void snake_address(int x, int y, int r, const rt_uint16_t da)
|
||||
{
|
||||
int f = 0; // 使蛇身成节
|
||||
if (r > 5)
|
||||
{
|
||||
f = 1;
|
||||
}
|
||||
for (int i = x * r + f; i < x * r + r - f; i++)
|
||||
{
|
||||
for (int j = y * r + f; j < y * r + r - f; j++)
|
||||
{
|
||||
lcd_address_set(i, j, i, j);
|
||||
lcd_write_half_word(da);
|
||||
}
|
||||
}
|
||||
}
|
||||
// bt 命令行
|
||||
int color_cmd(int argc, char **argv)
|
||||
{
|
||||
snake_address(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), BLACK);
|
||||
return 1;
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(color_cmd, snk, bt 命令行);
|
@@ -1,23 +0,0 @@
|
||||
#include <drv_lcd.h>
|
||||
#include <rtthread.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
// 当前方向
|
||||
void mytime();
|
||||
void xy_round(int x, int y, int x2, int y2, int r, int ii);
|
||||
void my_round(int r);
|
||||
void xy_sink();
|
||||
void lcd_black(int x, int y);
|
||||
void lcd_white(int x, int y);
|
||||
void snake_address(int x, int y, int r, const rt_uint16_t da);
|
||||
|
||||
|
||||
// typedef int QDataType;
|
||||
|
||||
// typedef struct QListNode
|
||||
// {
|
||||
// QDataType data;
|
||||
// struct QListNode* next;
|
||||
|
||||
// } QueueNode;
|
@@ -1,366 +0,0 @@
|
||||
#include "rtthread.h"
|
||||
#include "dev_sign_api.h"
|
||||
#include "mqtt_api.h"
|
||||
#include <board.h>
|
||||
#include <drv_gpio.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "aht10.h"
|
||||
#include <ap3216c.h>
|
||||
#include <dfs_posix.h>
|
||||
#include <drv_lcd.h>
|
||||
#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};
|
||||
|
||||
void *HAL_Malloc(uint32_t size);
|
||||
void HAL_Free(void *ptr);
|
||||
void HAL_Printf(const char *fmt, ...);
|
||||
int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN + 1]);
|
||||
int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN + 1]);
|
||||
int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN]);
|
||||
uint64_t HAL_UptimeMs(void);
|
||||
int HAL_Snprintf(char *str, const int len, const char *fmt, ...);
|
||||
|
||||
// 定义接受文件内容的缓冲区
|
||||
char buffer[1026] = {};
|
||||
char tmp[1026];
|
||||
extern int snake_len;
|
||||
rt_atomic_t page_chosen = 1;
|
||||
|
||||
#define PAGE_MAX 2
|
||||
|
||||
#define GPIO_LED_B GET_PIN(F, 11)
|
||||
#define GPIO_LED_R GET_PIN(F, 12)
|
||||
|
||||
// AHT挂载的总线名字
|
||||
#define AHT10_I2C_BUS "i2c3"
|
||||
|
||||
// AHT,ap3216c设备指针
|
||||
aht10_device_t Dev = RT_NULL;
|
||||
ap3216c_device_t dev;
|
||||
|
||||
// Humi:湿度值,Temp:温度值
|
||||
float Humi, Temp;
|
||||
rt_uint16_t ps_data;
|
||||
float brightness;
|
||||
int lcd_y;
|
||||
int int_tmp;
|
||||
|
||||
void ath_init(void);
|
||||
void mqt_init(void);
|
||||
int ap3_init(void);
|
||||
|
||||
#define EXAMPLE_TRACE(fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
HAL_Printf("%s|%03d :: ", __func__, __LINE__); \
|
||||
HAL_Printf(fmt, ##__VA_ARGS__); \
|
||||
HAL_Printf("%s", "\r\n"); \
|
||||
} while (0)
|
||||
|
||||
static void example_message_arrive(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt msg)
|
||||
{
|
||||
iotx_mqtt_topic_info_t *topic_info = (iotx_mqtt_topic_info_pt)msg->msg;
|
||||
|
||||
switch (msg->event_type)
|
||||
{
|
||||
case IOTX_MQTT_EVENT_PUBLISH_RECEIVED:
|
||||
/* print topic name and topic message */
|
||||
EXAMPLE_TRACE("Message Arrived:");
|
||||
rt_pin_mode(GPIO_LED_R, PIN_MODE_OUTPUT);
|
||||
// topic_info->payload 为发送的内容,可以据此设置命令
|
||||
if (rt_pin_read(GPIO_LED_R) == PIN_HIGH)
|
||||
{
|
||||
// rt_kprintf("LED_R should be ON\n");
|
||||
rt_pin_write(GPIO_LED_R, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
// rt_kprintf("LED_R should be OFF\n");
|
||||
rt_pin_write(GPIO_LED_R, PIN_HIGH);
|
||||
}
|
||||
EXAMPLE_TRACE("Topic : %.*s", topic_info->topic_len, topic_info->ptopic);
|
||||
EXAMPLE_TRACE("Payload: %.*s", topic_info->payload_len, topic_info->payload);
|
||||
EXAMPLE_TRACE("\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int example_subscribe(void *handle)
|
||||
{
|
||||
int res = 0;
|
||||
const char *fmt = "/%s/%s/user/get";
|
||||
char *topic = NULL;
|
||||
int topic_len = 0;
|
||||
|
||||
topic_len = strlen(fmt) + strlen(DEMO_PRODUCT_KEY) + strlen(DEMO_DEVICE_NAME) + 1;
|
||||
topic = HAL_Malloc(topic_len);
|
||||
if (topic == NULL)
|
||||
{
|
||||
EXAMPLE_TRACE("memory not enough");
|
||||
return -1;
|
||||
}
|
||||
memset(topic, 0, topic_len);
|
||||
HAL_Snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME);
|
||||
|
||||
res = IOT_MQTT_Subscribe(handle, topic, IOTX_MQTT_QOS0, example_message_arrive, NULL);
|
||||
if (res < 0)
|
||||
{
|
||||
EXAMPLE_TRACE("subscribe failed");
|
||||
HAL_Free(topic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAL_Free(topic);
|
||||
return 0;
|
||||
}
|
||||
int plus_lcd_y(int pls)
|
||||
{
|
||||
int_tmp = lcd_y;
|
||||
lcd_y += pls;
|
||||
return int_tmp;
|
||||
}
|
||||
void easy_show_lcd(char *title, float Temp)
|
||||
{
|
||||
lcd_show_string(10, plus_lcd_y(24), 24, title);
|
||||
sprintf(tmp, "%f", Temp);
|
||||
lcd_show_string(10, plus_lcd_y(32), 32, tmp);
|
||||
}
|
||||
void show_lcd()
|
||||
{
|
||||
lcd_y = 10;
|
||||
easy_show_lcd("Temperature:", Temp);
|
||||
easy_show_lcd("Humidity:", Humi);
|
||||
easy_show_lcd("Brightness:(lux)", brightness);
|
||||
easy_show_lcd("Ps data:", (float)ps_data);
|
||||
// lcd_show_string(10, plus_lcd_y(10), 24, "Temperature:");
|
||||
// sprintf(tmp, "%f", Temp);
|
||||
// lcd_show_string(10, plus_lcd_y(24), 32, tmp);
|
||||
|
||||
// lcd_show_string(10, plus_lcd_y(32), 24, "Humidity:");
|
||||
// sprintf(tmp, "%f", Humi);
|
||||
// lcd_show_string(10, plus_lcd_y(24), 32, tmp);
|
||||
|
||||
// lcd_show_string(10, plus_lcd_y(32), 24, "Brightness:");
|
||||
// sprintf(tmp, "%f(lux)", brightness);
|
||||
// lcd_show_string(10, plus_lcd_y(24), 32, tmp);
|
||||
}
|
||||
|
||||
void make_file()
|
||||
{
|
||||
// 文件描述符
|
||||
int fd;
|
||||
// 用只写方式打开文件,如果没有该文件,则创建一个文件
|
||||
fd = open("/fal/test/Data.txt", O_WRONLY | O_CREAT | O_APPEND); // 和原来相比,只是把O_TRUNC参数更改为O_APPEND,即更改为打开后,如果再进行写入,将从文件的末尾位置开始写。
|
||||
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,String);
|
||||
// 如果打开成功
|
||||
if (fd >= 0)
|
||||
{
|
||||
// 写入文件
|
||||
write(fd, tmp, sizeof(tmp));
|
||||
// rt_kprintf("Write done.\n");
|
||||
// 关闭文件
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("File Open Fail.\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
int cnt = 0;
|
||||
void tmp_payload(void)
|
||||
{
|
||||
// 读取温湿度值
|
||||
Humi = aht10_read_humidity(Dev);
|
||||
Temp = aht10_read_temperature(Dev);
|
||||
brightness = ap3216c_read_ambient_light(dev);
|
||||
ps_data = ap3216c_read_ps_data(dev);
|
||||
if (ps_data > 14)
|
||||
{
|
||||
page_chosen = (page_chosen % PAGE_MAX) + 1;
|
||||
}
|
||||
// icm20608_get_accel(icm20608_device_t dev, rt_int16_t *accel_x, rt_int16_t *accel_y, rt_int16_t *accel_z)
|
||||
// memset(tmp, 0, sizeof(tmp));
|
||||
// sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt);
|
||||
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp);
|
||||
// make_file();
|
||||
if (page_chosen == 2)
|
||||
{
|
||||
show_lcd();
|
||||
}
|
||||
sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f,\"LightLux\":%.2f,\"Psdata\":%d,\"Snakelen\":%d}}", Temp, Humi, brightness, ps_data, snake_len);
|
||||
return;
|
||||
}
|
||||
void test_lcd()
|
||||
{
|
||||
// show_str(10, 10+24+32+24+32, 100, 32, "你好", 32);
|
||||
ath_init();
|
||||
ap3_init();
|
||||
while (1)
|
||||
{
|
||||
tmp_payload();
|
||||
rt_thread_mdelay(100);
|
||||
}
|
||||
}
|
||||
MSH_CMD_EXPORT(test_lcd, run my project);
|
||||
static int example_publish(void *handle)
|
||||
{
|
||||
|
||||
tmp_payload();
|
||||
int res = 0;
|
||||
const char *fmt = "/sys/%s/%s/thing/event/property/post";
|
||||
// /k1lyriw1yGj/${deviceName}/user/get
|
||||
char *topic = NULL;
|
||||
int topic_len = 0;
|
||||
char *payload = tmp;
|
||||
// strcpy(payload,tmp_payload());
|
||||
// rt_kprintf("payload:%s\n",payload);
|
||||
topic_len = strlen(fmt) + strlen(DEMO_PRODUCT_KEY) + strlen(DEMO_DEVICE_NAME) + 1;
|
||||
topic = HAL_Malloc(topic_len);
|
||||
if (topic == NULL)
|
||||
{
|
||||
EXAMPLE_TRACE("memory not enough");
|
||||
return -1;
|
||||
}
|
||||
memset(topic, 0, topic_len);
|
||||
HAL_Snprintf(topic, topic_len, fmt, DEMO_PRODUCT_KEY, DEMO_DEVICE_NAME);
|
||||
|
||||
res = IOT_MQTT_Publish_Simple(0, topic, IOTX_MQTT_QOS0, payload, strlen(payload));
|
||||
if (res < 0)
|
||||
{
|
||||
EXAMPLE_TRACE("publish failed, res = %d", res);
|
||||
HAL_Free(topic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAL_Free(topic);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void example_event_handle(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt msg)
|
||||
{
|
||||
EXAMPLE_TRACE("msg->event_type : %d", msg->event_type);
|
||||
}
|
||||
|
||||
static void mqtt_example_main(void *parameter)
|
||||
{
|
||||
void *pclient = NULL;
|
||||
int res = 0;
|
||||
int loop_cnt = 0;
|
||||
iotx_mqtt_param_t mqtt_params;
|
||||
|
||||
HAL_GetProductKey(DEMO_PRODUCT_KEY);
|
||||
HAL_GetDeviceName(DEMO_DEVICE_NAME);
|
||||
HAL_GetDeviceSecret(DEMO_DEVICE_SECRET);
|
||||
|
||||
EXAMPLE_TRACE("mqtt example");
|
||||
|
||||
memset(&mqtt_params, 0x0, sizeof(mqtt_params));
|
||||
|
||||
mqtt_params.handle_event.h_fp = example_event_handle;
|
||||
|
||||
pclient = IOT_MQTT_Construct(&mqtt_params);
|
||||
if (NULL == pclient)
|
||||
{
|
||||
EXAMPLE_TRACE("MQTT construct failed");
|
||||
return;
|
||||
}
|
||||
|
||||
res = example_subscribe(pclient);
|
||||
if (res < 0)
|
||||
{
|
||||
IOT_MQTT_Destroy(&pclient);
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (0 == loop_cnt % 20)
|
||||
{
|
||||
example_publish(pclient);
|
||||
}
|
||||
|
||||
IOT_MQTT_Yield(pclient, 200);
|
||||
|
||||
loop_cnt += 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#define THREAD_PRIORITY 25
|
||||
#define THREAD_STACK_SIZE 4096
|
||||
#define THREAD_TIMESLICE 5
|
||||
|
||||
rt_thread_t MQTT_Thread = RT_NULL;
|
||||
rt_thread_t Snake_Thread = RT_NULL;
|
||||
|
||||
void ath_init(void)
|
||||
{
|
||||
// 初始化设备
|
||||
Dev = aht10_init(AHT10_I2C_BUS);
|
||||
if (Dev == RT_NULL)
|
||||
{
|
||||
rt_kprintf("AHT10_init Fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
void mqt_init(void)
|
||||
{
|
||||
MQTT_Thread = rt_thread_create("MTQQ_Thread", mqtt_example_main, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
|
||||
if (MQTT_Thread != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(MQTT_Thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("MQTT Thread Create Failed!\n");
|
||||
}
|
||||
}
|
||||
int ap3_init(void)
|
||||
{
|
||||
const char *i2c_bus_name = "i2c2";
|
||||
|
||||
dev = ap3216c_init(i2c_bus_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
void snk_init(void)
|
||||
{
|
||||
Snake_Thread = rt_thread_create("Snake_Thread", snake_entry, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
|
||||
if (Snake_Thread != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(Snake_Thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("Snake Thread Create Failed!\n");
|
||||
}
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(snk_init, snake, "snake game");
|
||||
// void i20_init(void)
|
||||
// {
|
||||
// const char* i2c_bus_name = "i2c2";
|
||||
|
||||
// icm20608_init(i2c_bus_name)
|
||||
|
||||
// return 0;
|
||||
|
||||
// }
|
||||
void my_project(void)
|
||||
{
|
||||
ath_init();
|
||||
|
||||
mqt_init();
|
||||
|
||||
ap3_init();
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(my_project, myproject, run my project);
|
@@ -1,116 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <rtthread.h>
|
||||
#include <stdbool.h>
|
||||
#include "my_func.h"
|
||||
#include "mysnake.h"
|
||||
#include <time.h>
|
||||
#include <rtatomic.h>
|
||||
|
||||
#define LCD_MAX 240
|
||||
#define SNAKE_SIZE 20
|
||||
#define SNAKE_MAX LCD_MAX / SNAKE_SIZE
|
||||
rt_atomic_t now_direction = 3;
|
||||
rt_atomic_t snake_pressed = 0;
|
||||
extern rt_atomic_t page_chosen;
|
||||
int snake_max = SNAKE_MAX * 3;
|
||||
int snake_len = 3;
|
||||
|
||||
// bool snake_table[SNAKE_MAX][SNAKE_MAX] = {0};
|
||||
// struct My_snake
|
||||
// {
|
||||
// int x;
|
||||
// int y;
|
||||
// }snake_list[SNAKE_MAX*SNAKE_MAX] = {0};
|
||||
// /* rt_event_t 是指向事件结构体的指针类型 */
|
||||
// typedef struct My_snake* my_snake_t;
|
||||
|
||||
void snake_entry(void *parameter)
|
||||
{
|
||||
system("irq");
|
||||
time_t t;
|
||||
/* 初始化随机数发生器 */
|
||||
srand((unsigned)time(&t));
|
||||
int snake_list[SNAKE_MAX + 1][2] = {0};
|
||||
int snake_direction[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; // 上,左,下,右
|
||||
int snake_food[2];
|
||||
bool food_flag = false;
|
||||
char snake_dirshow[4][7] = {"upup", "left", "down", "rigt"};
|
||||
char tmp[10];
|
||||
int snake_head = 2, snake_tail = 0; // 蛇头,蛇尾
|
||||
snake_list[1][0] = SNAKE_MAX / 2;
|
||||
snake_list[1][1] = SNAKE_MAX / 2;
|
||||
snake_list[0][0] = snake_list[1][0] - 1;
|
||||
snake_list[0][1] = snake_list[1][1];
|
||||
snake_list[2][0] = snake_list[1][0] + 1;
|
||||
snake_list[2][1] = snake_list[1][1];
|
||||
// snake_table[snake_list[0][0]][snake_list[0][1]] = 1;
|
||||
// snake_table[snake_list[1][0]][snake_list[1][1]] = 1;
|
||||
// snake_table[snake_list[2][0]][snake_list[2][1]] = 1;
|
||||
snake_address(snake_list[0][0], snake_list[0][1], SNAKE_SIZE, BLACK);
|
||||
snake_address(snake_list[1][0], snake_list[1][1], SNAKE_SIZE, BLACK);
|
||||
snake_address(snake_list[2][0], snake_list[2][1], SNAKE_SIZE, BLACK);
|
||||
snake_food[0] = rand() % SNAKE_MAX;
|
||||
snake_food[1] = rand() % SNAKE_MAX;
|
||||
snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
|
||||
int new_head_x = 0, new_head_y = 0;
|
||||
int new_direction = 0;
|
||||
while (1)
|
||||
{
|
||||
if (page_chosen == 1)
|
||||
{
|
||||
if (!snake_pressed)
|
||||
{
|
||||
// 50%的概率保持当前方向,20%的概率随机改变方向
|
||||
if (rand() % 100 < 50)
|
||||
{
|
||||
new_direction = rand() % 3;
|
||||
now_direction = (now_direction + 3 + new_direction) % 4; // 防止反向,走回头路
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_atomic_add(&snake_pressed, -1);
|
||||
}
|
||||
|
||||
new_head_x = (snake_list[snake_head][0] + snake_direction[now_direction][0] + SNAKE_MAX) % (SNAKE_MAX);
|
||||
new_head_y = (snake_list[snake_head][1] + snake_direction[now_direction][1] + SNAKE_MAX) % (SNAKE_MAX);
|
||||
|
||||
sprintf(tmp, "(%d,%d)", new_head_x, new_head_y);
|
||||
// rt_kprintf("head:%d,%d\n", snake_list[snake_head][0], snake_list[snake_head][1]);
|
||||
lcd_show_string(20, 20, 16, snake_dirshow[now_direction]);
|
||||
lcd_show_string(20 + 16 * 4, 20, 16, tmp);
|
||||
|
||||
snake_address(new_head_x, new_head_y, SNAKE_SIZE, BLACK);
|
||||
if (new_head_x == snake_food[0] && new_head_y == snake_food[1])
|
||||
{
|
||||
snake_food[0] = rand() % SNAKE_MAX;
|
||||
snake_food[1] = rand() % SNAKE_MAX;
|
||||
snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
|
||||
snake_len++;
|
||||
sprintf(tmp, "%d", snake_len);
|
||||
lcd_show_string(100, 105, 32, tmp);
|
||||
// 防止蛇咬尾出现bug
|
||||
if (snake_len >= SNAKE_MAX)
|
||||
{
|
||||
snake_address(snake_list[snake_tail][0], snake_list[snake_tail][1], SNAKE_SIZE, WHITE);
|
||||
snake_tail = (snake_tail + 1) % (SNAKE_MAX);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (snake_list[snake_tail][0] == snake_food[0] && snake_list[snake_tail][1] == snake_food[1])
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
snake_address(snake_list[snake_tail][0], snake_list[snake_tail][1], SNAKE_SIZE, WHITE);
|
||||
}
|
||||
snake_tail = (snake_tail + 1) % (SNAKE_MAX);
|
||||
}
|
||||
snake_head = (snake_head + 1) % (SNAKE_MAX);
|
||||
snake_list[snake_head][0] = new_head_x;
|
||||
snake_list[snake_head][1] = new_head_y;
|
||||
rt_thread_mdelay(900);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <rtthread.h>
|
||||
#include <stdbool.h>
|
||||
#include "my_func.h"
|
||||
|
||||
void snake_entry(void *parameter);
|
@@ -1,8 +0,0 @@
|
||||
### 使能了sd card
|
||||

|
||||
结果
|
||||

|
||||
关了就好了
|
||||

|
||||
### 开了soft rtc
|
||||

|
@@ -1,68 +0,0 @@
|
||||
#include <drv_gpio.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rtthread.h>
|
||||
#define LOG_TAG "pin.irq"
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
#include <ulog.h>
|
||||
#include <rtatomic.h>
|
||||
#include "my_func.h"
|
||||
|
||||
#define KEY_UP GET_PIN(C, 5)
|
||||
#define KEY_DOWN GET_PIN(C, 1)
|
||||
#define KEY_LEFT GET_PIN(C, 0)
|
||||
#define KEY_RIGHT GET_PIN(C, 4)
|
||||
extern rt_atomic_t now_direction ;
|
||||
extern rt_atomic_t snake_pressed ;
|
||||
extern int snake_max;
|
||||
void key_up_callback(void *args)
|
||||
{
|
||||
rt_atomic_store(&snake_pressed, snake_max+1);
|
||||
if(rt_atomic_load(&now_direction) != 2) rt_atomic_store(&now_direction, 0);
|
||||
int value = rt_pin_read(KEY_UP);
|
||||
LOG_I("key up value: %d\n", value);
|
||||
}
|
||||
|
||||
void key_down_callback(void *args)
|
||||
{
|
||||
rt_atomic_store(&snake_pressed, snake_max+1);
|
||||
int value = rt_pin_read(KEY_DOWN);
|
||||
if(rt_atomic_load(&now_direction) != 0) rt_atomic_store(&now_direction, 2);
|
||||
LOG_I("key down value: %d\n", value);
|
||||
}
|
||||
|
||||
void key_left_callback(void *args)
|
||||
{
|
||||
rt_atomic_store(&snake_pressed, snake_max+1);
|
||||
if(rt_atomic_load(&now_direction) != 3) rt_atomic_store(&now_direction, 1);
|
||||
int value = rt_pin_read(KEY_LEFT);
|
||||
LOG_I("key left value: %d\n", value);
|
||||
}
|
||||
|
||||
void key_right_callback(void *args)
|
||||
{
|
||||
rt_atomic_store(&snake_pressed, snake_max+1);
|
||||
if(rt_atomic_load(&now_direction) != 1) rt_atomic_store(&now_direction, 3);
|
||||
int value = rt_pin_read(KEY_RIGHT);
|
||||
LOG_I("key right value: %d\n", value);
|
||||
}
|
||||
|
||||
static int rt_pin_irq_example(void)
|
||||
{
|
||||
rt_pin_mode(KEY_UP, PIN_MODE_INPUT_PULLUP);
|
||||
rt_pin_mode(KEY_DOWN, PIN_MODE_INPUT_PULLUP);
|
||||
rt_pin_mode(KEY_LEFT, PIN_MODE_INPUT_PULLUP);
|
||||
rt_pin_mode(KEY_RIGHT, PIN_MODE_INPUT_PULLUP);
|
||||
|
||||
rt_pin_attach_irq(KEY_UP, PIN_IRQ_MODE_FALLING, key_up_callback, RT_NULL);
|
||||
rt_pin_attach_irq(KEY_DOWN, PIN_IRQ_MODE_FALLING, key_down_callback, RT_NULL);
|
||||
rt_pin_attach_irq(KEY_LEFT, PIN_IRQ_MODE_FALLING, key_left_callback, RT_NULL);
|
||||
rt_pin_attach_irq(KEY_RIGHT, PIN_IRQ_MODE_FALLING, key_right_callback, RT_NULL);
|
||||
|
||||
rt_pin_irq_enable(KEY_UP,PIN_IRQ_ENABLE);
|
||||
rt_pin_irq_enable(KEY_DOWN,PIN_IRQ_ENABLE);
|
||||
rt_pin_irq_enable(KEY_LEFT,PIN_IRQ_ENABLE);
|
||||
rt_pin_irq_enable(KEY_RIGHT,PIN_IRQ_ENABLE);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(rt_pin_irq_example,irq, pin_irq_example);
|
@@ -1,18 +0,0 @@
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
static int rt_device_test_init(void)
|
||||
{
|
||||
rt_device_t test_dev = rt_device_create(RT_Device_Class_Char,0);
|
||||
if(!test_dev)
|
||||
{
|
||||
rt_kprintf("test_dev create failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if(rt_device_register(test_dev,"test_dev",RT_DEVICE_FLAG_RDWR)!=RT_EOK)
|
||||
{
|
||||
rt_kprintf("test_dev register failed\n");
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(rt_device_test_init,devtest, test device init);
|
Reference in New Issue
Block a user