diff --git a/lorawan.cpp b/lorawan.cpp index b85fcbc446eff5c228d82785258a217c9635ec09..1e8e0469368e007c56a1ba20115244a0b3d876e3 100644 --- a/lorawan.cpp +++ b/lorawan.cpp @@ -1,4 +1,5 @@ #include "lorawan.h" +#if defined(ESP32) namespace config { // Values should be defined in config.h @@ -21,7 +22,6 @@ const lmic_pinmap lmic_pins = { .nss = 18, .rxtx = LMIC_UNUSED_PIN, .rst = 14, . // More info : https://www.thethingsnetwork.org/docs/applications/mqtt/quick-start.html //TODO: Add infos to webserver (last timestamp, sending interval, connected or not?) -//TODO: Merge back to other branch (and other git) //TODO: compile for both boards, and check ESP32 && LORA void os_getArtEui(u1_t *buf) { @@ -141,15 +141,17 @@ namespace lorawan { } else { uint8_t buff[3]; // Mapping CO2 from 0ppm to 5100ppm to [0, 255], with 20ppm increments. - buff[0] = (min(max(sensor::co2, 0), 5100) + 10) / 20; + buff[0] = (util::min(util::max(sensor::co2, 0), 5100) + 10) / 20; // Mapping temperatures from [-10°C, 41°C] to [0, 255], with 0.2°C increment - buff[1] = static_cast<uint8_t>((min(max(sensor::temperature, -10), 41) + 10.1f) * 5); + buff[1] = static_cast<uint8_t>((util::min(util::max(sensor::temperature, -10), 41) + 10.1f) * 5); // Mapping humidity from [0%, 100%] to [0, 200], with 0.5°C increment (0.4°C would also be possible) - buff[2] = static_cast<uint8_t>(min(max(sensor::humidity, 0) + 0.25f, 100) * 2); + buff[2] = static_cast<uint8_t>(util::min(util::max(sensor::humidity, 0) + 0.25f, 100) * 2); - Serial.print(F("LoRa - Payload : '0x")); + Serial.print(F("LoRa - Payload : '")); printHex2(buff[0]); + Serial.print(" "); printHex2(buff[1]); + Serial.print(" "); printHex2(buff[2]); Serial.print(F("', ")); Serial.print(buff[0] * 20); @@ -202,3 +204,4 @@ namespace lorawan { void onEvent(ev_t ev) { lorawan::onEvent(ev); } +#endif diff --git a/lorawan.h b/lorawan.h index 19282930f01f5b8a54ddba39a24e696cb6cacc73..e51d218428ad2a39ac6a3c793b37392053cb26ec 100644 --- a/lorawan.h +++ b/lorawan.h @@ -1,6 +1,6 @@ #ifndef AMPEL_LORAWAN_H_ #define AMPEL_LORAWAN_H_ - +#if defined(ESP32) #include <Arduino.h> #include <lmic.h> #include <hal/hal.h> @@ -22,3 +22,4 @@ namespace lorawan { } #endif +#endif diff --git a/util.h b/util.h index 8a8f927c107a08e717ec17ca4b69213a67e90a22..c1fc40a7b7c1e24c024469c5b6ffdecc6805cf5f 100644 --- a/util.h +++ b/util.h @@ -24,8 +24,18 @@ namespace ntp { String getLocalTime(); } -#define max(a,b) ((a)>(b)?(a):(b)) -#define min(a,b) ((a)<(b)?(a):(b)) +namespace util { + template<typename Tpa, typename Tpb> + inline auto min(const Tpa &a, const Tpb &b) -> decltype(a < b ? a : b) { + return b < a ? b : a; + } + + template<typename Tpa, typename Tpb> + inline auto max(const Tpa &a, const Tpb &b) -> decltype(b > a ? b : a) { + return b > a ? b : a; + } +} + #define seconds() (millis() / 1000UL) extern uint32_t max_loop_duration; const extern String SENSOR_ID;