evse_link feature
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "evse_limits.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
static const char *TAG = "evse_config";
|
||||
|
||||
@@ -60,7 +61,7 @@ void evse_check_defaults(void) {
|
||||
}
|
||||
|
||||
// Runtime charging current initialized from persisted default
|
||||
charging_current_runtime = charging_current;
|
||||
charging_current_runtime = max_charging_current;
|
||||
ESP_LOGD(TAG, "Runtime charging current initialized to: %d", charging_current_runtime);
|
||||
|
||||
// Auth required
|
||||
@@ -127,6 +128,7 @@ esp_err_t evse_set_max_charging_current(uint8_t value) {
|
||||
if (value < MIN_CHARGING_CURRENT_LIMIT || value > MAX_CHARGING_CURRENT_LIMIT)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
max_charging_current = value;
|
||||
evse_set_runtime_charging_current(value);
|
||||
nvs_set_u8(nvs, "max_chrg_curr", value);
|
||||
return nvs_commit(nvs);
|
||||
}
|
||||
@@ -161,19 +163,35 @@ esp_err_t evse_set_default_charging_current(uint16_t value) {
|
||||
// Runtime current (not saved)
|
||||
// ========================
|
||||
void evse_set_runtime_charging_current(uint16_t value) {
|
||||
|
||||
if (value > (max_charging_current)) {
|
||||
value= max_charging_current;
|
||||
}
|
||||
|
||||
if (value < (MIN_CHARGING_CURRENT_LIMIT) ) {
|
||||
value= MIN_CHARGING_CURRENT_LIMIT;
|
||||
ESP_LOGI(TAG, "Runtime charging current updated: %d", charging_current_runtime);
|
||||
|
||||
if (value > max_charging_current) {
|
||||
value = max_charging_current;
|
||||
} else if (value < MIN_CHARGING_CURRENT_LIMIT) {
|
||||
value = MIN_CHARGING_CURRENT_LIMIT;
|
||||
}
|
||||
|
||||
charging_current_runtime = value;
|
||||
ESP_LOGI(TAG, "Runtime charging current updated: %d", charging_current_runtime);
|
||||
|
||||
// --- PUBLICA ALTERAÇÃO DE CONFIG DO EVSE ---
|
||||
evse_config_event_data_t evt = {
|
||||
.charging = evse_state_is_charging(evse_get_state()),
|
||||
.hw_max_current = (float)evse_get_max_charging_current(),
|
||||
.runtime_current = (float)charging_current_runtime,
|
||||
.timestamp_us = esp_timer_get_time()
|
||||
};
|
||||
|
||||
esp_event_post(EVSE_EVENTS,
|
||||
EVSE_EVENT_CONFIG_UPDATED,
|
||||
&evt,
|
||||
sizeof(evt),
|
||||
portMAX_DELAY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint16_t evse_get_runtime_charging_current(void) {
|
||||
return charging_current_runtime;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user