From 60a12f26ad6ac8c7f1f9b2d7d745e519a65a199d Mon Sep 17 00:00:00 2001 From: chenxin Date: Wed, 18 Jun 2025 11:26:47 +0800 Subject: [PATCH] main --- src/main.cpp | 86 +++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a0c93d4..5559a1e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,7 +93,7 @@ void printSensorData() { switch (sensor_data.height_sta) { case 0x00: Serial.println("No Device"); break; case 0x01: Serial.println("Power Off"); break; - case 0x02: Serial.println("Valid"); break; + case 0x03: Serial.println("Valid"); break; default: Serial.println("Unknown"); break; } @@ -111,53 +111,55 @@ void setup() { Wire.begin(1,2); Serial.println("I2C Master Started..."); - delay(1000); + delay(500); } -// void loop() { - -// // 请求传感器数据 -// if (requestData()) { -// printSensorData(); -// } - -// delay(2000); - -// // sendCommand(0x02); -// // delay(2000); -// // sendCommand(0x04); -// } - -#define INTERVAL 5000 - -unsigned long previousMillis = 0; // 上次执行的时间点 -bool isGpsOn = true; // GPS 状态标志 - void loop() { - unsigned long currentMillis = millis(); - // 检查是否达到时间间隔 - if (currentMillis - previousMillis >= INTERVAL) { - previousMillis = currentMillis; - - // 切换状态 - if (isGpsOn) { - sendCommand(CMD_GPS_POWER_OFF); // 关闭 GPS - sendCommand(CMD_RANGING_POWER_OFF); // 关闭测距 - Serial.println("CLOSE..."); - } else { - sendCommand(CMD_GPS_POWER_ON); // 开启 GPS - sendCommand(CMD_RANGING_POWER_ON); // 开启测距 - Serial.println("OPEN..."); - } - - isGpsOn = !isGpsOn; // 翻转状态 - } - - // 请求传感器数据并打印 + // 请求传感器数据 if (requestData()) { printSensorData(); } - delay(1500); + + delay(1000); + + // sendCommand(0x02); + // delay(2000); + // sendCommand(0x04); } + +// ******命令测试************ +// #define INTERVAL 5000 + +// unsigned long previousMillis = 0; // 上次执行的时间点 +// bool isGpsOn = true; // GPS 状态标志 + +// void loop() { +// unsigned long currentMillis = millis(); + +// // 检查是否达到时间间隔 +// if (currentMillis - previousMillis >= INTERVAL) { +// previousMillis = currentMillis; + +// // 切换状态 +// if (isGpsOn) { +// sendCommand(CMD_GPS_POWER_OFF); // 关闭 GPS +// sendCommand(CMD_RANGING_POWER_OFF); // 关闭测距 +// Serial.println("CLOSE..."); +// } else { +// sendCommand(CMD_GPS_POWER_ON); // 开启 GPS +// sendCommand(CMD_RANGING_POWER_ON); // 开启测距 +// Serial.println("OPEN..."); +// } + +// isGpsOn = !isGpsOn; // 翻转状态 +// } + +// // 请求传感器数据并打印 +// if (requestData()) { +// printSensorData(); +// } +// delay(1500); +// } +