2019-06-28 03:13:18 +00:00
|
|
|
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
|
2019-01-07 07:16:47 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_vfs_dev.h"
|
|
|
|
#include "nvs.h"
|
|
|
|
#include "nvs_flash.h"
|
|
|
|
|
|
|
|
#include "esp_bt.h"
|
|
|
|
#include "esp_bt_main.h"
|
|
|
|
|
|
|
|
#include "esp_console.h"
|
|
|
|
|
|
|
|
#include "ble_mesh_console_decl.h"
|
|
|
|
|
|
|
|
#if CONFIG_STORE_HISTORY
|
|
|
|
|
|
|
|
#define MOUNT_PATH "/data"
|
|
|
|
#define HISTORY_PATH MOUNT_PATH "/history.txt"
|
|
|
|
|
2019-07-16 09:33:30 +00:00
|
|
|
static void initialize_filesystem(void)
|
2019-01-07 07:16:47 +00:00
|
|
|
{
|
|
|
|
static wl_handle_t wl_handle;
|
|
|
|
const esp_vfs_fat_mount_config_t mount_config = {
|
|
|
|
.max_files = 4,
|
|
|
|
.format_if_mount_failed = true
|
|
|
|
};
|
|
|
|
esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle);
|
|
|
|
if (err != ESP_OK) {
|
|
|
|
printf("Failed to mount FATFS (0x%x)", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // CONFIG_STORE_HISTORY
|
|
|
|
|
|
|
|
esp_err_t bluetooth_init(void)
|
|
|
|
{
|
|
|
|
esp_err_t ret;
|
|
|
|
|
|
|
|
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
|
|
|
ret = esp_bt_controller_init(&bt_cfg);
|
|
|
|
if (ret) {
|
|
|
|
printf("%s initialize controller failed\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
|
|
|
if (ret) {
|
|
|
|
printf("%s enable controller failed\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = esp_bluedroid_init();
|
|
|
|
if (ret) {
|
|
|
|
printf("%s init bluetooth failed\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = esp_bluedroid_enable();
|
|
|
|
if (ret) {
|
|
|
|
printf("%s enable bluetooth failed\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void app_main(void)
|
|
|
|
{
|
|
|
|
esp_err_t res;
|
|
|
|
|
|
|
|
nvs_flash_init();
|
|
|
|
|
|
|
|
// init and enable bluetooth
|
|
|
|
res = bluetooth_init();
|
|
|
|
if (res) {
|
|
|
|
printf("esp32_bluetooth_init failed (ret %d)", res);
|
|
|
|
}
|
|
|
|
|
2020-02-03 10:01:04 +00:00
|
|
|
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
2019-01-07 07:16:47 +00:00
|
|
|
#if CONFIG_STORE_HISTORY
|
|
|
|
initialize_filesystem();
|
2020-02-03 10:01:04 +00:00
|
|
|
repl_config.his_save_path = HISTORY_PATH;
|
2019-01-07 07:16:47 +00:00
|
|
|
#endif
|
2020-02-03 10:01:04 +00:00
|
|
|
ESP_ERROR_CHECK(esp_console_repl_init(&repl_config));
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Register commands */
|
|
|
|
register_system();
|
|
|
|
register_bluetooth();
|
|
|
|
ble_mesh_register_mesh_node();
|
|
|
|
ble_mesh_register_server();
|
|
|
|
|
2020-02-03 10:01:04 +00:00
|
|
|
// start console REPL
|
|
|
|
ESP_ERROR_CHECK(esp_console_repl_start());
|
2019-01-07 07:16:47 +00:00
|
|
|
}
|