diff --git a/firmware/baseband/fprotos/weatherprotos.hpp b/firmware/baseband/fprotos/weatherprotos.hpp index 9e08bb27..38c2887f 100644 --- a/firmware/baseband/fprotos/weatherprotos.hpp +++ b/firmware/baseband/fprotos/weatherprotos.hpp @@ -38,37 +38,48 @@ So include here the .hpp, and add a new element to the protos vector in the cons class WeatherProtos : public FProtoListGeneral { public: + WeatherProtos(const WeatherProtos&) { WeatherProtos(); }; // won't use, but makes compiler happy + WeatherProtos& operator=(const WeatherProtos&) { return *this; } // won't use, but makes compiler happy WeatherProtos() { // add protos - protos.push_back(std::make_unique()); // 1 - protos.push_back(std::make_unique()); // 2 - protos.push_back(std::make_unique()); // 3 - protos.push_back(std::make_unique()); // 4 - protos.push_back(std::make_unique()); // 5 - protos.push_back(std::make_unique()); // 6 - protos.push_back(std::make_unique()); // 7 - protos.push_back(std::make_unique()); // 8 - protos.push_back(std::make_unique()); // 9 - protos.push_back(std::make_unique()); // 10 - protos.push_back(std::make_unique()); // 11 - protos.push_back(std::make_unique()); // 12 - protos.push_back(std::make_unique()); // 13 - protos.push_back(std::make_unique()); // 14 - protos.push_back(std::make_unique()); // 15 - protos.push_back(std::make_unique()); // 16 - protos.push_back(std::make_unique()); // 17 - protos.push_back(std::make_unique()); // 18 - protos.push_back(std::make_unique()); // 19 - protos.push_back(std::make_unique()); // 20 - protos.push_back(std::make_unique()); // 21 - protos.push_back(std::make_unique()); // 22 + protos[FPW_NexusTH] = new FProtoWeatherNexusTH(); + protos[FPW_Acurite592TXR] = new FProtoWeatherAcurite592TXR(); + protos[FPW_Acurite606TX] = new FProtoWeatherAcurite606TX(); + protos[FPW_Acurite609TX] = new FProtoWeatherAcurite609TX(); + protos[FPW_Ambient] = new FProtoWeatherAmbient(); + protos[FPW_AuriolAhfl] = new FProtoWeatherAuriolAhfl(); + protos[FPW_AuriolTH] = new FProtoWeatherAuriolTh(); + protos[FPW_GTWT02] = new FProtoWeatherGTWT02(); + protos[FPW_GTWT03] = new FProtoWeatherGTWT03(); + protos[FPW_INFACTORY] = new FProtoWeatherInfactory(); + protos[FPW_LACROSSETX] = new FProtoWeatherLaCrosseTx(); + protos[FPW_LACROSSETX141thbv2] = new FProtoWeatherLaCrosseTx141thbv2(); + protos[FPW_OREGON2] = new FProtoWeatherOregon2(); + protos[FPW_OREGON3] = new FProtoWeatherOregon3(); + protos[FPW_OREGONv1] = new FProtoWeatherOregonV1(); + protos[FPW_THERMOPROTX4] = new FProtoWeatherThermoProTx4(); + protos[FPW_TX_8300] = new FProtoWeatherTX8300(); + protos[FPW_WENDOX_W6726] = new FProtoWeatherWendoxW6726(); + protos[FPW_Acurite986] = new FProtoWeatherAcurite986(); + protos[FPW_KEDSUM] = new FProtoWeatherKedsum(); + protos[FPW_Acurite5in1] = new FProtoWeatherAcurite5in1(); + protos[FPW_EmosE601x] = new FProtoWeatherEmosE601x(); // set callback for them - for (const auto& obj : protos) { - obj->setCallback(callbackTarget); + for (uint8_t i = 0; i < FPW_COUNT; ++i) { + protos[i]->setCallback(callbackTarget); } } + ~WeatherProtos() { // not needed for current operation logic, but a bit more elegant :) + for (uint8_t i = 0; i < FPW_COUNT; ++i) { + if (protos[i] != NULL) { + free(protos[i]); + protos[i] = NULL; + } + } + }; + static void callbackTarget(FProtoWeatherBase* instance) { WeatherDataMessage packet_message{instance->getSensorType(), instance->getSensorId(), instance->getTemp(), instance->getHumidity(), instance->getBattLow(), @@ -77,13 +88,13 @@ class WeatherProtos : public FProtoListGeneral { } void feed(bool level, uint32_t duration) { - for (const auto& obj : protos) { - obj->feed(level, duration); + for (uint8_t i = 0; i < FPW_COUNT; ++i) { + if (protos[i] != NULL) protos[i]->feed(level, duration); } } protected: - std::vector> protos{}; + FProtoWeatherBase* protos[FPW_COUNT] = {NULL}; }; #endif diff --git a/firmware/baseband/fprotos/weathertypes.hpp b/firmware/baseband/fprotos/weathertypes.hpp index c4935780..0f3de96a 100644 --- a/firmware/baseband/fprotos/weathertypes.hpp +++ b/firmware/baseband/fprotos/weathertypes.hpp @@ -37,8 +37,8 @@ enum FPROTO_WEATHER_SENSOR { FPW_Acurite986 = 19, FPW_KEDSUM = 20, FPW_Acurite5in1 = 21, - FPW_EmosE601x = 22 - + FPW_EmosE601x = 22, + FPW_COUNT // this must be the last }; #endif \ No newline at end of file