From 53169538bd049022fbe751ee551bc9ef4b21cfd2 Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Mon, 13 Oct 2025 09:54:39 +0800 Subject: [PATCH] Update boards.cpp --- .../ArduinoLoRa/LoRaReceiver/LoRaBoards.cpp | 38 +++++++------ .../ArduinoLoRa/LoRaReceiver/LoRaBoards.h | 57 ++++++++++--------- .../ArduinoLoRa/LoRaSender/LoRaBoards.cpp | 38 +++++++------ examples/ArduinoLoRa/LoRaSender/LoRaBoards.h | 57 ++++++++++--------- .../Display/Free_Font_Demo/LoRaBoards.cpp | 38 +++++++------ examples/Display/Free_Font_Demo/LoRaBoards.h | 57 ++++++++++--------- .../Display/TBeam_TFT_Shield/LoRaBoards.cpp | 38 +++++++------ .../Display/TBeam_TFT_Shield/LoRaBoards.h | 57 ++++++++++--------- .../Display/TFT_Char_times/LoRaBoards.cpp | 38 +++++++------ examples/Display/TFT_Char_times/LoRaBoards.h | 57 ++++++++++--------- examples/Display/UTFT_demo/LoRaBoards.cpp | 38 +++++++------ examples/Display/UTFT_demo/LoRaBoards.h | 57 ++++++++++--------- examples/Factory/LoRaBoards.cpp | 38 +++++++------ examples/Factory/LoRaBoards.h | 57 ++++++++++--------- examples/GPS/TinyGPS_Example/LoRaBoards.cpp | 38 +++++++------ examples/GPS/TinyGPS_Example/LoRaBoards.h | 57 ++++++++++--------- .../GPS/TinyGPS_FullExample/LoRaBoards.cpp | 38 +++++++------ examples/GPS/TinyGPS_FullExample/LoRaBoards.h | 57 ++++++++++--------- .../GPS/TinyGPS_KitchenSink/LoRaBoards.cpp | 38 +++++++------ examples/GPS/TinyGPS_KitchenSink/LoRaBoards.h | 57 ++++++++++--------- .../GPS/UBlox_BasicNMEARead/LoRaBoards.cpp | 38 +++++++------ examples/GPS/UBlox_BasicNMEARead/LoRaBoards.h | 57 ++++++++++--------- examples/GPS/UBlox_NMEAParsing/LoRaBoards.cpp | 38 +++++++------ examples/GPS/UBlox_NMEAParsing/LoRaBoards.h | 57 ++++++++++--------- examples/GPS/UBlox_OutputRate/LoRaBoards.cpp | 38 +++++++------ examples/GPS/UBlox_OutputRate/LoRaBoards.h | 57 ++++++++++--------- examples/GPS/UBlox_Recovery/LoRaBoards.cpp | 38 +++++++------ examples/GPS/UBlox_Recovery/LoRaBoards.h | 57 ++++++++++--------- .../LoRaWAN/LMIC_Library_OTTA/LoRaBoards.cpp | 38 +++++++------ .../LoRaWAN/LMIC_Library_OTTA/LoRaBoards.h | 57 ++++++++++--------- examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.cpp | 38 +++++++------ examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.h | 57 ++++++++++--------- examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.cpp | 38 +++++++------ examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.h | 57 ++++++++++--------- examples/OLED/SH1106FontUsage/LoRaBoards.cpp | 38 +++++++------ examples/OLED/SH1106FontUsage/LoRaBoards.h | 57 ++++++++++--------- .../OLED/SH1106GraphicsTest/LoRaBoards.cpp | 38 +++++++------ examples/OLED/SH1106GraphicsTest/LoRaBoards.h | 57 ++++++++++--------- examples/OLED/SH1106IconMenu/LoRaBoards.cpp | 38 +++++++------ examples/OLED/SH1106IconMenu/LoRaBoards.h | 57 ++++++++++--------- examples/OLED/SH1106PrintUTF8/LoRaBoards.cpp | 38 +++++++------ examples/OLED/SH1106PrintUTF8/LoRaBoards.h | 57 ++++++++++--------- .../OLED/SSD1306SimpleDemo/LoRaBoards.cpp | 38 +++++++------ examples/OLED/SSD1306SimpleDemo/LoRaBoards.h | 57 ++++++++++--------- examples/OLED/SSD1306UiDemo/LoRaBoards.cpp | 38 +++++++------ examples/OLED/SSD1306UiDemo/LoRaBoards.h | 57 ++++++++++--------- examples/PMU/LoRaBoards.cpp | 38 +++++++------ examples/PMU/LoRaBoards.h | 57 ++++++++++--------- .../Receive_Interrupt/LoRaBoards.cpp | 38 +++++++------ .../Receive_Interrupt/LoRaBoards.h | 57 ++++++++++--------- .../SX1280_Ranging/LoRaBoards.cpp | 38 +++++++------ .../SX1280_Ranging/LoRaBoards.h | 57 ++++++++++--------- .../Transmit_Interrupt/LoRaBoards.cpp | 38 +++++++------ .../Transmit_Interrupt/LoRaBoards.h | 57 ++++++++++--------- .../LoRaBoards.cpp | 38 +++++++------ .../LoRaBoards.h | 57 ++++++++++--------- .../Sensor/BME280_TestExample/LoRaBoards.cpp | 38 +++++++------ .../Sensor/BME280_TestExample/LoRaBoards.h | 57 ++++++++++--------- .../BME280_UnifiedExample/LoRaBoards.cpp | 38 +++++++------ .../Sensor/BME280_UnifiedExample/LoRaBoards.h | 57 ++++++++++--------- .../PCF8563_AlarmByUnits/LoRaBoards.cpp | 38 +++++++------ .../Sensor/PCF8563_AlarmByUnits/LoRaBoards.h | 57 ++++++++++--------- .../Sensor/PCF8563_SimpleTime/LoRaBoards.cpp | 38 +++++++------ .../Sensor/PCF8563_SimpleTime/LoRaBoards.h | 57 ++++++++++--------- .../Sensor/PCF8563_TimeLib/LoRaBoards.cpp | 38 +++++++------ examples/Sensor/PCF8563_TimeLib/LoRaBoards.h | 57 ++++++++++--------- .../LoRaBoards.cpp | 38 +++++++------ .../PCF8563_TimeSynchronization/LoRaBoards.h | 57 ++++++++++--------- .../QMC6310_CalibrateExample/LoRaBoards.cpp | 38 +++++++------ .../QMC6310_CalibrateExample/LoRaBoards.h | 57 ++++++++++--------- .../QMC6310_CompassExample/LoRaBoards.cpp | 38 +++++++------ .../QMC6310_CompassExample/LoRaBoards.h | 57 ++++++++++--------- .../QMC6310_GetDataExample/LoRaBoards.cpp | 38 +++++++------ .../QMC6310_GetDataExample/LoRaBoards.h | 57 ++++++++++--------- .../QMC6310_GetPolarExample/LoRaBoards.cpp | 38 +++++++------ .../QMC6310_GetPolarExample/LoRaBoards.h | 57 ++++++++++--------- .../QMI8658_BlockExample/LoRaBoards.cpp | 38 +++++++------ .../Sensor/QMI8658_BlockExample/LoRaBoards.h | 57 ++++++++++--------- .../QMI8658_GetDataExample/LoRaBoards.cpp | 38 +++++++------ .../QMI8658_GetDataExample/LoRaBoards.h | 57 ++++++++++--------- .../LoRaBoards.cpp | 38 +++++++------ .../LoRaBoards.h | 57 ++++++++++--------- .../QMI8658_InterruptExample/LoRaBoards.cpp | 38 +++++++------ .../QMI8658_InterruptExample/LoRaBoards.h | 57 ++++++++++--------- .../LoRaBoards.cpp | 38 +++++++------ .../LoRaBoards.h | 57 ++++++++++--------- .../QMI8658_MadgwickAHRS/LoRaBoards.cpp | 38 +++++++------ .../Sensor/QMI8658_MadgwickAHRS/LoRaBoards.h | 57 ++++++++++--------- .../QMI8658_PedometerExample/LoRaBoards.cpp | 38 +++++++------ .../QMI8658_PedometerExample/LoRaBoards.h | 57 ++++++++++--------- .../LoRaBoards.cpp | 38 +++++++------ .../QMI8658_ReadFromFifoExample/LoRaBoards.h | 57 ++++++++++--------- .../QMI8658_WakeOnMotion/LoRaBoards.cpp | 38 +++++++------ .../Sensor/QMI8658_WakeOnMotion/LoRaBoards.h | 57 ++++++++++--------- examples/T3S3Factory/LoRaBoards.cpp | 38 +++++++------ examples/T3S3Factory/LoRaBoards.h | 57 ++++++++++--------- examples/TBeamFactory/LoRaBoards.cpp | 38 +++++++------ examples/TBeamFactory/LoRaBoards.h | 57 ++++++++++--------- 98 files changed, 2450 insertions(+), 2205 deletions(-) diff --git a/examples/ArduinoLoRa/LoRaReceiver/LoRaBoards.cpp b/examples/ArduinoLoRa/LoRaReceiver/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/ArduinoLoRa/LoRaReceiver/LoRaBoards.cpp +++ b/examples/ArduinoLoRa/LoRaReceiver/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/ArduinoLoRa/LoRaReceiver/LoRaBoards.h b/examples/ArduinoLoRa/LoRaReceiver/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/ArduinoLoRa/LoRaReceiver/LoRaBoards.h +++ b/examples/ArduinoLoRa/LoRaReceiver/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/ArduinoLoRa/LoRaSender/LoRaBoards.cpp b/examples/ArduinoLoRa/LoRaSender/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/ArduinoLoRa/LoRaSender/LoRaBoards.cpp +++ b/examples/ArduinoLoRa/LoRaSender/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/ArduinoLoRa/LoRaSender/LoRaBoards.h b/examples/ArduinoLoRa/LoRaSender/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/ArduinoLoRa/LoRaSender/LoRaBoards.h +++ b/examples/ArduinoLoRa/LoRaSender/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Display/Free_Font_Demo/LoRaBoards.cpp b/examples/Display/Free_Font_Demo/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Display/Free_Font_Demo/LoRaBoards.cpp +++ b/examples/Display/Free_Font_Demo/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Display/Free_Font_Demo/LoRaBoards.h b/examples/Display/Free_Font_Demo/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Display/Free_Font_Demo/LoRaBoards.h +++ b/examples/Display/Free_Font_Demo/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Display/TBeam_TFT_Shield/LoRaBoards.cpp b/examples/Display/TBeam_TFT_Shield/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Display/TBeam_TFT_Shield/LoRaBoards.cpp +++ b/examples/Display/TBeam_TFT_Shield/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Display/TBeam_TFT_Shield/LoRaBoards.h b/examples/Display/TBeam_TFT_Shield/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Display/TBeam_TFT_Shield/LoRaBoards.h +++ b/examples/Display/TBeam_TFT_Shield/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Display/TFT_Char_times/LoRaBoards.cpp b/examples/Display/TFT_Char_times/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Display/TFT_Char_times/LoRaBoards.cpp +++ b/examples/Display/TFT_Char_times/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Display/TFT_Char_times/LoRaBoards.h b/examples/Display/TFT_Char_times/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Display/TFT_Char_times/LoRaBoards.h +++ b/examples/Display/TFT_Char_times/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Display/UTFT_demo/LoRaBoards.cpp b/examples/Display/UTFT_demo/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Display/UTFT_demo/LoRaBoards.cpp +++ b/examples/Display/UTFT_demo/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Display/UTFT_demo/LoRaBoards.h b/examples/Display/UTFT_demo/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Display/UTFT_demo/LoRaBoards.h +++ b/examples/Display/UTFT_demo/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Factory/LoRaBoards.cpp b/examples/Factory/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Factory/LoRaBoards.cpp +++ b/examples/Factory/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Factory/LoRaBoards.h b/examples/Factory/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Factory/LoRaBoards.h +++ b/examples/Factory/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/GPS/TinyGPS_Example/LoRaBoards.cpp b/examples/GPS/TinyGPS_Example/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/GPS/TinyGPS_Example/LoRaBoards.cpp +++ b/examples/GPS/TinyGPS_Example/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/GPS/TinyGPS_Example/LoRaBoards.h b/examples/GPS/TinyGPS_Example/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/GPS/TinyGPS_Example/LoRaBoards.h +++ b/examples/GPS/TinyGPS_Example/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/GPS/TinyGPS_FullExample/LoRaBoards.cpp b/examples/GPS/TinyGPS_FullExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/GPS/TinyGPS_FullExample/LoRaBoards.cpp +++ b/examples/GPS/TinyGPS_FullExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/GPS/TinyGPS_FullExample/LoRaBoards.h b/examples/GPS/TinyGPS_FullExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/GPS/TinyGPS_FullExample/LoRaBoards.h +++ b/examples/GPS/TinyGPS_FullExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/GPS/TinyGPS_KitchenSink/LoRaBoards.cpp b/examples/GPS/TinyGPS_KitchenSink/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/GPS/TinyGPS_KitchenSink/LoRaBoards.cpp +++ b/examples/GPS/TinyGPS_KitchenSink/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/GPS/TinyGPS_KitchenSink/LoRaBoards.h b/examples/GPS/TinyGPS_KitchenSink/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/GPS/TinyGPS_KitchenSink/LoRaBoards.h +++ b/examples/GPS/TinyGPS_KitchenSink/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/GPS/UBlox_BasicNMEARead/LoRaBoards.cpp b/examples/GPS/UBlox_BasicNMEARead/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/GPS/UBlox_BasicNMEARead/LoRaBoards.cpp +++ b/examples/GPS/UBlox_BasicNMEARead/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/GPS/UBlox_BasicNMEARead/LoRaBoards.h b/examples/GPS/UBlox_BasicNMEARead/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/GPS/UBlox_BasicNMEARead/LoRaBoards.h +++ b/examples/GPS/UBlox_BasicNMEARead/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/GPS/UBlox_NMEAParsing/LoRaBoards.cpp b/examples/GPS/UBlox_NMEAParsing/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/GPS/UBlox_NMEAParsing/LoRaBoards.cpp +++ b/examples/GPS/UBlox_NMEAParsing/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/GPS/UBlox_NMEAParsing/LoRaBoards.h b/examples/GPS/UBlox_NMEAParsing/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/GPS/UBlox_NMEAParsing/LoRaBoards.h +++ b/examples/GPS/UBlox_NMEAParsing/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/GPS/UBlox_OutputRate/LoRaBoards.cpp b/examples/GPS/UBlox_OutputRate/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/GPS/UBlox_OutputRate/LoRaBoards.cpp +++ b/examples/GPS/UBlox_OutputRate/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/GPS/UBlox_OutputRate/LoRaBoards.h b/examples/GPS/UBlox_OutputRate/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/GPS/UBlox_OutputRate/LoRaBoards.h +++ b/examples/GPS/UBlox_OutputRate/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/GPS/UBlox_Recovery/LoRaBoards.cpp b/examples/GPS/UBlox_Recovery/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/GPS/UBlox_Recovery/LoRaBoards.cpp +++ b/examples/GPS/UBlox_Recovery/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/GPS/UBlox_Recovery/LoRaBoards.h b/examples/GPS/UBlox_Recovery/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/GPS/UBlox_Recovery/LoRaBoards.h +++ b/examples/GPS/UBlox_Recovery/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/LoRaWAN/LMIC_Library_OTTA/LoRaBoards.cpp b/examples/LoRaWAN/LMIC_Library_OTTA/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/LoRaWAN/LMIC_Library_OTTA/LoRaBoards.cpp +++ b/examples/LoRaWAN/LMIC_Library_OTTA/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/LoRaWAN/LMIC_Library_OTTA/LoRaBoards.h b/examples/LoRaWAN/LMIC_Library_OTTA/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/LoRaWAN/LMIC_Library_OTTA/LoRaBoards.h +++ b/examples/LoRaWAN/LMIC_Library_OTTA/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.cpp b/examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.cpp +++ b/examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.h b/examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.h +++ b/examples/LoRaWAN/LoRaWAN_ABP/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.cpp b/examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.cpp +++ b/examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.h b/examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.h +++ b/examples/LoRaWAN/RadioLib_OTAA/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/OLED/SH1106FontUsage/LoRaBoards.cpp b/examples/OLED/SH1106FontUsage/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/OLED/SH1106FontUsage/LoRaBoards.cpp +++ b/examples/OLED/SH1106FontUsage/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/OLED/SH1106FontUsage/LoRaBoards.h b/examples/OLED/SH1106FontUsage/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/OLED/SH1106FontUsage/LoRaBoards.h +++ b/examples/OLED/SH1106FontUsage/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/OLED/SH1106GraphicsTest/LoRaBoards.cpp b/examples/OLED/SH1106GraphicsTest/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/OLED/SH1106GraphicsTest/LoRaBoards.cpp +++ b/examples/OLED/SH1106GraphicsTest/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/OLED/SH1106GraphicsTest/LoRaBoards.h b/examples/OLED/SH1106GraphicsTest/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/OLED/SH1106GraphicsTest/LoRaBoards.h +++ b/examples/OLED/SH1106GraphicsTest/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/OLED/SH1106IconMenu/LoRaBoards.cpp b/examples/OLED/SH1106IconMenu/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/OLED/SH1106IconMenu/LoRaBoards.cpp +++ b/examples/OLED/SH1106IconMenu/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/OLED/SH1106IconMenu/LoRaBoards.h b/examples/OLED/SH1106IconMenu/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/OLED/SH1106IconMenu/LoRaBoards.h +++ b/examples/OLED/SH1106IconMenu/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/OLED/SH1106PrintUTF8/LoRaBoards.cpp b/examples/OLED/SH1106PrintUTF8/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/OLED/SH1106PrintUTF8/LoRaBoards.cpp +++ b/examples/OLED/SH1106PrintUTF8/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/OLED/SH1106PrintUTF8/LoRaBoards.h b/examples/OLED/SH1106PrintUTF8/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/OLED/SH1106PrintUTF8/LoRaBoards.h +++ b/examples/OLED/SH1106PrintUTF8/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/OLED/SSD1306SimpleDemo/LoRaBoards.cpp b/examples/OLED/SSD1306SimpleDemo/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/OLED/SSD1306SimpleDemo/LoRaBoards.cpp +++ b/examples/OLED/SSD1306SimpleDemo/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/OLED/SSD1306SimpleDemo/LoRaBoards.h b/examples/OLED/SSD1306SimpleDemo/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/OLED/SSD1306SimpleDemo/LoRaBoards.h +++ b/examples/OLED/SSD1306SimpleDemo/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/OLED/SSD1306UiDemo/LoRaBoards.cpp b/examples/OLED/SSD1306UiDemo/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/OLED/SSD1306UiDemo/LoRaBoards.cpp +++ b/examples/OLED/SSD1306UiDemo/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/OLED/SSD1306UiDemo/LoRaBoards.h b/examples/OLED/SSD1306UiDemo/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/OLED/SSD1306UiDemo/LoRaBoards.h +++ b/examples/OLED/SSD1306UiDemo/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/PMU/LoRaBoards.cpp b/examples/PMU/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/PMU/LoRaBoards.cpp +++ b/examples/PMU/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/PMU/LoRaBoards.h b/examples/PMU/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/PMU/LoRaBoards.h +++ b/examples/PMU/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/RadioLibExamples/Receive_Interrupt/LoRaBoards.cpp b/examples/RadioLibExamples/Receive_Interrupt/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/RadioLibExamples/Receive_Interrupt/LoRaBoards.cpp +++ b/examples/RadioLibExamples/Receive_Interrupt/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/RadioLibExamples/Receive_Interrupt/LoRaBoards.h b/examples/RadioLibExamples/Receive_Interrupt/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/RadioLibExamples/Receive_Interrupt/LoRaBoards.h +++ b/examples/RadioLibExamples/Receive_Interrupt/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/RadioLibExamples/SX1280_Ranging/LoRaBoards.cpp b/examples/RadioLibExamples/SX1280_Ranging/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/RadioLibExamples/SX1280_Ranging/LoRaBoards.cpp +++ b/examples/RadioLibExamples/SX1280_Ranging/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/RadioLibExamples/SX1280_Ranging/LoRaBoards.h b/examples/RadioLibExamples/SX1280_Ranging/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/RadioLibExamples/SX1280_Ranging/LoRaBoards.h +++ b/examples/RadioLibExamples/SX1280_Ranging/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/RadioLibExamples/Transmit_Interrupt/LoRaBoards.cpp b/examples/RadioLibExamples/Transmit_Interrupt/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/RadioLibExamples/Transmit_Interrupt/LoRaBoards.cpp +++ b/examples/RadioLibExamples/Transmit_Interrupt/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/RadioLibExamples/Transmit_Interrupt/LoRaBoards.h b/examples/RadioLibExamples/Transmit_Interrupt/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/RadioLibExamples/Transmit_Interrupt/LoRaBoards.h +++ b/examples/RadioLibExamples/Transmit_Interrupt/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/BME280_AdvancedsettingsExample/LoRaBoards.cpp b/examples/Sensor/BME280_AdvancedsettingsExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/BME280_AdvancedsettingsExample/LoRaBoards.cpp +++ b/examples/Sensor/BME280_AdvancedsettingsExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/BME280_AdvancedsettingsExample/LoRaBoards.h b/examples/Sensor/BME280_AdvancedsettingsExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/BME280_AdvancedsettingsExample/LoRaBoards.h +++ b/examples/Sensor/BME280_AdvancedsettingsExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/BME280_TestExample/LoRaBoards.cpp b/examples/Sensor/BME280_TestExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/BME280_TestExample/LoRaBoards.cpp +++ b/examples/Sensor/BME280_TestExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/BME280_TestExample/LoRaBoards.h b/examples/Sensor/BME280_TestExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/BME280_TestExample/LoRaBoards.h +++ b/examples/Sensor/BME280_TestExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/BME280_UnifiedExample/LoRaBoards.cpp b/examples/Sensor/BME280_UnifiedExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/BME280_UnifiedExample/LoRaBoards.cpp +++ b/examples/Sensor/BME280_UnifiedExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/BME280_UnifiedExample/LoRaBoards.h b/examples/Sensor/BME280_UnifiedExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/BME280_UnifiedExample/LoRaBoards.h +++ b/examples/Sensor/BME280_UnifiedExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/PCF8563_AlarmByUnits/LoRaBoards.cpp b/examples/Sensor/PCF8563_AlarmByUnits/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/PCF8563_AlarmByUnits/LoRaBoards.cpp +++ b/examples/Sensor/PCF8563_AlarmByUnits/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/PCF8563_AlarmByUnits/LoRaBoards.h b/examples/Sensor/PCF8563_AlarmByUnits/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/PCF8563_AlarmByUnits/LoRaBoards.h +++ b/examples/Sensor/PCF8563_AlarmByUnits/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/PCF8563_SimpleTime/LoRaBoards.cpp b/examples/Sensor/PCF8563_SimpleTime/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/PCF8563_SimpleTime/LoRaBoards.cpp +++ b/examples/Sensor/PCF8563_SimpleTime/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/PCF8563_SimpleTime/LoRaBoards.h b/examples/Sensor/PCF8563_SimpleTime/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/PCF8563_SimpleTime/LoRaBoards.h +++ b/examples/Sensor/PCF8563_SimpleTime/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/PCF8563_TimeLib/LoRaBoards.cpp b/examples/Sensor/PCF8563_TimeLib/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/PCF8563_TimeLib/LoRaBoards.cpp +++ b/examples/Sensor/PCF8563_TimeLib/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/PCF8563_TimeLib/LoRaBoards.h b/examples/Sensor/PCF8563_TimeLib/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/PCF8563_TimeLib/LoRaBoards.h +++ b/examples/Sensor/PCF8563_TimeLib/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/PCF8563_TimeSynchronization/LoRaBoards.cpp b/examples/Sensor/PCF8563_TimeSynchronization/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/PCF8563_TimeSynchronization/LoRaBoards.cpp +++ b/examples/Sensor/PCF8563_TimeSynchronization/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/PCF8563_TimeSynchronization/LoRaBoards.h b/examples/Sensor/PCF8563_TimeSynchronization/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/PCF8563_TimeSynchronization/LoRaBoards.h +++ b/examples/Sensor/PCF8563_TimeSynchronization/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMC6310_CalibrateExample/LoRaBoards.cpp b/examples/Sensor/QMC6310_CalibrateExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMC6310_CalibrateExample/LoRaBoards.cpp +++ b/examples/Sensor/QMC6310_CalibrateExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMC6310_CalibrateExample/LoRaBoards.h b/examples/Sensor/QMC6310_CalibrateExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMC6310_CalibrateExample/LoRaBoards.h +++ b/examples/Sensor/QMC6310_CalibrateExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMC6310_CompassExample/LoRaBoards.cpp b/examples/Sensor/QMC6310_CompassExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMC6310_CompassExample/LoRaBoards.cpp +++ b/examples/Sensor/QMC6310_CompassExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMC6310_CompassExample/LoRaBoards.h b/examples/Sensor/QMC6310_CompassExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMC6310_CompassExample/LoRaBoards.h +++ b/examples/Sensor/QMC6310_CompassExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMC6310_GetDataExample/LoRaBoards.cpp b/examples/Sensor/QMC6310_GetDataExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMC6310_GetDataExample/LoRaBoards.cpp +++ b/examples/Sensor/QMC6310_GetDataExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMC6310_GetDataExample/LoRaBoards.h b/examples/Sensor/QMC6310_GetDataExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMC6310_GetDataExample/LoRaBoards.h +++ b/examples/Sensor/QMC6310_GetDataExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMC6310_GetPolarExample/LoRaBoards.cpp b/examples/Sensor/QMC6310_GetPolarExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMC6310_GetPolarExample/LoRaBoards.cpp +++ b/examples/Sensor/QMC6310_GetPolarExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMC6310_GetPolarExample/LoRaBoards.h b/examples/Sensor/QMC6310_GetPolarExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMC6310_GetPolarExample/LoRaBoards.h +++ b/examples/Sensor/QMC6310_GetPolarExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_BlockExample/LoRaBoards.cpp b/examples/Sensor/QMI8658_BlockExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_BlockExample/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_BlockExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_BlockExample/LoRaBoards.h b/examples/Sensor/QMI8658_BlockExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_BlockExample/LoRaBoards.h +++ b/examples/Sensor/QMI8658_BlockExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_GetDataExample/LoRaBoards.cpp b/examples/Sensor/QMI8658_GetDataExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_GetDataExample/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_GetDataExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_GetDataExample/LoRaBoards.h b/examples/Sensor/QMI8658_GetDataExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_GetDataExample/LoRaBoards.h +++ b/examples/Sensor/QMI8658_GetDataExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_InterruptBlockExample/LoRaBoards.cpp b/examples/Sensor/QMI8658_InterruptBlockExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_InterruptBlockExample/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_InterruptBlockExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_InterruptBlockExample/LoRaBoards.h b/examples/Sensor/QMI8658_InterruptBlockExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_InterruptBlockExample/LoRaBoards.h +++ b/examples/Sensor/QMI8658_InterruptBlockExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_InterruptExample/LoRaBoards.cpp b/examples/Sensor/QMI8658_InterruptExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_InterruptExample/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_InterruptExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_InterruptExample/LoRaBoards.h b/examples/Sensor/QMI8658_InterruptExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_InterruptExample/LoRaBoards.h +++ b/examples/Sensor/QMI8658_InterruptExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_LockingMechanismExample/LoRaBoards.cpp b/examples/Sensor/QMI8658_LockingMechanismExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_LockingMechanismExample/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_LockingMechanismExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_LockingMechanismExample/LoRaBoards.h b/examples/Sensor/QMI8658_LockingMechanismExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_LockingMechanismExample/LoRaBoards.h +++ b/examples/Sensor/QMI8658_LockingMechanismExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_MadgwickAHRS/LoRaBoards.cpp b/examples/Sensor/QMI8658_MadgwickAHRS/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_MadgwickAHRS/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_MadgwickAHRS/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_MadgwickAHRS/LoRaBoards.h b/examples/Sensor/QMI8658_MadgwickAHRS/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_MadgwickAHRS/LoRaBoards.h +++ b/examples/Sensor/QMI8658_MadgwickAHRS/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_PedometerExample/LoRaBoards.cpp b/examples/Sensor/QMI8658_PedometerExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_PedometerExample/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_PedometerExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_PedometerExample/LoRaBoards.h b/examples/Sensor/QMI8658_PedometerExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_PedometerExample/LoRaBoards.h +++ b/examples/Sensor/QMI8658_PedometerExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_ReadFromFifoExample/LoRaBoards.cpp b/examples/Sensor/QMI8658_ReadFromFifoExample/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_ReadFromFifoExample/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_ReadFromFifoExample/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_ReadFromFifoExample/LoRaBoards.h b/examples/Sensor/QMI8658_ReadFromFifoExample/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_ReadFromFifoExample/LoRaBoards.h +++ b/examples/Sensor/QMI8658_ReadFromFifoExample/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/Sensor/QMI8658_WakeOnMotion/LoRaBoards.cpp b/examples/Sensor/QMI8658_WakeOnMotion/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/Sensor/QMI8658_WakeOnMotion/LoRaBoards.cpp +++ b/examples/Sensor/QMI8658_WakeOnMotion/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/Sensor/QMI8658_WakeOnMotion/LoRaBoards.h b/examples/Sensor/QMI8658_WakeOnMotion/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/Sensor/QMI8658_WakeOnMotion/LoRaBoards.h +++ b/examples/Sensor/QMI8658_WakeOnMotion/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/T3S3Factory/LoRaBoards.cpp b/examples/T3S3Factory/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/T3S3Factory/LoRaBoards.cpp +++ b/examples/T3S3Factory/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/T3S3Factory/LoRaBoards.h b/examples/T3S3Factory/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/T3S3Factory/LoRaBoards.h +++ b/examples/T3S3Factory/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline; diff --git a/examples/TBeamFactory/LoRaBoards.cpp b/examples/TBeamFactory/LoRaBoards.cpp index f1b3a71..ec0fe33 100644 --- a/examples/TBeamFactory/LoRaBoards.cpp +++ b/examples/TBeamFactory/LoRaBoards.cpp @@ -33,8 +33,11 @@ HardwareSerial SerialGPS(GPS_RX_PIN, GPS_TX_PIN); #include "driver/gpio.h" #endif //ARDUINO_ARCH_ESP32 - +#ifdef DISPLAY_MODEL DISPLAY_MODEL *u8g2 = NULL; +#endif + + static DevInfo_t devInfo; #ifdef HAS_GPS @@ -45,6 +48,7 @@ String gps_model = "None"; uint32_t deviceOnline = 0x00; +static void enable_slow_clock(); #ifdef HAS_PMU XPowersLibInterface *PMU = NULL; @@ -54,14 +58,8 @@ static void setPmuFlag() { pmuInterrupt = true; } -#endif - -static void enable_slow_clock(); - - bool beginPower() { -#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(PMU_WIRE_PORT); if (!PMU->init()) { @@ -340,14 +338,12 @@ bool beginPower() default: break; } -#endif return true; } void disablePeripherals() { -#ifdef HAS_PMU if (!PMU)return; PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -403,12 +399,10 @@ void disablePeripherals() } #endif -#endif } void loopPMU(void (*pressed_cb)(void)) { -#ifdef HAS_PMU if (!PMU) { return; } @@ -453,9 +447,10 @@ void loopPMU(void (*pressed_cb)(void)) } // Clear PMU Interrupt Status Register PMU->clearIrqStatus(); -#endif } +#endif +#ifdef DISPLAY_ADDR bool beginDisplay() { Wire.beginTransmission(DISPLAY_ADDR); @@ -481,6 +476,7 @@ bool beginDisplay() Serial.printf("Warning: Failed to find Display at 0x%0X address\n", DISPLAY_ADDR); return false; } +#endif #ifdef HAS_SDCARD bool writeFile(const char *path, const char *buffer) @@ -538,9 +534,9 @@ bool testSDWriteAndRead() } #endif /*HAS_SDCARD*/ +#ifdef HAS_SDCARD bool beginSDCard() { -#ifdef HAS_SDCARD #if defined(HAS_SDCARD) && defined(SD_SHARE_SPI_BUS) bool rlst = SD.begin(SDCARD_CS); #else @@ -557,9 +553,9 @@ bool beginSDCard() } else { Serial.println("Warning: Failed to init Sd Card"); } -#endif /*HAS_SDCARD*/ return false; } +#endif /*HAS_SDCARD*/ void beginWiFi() { @@ -814,9 +810,11 @@ void setupBoards(bool disable_u8g2 ) beginSDCard(); +#ifdef DISPLAY_ADDR if (!disable_u8g2) { beginDisplay(); } +#endif // scanWiFi(); @@ -872,8 +870,10 @@ void printResult(bool radio_online) Serial.print("PSRAM : "); Serial.println((psramFound()) ? "+" : "-"); +#ifdef DISPLAY_MODEL Serial.print("Display : "); Serial.println(( u8g2) ? "+" : "-"); +#endif #ifdef HAS_SDCARD Serial.print("Sd Card : "); @@ -890,6 +890,7 @@ void printResult(bool radio_online) Serial.println(( find_gps ) ? "+" : "-"); #endif +#ifdef DISPLAY_MODEL if (u8g2) { u8g2->clearBuffer(); @@ -915,6 +916,7 @@ void printResult(bool radio_online) delay(2000); } #endif +#endif /*DISPLAY_MODEL*/ } @@ -925,9 +927,9 @@ static uint32_t lastDebounceTime = 0; #endif +#ifdef BOARD_LED void flashLed() { -#ifdef BOARD_LED if ((millis() - lastDebounceTime) > debounceDelay) { ledState = !ledState; if (ledState) { @@ -937,8 +939,8 @@ void flashLed() } lastDebounceTime = millis(); } -#endif } +#endif void scanDevices(TwoWire *w) @@ -1201,13 +1203,13 @@ float getTempForNTC() return temperature; } +#ifdef ENABLE_BLE #define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" void setupBLE() { -#ifdef ENABLE_BLE uint8_t mac[6]; char macStr[18] = { 0 }; @@ -1239,8 +1241,8 @@ void setupBLE() pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); -#endif } +#endif #define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) diff --git a/examples/TBeamFactory/LoRaBoards.h b/examples/TBeamFactory/LoRaBoards.h index e69f933..3bca53c 100644 --- a/examples/TBeamFactory/LoRaBoards.h +++ b/examples/TBeamFactory/LoRaBoards.h @@ -16,7 +16,7 @@ #include #endif -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP32) #include #include #endif @@ -24,30 +24,18 @@ #include #include #include + +#ifdef DISPLAY_MODEL #include +#endif + +#ifdef HAS_PMU #include +#endif #include -#ifndef DISPLAY_MODEL -#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C -#endif - -#ifndef OLED_WIRE_PORT -#define OLED_WIRE_PORT Wire -#endif - -#ifndef PMU_WIRE_PORT -#define PMU_WIRE_PORT Wire -#endif - -#ifndef DISPLAY_ADDR -#define DISPLAY_ADDR 0x3C -#endif - -#ifndef LORA_FREQ_CONFIG -#define LORA_FREQ_CONFIG 915.0 -#endif +// #define ENABLE_BLE //Enable ble function enum { POWERMANAGE_ONLINE = _BV(0), @@ -67,7 +55,6 @@ enum { }; -#define ENABLE_BLE //Enable ble function typedef struct { String chipModel; @@ -81,17 +68,24 @@ typedef struct { void setupBoards(bool disable_u8g2 = false); +#ifdef HAS_SDCARD bool beginSDCard(); +#else +#define beginSDCard() +#endif +#ifdef DISPLAY_ADDR bool beginDisplay(); +#endif -void disablePeripherals(); - -bool beginPower(); void printResult(bool radio_online); +#ifdef BOARD_LED void flashLed(); +#else +#define flashLed() +#endif void scanDevices(TwoWire *w); @@ -99,18 +93,23 @@ bool beginGPS(); bool recoveryGPS(); -void loopPMU(void (*pressed_cb)(void)); - void scanWiFi(); #ifdef HAS_PMU extern XPowersLibInterface *PMU; extern bool pmuInterrupt; +void loopPMU(void (*pressed_cb)(void)); +bool beginPower(); +void disablePeripherals(); +#else +#define beginPower() #endif -extern DISPLAY_MODEL *u8g2; +#ifdef DISPLAY_MODEL +extern DISPLAY_MODEL *u8g2; #define U8G2_HOR_ALIGN_CENTER(t) ((u8g2->getDisplayWidth() - (u8g2->getUTF8Width(t))) / 2) #define U8G2_HOR_ALIGN_RIGHT(t) ( u8g2->getDisplayWidth() - u8g2->getUTF8Width(t)) +#endif #if defined(ARDUINO_ARCH_ESP32) @@ -124,8 +123,12 @@ extern SPIClass SDCardSPI; extern HardwareSerial SerialGPS; #endif +#ifdef HAS_NTC float getTempForNTC(); +#endif +#ifdef ENABLE_BLE void setupBLE(); +#endif extern uint32_t deviceOnline;