diff --git a/platformio.ini b/platformio.ini index ead659b4..e044e726 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,11 +11,11 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;env_default = generic +env_default = generic ;env_default = heltec ;env_default = ttgov1 ;env_default = ttgov2 -env_default = ttgov21 +;env_default = ttgov21 ;env_default = ttgobeam ;env_default = lopy ;env_default = lopy4 diff --git a/src/blescan.h b/src/blescan.h index a546f532..fa66b551 100644 --- a/src/blescan.h +++ b/src/blescan.h @@ -1,6 +1,8 @@ #ifndef BLESCAN_H #define BLESCAN_H +#include "macsniff.h" + void start_BLEscan(void); void stop_BLEscan(void); diff --git a/src/globals.h b/src/globals.h index b6cb1c2f..83ee51e6 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,16 +1,37 @@ // The mother of all embedded development... #include +// needed for ESP_LOGx on arduino framework +#include + +// attn: increment version after modifications to configData_t truct! +#define PROGVERSION "1.3.91" // use max 10 chars here! +#define PROGNAME "PAXCNT" + // std::set for unified array functions #include #include #include -// basics -#include "main.h" -#include "led.h" -#include "macsniff.h" -#include "payload.h" +// Struct holding devices's runtime configuration +typedef struct { + uint8_t lorasf; // 7-12, lora spreadfactor + uint8_t txpower; // 2-15, lora tx power + uint8_t adrmode; // 0=disabled, 1=enabled + uint8_t screensaver; // 0=disabled, 1=enabled + uint8_t screenon; // 0=disabled, 1=enabled + uint8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed + int16_t rssilimit; // threshold for rssilimiter, negative value! + uint8_t sendcycle; // payload send cycle [seconds/2] + uint8_t wifichancycle; // wifi channel switch cycle [seconds/100] + uint8_t blescantime; // BLE scan cycle duration [seconds] + uint8_t blescan; // 0=disabled, 1=enabled + uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4) + uint8_t vendorfilter; // 0=disabled, 1=enabled + uint8_t rgblum; // RGB Led luminosity (0..100%) + uint8_t gpsmode; // 0=disabled, 1=enabled + char version[10]; // Firmware version +} configData_t; extern configData_t cfg; extern char display_line6[], display_line7[]; @@ -21,11 +42,41 @@ extern std::set macs; extern hw_timer_t *channelSwitch, *sendCycle; extern portMUX_TYPE timerMux; -#ifdef HAS_GPS -extern gpsStatus_t gps_status; // struct for storing gps data -extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe +#ifdef HAS_LORA +#include "lorawan.h" #endif +#ifdef HAS_DISPLAY +#include "display.h" +#endif + +#ifdef HAS_GPS +#include "gps.h" +typedef struct { + uint32_t latitude; + uint32_t longitude; + uint8_t satellites; + uint16_t hdop; + uint16_t altitude; +} gpsStatus_t; +extern gpsStatus_t gps_status; // struct for storing gps data +#endif + +#ifdef BLECOUNTER +#include "blescan.h" +#endif + +#ifdef HAS_BATTERY_PROBE +#include "battery.h" +#endif + +#ifdef HAS_ANTENNA_SWITCH +#include "antenna.h" +#endif + +// class for preparing payload data +#include "payload.h" + // payload encoder #if PAYLOAD_ENCODER == 1 extern TTNplain payload; @@ -35,4 +86,10 @@ extern TTNpacked payload; extern CayenneLPP payload; #else #error "No valid payload converter defined" -#endif \ No newline at end of file +#endif + + +void reset_counters(void); +void blink_LED(uint16_t set_color, uint16_t set_blinkduration); +void led_loop(void); +uint64_t uptime(); \ No newline at end of file diff --git a/src/gps.cpp b/src/gps.cpp index d0a83e39..98952f53 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -1,7 +1,6 @@ #ifdef HAS_GPS #include "globals.h" -#include // Local logging tag static const char TAG[] = "main"; diff --git a/src/gps.h b/src/gps.h index 00c98d38..cb0860ad 100644 --- a/src/gps.h +++ b/src/gps.h @@ -3,6 +3,8 @@ #include +extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe + void gps_read(void); void gps_loop(void *pvParameters); diff --git a/src/led.h b/src/led.h index 591db1cc..9ed8699d 100644 --- a/src/led.h +++ b/src/led.h @@ -1,5 +1,5 @@ - -//#pragma once +#ifndef led_H +#define led_H #ifdef HAS_RGB_LED #include @@ -35,3 +35,5 @@ enum led_states { LED_OFF, LED_ON }; void rgb_set_color(uint16_t hue); void blink_LED(uint16_t set_color, uint16_t set_blinkduration); void led_loop(); + +#endif \ No newline at end of file diff --git a/src/macsniff.h b/src/macsniff.h index 442b5068..23ff36a0 100644 --- a/src/macsniff.h +++ b/src/macsniff.h @@ -7,6 +7,8 @@ // Hash function for scrambling MAC addresses #include "hash.h" +#include "led.h" + #define MAC_SNIFF_WIFI 0 #define MAC_SNIFF_BLE 1 diff --git a/src/main.cpp b/src/main.cpp index 684f12de..b0e97869 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,7 @@ licenses. Refer to LICENSE.txt file in repository for more details. // Basic Config #include "globals.h" +#include "main.h" // Initialize global variables configData_t cfg; // struct holds current device configuration diff --git a/src/main.h b/src/main.h index 218034f2..2c330989 100644 --- a/src/main.h +++ b/src/main.h @@ -1,77 +1,17 @@ +#ifndef main_H +#define main_H +#include "led.h" +#include "macsniff.h" #include "configmanager.h" #include "senddata.h" -// Does nothing and avoid any compilation error with I2C -#include - -// ESP32 lib Functions -#include // needed for ESP_LOGx on arduino framework -#include // needed for Wifi event handler #include // needed for reading ESP32 chip attributes - -#ifdef HAS_LORA -#include "lorawan.h" -#endif - -#ifdef HAS_DISPLAY -#include "display.h" -#endif - -#ifdef HAS_GPS -#include "gps.h" -#endif - -#ifdef BLECOUNTER -#include "blescan.h" -#endif - -#ifdef HAS_BATTERY_PROBE -#include "battery.h" -#endif - -#ifdef HAS_ANTENNA_SWITCH -#include "antenna.h" -#endif - -// program version - note: increment version after modifications to configData_t -// struct!! -#define PROGVERSION "1.3.91" // use max 10 chars here! -#define PROGNAME "PAXCNT" - -// Struct holding devices's runtime configuration -typedef struct { - uint8_t lorasf; // 7-12, lora spreadfactor - uint8_t txpower; // 2-15, lora tx power - uint8_t adrmode; // 0=disabled, 1=enabled - uint8_t screensaver; // 0=disabled, 1=enabled - uint8_t screenon; // 0=disabled, 1=enabled - uint8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed - int16_t rssilimit; // threshold for rssilimiter, negative value! - uint8_t sendcycle; // payload send cycle [seconds/2] - uint8_t wifichancycle; // wifi channel switch cycle [seconds/100] - uint8_t blescantime; // BLE scan cycle duration [seconds] - uint8_t blescan; // 0=disabled, 1=enabled - uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4) - uint8_t vendorfilter; // 0=disabled, 1=enabled - uint8_t rgblum; // RGB Led luminosity (0..100%) - uint8_t gpsmode; // 0=disabled, 1=enabled - char version[10]; // Firmware version -} configData_t; - -#ifdef HAS_GPS -typedef struct { - uint32_t latitude; - uint32_t longitude; - uint8_t satellites; - uint16_t hdop; - uint16_t altitude; -} gpsStatus_t; -extern gpsStatus_t gps_status; // struct for storing gps data -extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe -#endif +#include // needed for Wifi event handler void reset_counters(void); void blink_LED(uint16_t set_color, uint16_t set_blinkduration); void led_loop(void); -uint64_t uptime(); \ No newline at end of file +uint64_t uptime(); + +#endif \ No newline at end of file diff --git a/src/rcommand.cpp b/src/rcommand.cpp index a8d735a5..f6183855 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -5,6 +5,7 @@ // Basic Config #include "globals.h" +#include "rcommand.h" // Local logging tag static const char TAG[] = "main"; diff --git a/src/rcommand.h b/src/rcommand.h index 9cc55e69..71ee79fe 100644 --- a/src/rcommand.h +++ b/src/rcommand.h @@ -1,6 +1,9 @@ #ifndef rcommand_H #define rcommand_H +#include "senddata.h" +#include "configmanager.h" + void rcommand(uint8_t cmd, uint8_t arg); void switch_lora(uint8_t sf, uint8_t tx);