Add grid and EVSE meter components with load balancer
This commit is contained in:
9
components/evsemeter/CMakeLists.txt
Normal file
9
components/evsemeter/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
set(srcs
|
||||
"src/evsemeter_modbus.c"
|
||||
"src/evsemeter_ade7758.c"
|
||||
"src/evsemeter_events.c"
|
||||
)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES meter_orno_modbus)
|
||||
24
components/evsemeter/include/evsemeter.h
Normal file
24
components/evsemeter/include/evsemeter.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef EVSEMETER_H_
|
||||
#define EVSEMETER_H_
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_event_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(EVSEMETER_EVENT);
|
||||
|
||||
typedef enum {
|
||||
EVSEMETER_EVENT_UPDATE
|
||||
} evsemeter_event_id_t;
|
||||
|
||||
esp_err_t evsemeter_init(void);
|
||||
esp_err_t evsemeter_read_current(float *current);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EVSEMETER_H_ */
|
||||
21
components/evsemeter/src/evsemeter_ade7758.c
Normal file
21
components/evsemeter/src/evsemeter_ade7758.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "evsemeter.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "evsemeter_ade7758";
|
||||
|
||||
esp_err_t evsemeter_init(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initializing EVSE meter (ADE7758)");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t evsemeter_read_current(float *current)
|
||||
{
|
||||
if (!current) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
*current = 0.0f;
|
||||
esp_event_post(EVSEMETER_EVENT, EVSEMETER_EVENT_UPDATE, current, sizeof(float), portMAX_DELAY);
|
||||
return ESP_OK;
|
||||
}
|
||||
3
components/evsemeter/src/evsemeter_events.c
Normal file
3
components/evsemeter/src/evsemeter_events.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "evsemeter.h"
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(EVSEMETER_EVENT);
|
||||
22
components/evsemeter/src/evsemeter_modbus.c
Normal file
22
components/evsemeter/src/evsemeter_modbus.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user