new upgrade

This commit is contained in:
2025-12-21 23:28:26 +00:00
parent 82fa194bd8
commit 023644a887
99 changed files with 7457 additions and 7079 deletions

View File

@@ -6,90 +6,68 @@
#include "evse_events.h"
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
// ============================
// EVSE Pilot Signal States
// ============================
typedef enum
{
EVSE_STATE_A, // EV Not Connected (12V)
EVSE_STATE_B1, // EV Connected (9V, Not Authorized)
EVSE_STATE_B2, // EV Connected (9V, Authorized and Ready)
EVSE_STATE_C1, // Charging Requested (6V, Relay Off)
EVSE_STATE_C2, // Charging Active (6V, Relay On)
EVSE_STATE_D1, // Ventilation Required (3V, Relay Off)
EVSE_STATE_D2, // Ventilation Active (3V, Relay On)
EVSE_STATE_E, // Error: Pilot Short to Ground (0V)
EVSE_STATE_F // Fault: No Pilot or EVSE Unavailable
} evse_state_t;
typedef enum {
EVSE_STATE_A, // EV Not Connected (12V)
EVSE_STATE_B1, // EV Connected (9V, Not Authorized)
EVSE_STATE_B2, // EV Connected (9V, Authorized and Ready)
EVSE_STATE_C1, // Charging Requested (6V, Relay Off)
EVSE_STATE_C2, // Charging Active (6V, Relay On)
EVSE_STATE_D1, // Ventilation Required (3V, Relay Off)
EVSE_STATE_D2, // Ventilation Active (3V, Relay On)
EVSE_STATE_E, // Error: Pilot Short to Ground (0V)
EVSE_STATE_F // Fault: No Pilot or EVSE Unavailable
} evse_state_t;
// Initialization
void evse_state_init(void);
void evse_state_tick(void);
// ============================
// Initialization
// ============================
// State Access & Control
evse_state_t evse_get_state(void);
void evse_set_state(evse_state_t state);
const char *evse_state_to_str(evse_state_t state);
/**
* @brief Initializes the EVSE state machine and default state.
*/
void evse_state_init(void);
// ---------------------------
// State Evaluation Helpers
// ---------------------------
/**
* @brief Periodic tick for state handling (optional hook).
*/
void evse_state_tick(void);
/**
* @brief True se existe uma sessão "lógica" ativa (carro ligado e autorizado/pronto ou a carregar).
* Inclui B2, C1/C2, D1/D2.
*/
bool evse_state_is_session(evse_state_t state);
// ============================
// State Access & Control
// ============================
/**
* @brief True se o EVSE está a fornecer energia (relé ON).
* Estados com energia: C2 e D2.
*
* Nota: isto substitui a antiga interpretação “C1/C2”.
*/
bool evse_state_is_charging(evse_state_t state);
/**
* @brief Returns the current EVSE state.
*/
evse_state_t evse_get_state(void);
/**
* @brief True se o EV pediu carga mas o relé ainda está OFF (C1/D1).
*/
bool evse_state_is_requesting(evse_state_t state);
/**
* @brief Sets the current EVSE state and emits a change event if needed.
*/
void evse_set_state(evse_state_t state);
/**
* @brief True se há fluxo de energia (alias explícito para charging).
*/
bool evse_state_is_power_flowing(evse_state_t state);
/**
* @brief Converts the state enum into a human-readable string.
*/
const char* evse_state_to_str(evse_state_t state);
/**
* @brief True se o EV está fisicamente ligado (B1 e além).
*/
bool evse_state_is_plugged(evse_state_t state);
// ============================
// State Evaluation Helpers
// ============================
/**
* @brief True if EV is in an active session (B2, C1, C2).
*/
bool evse_state_is_session(evse_state_t state);
/**
* @brief True if EV is actively charging (C1, C2).
*/
bool evse_state_is_charging(evse_state_t state);
/**
* @brief True if EV is physically plugged in (B1 and beyond).
*/
bool evse_state_is_plugged(evse_state_t state);
// ============================
// Authorization Control
// ============================
/**
* @brief Sets whether the EV is authorized to charge.
*/
void evse_state_set_authorized(bool authorized);
/**
* @brief Gets whether the EV is currently authorized.
*/
bool evse_state_get_authorized(void);
// Authorization Control
void evse_state_set_authorized(bool authorized);
bool evse_state_get_authorized(void);
#ifdef __cplusplus
}