Fix LD2410 bad reception detection

This commit is contained in:
Theo Arends 2022-12-04 12:37:50 +01:00
parent fca19401b7
commit 5f8ef0c5cb
1 changed files with 31 additions and 30 deletions

View File

@ -80,6 +80,7 @@ uint32_t ToBcd(uint32_t value) {
/********************************************************************************************/ /********************************************************************************************/
void Ld1410HandleTargetData(void) { void Ld1410HandleTargetData(void) {
if ((0x0D == LD2410.buffer[4]) && (0x55 == LD2410.buffer[17])) { // Add bad reception detection
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
// F4 F3 F2 F1 0D 00 02 AA 00 00 00 00 00 00 37 00 00 55 00 F8 F7 F6 F5 - No target // F4 F3 F2 F1 0D 00 02 AA 00 00 00 00 00 00 37 00 00 55 00 F8 F7 F6 F5 - No target
// F4 F3 F2 F1 0D 00 02 AA 00 45 00 3E 00 00 3A 00 00 55 00 F8 F7 F6 F5 - No target // F4 F3 F2 F1 0D 00 02 AA 00 45 00 3E 00 00 3A 00 00 55 00 F8 F7 F6 F5 - No target
@ -94,13 +95,13 @@ void Ld1410HandleTargetData(void) {
LD2410.static_distance = LD2410.buffer[13] << 8 | LD2410.buffer[12]; LD2410.static_distance = LD2410.buffer[13] << 8 | LD2410.buffer[12];
LD2410.static_energy = LD2410.buffer[14]; LD2410.static_energy = LD2410.buffer[14];
LD2410.detect_distance = LD2410.buffer[16] << 8 | LD2410.buffer[15]; LD2410.detect_distance = LD2410.buffer[16] << 8 | LD2410.buffer[15];
/* /*
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("LD2: Type %d, State %d, Moving %d/%d%%, Static %d/%d%%, Detect %d"), AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("LD2: Type %d, State %d, Moving %d/%d%%, Static %d/%d%%, Detect %d"),
LD2410.buffer[6], LD2410.buffer[8], LD2410.buffer[6], LD2410.buffer[8],
LD2410.moving_distance, LD2410.moving_energy, LD2410.moving_distance, LD2410.moving_energy,
LD2410.static_distance, LD2410.static_energy, LD2410.static_distance, LD2410.static_energy,
LD2410.detect_distance); LD2410.detect_distance);
*/ */
if (0x01 == LD2410.buffer[6]) { // Engineering mode data if (0x01 == LD2410.buffer[6]) { // Engineering mode data
// Adds 22 extra bytes of data // Adds 22 extra bytes of data
@ -112,6 +113,7 @@ void Ld1410HandleTargetData(void) {
LD2410.static_energy = 0; LD2410.static_energy = 0;
LD2410.detect_distance = 0; LD2410.detect_distance = 0;
} }
}
} }
void Ld1410HandleConfigData(void) { void Ld1410HandleConfigData(void) {
@ -403,7 +405,6 @@ void Ld2410Detect(void) {
LD2410.buffer = (uint8_t*)malloc(LD2410_BUFFER_SIZE); // Default 64 LD2410.buffer = (uint8_t*)malloc(LD2410_BUFFER_SIZE); // Default 64
if (!LD2410.buffer) { return; } if (!LD2410.buffer) { return; }
LD2410Serial = new TasmotaSerial(Pin(GPIO_LD2410_RX), Pin(GPIO_LD2410_TX), 2); LD2410Serial = new TasmotaSerial(Pin(GPIO_LD2410_RX), Pin(GPIO_LD2410_TX), 2);
// LD2410Serial = new TasmotaSerial(Pin(GPIO_LD2410_RX), Pin(GPIO_LD2410_TX), 2, 1);
if (LD2410Serial->begin(256000)) { if (LD2410Serial->begin(256000)) {
if (LD2410Serial->hardwareSerial()) { ClaimSerial(); } if (LD2410Serial->hardwareSerial()) { ClaimSerial(); }