From 1f85c6cc4b829c8dbce1de6b79836063be778dc2 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Sat, 7 Sep 2024 17:43:07 +0200 Subject: [PATCH] Added temperature type --- NetworkSync.cpp | 6 +++--- Sensor.h | 4 ---- TemperatureSensor.cpp | 2 +- TemperatureSensor.h | 1 - Thing.cpp | 3 +++ Thing.h | 5 ++++- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/NetworkSync.cpp b/NetworkSync.cpp index 7616d63..b6050ad 100644 --- a/NetworkSync.cpp +++ b/NetworkSync.cpp @@ -224,7 +224,7 @@ void NetworkSync::BroadcastPerception(Roboid *roboid) { if (perception == nullptr) return; - for (int sensorIx = 0; sensorIx < perception->sensorCount; sensorIx++) { + for (unsigned int sensorIx = 0; sensorIx < perception->sensorCount; sensorIx++) { Sensor* sensor = perception->sensors[sensorIx]; if (sensor == nullptr) continue; @@ -362,7 +362,7 @@ void NetworkSync::SendText(const char* s) { if (length >= 253) return; - unsigned char ix; + unsigned char ix = 0; buffer[ix++] = 0xB0; buffer[ix++] = length; for (int urlIx = 0; urlIx < length; urlIx++) @@ -375,7 +375,7 @@ void NetworkSync::SendInt(const int x) { String s = String(x); byte length = s.length(); - unsigned char ix; + unsigned char ix = 0; buffer[ix++] = 0xB0; buffer[ix++] = length; for (int urlIx = 0; urlIx < length; urlIx++) diff --git a/Sensor.h b/Sensor.h index fec6cd4..11a79d8 100644 --- a/Sensor.h +++ b/Sensor.h @@ -17,10 +17,6 @@ public: virtual void BroadcastState() {}; - enum SensorType { - Unknown = 0, - Temperature = 1, - }; virtual void* GetValue() { return nullptr; }; }; diff --git a/TemperatureSensor.cpp b/TemperatureSensor.cpp index 8f57215..009317a 100644 --- a/TemperatureSensor.cpp +++ b/TemperatureSensor.cpp @@ -2,7 +2,7 @@ TemperatureSensor::TemperatureSensor() { - this->type = (unsigned int) SensorType::Temperature; + this->type = Thing::TemperatureSensorType; } float TemperatureSensor::InCelsius() diff --git a/TemperatureSensor.h b/TemperatureSensor.h index 01f7f92..b3630ba 100644 --- a/TemperatureSensor.h +++ b/TemperatureSensor.h @@ -11,7 +11,6 @@ public: float InCelsius(); virtual void* GetValue() override; - // virtual void BroadcastState() override; protected: float temperature = 0; // in Celsius }; diff --git a/Thing.cpp b/Thing.cpp index c154374..1f346a0 100644 --- a/Thing.cpp +++ b/Thing.cpp @@ -13,6 +13,9 @@ Thing::Thing(unsigned char id) : id(id) { const unsigned int Thing::SwitchType = SensorType | (unsigned int)Type::Switch; const unsigned int Thing::DistanceSensorType = SensorType | (unsigned int)Type::DistanceSensor; +const unsigned int Thing::TemperatureSensorType = + SensorType | (unsigned int)Type::TemperatureSensor; + const unsigned int Thing::ControlledMotorType = MotorType | (unsigned int)Type::ControlledMotor; const unsigned int Thing::UncontrolledMotorType = diff --git a/Thing.h b/Thing.h index 2aad418..68e72ac 100644 --- a/Thing.h +++ b/Thing.h @@ -1,6 +1,5 @@ #pragma once -// #include "LinearAlgebra/Polar.h" #include "LinearAlgebra/Quaternion.h" #include "LinearAlgebra/Spherical.h" @@ -18,10 +17,13 @@ class Thing { /// @brief The type of Thing unsigned int type; + // I hate this, better is to have an additional field stating the thing classificaton + // Motor, Sensor etc. /// @brief The type of a switch sensor static const unsigned int SwitchType; /// @brief The type of a distance sensor static const unsigned int DistanceSensorType; + static const unsigned int TemperatureSensorType; /// @brief The type of a controlled motor static const unsigned int ControlledMotorType; /// @brief The type of an uncontrolled motor @@ -96,6 +98,7 @@ class Thing { // Sensor, Switch, DistanceSensor, + TemperatureSensor, // Motor, ControlledMotor, UncontrolledMotor,