按键控制运动(方向)
This commit is contained in:
@@ -4,14 +4,17 @@
|
||||
#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 ;
|
||||
void key_up_callback(void *args)
|
||||
{
|
||||
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);
|
||||
}
|
||||
@@ -19,17 +22,20 @@ void key_up_callback(void *args)
|
||||
void key_down_callback(void *args)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user