diff --git a/include/cyclic.h b/include/cyclic.h index ffdee8f5..7045cb77 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -5,9 +5,11 @@ #include "senddata.h" #include "rcommand.h" #include "spislave.h" +#if(HAS_LORA) #include +#endif -#ifdef HAS_BME +#if(HAS_BME) #include "bme680mems.h" #endif @@ -19,4 +21,4 @@ uint64_t uptime(void); void reset_counters(void); uint32_t getFreeRAM(); -#endif \ No newline at end of file +#endif diff --git a/include/globals.h b/include/globals.h index 24c83580..b77cf552 100644 --- a/include/globals.h +++ b/include/globals.h @@ -123,15 +123,15 @@ extern time_t userUTCTime; #include "payload.h" #include "blescan.h" -#ifdef HAS_GPS +#if(HAS_GPS) #include "gpsread.h" #endif -#ifdef HAS_LORA +#if(HAS_LORA) #include "lorawan.h" #endif -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) #include "display.h" #endif @@ -147,11 +147,11 @@ extern time_t userUTCTime; #include "antenna.h" #endif -#ifdef HAS_SENSORS +#if(HAS_SENSORS) #include "sensor.h" #endif -#ifdef HAS_BME +#if(HAS_BME) #include "bme680mems.h" #endif diff --git a/include/irqhandler.h b/include/irqhandler.h index ad74f700..5c73410e 100644 --- a/include/irqhandler.h +++ b/include/irqhandler.h @@ -14,7 +14,7 @@ void irqHandler(void *pvParameters); -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) #include "display.h" void IRAM_ATTR DisplayIRQ(); #endif diff --git a/include/main.h b/include/main.h index b60ab7b9..bce12e51 100644 --- a/include/main.h +++ b/include/main.h @@ -16,6 +16,8 @@ #include "irqhandler.h" #include "led.h" #include "spislave.h" +#if(HAS_LORA) #include "lorawan.h" +#endif #include "timekeeper.h" -#endif \ No newline at end of file +#endif diff --git a/include/ota.h b/include/ota.h index 3c6c8318..0371d71c 100644 --- a/include/ota.h +++ b/include/ota.h @@ -18,7 +18,7 @@ void start_ota_update(); int version_compare(const String v1, const String v2); void display(const uint8_t row, const std::string status, const std::string msg); -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) void show_progress(unsigned long current, unsigned long size); #endif diff --git a/include/rcommand.h b/include/rcommand.h index 9eb06384..dc169e1d 100644 --- a/include/rcommand.h +++ b/include/rcommand.h @@ -4,7 +4,9 @@ #include "senddata.h" #include "cyclic.h" #include "configmanager.h" +#if(HAS_LORA) #include "lorawan.h" +#endif #include "macsniff.h" #include #include "cyclic.h" @@ -24,4 +26,4 @@ typedef struct { void rcommand(uint8_t cmd[], uint8_t cmdlength); void do_reset(); -#endif \ No newline at end of file +#endif diff --git a/include/senddata.h b/include/senddata.h index e0eb4ecf..d81b852b 100644 --- a/include/senddata.h +++ b/include/senddata.h @@ -2,7 +2,9 @@ #define _SENDDATA_H #include "spislave.h" +#if(HAS_LORA) #include "lorawan.h" +#endif #include "cyclic.h" extern Ticker sendcycler; @@ -13,4 +15,4 @@ void checkSendQueues(void); void flushQueues(); void sendcycle(void); -#endif // _SENDDATA_H_ \ No newline at end of file +#endif // _SENDDATA_H_ diff --git a/include/timekeeper.h b/include/timekeeper.h index ef83b11b..fc12e4a9 100644 --- a/include/timekeeper.h +++ b/include/timekeeper.h @@ -6,7 +6,7 @@ #include "TimeLib.h" #include "irqhandler.h" -#ifdef HAS_GPS +#if(HAS_GPS) #include "gpsread.h" #endif #ifdef HAS_IF482 diff --git a/platformio.ini b/platformio.ini index 47ca6e73..599b8e02 100644 --- a/platformio.ini +++ b/platformio.ini @@ -218,7 +218,7 @@ lib_deps = ${common.lib_deps_lora} ${common.lib_deps_display} ${common.lib_deps_rtc} -build_flags = +build_flags = ${common.build_flags_basic} upload_protocol = ${common.upload_protocol} extra_scripts = ${common.extra_scripts} diff --git a/src/bme680mems.cpp b/src/bme680mems.cpp index d0679507..9104a74a 100644 --- a/src/bme680mems.cpp +++ b/src/bme680mems.cpp @@ -1,4 +1,4 @@ -#ifdef HAS_BME +#if(HAS_BME) #include "bme680mems.h" @@ -103,7 +103,7 @@ void bme_loop(void *pvParameters) { configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check -#ifdef HAS_BME +#if(HAS_BME) while (1) { // block i2c bus access if (I2C_MUTEX_LOCK()) { diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 8899d05b..face4564 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -24,7 +24,7 @@ void doHousekeeping() { #ifdef HAS_SPI spi_housekeeping(); #endif -#ifdef HAS_LORA +#if(HAS_LORA) lora_housekeeping(); #endif @@ -32,11 +32,11 @@ void doHousekeeping() { ESP_LOGD(TAG, "IRQhandler %d bytes left | Taskstate = %d", uxTaskGetStackHighWaterMark(irqHandlerTask), eTaskGetState(irqHandlerTask)); -#ifdef HAS_GPS +#if(HAS_GPS) ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d", uxTaskGetStackHighWaterMark(GpsTask), eTaskGetState(GpsTask)); #endif -#ifdef HAS_BME +#if(HAS_BME) ESP_LOGD(TAG, "Bmeloop %d bytes left | Taskstate = %d", uxTaskGetStackHighWaterMark(BmeTask), eTaskGetState(BmeTask)); #endif @@ -58,7 +58,7 @@ void doHousekeeping() { #endif // display BME sensor data -#ifdef HAS_BME +#if(HAS_BME) ESP_LOGI(TAG, "BME680 Temp: %.2f°C | IAQ: %.2f | IAQacc: %d", bme_status.temperature, bme_status.iaq, bme_status.iaq_accuracy); #endif diff --git a/src/display.cpp b/src/display.cpp index 80d206e7..96adebf9 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1,4 +1,4 @@ -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) /* @@ -105,7 +105,7 @@ void init_display(const char *Productname, const char *Version) { u8x8.print(" v"); u8x8.println(PROGVERSION); -#ifdef HAS_LORA +#if(HAS_LORA) u8x8.println("DEVEUI:"); os_getDevEui((u1_t *)buf); DisplayKey(buf, 8, true); @@ -163,7 +163,7 @@ void refreshtheDisplay() { #endif // update GPS status (line 2) -#ifdef HAS_GPS +#if(HAS_GPS) // have we ever got valid gps data? if (gps.passedChecksum() > 0) { u8x8.setCursor(9, 2); @@ -186,7 +186,7 @@ void refreshtheDisplay() { u8x8.printf("%s", "BLTH:off"); #endif -#ifdef HAS_LORA +#if(HAS_LORA) u8x8.setCursor(11, 3); u8x8.printf("SF:"); if (cfg.adrmode) // if ADR=on then display SF value inverse @@ -209,7 +209,7 @@ void refreshtheDisplay() { u8x8.setCursor(10, 5); u8x8.printf("%4dKB", getFreeRAM() / 1024); -#ifdef HAS_LORA +#if(HAS_LORA) u8x8.setCursor(0, 6); #if (!defined HAS_DCF77) && (!defined HAS_IF482) // update LoRa status display (line 6) diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 59739bf4..27cc0eec 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -1,4 +1,4 @@ -#ifdef HAS_GPS +#if(HAS_GPS) #include "globals.h" diff --git a/src/hal/lolin32lite.h b/src/hal/lolin32lite.h index 3995fac7..70dfbcdf 100644 --- a/src/hal/lolin32lite.h +++ b/src/hal/lolin32lite.h @@ -7,8 +7,9 @@ // Hardware related definitions for lolin32lite (without LoRa shield) +#define HAS_LORA 0 // no LoRa module #define CFG_sx1272_radio 1 // dummy #define HAS_LED LED_BUILTIN // on board LED on GPIO5 #define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW -#endif \ No newline at end of file +#endif diff --git a/src/irqhandler.cpp b/src/irqhandler.cpp index 0757430b..28725b1e 100644 --- a/src/irqhandler.cpp +++ b/src/irqhandler.cpp @@ -24,7 +24,7 @@ void irqHandler(void *pvParameters) { #endif // display needs refresh? -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) if (InterruptStatus & DISPLAY_IRQ) refreshtheDisplay(); #endif @@ -49,7 +49,7 @@ void irqHandler(void *pvParameters) { // esp32 hardware timer triggered interrupt service routines // they notify the irq handler task -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) void IRAM_ATTR DisplayIRQ() { BaseType_t xHigherPriorityTaskWoken; xHigherPriorityTaskWoken = pdFALSE; diff --git a/src/led.cpp b/src/led.cpp index a52315c5..edaa135a 100644 --- a/src/led.cpp +++ b/src/led.cpp @@ -137,7 +137,7 @@ void ledLoop(void *parameter) { // No custom blink, check LoRaWAN state } else { -#ifdef HAS_LORA +#if(HAS_LORA) // LED indicators for viusalizing LoRaWAN state if (LMIC.opmode & (OP_JOINING | OP_REJOIN)) { LEDColor = COLOR_YELLOW; diff --git a/src/loraconf.sample.h b/src/loraconf.sample.h index 3ad10a0d..5e60c0a5 100644 --- a/src/loraconf.sample.h +++ b/src/loraconf.sample.h @@ -1,4 +1,4 @@ -#ifdef HAS_LORA +#if(HAS_LORA) /************************************************************ * LMIC LoRaWAN configuration diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 04fb0fb6..fd0398fa 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -1,10 +1,12 @@ // Basic Config +#if(HAS_LORA) #include "lorawan.h" +#endif // Local logging Tag static const char TAG[] = "lora"; -#ifdef HAS_LORA +#if(HAS_LORA) #if CLOCK_ERROR_PROCENTAGE > 7 #warning CLOCK_ERROR_PROCENTAGE value in lmic_config.h is too high; values > 7 will cause side effects @@ -479,4 +481,4 @@ void user_request_network_time_callback(void *pVoidUserUTCTime, ESP_LOGI(TAG, "Invalid time received from LoRa"); } // user_request_network_time_callback -#endif // HAS_LORA \ No newline at end of file +#endif // HAS_LORA diff --git a/src/main.cpp b/src/main.cpp index 0b44c850..b89525a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -155,7 +155,7 @@ void setup() { ESP.getFlashChipSpeed()); ESP_LOGI(TAG, "Wifi/BT software coexist version %s", esp_coex_version_get()); -#ifdef HAS_LORA +#if(HAS_LORA) ESP_LOGI(TAG, "IBM LMIC version %d.%d.%d", LMIC_VERSION_MAJOR, LMIC_VERSION_MINOR, LMIC_VERSION_BUILD); ESP_LOGI(TAG, "Arduino LMIC version %d.%d.%d.%d", @@ -167,7 +167,7 @@ void setup() { showLoraKeys(); #endif // HAS_LORA -#ifdef HAS_GPS +#if(HAS_GPS) ESP_LOGI(TAG, "TinyGPS+ version %s", TinyGPSPlus::libraryVersion()); #endif @@ -269,7 +269,7 @@ void setup() { #endif // HAS_BUTTON // initialize gps -#ifdef HAS_GPS +#if(HAS_GPS) strcat_P(features, " GPS"); if (gps_init()) { ESP_LOGI(TAG, "Starting GPS Feed..."); @@ -284,13 +284,13 @@ void setup() { #endif // initialize sensors -#ifdef HAS_SENSORS +#if(HAS_SENSORS) strcat_P(features, " SENS"); sensor_init(); #endif // initialize LoRa -#ifdef HAS_LORA +#if(HAS_LORA) strcat_P(features, " LORA"); assert(lora_stack_init() == ESP_OK); #endif @@ -306,7 +306,7 @@ void setup() { #endif // initialize display -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) strcat_P(features, " OLED"); DisplayState = cfg.screenon; init_display(PRODUCTNAME, PROGVERSION); // note: blocking call @@ -359,7 +359,7 @@ void setup() { 1); // CPU core // initialize bme -#ifdef HAS_BME +#if(HAS_BME) strcat_P(features, " BME"); if (bme_init()) { ESP_LOGI(TAG, "Starting BME sensor..."); @@ -378,7 +378,7 @@ void setup() { ESP_LOGI(TAG, "Starting Timers..."); // display interrupt -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) // https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/ // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 0, count up displayIRQ = timerBegin(0, 80, true); @@ -421,7 +421,7 @@ void setup() { void loop() { while (1) { -#ifdef HAS_LORA +#if(HAS_LORA) os_runloop_once(); // execute lmic scheduled jobs and events #endif delay(2); // yield to CPU diff --git a/src/ota.cpp b/src/ota.cpp index a2623702..a7c3f326 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -48,7 +48,7 @@ void start_ota_update() { switch_LED(LED_ON); -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) u8x8.begin(); u8x8.setFont(u8x8_font_chroma48medium8_r); u8x8.clear(); @@ -266,7 +266,7 @@ int do_ota_update() { goto abort; } -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) // register callback function for showing progress while streaming data Update.onProgress(&show_progress); #endif @@ -309,7 +309,7 @@ retry: void display(const uint8_t row, const std::string status, const std::string msg) { -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) u8x8.setCursor(14, row); u8x8.print((status.substr(0, 2)).c_str()); if (!msg.empty()) { @@ -320,7 +320,7 @@ void display(const uint8_t row, const std::string status, #endif } -#ifdef HAS_DISPLAY +#if(HAS_DISPLAY) // callback function to show download progress while streaming data void show_progress(unsigned long current, unsigned long size) { char buf[17]; diff --git a/src/payload.cpp b/src/payload.cpp index 45d7e6e3..a5990d26 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -78,7 +78,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, } void PayloadConvert::addGPS(gpsStatus_t value) { -#ifdef HAS_GPS +#if(HAS_GPS) buffer[cursor++] = (byte)((value.latitude & 0xFF000000) >> 24); buffer[cursor++] = (byte)((value.latitude & 0x00FF0000) >> 16); buffer[cursor++] = (byte)((value.latitude & 0x0000FF00) >> 8); @@ -96,7 +96,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#ifdef HAS_SENSORS +#if(HAS_SENSORS) uint8_t length = buf[0]; memcpy(buffer, buf + 1, length); cursor += length; // length of buffer @@ -104,7 +104,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) { } void PayloadConvert::addBME(bmeStatus_t value) { -#ifdef HAS_BME +#if(HAS_BME) int16_t temperature = (int16_t)(value.temperature); // float -> int uint16_t humidity = (uint16_t)(value.humidity); // float -> int uint16_t pressure = (uint16_t)(value.pressure); // float -> int @@ -187,7 +187,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp, } void PayloadConvert::addGPS(gpsStatus_t value) { -#ifdef HAS_GPS +#if(HAS_GPS) writeLatLng(value.latitude, value.longitude); writeUint8(value.satellites); writeUint16(value.hdop); @@ -196,7 +196,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#ifdef HAS_SENSORS +#if(HAS_SENSORS) uint8_t length = buf[0]; memcpy(buffer, buf + 1, length); cursor += length; // length of buffer @@ -204,7 +204,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) { } void PayloadConvert::addBME(bmeStatus_t value) { -#ifdef HAS_BME +#if(HAS_BME) writeFloat(value.temperature); writePressure(value.pressure); writeUFloat(value.humidity); @@ -375,7 +375,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius, } void PayloadConvert::addGPS(gpsStatus_t value) { -#ifdef HAS_GPS +#if(HAS_GPS) int32_t lat = value.latitude / 100; int32_t lon = value.longitude / 100; int32_t alt = value.altitude * 100; @@ -396,7 +396,7 @@ void PayloadConvert::addGPS(gpsStatus_t value) { } void PayloadConvert::addSensor(uint8_t buf[]) { -#ifdef HAS_SENSORS +#if(HAS_SENSORS) // to come /* uint8_t length = buf[0]; @@ -407,7 +407,7 @@ void PayloadConvert::addSensor(uint8_t buf[]) { } void PayloadConvert::addBME(bmeStatus_t value) { -#ifdef HAS_BME +#if(HAS_BME) // data value conversions to meet cayenne data type definition // 0.1°C per bit => -3276,7 .. +3276,7 °C diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 34054bc2..727b4265 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -8,7 +8,9 @@ static const char TAG[] = __FILE__; // helper function void do_reset() { ESP_LOGI(TAG, "Remote command: restart device"); +#if(HAS_LORA) LMIC_shutdown(); +#endif delay(3000); esp_restart(); } @@ -130,7 +132,7 @@ void set_gps(uint8_t val[]) { } void set_sensor(uint8_t val[]) { -#ifdef HAS_SENSORS +#if(HAS_SENSORS) switch (val[0]) { // check if valid sensor number 1...4 case 1: case 2: @@ -168,7 +170,7 @@ void set_monitor(uint8_t val[]) { } void set_lorasf(uint8_t val[]) { -#ifdef HAS_LORA +#if(HAS_LORA) ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val[0]); switch_lora(val[0], cfg.txpower); #else @@ -177,7 +179,7 @@ void set_lorasf(uint8_t val[]) { } void set_loraadr(uint8_t val[]) { -#ifdef HAS_LORA +#if(HAS_LORA) ESP_LOGI(TAG, "Remote command: set LoRa ADR mode to %s", val[0] ? "on" : "off"); cfg.adrmode = val[0] ? 1 : 0; @@ -220,7 +222,7 @@ void set_rgblum(uint8_t val[]) { }; void set_lorapower(uint8_t val[]) { -#ifdef HAS_LORA +#if(HAS_LORA) ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", val[0]); switch_lora(cfg.lorasf, val[0]); #else @@ -250,7 +252,7 @@ void get_status(uint8_t val[]) { void get_gps(uint8_t val[]) { ESP_LOGI(TAG, "Remote command: get gps status"); -#ifdef HAS_GPS +#if(HAS_GPS) gps_read(); payload.reset(); payload.addGPS(gps_status); @@ -262,7 +264,7 @@ void get_gps(uint8_t val[]) { void get_bme(uint8_t val[]) { ESP_LOGI(TAG, "Remote command: get bme680 sensor data"); -#ifdef HAS_BME +#if(HAS_BME) payload.reset(); payload.addBME(bme_status); SendPayload(BMEPORT, prio_high); @@ -355,4 +357,4 @@ void rcommand(uint8_t cmd[], uint8_t cmdlength) { if (storeflag) saveConfig(); -} // rcommand() \ No newline at end of file +} // rcommand() diff --git a/src/senddata.cpp b/src/senddata.cpp index 36e8b278..816ee7c7 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -39,7 +39,7 @@ void SendPayload(uint8_t port, sendprio_t prio) { memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize()); // enqueue message in device's send queues -#ifdef HAS_LORA +#if(HAS_LORA) lora_enqueuedata(&SendBuffer, prio); #endif #ifdef HAS_SPI @@ -63,7 +63,7 @@ void sendCounter() { if (cfg.blescan) payload.addCount(macs_ble, MAC_SNIFF_BLE); -#ifdef HAS_GPS +#if(HAS_GPS) if (gps.location.isValid()) { // send GPS position only if we have a fix gps_read(); payload.addGPS(gps_status); @@ -83,7 +83,7 @@ void sendCounter() { } break; -#ifdef HAS_BME +#if(HAS_BME) case MEMS_DATA: payload.reset(); payload.addBME(bme_status); @@ -91,7 +91,7 @@ void sendCounter() { break; #endif -#ifdef HAS_GPS +#if(HAS_GPS) case GPS_DATA: // send GPS position only if we have a fix if (gps.location.isValid()) { @@ -104,7 +104,7 @@ void sendCounter() { break; #endif -#ifdef HAS_SENSORS +#if(HAS_SENSORS) case SENSOR1_DATA: payload.reset(); payload.addSensor(sensor_read(1)); @@ -138,7 +138,7 @@ void sendCounter() { } // sendCounter() void flushQueues() { -#ifdef HAS_LORA +#if(HAS_LORA) lora_queuereset(); #endif #ifdef HAS_SPI diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 21259b21..bd33f7e6 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -14,7 +14,7 @@ time_t timeProvider(void) { time_t t = 0; -#ifdef HAS_GPS +#if(HAS_GPS) t = get_gpstime(); // fetch recent time from last NEMA record if (t) { #ifdef HAS_RTC @@ -39,7 +39,7 @@ time_t timeProvider(void) { #if(DBTIMESYNC) send_DBtime_req(); // kick off asychronous lora sync if we have -#elif defined HAS_LORA && (TIME_SYNC_LORA) +#elif (HAS_LORA) && (TIME_SYNC_LORA) LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime); #endif @@ -237,4 +237,4 @@ void clock_loop(void *taskparameter) { // ClockTask } // for } // clock_loop() -#endif // HAS_IF482 || defined HAS_DCF77 \ No newline at end of file +#endif // HAS_IF482 || defined HAS_DCF77