clang-format: configmanager.cpp, globals.h, gpsread.cpp
This commit is contained in:
parent
0cbfb1c354
commit
4466889a18
@ -13,12 +13,12 @@ esp_err_t err;
|
|||||||
|
|
||||||
// defined in antenna.cpp
|
// defined in antenna.cpp
|
||||||
#ifdef HAS_ANTENNA_SWITCH
|
#ifdef HAS_ANTENNA_SWITCH
|
||||||
void antenna_select(const uint8_t _ant);
|
void antenna_select(const uint8_t _ant);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// populate cfg vars with factory settings
|
// populate cfg vars with factory settings
|
||||||
void defaultConfig() {
|
void defaultConfig() {
|
||||||
cfg.lorasf = LORASFDEFAULT; // 7-12, initial lora spreadfactor defined in paxcounter.conf
|
cfg.lorasf = LORASFDEFAULT; // 7-12, initial lora sf, see pacounter.conf
|
||||||
cfg.txpower = 15; // 2-15, lora tx power
|
cfg.txpower = 15; // 2-15, lora tx power
|
||||||
cfg.adrmode = 1; // 0=disabled, 1=enabled
|
cfg.adrmode = 1; // 0=disabled, 1=enabled
|
||||||
cfg.screensaver = 0; // 0=disabled, 1=enabled
|
cfg.screensaver = 0; // 0=disabled, 1=enabled
|
||||||
@ -26,15 +26,18 @@ void defaultConfig() {
|
|||||||
cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed
|
cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed
|
||||||
cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
|
cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
|
||||||
cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2]
|
cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2]
|
||||||
cfg.wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
|
cfg.wifichancycle =
|
||||||
cfg.blescantime = BLESCANINTERVAL / 10; // BT channel scan cycle duration [seconds/100], default 1 (= 10ms)
|
WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
|
||||||
|
cfg.blescantime =
|
||||||
|
BLESCANINTERVAL /
|
||||||
|
10; // BT channel scan cycle [seconds/100], default 1 (= 10ms)
|
||||||
cfg.blescan = 1; // 0=disabled, 1=enabled
|
cfg.blescan = 1; // 0=disabled, 1=enabled
|
||||||
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||||
cfg.vendorfilter = 1; // 0=disabled, 1=enabled
|
cfg.vendorfilter = 1; // 0=disabled, 1=enabled
|
||||||
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
|
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
|
||||||
cfg.gpsmode = 1; // 0=disabled, 1=enabled
|
cfg.gpsmode = 1; // 0=disabled, 1=enabled
|
||||||
|
|
||||||
strncpy( cfg.version, PROGVERSION, sizeof(cfg.version)-1 );
|
strncpy(cfg.version, PROGVERSION, sizeof(cfg.version) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_storage() {
|
void open_storage() {
|
||||||
@ -45,7 +48,7 @@ void open_storage() {
|
|||||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
err = nvs_flash_init();
|
err = nvs_flash_init();
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK( err );
|
ESP_ERROR_CHECK(err);
|
||||||
|
|
||||||
// Open
|
// Open
|
||||||
ESP_LOGI(TAG, "Opening NVS");
|
ESP_LOGI(TAG, "Opening NVS");
|
||||||
@ -64,9 +67,10 @@ void eraseConfig() {
|
|||||||
nvs_erase_all(my_handle);
|
nvs_erase_all(my_handle);
|
||||||
nvs_commit(my_handle);
|
nvs_commit(my_handle);
|
||||||
nvs_close(my_handle);
|
nvs_close(my_handle);
|
||||||
ESP_LOGI(TAG, "Done");}
|
ESP_LOGI(TAG, "Done");
|
||||||
else {
|
} else {
|
||||||
ESP_LOGW(TAG, "NVS erase failed"); }
|
ESP_LOGW(TAG, "NVS erase failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// save current configuration from RAM to NVRAM
|
// save current configuration from RAM to NVRAM
|
||||||
@ -79,57 +83,74 @@ void saveConfig() {
|
|||||||
size_t required_size;
|
size_t required_size;
|
||||||
char storedversion[10];
|
char storedversion[10];
|
||||||
|
|
||||||
if( nvs_get_str(my_handle, "version", storedversion, &required_size) != ESP_OK || strcmp(storedversion, cfg.version) != 0 )
|
if (nvs_get_str(my_handle, "version", storedversion, &required_size) !=
|
||||||
|
ESP_OK ||
|
||||||
|
strcmp(storedversion, cfg.version) != 0)
|
||||||
nvs_set_str(my_handle, "version", cfg.version);
|
nvs_set_str(my_handle, "version", cfg.version);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "lorasf", &flash8) != ESP_OK || flash8 != cfg.lorasf )
|
if (nvs_get_i8(my_handle, "lorasf", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.lorasf)
|
||||||
nvs_set_i8(my_handle, "lorasf", cfg.lorasf);
|
nvs_set_i8(my_handle, "lorasf", cfg.lorasf);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "txpower", &flash8) != ESP_OK || flash8 != cfg.txpower )
|
if (nvs_get_i8(my_handle, "txpower", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.txpower)
|
||||||
nvs_set_i8(my_handle, "txpower", cfg.txpower);
|
nvs_set_i8(my_handle, "txpower", cfg.txpower);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "adrmode", &flash8) != ESP_OK || flash8 != cfg.adrmode )
|
if (nvs_get_i8(my_handle, "adrmode", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.adrmode)
|
||||||
nvs_set_i8(my_handle, "adrmode", cfg.adrmode);
|
nvs_set_i8(my_handle, "adrmode", cfg.adrmode);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "screensaver", &flash8) != ESP_OK || flash8 != cfg.screensaver )
|
if (nvs_get_i8(my_handle, "screensaver", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.screensaver)
|
||||||
nvs_set_i8(my_handle, "screensaver", cfg.screensaver);
|
nvs_set_i8(my_handle, "screensaver", cfg.screensaver);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "screenon", &flash8) != ESP_OK || flash8 != cfg.screenon )
|
if (nvs_get_i8(my_handle, "screenon", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.screenon)
|
||||||
nvs_set_i8(my_handle, "screenon", cfg.screenon);
|
nvs_set_i8(my_handle, "screenon", cfg.screenon);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "countermode", &flash8) != ESP_OK || flash8 != cfg.countermode )
|
if (nvs_get_i8(my_handle, "countermode", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.countermode)
|
||||||
nvs_set_i8(my_handle, "countermode", cfg.countermode);
|
nvs_set_i8(my_handle, "countermode", cfg.countermode);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "sendcycle", &flash8) != ESP_OK || flash8 != cfg.sendcycle )
|
if (nvs_get_i8(my_handle, "sendcycle", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.sendcycle)
|
||||||
nvs_set_i8(my_handle, "sendcycle", cfg.sendcycle);
|
nvs_set_i8(my_handle, "sendcycle", cfg.sendcycle);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "wifichancycle", &flash8) != ESP_OK || flash8 != cfg.wifichancycle )
|
if (nvs_get_i8(my_handle, "wifichancycle", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.wifichancycle)
|
||||||
nvs_set_i8(my_handle, "wifichancycle", cfg.wifichancycle);
|
nvs_set_i8(my_handle, "wifichancycle", cfg.wifichancycle);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "blescantime", &flash8) != ESP_OK || flash8 != cfg.blescantime )
|
if (nvs_get_i8(my_handle, "blescantime", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.blescantime)
|
||||||
nvs_set_i8(my_handle, "blescantime", cfg.blescantime);
|
nvs_set_i8(my_handle, "blescantime", cfg.blescantime);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "blescanmode", &flash8) != ESP_OK || flash8 != cfg.blescan )
|
if (nvs_get_i8(my_handle, "blescanmode", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.blescan)
|
||||||
nvs_set_i8(my_handle, "blescanmode", cfg.blescan);
|
nvs_set_i8(my_handle, "blescanmode", cfg.blescan);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK || flash8 != cfg.wifiant )
|
if (nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.wifiant)
|
||||||
nvs_set_i8(my_handle, "wifiant", cfg.wifiant);
|
nvs_set_i8(my_handle, "wifiant", cfg.wifiant);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "vendorfilter", &flash8) != ESP_OK || flash8 != cfg.vendorfilter )
|
if (nvs_get_i8(my_handle, "vendorfilter", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.vendorfilter)
|
||||||
nvs_set_i8(my_handle, "vendorfilter", cfg.vendorfilter);
|
nvs_set_i8(my_handle, "vendorfilter", cfg.vendorfilter);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "rgblum", &flash8) != ESP_OK || flash8 != cfg.rgblum )
|
if (nvs_get_i8(my_handle, "rgblum", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.rgblum)
|
||||||
nvs_set_i8(my_handle, "rgblum", cfg.rgblum);
|
nvs_set_i8(my_handle, "rgblum", cfg.rgblum);
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "gpsmode", &flash8) != ESP_OK || flash8 != cfg.gpsmode )
|
if (nvs_get_i8(my_handle, "gpsmode", &flash8) != ESP_OK ||
|
||||||
|
flash8 != cfg.gpsmode)
|
||||||
nvs_set_i8(my_handle, "gpsmode", cfg.gpsmode);
|
nvs_set_i8(my_handle, "gpsmode", cfg.gpsmode);
|
||||||
|
|
||||||
if( nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK || flash16 != cfg.rssilimit )
|
if (nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK ||
|
||||||
|
flash16 != cfg.rssilimit)
|
||||||
nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit);
|
nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit);
|
||||||
|
|
||||||
err = nvs_commit(my_handle);
|
err = nvs_commit(my_handle);
|
||||||
nvs_close(my_handle);
|
nvs_close(my_handle);
|
||||||
if ( err == ESP_OK ) {
|
if (err == ESP_OK) {
|
||||||
ESP_LOGI(TAG, "Done");
|
ESP_LOGI(TAG, "Done");
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "NVS config write failed");
|
ESP_LOGW(TAG, "NVS config write failed");
|
||||||
@ -152,19 +173,21 @@ void loadConfig() {
|
|||||||
ESP_LOGI(TAG, "Reading settings from NVS");
|
ESP_LOGI(TAG, "Reading settings from NVS");
|
||||||
open_storage();
|
open_storage();
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGW(TAG,"Error (%d) opening NVS handle, storing defaults", err);
|
ESP_LOGW(TAG, "Error (%d) opening NVS handle, storing defaults", err);
|
||||||
saveConfig(); } // saves factory settings to NVRAM
|
saveConfig();
|
||||||
|
} // saves factory settings to NVRAM
|
||||||
else {
|
else {
|
||||||
int8_t flash8 = 0;
|
int8_t flash8 = 0;
|
||||||
int16_t flash16 = 0;
|
int16_t flash16 = 0;
|
||||||
size_t required_size;
|
size_t required_size;
|
||||||
|
|
||||||
// check if configuration stored in NVRAM matches PROGVERSION
|
// check if configuration stored in NVRAM matches PROGVERSION
|
||||||
if( nvs_get_str(my_handle, "version", NULL, &required_size) == ESP_OK ) {
|
if (nvs_get_str(my_handle, "version", NULL, &required_size) == ESP_OK) {
|
||||||
nvs_get_str(my_handle, "version", cfg.version, &required_size);
|
nvs_get_str(my_handle, "version", cfg.version, &required_size);
|
||||||
ESP_LOGI(TAG, "NVRAM settings version = %s", cfg.version);
|
ESP_LOGI(TAG, "NVRAM settings version = %s", cfg.version);
|
||||||
if (strcmp(cfg.version, PROGVERSION)) {
|
if (strcmp(cfg.version, PROGVERSION)) {
|
||||||
ESP_LOGI(TAG, "migrating NVRAM settings to new version %s", PROGVERSION);
|
ESP_LOGI(TAG, "migrating NVRAM settings to new version %s",
|
||||||
|
PROGVERSION);
|
||||||
nvs_close(my_handle);
|
nvs_close(my_handle);
|
||||||
migrateVersion();
|
migrateVersion();
|
||||||
}
|
}
|
||||||
@ -176,7 +199,7 @@ void loadConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// overwrite defaults with valid values from NVRAM
|
// overwrite defaults with valid values from NVRAM
|
||||||
if( nvs_get_i8(my_handle, "lorasf", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "lorasf", &flash8) == ESP_OK) {
|
||||||
cfg.lorasf = flash8;
|
cfg.lorasf = flash8;
|
||||||
ESP_LOGI(TAG, "lorasf = %d", flash8);
|
ESP_LOGI(TAG, "lorasf = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -184,7 +207,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "txpower", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "txpower", &flash8) == ESP_OK) {
|
||||||
cfg.txpower = flash8;
|
cfg.txpower = flash8;
|
||||||
ESP_LOGI(TAG, "txpower = %d", flash8);
|
ESP_LOGI(TAG, "txpower = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -192,7 +215,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "adrmode", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "adrmode", &flash8) == ESP_OK) {
|
||||||
cfg.adrmode = flash8;
|
cfg.adrmode = flash8;
|
||||||
ESP_LOGI(TAG, "adrmode = %d", flash8);
|
ESP_LOGI(TAG, "adrmode = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -200,7 +223,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "screensaver", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "screensaver", &flash8) == ESP_OK) {
|
||||||
cfg.screensaver = flash8;
|
cfg.screensaver = flash8;
|
||||||
ESP_LOGI(TAG, "screensaver = %d", flash8);
|
ESP_LOGI(TAG, "screensaver = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -208,7 +231,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "screenon", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "screenon", &flash8) == ESP_OK) {
|
||||||
cfg.screenon = flash8;
|
cfg.screenon = flash8;
|
||||||
ESP_LOGI(TAG, "screenon = %d", flash8);
|
ESP_LOGI(TAG, "screenon = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -216,7 +239,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "countermode", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "countermode", &flash8) == ESP_OK) {
|
||||||
cfg.countermode = flash8;
|
cfg.countermode = flash8;
|
||||||
ESP_LOGI(TAG, "countermode = %d", flash8);
|
ESP_LOGI(TAG, "countermode = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -224,7 +247,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "sendcycle", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "sendcycle", &flash8) == ESP_OK) {
|
||||||
cfg.sendcycle = flash8;
|
cfg.sendcycle = flash8;
|
||||||
ESP_LOGI(TAG, "sendcycle = %d", flash8);
|
ESP_LOGI(TAG, "sendcycle = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -232,7 +255,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "wifichancycle", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "wifichancycle", &flash8) == ESP_OK) {
|
||||||
cfg.wifichancycle = flash8;
|
cfg.wifichancycle = flash8;
|
||||||
ESP_LOGI(TAG, "wifichancycle = %d", flash8);
|
ESP_LOGI(TAG, "wifichancycle = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -240,7 +263,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "wifiant", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "wifiant", &flash8) == ESP_OK) {
|
||||||
cfg.wifiant = flash8;
|
cfg.wifiant = flash8;
|
||||||
ESP_LOGI(TAG, "wifiantenna = %d", flash8);
|
ESP_LOGI(TAG, "wifiantenna = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -248,7 +271,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "vendorfilter", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "vendorfilter", &flash8) == ESP_OK) {
|
||||||
cfg.vendorfilter = flash8;
|
cfg.vendorfilter = flash8;
|
||||||
ESP_LOGI(TAG, "vendorfilter = %d", flash8);
|
ESP_LOGI(TAG, "vendorfilter = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -256,7 +279,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK) {
|
||||||
cfg.rgblum = flash8;
|
cfg.rgblum = flash8;
|
||||||
ESP_LOGI(TAG, "rgbluminosity = %d", flash8);
|
ESP_LOGI(TAG, "rgbluminosity = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -264,7 +287,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "blescantime", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "blescantime", &flash8) == ESP_OK) {
|
||||||
cfg.blescantime = flash8;
|
cfg.blescantime = flash8;
|
||||||
ESP_LOGI(TAG, "blescantime = %d", flash8);
|
ESP_LOGI(TAG, "blescantime = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -272,7 +295,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "blescanmode", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "blescanmode", &flash8) == ESP_OK) {
|
||||||
cfg.blescan = flash8;
|
cfg.blescan = flash8;
|
||||||
ESP_LOGI(TAG, "BLEscanmode = %d", flash8);
|
ESP_LOGI(TAG, "BLEscanmode = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -280,7 +303,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK ) {
|
if (nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK) {
|
||||||
cfg.rssilimit = flash16;
|
cfg.rssilimit = flash16;
|
||||||
ESP_LOGI(TAG, "rssilimit = %d", flash16);
|
ESP_LOGI(TAG, "rssilimit = %d", flash16);
|
||||||
} else {
|
} else {
|
||||||
@ -288,7 +311,7 @@ void loadConfig() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nvs_get_i8(my_handle, "gpsmode", &flash8) == ESP_OK ) {
|
if (nvs_get_i8(my_handle, "gpsmode", &flash8) == ESP_OK) {
|
||||||
cfg.gpsmode = flash8;
|
cfg.gpsmode = flash8;
|
||||||
ESP_LOGI(TAG, "GPSmode = %d", flash8);
|
ESP_LOGI(TAG, "GPSmode = %d", flash8);
|
||||||
} else {
|
} else {
|
||||||
@ -301,8 +324,8 @@ void loadConfig() {
|
|||||||
|
|
||||||
// put actions to be triggered after config loaded here
|
// put actions to be triggered after config loaded here
|
||||||
|
|
||||||
#ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one
|
#ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one
|
||||||
antenna_select(cfg.wifiant);
|
antenna_select(cfg.wifiant);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
// OLED Display
|
// OLED Display
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
#include <U8x8lib.h>
|
#include <U8x8lib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//GPS
|
// GPS
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
#include <TinyGPS++.h>
|
#include <TinyGPS++.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// LMIC-Arduino LoRaWAN Stack
|
// LMIC-Arduino LoRaWAN Stack
|
||||||
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
// LED controls
|
// LED controls
|
||||||
#ifdef HAS_RGB_LED
|
#ifdef HAS_RGB_LED
|
||||||
#include <SmartLeds.h>
|
#include <SmartLeds.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "rgb_led.h"
|
#include "rgb_led.h"
|
||||||
@ -47,18 +47,18 @@ typedef struct {
|
|||||||
uint8_t rgblum; // RGB Led luminosity (0..100%)
|
uint8_t rgblum; // RGB Led luminosity (0..100%)
|
||||||
uint8_t gpsmode; // 0=disabled, 1=enabled
|
uint8_t gpsmode; // 0=disabled, 1=enabled
|
||||||
char version[10]; // Firmware version
|
char version[10]; // Firmware version
|
||||||
} configData_t;
|
} configData_t;
|
||||||
|
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t latitude;
|
uint32_t latitude;
|
||||||
uint32_t longitude;
|
uint32_t longitude;
|
||||||
uint8_t satellites;
|
uint8_t satellites;
|
||||||
uint16_t hdop;
|
uint16_t hdop;
|
||||||
uint16_t altitude;
|
uint16_t altitude;
|
||||||
} gpsStatus_t;
|
} gpsStatus_t;
|
||||||
extern gpsStatus_t gps_status; // struct for storing gps data
|
extern gpsStatus_t gps_status; // struct for storing gps data
|
||||||
extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe
|
extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern configData_t cfg;
|
extern configData_t cfg;
|
||||||
@ -68,6 +68,7 @@ extern char display_lora[], display_lmic[];
|
|||||||
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
||||||
extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters
|
extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters
|
||||||
extern std::set<uint16_t> macs;
|
extern std::set<uint16_t> macs;
|
||||||
extern hw_timer_t * channelSwitch; // hardware timer used for wifi channel switching
|
extern hw_timer_t
|
||||||
|
*channelSwitch; // hardware timer used for wifi channel switching
|
||||||
extern xref2u1_t rcmd_data; // buffer for rcommand results size
|
extern xref2u1_t rcmd_data; // buffer for rcommand results size
|
||||||
extern u1_t rcmd_data_size; // buffer for rcommand results size
|
extern u1_t rcmd_data_size; // buffer for rcommand results size
|
||||||
|
@ -7,45 +7,44 @@ static const char TAG[] = "main";
|
|||||||
|
|
||||||
// read GPS data and cast to global struct
|
// read GPS data and cast to global struct
|
||||||
void gps_read() {
|
void gps_read() {
|
||||||
gps_status.latitude = (uint32_t) (gps.location.lat() * 1000000);
|
gps_status.latitude = (uint32_t)(gps.location.lat() * 1000000);
|
||||||
gps_status.longitude = (uint32_t) (gps.location.lng() * 1000000);
|
gps_status.longitude = (uint32_t)(gps.location.lng() * 1000000);
|
||||||
gps_status.satellites = (uint8_t) gps.satellites.value();
|
gps_status.satellites = (uint8_t)gps.satellites.value();
|
||||||
gps_status.hdop = (uint16_t) gps.hdop.value();
|
gps_status.hdop = (uint16_t)gps.hdop.value();
|
||||||
gps_status.altitude = (uint16_t) gps.altitude.meters();
|
gps_status.altitude = (uint16_t)gps.altitude.meters();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GPS serial feed FreeRTos Task
|
// GPS serial feed FreeRTos Task
|
||||||
void gps_loop(void * pvParameters) {
|
void gps_loop(void *pvParameters) {
|
||||||
|
|
||||||
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
|
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
||||||
|
|
||||||
// initialize and, if needed, configure, GPS
|
// initialize and, if needed, configure, GPS
|
||||||
#if defined GPS_SERIAL
|
#if defined GPS_SERIAL
|
||||||
HardwareSerial GPS_Serial(1);
|
HardwareSerial GPS_Serial(1);
|
||||||
#elif defined GPS_I2C
|
#elif defined GPS_I2C
|
||||||
// to be done
|
// to be done
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
|
|
||||||
if (cfg.gpsmode)
|
if (cfg.gpsmode) {
|
||||||
{
|
#if defined GPS_SERIAL
|
||||||
#if defined GPS_SERIAL
|
|
||||||
|
|
||||||
// serial connect to GPS device
|
// serial connect to GPS device
|
||||||
GPS_Serial.begin(GPS_SERIAL);
|
GPS_Serial.begin(GPS_SERIAL);
|
||||||
|
|
||||||
while(cfg.gpsmode) {
|
while (cfg.gpsmode) {
|
||||||
// feed GPS decoder with serial NMEA data from GPS device
|
// feed GPS decoder with serial NMEA data from GPS device
|
||||||
while (GPS_Serial.available()) {
|
while (GPS_Serial.available()) {
|
||||||
gps.encode(GPS_Serial.read());
|
gps.encode(GPS_Serial.read());
|
||||||
}
|
}
|
||||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
|
||||||
}
|
}
|
||||||
// after GPS function was disabled, close connect to GPS device
|
// after GPS function was disabled, close connect to GPS device
|
||||||
GPS_Serial.end();
|
GPS_Serial.end();
|
||||||
|
|
||||||
#elif defined GPS_I2C
|
#elif defined GPS_I2C
|
||||||
|
|
||||||
// I2C connect to GPS device with 100 kHz
|
// I2C connect to GPS device with 100 kHz
|
||||||
Wire.begin(GPS_I2C_PINS, 100000);
|
Wire.begin(GPS_I2C_PINS, 100000);
|
||||||
@ -54,12 +53,12 @@ void gps_loop(void * pvParameters) {
|
|||||||
|
|
||||||
i2c_ret == Wire.beginTransmission(GPS_I2C_ADDRESS_READ);
|
i2c_ret == Wire.beginTransmission(GPS_I2C_ADDRESS_READ);
|
||||||
if (i2c_ret == 0) { // check if device seen on i2c bus
|
if (i2c_ret == 0) { // check if device seen on i2c bus
|
||||||
while(cfg.gpsmode) {
|
while (cfg.gpsmode) {
|
||||||
// feed GPS decoder with serial NMEA data from GPS device
|
// feed GPS decoder with serial NMEA data from GPS device
|
||||||
while (Wire.available()) {
|
while (Wire.available()) {
|
||||||
Wire.requestFrom(GPS_I2C_ADDRESS_READ, 255);
|
Wire.requestFrom(GPS_I2C_ADDRESS_READ, 255);
|
||||||
gps.encode(Wire.read());
|
gps.encode(Wire.read());
|
||||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// after GPS function was disabled, close connect to GPS device
|
// after GPS function was disabled, close connect to GPS device
|
||||||
@ -68,10 +67,10 @@ void gps_loop(void * pvParameters) {
|
|||||||
Wire.setClock(400000); // Set back to 400KHz to speed up OLED
|
Wire.setClock(400000); // Set back to 400KHz to speed up OLED
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog
|
vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
|
||||||
|
|
||||||
} // end of infinite loop
|
} // end of infinite loop
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user