freeRTOS操作系统机器人实现
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.7 KiB

3 days ago
/******************************************************************************
(C), 2018-2099, Radkil_Std
******************************************************************************
: peripheral.c
: 稿
: Radkil
: 2023213
:
:
:
1. : 2023213
: Radkil
:
******************************************************************************/
#include <unistd.h>
#include "led.h"
#include "button.h"
#include "common.h"
#include "rd_time.h"
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
#ifdef MAIN
#include "rd_thread.h"
static void *rd_Led_Proc(void *arg)
{
while (1)
{
rd_LedProcess();
Rd_Delay(100);
}
return (void *)0;
}
int rd_Led_init(void)
{
pthread_t pTid;
int iRet = RD_SUCCESS;
iRet = pthread_create(&pTid, NULL, rd_Led_Proc, NULL);
return iRet;
}
void Test_led(l_led_t *pLed, int _iState)
{
log_i("lzd = %d", _iState);
}
void Test_led0(l_led_t *pLed, int _iState)
{
log_i("======= = %d", _iState);
}
int Btn(void)
{
/*if (0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_15)) return 0;
else if (0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14)) return 1;
else if (0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13)) return 2;
else if (0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12)) return 3;
else*/
return -1;
}
void Btn15cbk(rd_btn_t *pBtn)
{
printf("Radkil 15 EVENT_PRESS_DOWN !\r\n");
}
void Btn14cbk(rd_btn_t *pBtn)
{
printf("Radkil 14 EVENT_HOLD !\r\n");
}
void Btn13cbk(rd_btn_t *pBtn)
{
printf("Radkil 13 EVENT_PRESS_UP !\r\n");
}
void Btn12cbk(rd_btn_t *pBtn)
{
printf("Radkil 12 EVENT_CLICK !\r\n");
}
int main(int argc, const char *argv[])
{
RD_INIT();
rd_btn_t *pBtn15 = rd_BtnCreate(0);
rd_btn_t *pBtn14 = rd_BtnCreate(1);
rd_btn_t *pBtn13 = rd_BtnCreate(2);
rd_btn_t *pBtn12 = rd_BtnCreate(3);
rd_BtnSetEventCbk(pBtn15, EVENT_PRESS_DOWN, Btn15cbk);
rd_BtnSetEventCbk(pBtn14, EVENT_HOLD, Btn14cbk);
rd_BtnSetEventCbk(pBtn13, EVENT_PRESS_UP, Btn13cbk);
rd_BtnSetEventCbk(pBtn12, EVENT_CLICK, Btn12cbk);
rd_BtnStart(pBtn15);
rd_BtnStart(pBtn14);
rd_BtnStart(pBtn13);
rd_BtnStart(pBtn12);
rd_led_t *dled0 = rd_LedCreate(0, "500,500", 1, Test_led, NULL);
rd_led_t *dled1 = rd_LedCreate(0, "1000,1000", 1, Test_led0, NULL);
rd_LedDynamicChangeLightMode(dled0, "1000,1000", 1);
rd_LedDynamicChangeLightMode(dled1, "1000,1000", 1);
rd_LedStart(dled0);
rd_LedStart(dled1);
while(1)
{
rd_LedProcess();
rd_BtnProcess(Btn);
}
return 0;
}
#endif