mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	[ld2450] Fix misplaced `ifdef` and related logic (#8335)
				
					
				
			This commit is contained in:
		| @@ -386,10 +386,11 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, uint8_t len) { | |||||||
|   std::string direction{}; |   std::string direction{}; | ||||||
|   bool is_moving = false; |   bool is_moving = false; | ||||||
|  |  | ||||||
| #ifdef USE_SENSOR | #if defined(USE_BINARY_SENSOR) || defined(USE_SENSOR) || defined(USE_TEXT_SENSOR) | ||||||
|   // Loop thru targets |   // Loop thru targets | ||||||
|   // X |  | ||||||
|   for (index = 0; index < MAX_TARGETS; index++) { |   for (index = 0; index < MAX_TARGETS; index++) { | ||||||
|  | #ifdef USE_SENSOR | ||||||
|  |     // X | ||||||
|     start = TARGET_X + index * 8; |     start = TARGET_X + index * 8; | ||||||
|     is_moving = false; |     is_moving = false; | ||||||
|     sensor::Sensor *sx = this->move_x_sensors_[index]; |     sensor::Sensor *sx = this->move_x_sensors_[index]; | ||||||
| @@ -406,18 +407,6 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, uint8_t len) { | |||||||
|       ty = val; |       ty = val; | ||||||
|       sy->publish_state(val); |       sy->publish_state(val); | ||||||
|     } |     } | ||||||
|     // SPEED |  | ||||||
|     start = TARGET_SPEED + index * 8; |  | ||||||
|     sensor::Sensor *ss = this->move_speed_sensors_[index]; |  | ||||||
|     if (ss != nullptr) { |  | ||||||
|       val = ld2450::decode_speed(buffer[start], buffer[start + 1]); |  | ||||||
|       ts = val; |  | ||||||
|       if (val) { |  | ||||||
|         is_moving = true; |  | ||||||
|         moving_target_count++; |  | ||||||
|       } |  | ||||||
|       ss->publish_state(val); |  | ||||||
|     } |  | ||||||
|     // RESOLUTION |     // RESOLUTION | ||||||
|     start = TARGET_RESOLUTION + index * 8; |     start = TARGET_RESOLUTION + index * 8; | ||||||
|     sensor::Sensor *sr = this->move_resolution_sensors_[index]; |     sensor::Sensor *sr = this->move_resolution_sensors_[index]; | ||||||
| @@ -425,9 +414,22 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, uint8_t len) { | |||||||
|       val = (buffer[start + 1] << 8) | buffer[start]; |       val = (buffer[start + 1] << 8) | buffer[start]; | ||||||
|       sr->publish_state(val); |       sr->publish_state(val); | ||||||
|     } |     } | ||||||
|  | #endif | ||||||
|  |     // SPEED | ||||||
|  |     start = TARGET_SPEED + index * 8; | ||||||
|  |     val = ld2450::decode_speed(buffer[start], buffer[start + 1]); | ||||||
|  |     ts = val; | ||||||
|  |     if (val) { | ||||||
|  |       is_moving = true; | ||||||
|  |       moving_target_count++; | ||||||
|  |     } | ||||||
|  | #ifdef USE_SENSOR | ||||||
|  |     sensor::Sensor *ss = this->move_speed_sensors_[index]; | ||||||
|  |     if (ss != nullptr) { | ||||||
|  |       ss->publish_state(val); | ||||||
|  |     } | ||||||
|  | #endif | ||||||
|     // DISTANCE |     // DISTANCE | ||||||
|     sensor::Sensor *sd = this->move_distance_sensors_[index]; |  | ||||||
|     if (sd != nullptr) { |  | ||||||
|     val = (uint16_t) sqrt( |     val = (uint16_t) sqrt( | ||||||
|         pow(ld2450::decode_coordinate(buffer[TARGET_X + index * 8], buffer[(TARGET_X + index * 8) + 1]), 2) + |         pow(ld2450::decode_coordinate(buffer[TARGET_X + index * 8], buffer[(TARGET_X + index * 8) + 1]), 2) + | ||||||
|         pow(ld2450::decode_coordinate(buffer[TARGET_Y + index * 8], buffer[(TARGET_Y + index * 8) + 1]), 2)); |         pow(ld2450::decode_coordinate(buffer[TARGET_Y + index * 8], buffer[(TARGET_Y + index * 8) + 1]), 2)); | ||||||
| @@ -435,7 +437,9 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, uint8_t len) { | |||||||
|     if (val > 0) { |     if (val > 0) { | ||||||
|       target_count++; |       target_count++; | ||||||
|     } |     } | ||||||
|  | #ifdef USE_SENSOR | ||||||
|  |     sensor::Sensor *sd = this->move_distance_sensors_[index]; | ||||||
|  |     if (sd != nullptr) { | ||||||
|       sd->publish_state(val); |       sd->publish_state(val); | ||||||
|     } |     } | ||||||
|     // ANGLE |     // ANGLE | ||||||
| @@ -448,8 +452,8 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, uint8_t len) { | |||||||
|       sa->publish_state(angle); |       sa->publish_state(angle); | ||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|     // DIRECTION |  | ||||||
| #ifdef USE_TEXT_SENSOR | #ifdef USE_TEXT_SENSOR | ||||||
|  |     // DIRECTION | ||||||
|     direction = get_direction(ts); |     direction = get_direction(ts); | ||||||
|     if (td == 0) { |     if (td == 0) { | ||||||
|       direction = "NA"; |       direction = "NA"; | ||||||
| @@ -467,6 +471,9 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, uint8_t len) { | |||||||
|  |  | ||||||
|   }  // End loop thru targets |   }  // End loop thru targets | ||||||
|  |  | ||||||
|  |   still_target_count = target_count - moving_target_count; | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #ifdef USE_SENSOR | #ifdef USE_SENSOR | ||||||
|   // Loop thru zones |   // Loop thru zones | ||||||
|   uint8_t zone_still_targets = 0; |   uint8_t zone_still_targets = 0; | ||||||
| @@ -496,7 +503,6 @@ void LD2450Component::handle_periodic_data_(uint8_t *buffer, uint8_t len) { | |||||||
|  |  | ||||||
|   }  // End loop thru zones |   }  // End loop thru zones | ||||||
|  |  | ||||||
|   still_target_count = target_count - moving_target_count; |  | ||||||
|   // Target Count |   // Target Count | ||||||
|   if (this->target_count_sensor_ != nullptr) { |   if (this->target_count_sensor_ != nullptr) { | ||||||
|     this->target_count_sensor_->publish_state(target_count); |     this->target_count_sensor_->publish_state(target_count); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user