diff --git a/include/configmanager.h b/include/configmanager.h index 95864994..e9c5e7c0 100644 --- a/include/configmanager.h +++ b/include/configmanager.h @@ -5,6 +5,8 @@ #include "reset.h" #include +extern configData_t cfg; + void saveConfig(bool erase = false); bool loadConfig(void); void eraseConfig(void); diff --git a/include/cyclic.h b/include/cyclic.h index 3623a7b5..94619a14 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -13,6 +13,7 @@ #include "sdcard.h" #include "reset.h" #include "led.h" +#include "power.h" extern Ticker cyclicTimer; diff --git a/include/display.h b/include/display.h index 8b16f412..338f62d5 100644 --- a/include/display.h +++ b/include/display.h @@ -4,6 +4,7 @@ #include #include "cyclic.h" #include "qrcode.h" +#include "power.h" #if (COUNT_ENS) #include "corona.h" @@ -77,7 +78,10 @@ #define QR_VERSION 3 // 29 x 29px const uint8_t QR_SCALEFACTOR = (MY_DISPLAY_HEIGHT - 4) / 29; // 4px borderlines + extern uint8_t DisplayIsOn, displaybuf[]; +extern hw_timer_t *displayIRQ; +extern uint8_t volatile channel; // wifi channel rotation counter void dp_setup(int contrast = 0); void dp_refresh(bool nextPage = false); diff --git a/include/globals.h b/include/globals.h index 225ebd93..b6479048 100644 --- a/include/globals.h +++ b/include/globals.h @@ -50,16 +50,7 @@ #define _seconds() millis() / 1000.0 -enum timesource_t { _gps, _rtc, _lora, _set, _unsynced }; enum snifftype_t { MAC_SNIFF_WIFI, MAC_SNIFF_BLE, MAC_SNIFF_BLE_ENS }; -enum runmode_t { - RUNMODE_POWERCYCLE, - RUNMODE_NORMAL, - RUNMODE_WAKEUP, - RUNMODE_UPDATE, - RUNMODE_SLEEP, - RUNMODE_MAINTENANCE -}; // Struct holding devices's runtime configuration // using packed to avoid compiler padding, because struct will be memcpy'd to @@ -125,16 +116,6 @@ typedef struct { extern std::array::iterator it; extern std::array beacons; -extern configData_t cfg; // current device configuration -extern char clientId[20]; // unique clientID -extern uint8_t batt_level; // display value -extern uint16_t volatile libpax_macs_ble, libpax_macs_wifi; // libpax values -extern uint8_t volatile channel; // wifi channel rotation counter -extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC -extern timesource_t timeSource; -extern hw_timer_t *displayIRQ, *matrixDisplayIRQ, *ppsIRQ; -extern SemaphoreHandle_t I2Caccess; -extern TaskHandle_t irqHandlerTask, ClockTask; -extern Timezone myTZ; +extern char clientId[20]; // unique clientID #endif diff --git a/include/i2c.h b/include/i2c.h index 7fcbd33a..ce64ff70 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -21,6 +21,8 @@ #define MY_DISPLAY_SCL SCL #endif +extern SemaphoreHandle_t I2Caccess; + void i2c_init(void); void i2c_deinit(void); void i2c_scan(void); diff --git a/include/irqhandler.h b/include/irqhandler.h index 5d40c63c..8b14b293 100644 --- a/include/irqhandler.h +++ b/include/irqhandler.h @@ -26,6 +26,8 @@ void mask_user_IRQ(); void unmask_user_IRQ(); void doIRQ(int irq); +extern TaskHandle_t irqHandlerTask; + #ifdef HAS_DISPLAY void IRAM_ATTR DisplayIRQ(); #endif diff --git a/include/ledmatrixdisplay.h b/include/ledmatrixdisplay.h index 9db9ebee..b27914c1 100644 --- a/include/ledmatrixdisplay.h +++ b/include/ledmatrixdisplay.h @@ -6,8 +6,8 @@ #include "ledmatrixdisplay.h" extern uint8_t MatrixDisplayIsOn; - extern LEDMatrix matrix; +extern hw_timer_t *matrixDisplayIRQ; void init_matrix_display(bool reverse = false); void refreshTheMatrixDisplay(bool nextPage = false); diff --git a/include/libpax_helpers.h b/include/libpax_helpers.h index dd3c0238..59749226 100644 --- a/include/libpax_helpers.h +++ b/include/libpax_helpers.h @@ -7,4 +7,6 @@ void init_libpax(); +extern uint16_t volatile libpax_macs_ble, libpax_macs_wifi; // libpax values + #endif \ No newline at end of file diff --git a/include/main.h b/include/main.h index 765dc7bd..8a46c6e4 100644 --- a/include/main.h +++ b/include/main.h @@ -21,5 +21,6 @@ #include "corona.h" #include "boot.h" #include "libpax_helpers.h" +#include "power.h" #endif \ No newline at end of file diff --git a/include/payload.h b/include/payload.h index bf6a4577..cfa58720 100644 --- a/include/payload.h +++ b/include/payload.h @@ -3,6 +3,7 @@ #include "sensor.h" #include "sds011read.h" +#include "gpsread.h" // MyDevices CayenneLPP 1.0 channels for Synamic sensor payload format // all payload goes out on LoRa FPort 1 @@ -100,5 +101,6 @@ private: }; extern PayloadConvert payload; +extern uint8_t batt_level; #endif // _PAYLOAD_H_ diff --git a/include/rcommand.h b/include/rcommand.h index 4d59d75f..ae4a62f2 100644 --- a/include/rcommand.h +++ b/include/rcommand.h @@ -11,6 +11,7 @@ #include "cyclic.h" #include "timekeeper.h" #include "timesync.h" +#include "power.h" // maximum number of elements in rcommand interpreter queue #define RCMD_QUEUE_SIZE 5 diff --git a/include/reset.h b/include/reset.h index d55163b2..bffff1bc 100644 --- a/include/reset.h +++ b/include/reset.h @@ -16,6 +16,15 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60, const gpio_num_t wakeup_gpio = GPIO_NUM_MAX); unsigned long long uptime(void); +enum runmode_t { + RUNMODE_POWERCYCLE, + RUNMODE_NORMAL, + RUNMODE_WAKEUP, + RUNMODE_UPDATE, + RUNMODE_SLEEP, + RUNMODE_MAINTENANCE +}; + extern RTC_NOINIT_ATTR runmode_t RTC_runmode; extern RTC_NOINIT_ATTR uint32_t RTC_restarts; diff --git a/include/senddata.h b/include/senddata.h index f8666770..cc00c796 100644 --- a/include/senddata.h +++ b/include/senddata.h @@ -2,6 +2,7 @@ #define _SENDDATA_H #include +#include "libpax_helpers.h" #include "spislave.h" #include "mqttclient.h" #include "cyclic.h" diff --git a/include/sensor.h b/include/sensor.h index 322c78a7..06ba5fed 100644 --- a/include/sensor.h +++ b/include/sensor.h @@ -1,6 +1,8 @@ #ifndef _SENSOR_H #define _SENSOR_H +#include "configmanager.h" + #define HAS_SENSORS (HAS_SENSOR_1 || HAS_SENSOR_2 || HAS_SENSOR_3) uint8_t sensor_mask(uint8_t sensor_no); diff --git a/include/timekeeper.h b/include/timekeeper.h index f9455746..35482d40 100644 --- a/include/timekeeper.h +++ b/include/timekeeper.h @@ -10,8 +10,15 @@ #include "if482.h" #include "dcf77.h" +enum timesource_t { _gps, _rtc, _lora, _set, _unsynced }; + extern const char timeSetSymbols[]; extern Ticker timesyncer; +extern timesource_t timeSource; +extern TaskHandle_t ClockTask; +extern Timezone myTZ; +extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC +extern hw_timer_t *ppsIRQ; void IRAM_ATTR CLOCKIRQ(void); void clock_init(void); diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 55c604dd..e80b06fd 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -17,6 +17,8 @@ static const char TAG[] = __FILE__; Preferences nvram; +configData_t cfg; // struct holds current device configuration + static const uint8_t cfgMagicBytes[] = {0x21, 0x76, 0x87, 0x32, 0xf4}; static const size_t cfgLen = sizeof(cfg), cfgLen2 = sizeof(cfgMagicBytes); static uint8_t buffer[cfgLen + cfgLen2]; diff --git a/src/main.cpp b/src/main.cpp index b20d5f34..9337375c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,8 +89,6 @@ triggers pps 1 sec impulse // local Tag for logging static const char TAG[] = __FILE__; -configData_t cfg; // struct holds current device configuration -uint8_t batt_level = 0; // display value char clientId[20] = {0}; // unique ClientID void setup() { diff --git a/src/power.cpp b/src/power.cpp index 6453f1b2..e918a350 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -5,6 +5,8 @@ // Local logging tag static const char TAG[] = __FILE__; +uint8_t batt_level = 0; // display value + #ifdef BAT_MEASURE_ADC esp_adc_cal_characteristics_t *adc_characs = (esp_adc_cal_characteristics_t *)calloc(