From a77645b58248dafd205762a59552aaaddaa589ad Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Fri, 25 Dec 2020 01:30:25 +0100 Subject: [PATCH] Trying to avoid conflict with ESP8266 --- lorawan.cpp | 13 ++++++++----- lorawan.h | 3 ++- util.h | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lorawan.cpp b/lorawan.cpp index b85fcbc..1e8e046 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 1928293..e51d218 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 8a8f927..c1fc40a 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; -- GitLab