adding in stored config
This commit is contained in:
parent
68b95b03ce
commit
319e797132
3 changed files with 39 additions and 8 deletions
|
@ -1,9 +1,17 @@
|
||||||
#ifndef __MAIN_H_
|
#ifndef __MAIN_H_
|
||||||
#define __MAIN_H_
|
#define __MAIN_H_
|
||||||
|
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
|
||||||
#include "esp32-lora.h"
|
#include "esp32-lora.h"
|
||||||
|
|
||||||
extern uint8_t mac[6];
|
extern uint8_t mac[6];
|
||||||
extern lora32_cfg_t lora;
|
extern lora32_cfg_t lora;
|
||||||
|
|
||||||
|
struct lorcomm_cfg {
|
||||||
|
lora32_cfg_t *lora;
|
||||||
|
nvs_handle_t *nvs_handle;
|
||||||
|
} lorcomm_cfg;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "esp32-lora.h"
|
#include "esp32-lora.h"
|
||||||
|
|
||||||
#include "cmd_lora.h"
|
#include "cmd_lora.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
// main console setup and task, assume mostly copied from example
|
// main console setup and task, assume mostly copied from example
|
||||||
void console_task(void *args) {
|
void console_task(void *args) {
|
||||||
|
@ -49,16 +50,17 @@ void console_task(void *args) {
|
||||||
linenoiseHistorySetMaxLen(100);
|
linenoiseHistorySetMaxLen(100);
|
||||||
|
|
||||||
esp_console_register_help_command();
|
esp_console_register_help_command();
|
||||||
cmd_bw_register(args);
|
cmd_bw_register(lorcomm_cfg.lora);
|
||||||
cmd_cr_register(args);
|
cmd_cr_register(lorcomm_cfg.lora);
|
||||||
cmd_sf_register(args);
|
cmd_sf_register(lorcomm_cfg.lora);
|
||||||
cmd_preamble_register(args);
|
cmd_preamble_register(lorcomm_cfg.lora);
|
||||||
cmd_send_register(args);
|
cmd_send_register(lorcomm_cfg.lora);
|
||||||
cmd_dump_register(args);
|
cmd_dump_register(lorcomm_cfg.lora);
|
||||||
|
|
||||||
const char* prompt = LOG_COLOR_I "lorcomm> " LOG_RESET_COLOR;
|
char *prompt;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
asprintf(&prompt, LOG_COLOR_I "%s > " LOG_RESET_COLOR, "lorcomm");
|
||||||
char* line = linenoise(prompt);
|
char* line = linenoise(prompt);
|
||||||
|
|
||||||
if (line == NULL) { /* Ignore empty lines */
|
if (line == NULL) { /* Ignore empty lines */
|
||||||
|
|
23
main/main.c
23
main/main.c
|
@ -6,6 +6,8 @@
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_debug_helpers.h"
|
#include "esp_debug_helpers.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "esp_vfs_dev.h"
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "lorcomm.h"
|
#include "lorcomm.h"
|
||||||
|
@ -87,6 +89,23 @@ receive_cleanup:
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
|
esp_err_t err = nvs_flash_init();
|
||||||
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
err = nvs_flash_init();
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK( err );
|
||||||
|
|
||||||
|
nvs_handle_t nvs_handle;
|
||||||
|
err = nvs_open("config", NVS_READWRITE, &nvs_handle);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
|
||||||
|
|
||||||
|
lorcomm_cfg.nvs_handle = NULL;
|
||||||
|
} else {
|
||||||
|
lorcomm_cfg.nvs_handle = &nvs_handle;
|
||||||
|
}
|
||||||
|
|
||||||
esp_efuse_mac_get_default((uint8_t*)&mac);
|
esp_efuse_mac_get_default((uint8_t*)&mac);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "MAC: [%02X:%02X:%02X:%02X:%02X:%02X]", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
ESP_LOGI(TAG, "MAC: [%02X:%02X:%02X:%02X:%02X:%02X]", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
@ -114,7 +133,9 @@ void app_main(void) {
|
||||||
|
|
||||||
lora32_dump_regs(&lora);
|
lora32_dump_regs(&lora);
|
||||||
|
|
||||||
xTaskCreate(console_task, "console", 4048, &lora, tskIDLE_PRIORITY + 3, NULL);
|
lorcomm_cfg.lora = &lora;
|
||||||
|
|
||||||
|
xTaskCreate(console_task, "console", 4048, &lorcomm_cfg, tskIDLE_PRIORITY + 3, NULL);
|
||||||
|
|
||||||
//lora32_send(&lora, (uint8_t*)"hi\0", 3);
|
//lora32_send(&lora, (uint8_t*)"hi\0", 3);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue