#include "DistanceSensor.h" #include DistanceSensor::DistanceSensor() { this->type = Thing::DistanceSensorType; this->distance = INFINITY; this->triggerDistance = 1.0F; } DistanceSensor::DistanceSensor(float triggerDistance) : DistanceSensor() { this->triggerDistance = triggerDistance; } float DistanceSensor::GetDistance() { if (distance < minRange || distance > maxRange) return -1; // invalid distance return distance; }; bool DistanceSensor::ObjectNearby() { if (distance < minRange || distance > maxRange) return false; bool isOn = distance <= triggerDistance; return isOn; }