#include "evsemeter.h"
#include "orno_modbus.h"
#include "esp_event.h"
#include "esp_log.h"

static const char *TAG = "evsemeter_modbus";

esp_err_t evsemeter_init(void)
{
    ESP_LOGI(TAG, "Initializing EVSE meter (Modbus)");
    return orno_modbus_init();
}

esp_err_t evsemeter_read_current(float *current)
{
    esp_err_t err = orno_modbus_read_current(ORNO_METER_EVSE, current);
    if (err == ESP_OK)
    {
        esp_event_post(EVSEMETER_EVENT, EVSEMETER_EVENT_UPDATE, current, sizeof(float), portMAX_DELAY);
    }
    return err;
}
