Реализована функция lidar_update(), обновляющая данные

This commit is contained in:
Radzhab Bisultanov
2026-02-20 15:16:59 +03:00
parent a6f47a2e73
commit 2b3e4129e8
2 changed files with 29 additions and 12 deletions

View File

@@ -7,6 +7,8 @@
#define USART3_START_BYTE 0x59 #define USART3_START_BYTE 0x59
#define USART3_FRAME_SIZE 9 #define USART3_FRAME_SIZE 9
#define LIDAR_MIN_DIST 0.01f
#define LIDAR_MAX_DIST 40.0f
typedef struct typedef struct
{ {
@@ -21,7 +23,14 @@ typedef struct
uint8_t checksum; uint8_t checksum;
} lidar_data_buf; } lidar_data_buf;
typedef struct
{
uint16_t distance; // meters
uint16_t strength;
uint16_t temperature;
} lidar_data;
void lidar_init(); void lidar_init();
void lidar_update(); void lidar_update(lidar_data* lidar);
#endif #endif

View File

@@ -75,17 +75,25 @@ void USART3_IRQHandler()
if (usart3_index == USART3_FRAME_SIZE) if (usart3_index == USART3_FRAME_SIZE)
{ {
for (uint8_t i = 0; i < USART3_FRAME_SIZE; ++i) usart3_checksum += buff_data[i]; usart3_index = 0;
if (buffer.checksum == usart3_checksum) usart3_frame_ready = 1;
{
usart3_index = 0;
usart3_frame_ready = 1;
}
else
{
usart3_index = 0;
usart3_frame_ready = 0;
}
} }
} }
} }
void lidar_update(lidar_data* lidar)
{
if (!usart3_frame_ready)
return;
usart3_frame_ready = 0;
for (uint8_t i = 0; i < USART3_FRAME_SIZE; ++i) usart3_checksum += buff_data[i];
if (buffer.checksum != usart3_checksum)
return;
lidar->distance = buffer.distance_l | (buffer.distance_h << 8);
lidar->strength = buffer.strength_l | (buffer.strength_h << 8);
lidar->temperature = buffer.temp_l | (buffer.temp_h << 8);
}