// ===================================================================== // ZoneManager.h // // Rectangular detection-zone logic, ported from the ESP32-LD2450 // project's main_zone.cpp. Works entirely on RadarTarget X/Y values, // so it is unaffected by however LD2453Parser ends up decoding raw // frames — nothing here needs to change once the parser is confirmed. // ===================================================================== #pragma once #include #include "LD2453Parser.h" static const uint8_t MAX_ZONES = 3; struct Zone { int x1, y1, x2, y2; // millimeters, same coordinate system as RadarTarget }; class ZoneManager { public: ZoneManager(); // Re-evaluate occupancy for all zones against the targets in // `frame`. Call this once per new radar frame. void update(const RadarFrame &frame); bool isZoneOccupied(uint8_t zoneIndex) const; Zone getZone(uint8_t zoneIndex) const; void setZone(uint8_t zoneIndex, const Zone &zone); // Serialize current zone definitions to JSON, e.g. for GET /zones. // Returns the JSON string. String zonesToJson() const; // Parse a JSON body (as sent by POST /updateZones) and update // zones in place. Missing fields keep their previous value. // Returns false on JSON parse failure. bool zonesFromJson(const uint8_t *data, size_t len); private: Zone _zones[MAX_ZONES]; bool _occupied[MAX_ZONES]; static bool pointInZone(int x, int y, const Zone &z); };