From d0d2f216d273ec1f49c268275cd82d2bf5a40988 Mon Sep 17 00:00:00 2001 From: chenxin Date: Wed, 18 Jun 2025 14:45:24 +0800 Subject: [PATCH] main --- src/i2c_communication.cpp | 6 ++++-- src/i2c_communication.h | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/i2c_communication.cpp b/src/i2c_communication.cpp index 673d2cf..31dbb3a 100644 --- a/src/i2c_communication.cpp +++ b/src/i2c_communication.cpp @@ -62,7 +62,8 @@ void onReceiveEvent(int bytes) { static uint8_t last_receive_cnt = 0; void update_sensor_data() { //gps - if (millis() > 5000 && gps.charsProcessed() < 10 && digitalRead(GPS_POWER_PIN) == HIGH) { + //if (millis() > 5000 && gps.charsProcessed() < 10 && digitalRead(GPS_POWER_PIN) == HIGH) + if (millis() > 5000 && gps.charsProcessed() < 10) { sensor_data.gps_sta = 0x00; // 无设备 sensor_data.gps_lat = 0.0f; sensor_data.gps_lon = 0.0f; @@ -81,7 +82,8 @@ void update_sensor_data() { } //测距 - if (receive_cnt == last_receive_cnt && digitalRead(RANGING_POWER_PIN) == HIGH) { + //if (receive_cnt == last_receive_cnt && digitalRead(RANGING_POWER_PIN) == HIGH) + if (receive_cnt == last_receive_cnt){ sensor_data.height_sta = 0x00; // 无设备 sensor_data.height = 0.0f; }else if (digitalRead(RANGING_POWER_PIN) == LOW){ diff --git a/src/i2c_communication.h b/src/i2c_communication.h index 422f89f..e16e8c7 100644 --- a/src/i2c_communication.h +++ b/src/i2c_communication.h @@ -13,13 +13,14 @@ // 数据结构定义 typedef struct { - uint8_t gps_sta; // 0x00 ~ 0x03 - uint8_t height_sta; // 0x00 ~ 0x01 - float gps_lat; - float gps_lon; - float height; + uint8_t gps_sta; // 0x00 ~ 0x03 ////0x00没有设备,0x01关机,0x02没有搜到gps,0x03搜到gps + uint8_t height_sta; // 0x00 ~ 0x01 ////0x00没有设备,0x01关机 + float gps_lat; //没有设备返回0 + float gps_lon; //没有设备返回0 + float height; //没有设备返回0 } hh3_slave_data; - +//03 03 00 00 C4 79 09 42 2E B1 D9 42 E3 A5 9B 3C +//00 00 由编译器自动插入的内存对齐填充字节,用于确保后续的 float 类型字段(如 gps_lat)能够正确地按照 4 字节对齐存储在内存中。 extern hh3_slave_data sensor_data; // 函数声明