#include "driver_manager.h"

#include <string.h>
#include "betteryread.h"
#include "device_nvs.h"
#include "esp_log.h"
#include "rc_pwm_control.h"
#include "wifidevnum_config.h"

static const char *tag_s = "DRV_MGR";

esp_err_t driver_manager_init_from_nvs(void)
{
    char devid[32] = {0};
    if (read_from_nvs(DEVICE_CFG_KEY_DEVICE_ID, devid, sizeof(devid)) == ESP_OK && strlen(devid) > 0) {
        rc_pwm_control_set_drive_from_device_id(devid);
    } else {
        rc_pwm_control_set_drive_from_device_id(NULL);
    }

    ESP_ERROR_CHECK(board_adc_init());
    ESP_ERROR_CHECK(rc_pwm_control_init());
    ESP_LOGI(tag_s, "drivers init done");
    return ESP_OK;
}
