barback32/main/main.c

60 lines
1.4 KiB
C
Raw Normal View History

2020-02-26 00:31:55 -05:00
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/uart.h"
#include "esp_log.h"
#include "esp_debug_helpers.h"
2020-04-23 01:43:27 -04:00
#include "nvs_flash.h"
#include "esp_vfs_dev.h"
2020-02-26 00:31:55 -05:00
#include "main.h"
2020-02-26 10:11:57 -05:00
#include "console.h"
#include "ble.h"
#include "user_button.h"
2020-10-25 22:49:14 -04:00
#include "pumps.h"
#include "dfplayermini.h"
2020-02-26 00:31:55 -05:00
2020-10-13 00:38:23 -04:00
static const char *TAG = "BARBACK";
2020-02-26 00:31:55 -05:00
uint8_t mac[6];
2020-02-26 00:31:55 -05:00
void app_main(void) {
2020-04-23 01:43:27 -04:00
esp_err_t err = nvs_flash_init();
2020-10-25 23:21:07 -04:00
2020-04-23 01:43:27 -04:00
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 );
2020-10-25 22:49:14 -04:00
err = nvs_open("config", NVS_READWRITE, &config_handle);
2020-04-23 01:43:27 -04:00
if (err != ESP_OK) {
printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
} else {
2020-10-25 22:49:14 -04:00
ESP_LOGI(TAG, "config_handle: %d", config_handle);
2020-04-23 01:43:27 -04:00
}
2020-02-26 00:31:55 -05:00
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]);
2021-09-08 23:41:24 -04:00
char *name = malloc(strlen(TAG) + 4);
sprintf(name, "%s-%02X", TAG, mac[5]);
vTaskDelay(1000 / portTICK_PERIOD_MS);
dfplayermini_init();
2020-10-25 22:49:14 -04:00
user_button_init();
pumps_init();
2021-09-08 23:41:24 -04:00
ble_init(name);
2020-02-29 18:43:15 -05:00
2020-10-25 22:49:14 -04:00
xTaskCreate(console_task, "console", 4048, NULL, tskIDLE_PRIORITY + 3, NULL);
2020-10-13 00:38:23 -04:00
2020-02-26 00:31:55 -05:00
while(1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
2020-02-26 00:31:55 -05:00
}
}