暂存
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
<FLASH_IRQHandler>0;0;0</FLASH_IRQHandler>
|
||||
<CRM_IRQHandler>0;0;0</CRM_IRQHandler>
|
||||
<CAN1_TX_IRQHandler>0;0;0</CAN1_TX_IRQHandler>
|
||||
<CAN1_RX0_IRQHandler>0;0;0</CAN1_RX0_IRQHandler>
|
||||
<CAN1_RX0_IRQHandler>1;0;0</CAN1_RX0_IRQHandler>
|
||||
<CAN1_RX1_IRQHandler>0;0;0</CAN1_RX1_IRQHandler>
|
||||
<CAN1_SE_IRQHandler>0;0;0</CAN1_SE_IRQHandler>
|
||||
<TMR1_OVF_TMR10_IRQHandler>0;0;0</TMR1_OVF_TMR10_IRQHandler>
|
||||
@@ -67,7 +67,6 @@
|
||||
<Signal SignalName="GPIO_Output" PinName="PB6">
|
||||
<Parameters name="GPIO_Outputlevel" value="GPIO_OUTPUTLEVEL_HIGH"/>
|
||||
<Parameters name="GPIO_Type" value="GPIO_OUTPUT_OPEN_DRAIN"/>
|
||||
<Parameters name="GPIO_DriverCapability" value="GPIO_DRIVE_STRENGTH_STRONGER"/>
|
||||
</Signal>
|
||||
<Signal SignalName="GPIO_Output" PinName="PB7">
|
||||
<Parameters name="GPIO_Outputlevel" value="GPIO_OUTPUTLEVEL_HIGH"/>
|
||||
|
||||
37
app/by_measure.c
Normal file
37
app/by_measure.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "by_measure.h"
|
||||
|
||||
#include "by_debug.h"
|
||||
#include "vl53l0x_wmd_api.h"
|
||||
|
||||
void by_measure_init(void)
|
||||
{
|
||||
VL53L0X_Init();
|
||||
}
|
||||
|
||||
void by_measure_run(void)
|
||||
{
|
||||
float x = VL53L0X_GetValue();
|
||||
float distance = x;
|
||||
static float distance_last = 0;
|
||||
|
||||
if (x < 270) {
|
||||
distance = x - 80.0f;
|
||||
} else if (x < 330) {
|
||||
distance = 2.0755f * x - 368.85f;
|
||||
}
|
||||
|
||||
// 错误值
|
||||
if (distance <= 20 || distance > 330) {
|
||||
distance = distance_last;
|
||||
}
|
||||
|
||||
// if (distance <= 20) {
|
||||
// distance = distance_last;
|
||||
// } else if (distance > 330) {
|
||||
// distance = 330;
|
||||
// }
|
||||
|
||||
distance_last = distance;
|
||||
|
||||
LOGI("distance:%f", distance);
|
||||
}
|
||||
8
app/by_measure.h
Normal file
8
app/by_measure.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _BY_MEASURE_H__
|
||||
#define _BY_MEASURE_H__
|
||||
|
||||
|
||||
void by_measure_init(void);
|
||||
void by_measure_run(void);
|
||||
|
||||
#endif
|
||||
@@ -65,6 +65,7 @@ void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
|
||||
void CAN1_RX0_IRQHandler(void);
|
||||
void TMR4_GLOBAL_IRQHandler(void);
|
||||
|
||||
/* add user code begin exported functions */
|
||||
|
||||
@@ -204,6 +204,25 @@ void PendSV_Handler(void)
|
||||
/* add user code end PendSV_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles CAN1 RX0 handler.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void CAN1_RX0_IRQHandler(void)
|
||||
{
|
||||
/* add user code begin CAN1_RX0_IRQ 0 */
|
||||
if (SET == can_interrupt_flag_get(CAN1, CAN_RF0MN_FLAG)){
|
||||
can_rx_message_type can_rx_message;
|
||||
can_message_receive(CAN1, CAN_RX_FIFO0, &can_rx_message);
|
||||
can_flag_clear(CAN1, CAN_RF0MN_FLAG);
|
||||
}
|
||||
/* add user code end CAN1_RX0_IRQ 0 */
|
||||
/* add user code begin CAN1_RX0_IRQ 1 */
|
||||
|
||||
/* add user code end CAN1_RX0_IRQ 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles TMR4 handler.
|
||||
* @param none
|
||||
|
||||
@@ -189,6 +189,7 @@ void wk_nvic_config(void)
|
||||
{
|
||||
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||
|
||||
nvic_irq_enable(CAN1_RX0_IRQn, 0, 0);
|
||||
nvic_irq_enable(TMR4_GLOBAL_IRQn, 0, 0);
|
||||
}
|
||||
|
||||
@@ -224,14 +225,7 @@ void wk_gpio_config(void)
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
||||
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_6;
|
||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||
gpio_init(GPIOB, &gpio_init_struct);
|
||||
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
|
||||
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_7;
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7;
|
||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||
gpio_init(GPIOB, &gpio_init_struct);
|
||||
|
||||
@@ -457,8 +451,16 @@ void wk_can1_init(void)
|
||||
|
||||
can_filter_init(CAN1, &can_filter_init_struct);
|
||||
|
||||
/* add user code begin can1_init 2 */
|
||||
/**
|
||||
* Users need to configure CAN1 interrupt functions according to the actual application.
|
||||
* 1. Call the below function to enable the corresponding CAN1 interrupt.
|
||||
* --can_interrupt_enable(...)
|
||||
* 2. Add the user's interrupt handler code into the below function in the at32f415_int.c file.
|
||||
* --void CAN1_RX0_IRQHandler(void)
|
||||
*/
|
||||
|
||||
/* add user code begin can1_init 2 */
|
||||
can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE);
|
||||
/* add user code end can1_init 2 */
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
|
||||
/* private includes ----------------------------------------------------------*/
|
||||
/* add user code begin private includes */
|
||||
#include "vl53l0x_wmd_api.h"
|
||||
#include "by_debug.h"
|
||||
#include "by_led.h"
|
||||
#include "by_measure.h"
|
||||
/* add user code end private includes */
|
||||
|
||||
/* private typedef -----------------------------------------------------------*/
|
||||
@@ -105,25 +105,15 @@ int main(void)
|
||||
/* add user code begin 2 */
|
||||
delay_init();
|
||||
by_led_set(10);
|
||||
delay_ms(1000);
|
||||
VL53L0X_Init();
|
||||
delay_ms(1000);
|
||||
by_measure_init();
|
||||
|
||||
by_led_set(0);
|
||||
/* add user code end 2 */
|
||||
|
||||
while (1) {
|
||||
/* add user code begin 3 */
|
||||
// gpio_bits_write(GPIOB, GPIO_PINS_8, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_8));
|
||||
// gpio_bits_set(GPIOA, GPIO_PINS_4);
|
||||
// delay_ms(250);
|
||||
// gpio_bits_reset(GPIOA, GPIO_PINS_4);
|
||||
// delay_ms(250);
|
||||
by_led_set(40);
|
||||
delay_ms(10);
|
||||
LOGI("distance:%d", VL53L0X_GetValue());
|
||||
by_led_set(0);
|
||||
delay_ms(10);
|
||||
gpio_bits_write(GPIOA, GPIO_PINS_4, !gpio_output_data_bit_read(GPIOA, GPIO_PINS_4));
|
||||
by_measure_run();
|
||||
/* add user code end 3 */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user