Add grid and EVSE meter components with load balancer
This commit is contained in:
8
components/gridmeter/CMakeLists.txt
Normal file
8
components/gridmeter/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
set(srcs
|
||||
"src/gridmeter_modbus.c"
|
||||
"src/gridmeter_events.c"
|
||||
)
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES meter_orno_modbus)
|
||||
24
components/gridmeter/include/gridmeter.h
Normal file
24
components/gridmeter/include/gridmeter.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef GRIDMETER_H_
|
||||
#define GRIDMETER_H_
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_event_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(GRIDMETER_EVENT);
|
||||
|
||||
typedef enum {
|
||||
GRIDMETER_EVENT_UPDATE
|
||||
} gridmeter_event_id_t;
|
||||
|
||||
esp_err_t gridmeter_init(void);
|
||||
esp_err_t gridmeter_read_current(float *current);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GRIDMETER_H_ */
|
||||
3
components/gridmeter/src/gridmeter_events.c
Normal file
3
components/gridmeter/src/gridmeter_events.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "gridmeter.h"
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(GRIDMETER_EVENT);
|
||||
22
components/gridmeter/src/gridmeter_modbus.c
Normal file
22
components/gridmeter/src/gridmeter_modbus.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "gridmeter.h"
|
||||
#include "orno_modbus.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "gridmeter_modbus";
|
||||
|
||||
esp_err_t gridmeter_init(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Initializing grid meter (Modbus)");
|
||||
return orno_modbus_init();
|
||||
}
|
||||
|
||||
esp_err_t gridmeter_read_current(float *current)
|
||||
{
|
||||
esp_err_t err = orno_modbus_read_current(ORNO_METER_GRID, current);
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
esp_event_post(GRIDMETER_EVENT, GRIDMETER_EVENT_UPDATE, current, sizeof(float), portMAX_DELAY);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
Reference in New Issue
Block a user