replace #ifdef with #if to streamline feature setting

This commit is contained in:
Oliver Brandmueller 2019-03-11 18:09:01 +01:00
parent 8c58fa04a7
commit 4a7525efcb
24 changed files with 84 additions and 71 deletions

View File

@ -5,9 +5,11 @@
#include "senddata.h"
#include "rcommand.h"
#include "spislave.h"
#if(HAS_LORA)
#include <lmic.h>
#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
#endif

View File

@ -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

View File

@ -14,7 +14,7 @@
void irqHandler(void *pvParameters);
#ifdef HAS_DISPLAY
#if(HAS_DISPLAY)
#include "display.h"
void IRAM_ATTR DisplayIRQ();
#endif

View File

@ -16,6 +16,8 @@
#include "irqhandler.h"
#include "led.h"
#include "spislave.h"
#if(HAS_LORA)
#include "lorawan.h"
#endif
#include "timekeeper.h"
#endif
#endif

View File

@ -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

View File

@ -4,7 +4,9 @@
#include "senddata.h"
#include "cyclic.h"
#include "configmanager.h"
#if(HAS_LORA)
#include "lorawan.h"
#endif
#include "macsniff.h"
#include <rom/rtc.h>
#include "cyclic.h"
@ -24,4 +26,4 @@ typedef struct {
void rcommand(uint8_t cmd[], uint8_t cmdlength);
void do_reset();
#endif
#endif

View File

@ -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_
#endif // _SENDDATA_H_

View File

@ -6,7 +6,7 @@
#include "TimeLib.h"
#include "irqhandler.h"
#ifdef HAS_GPS
#if(HAS_GPS)
#include "gpsread.h"
#endif
#ifdef HAS_IF482

View File

@ -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}

View File

@ -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()) {

View File

@ -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

View File

@ -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)

View File

@ -1,4 +1,4 @@
#ifdef HAS_GPS
#if(HAS_GPS)
#include "globals.h"

View File

@ -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
#endif

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,4 @@
#ifdef HAS_LORA
#if(HAS_LORA)
/************************************************************
* LMIC LoRaWAN configuration

View File

@ -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
#endif // HAS_LORA

View File

@ -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

View File

@ -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];

View File

@ -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

View File

@ -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()
} // rcommand()

View File

@ -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

View File

@ -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
#endif // HAS_IF482 || defined HAS_DCF77