124 lines
3.0 KiB
C
124 lines
3.0 KiB
C
#ifndef VALVE_H
|
|
#define VALVE_H
|
|
|
|
#include <stdint.h>
|
|
#include <zephyr/drivers/gpio.h>
|
|
|
|
/**
|
|
* @file valve.h
|
|
* @brief API for controlling the motorized valve.
|
|
*
|
|
* This library provides functions to initialize, open, close, and stop the
|
|
* valve. It also allows getting the valve's state and movement status, and
|
|
* configuring the maximum opening and closing times.
|
|
*/
|
|
|
|
/**
|
|
* @brief Defines the GPIO pins used for the valve controller.
|
|
*/
|
|
struct valve_gpios {
|
|
const struct gpio_dt_spec
|
|
in0; /**< Control input 0 for the VND7050AJ driver. */
|
|
const struct gpio_dt_spec
|
|
in1; /**< Control input 1 for the VND7050AJ driver. */
|
|
const struct gpio_dt_spec rst; /**< Reset pin for the VND7050AJ driver. */
|
|
const struct gpio_dt_spec sen; /**< Sense (current measurement) pin. */
|
|
const struct gpio_dt_spec s0; /**< S0 select pin. */
|
|
const struct gpio_dt_spec s1; /**< S1 select pin. */
|
|
};
|
|
|
|
/**
|
|
* @brief Represents the static state of the valve (open or closed).
|
|
*/
|
|
enum valve_state {
|
|
VALVE_STATE_CLOSED, /**< The valve is fully closed. */
|
|
VALVE_STATE_OPEN, /**< The valve is fully open. */
|
|
};
|
|
|
|
/**
|
|
* @brief Represents the dynamic movement status of the valve.
|
|
*/
|
|
enum valve_movement {
|
|
VALVE_MOVEMENT_IDLE, /**< The valve is not moving. */
|
|
VALVE_MOVEMENT_OPENING, /**< The valve is currently opening. */
|
|
VALVE_MOVEMENT_CLOSING, /**< The valve is currently closing. */
|
|
VALVE_MOVEMENT_ERROR /**< An error occurred during movement. */
|
|
};
|
|
|
|
/**
|
|
* @brief Initializes the valve control system.
|
|
*
|
|
* Configures the GPIOs and loads saved settings for timeouts.
|
|
*/
|
|
void valve_init(void);
|
|
|
|
/**
|
|
* @brief Starts opening the valve.
|
|
*
|
|
* The valve will open for the configured maximum opening time.
|
|
*/
|
|
void valve_open(void);
|
|
|
|
/**
|
|
* @brief Starts closing the valve.
|
|
*
|
|
* The valve will close for the configured maximum closing time.
|
|
*/
|
|
void valve_close(void);
|
|
|
|
/**
|
|
* @brief Stops any ongoing valve movement immediately.
|
|
*/
|
|
void valve_stop(void);
|
|
|
|
/**
|
|
* @brief Gets the current static state of the valve.
|
|
*
|
|
* @return The current valve state (VALVE_STATE_CLOSED or VALVE_STATE_OPEN).
|
|
*/
|
|
enum valve_state valve_get_state(void);
|
|
|
|
/**
|
|
* @brief Gets the current movement status of the valve.
|
|
*
|
|
* @return The current movement status.
|
|
*/
|
|
enum valve_movement valve_get_movement(void);
|
|
|
|
/**
|
|
* @brief Gets the motor current.
|
|
*
|
|
* @return The motor current in milliamps (currently simulated).
|
|
*/
|
|
uint16_t valve_get_motor_current(void);
|
|
|
|
/**
|
|
* @brief Sets the maximum time for the valve to open.
|
|
*
|
|
* @param seconds The timeout in seconds.
|
|
*/
|
|
void valve_set_max_open_time(uint16_t seconds);
|
|
|
|
/**
|
|
* @brief Sets the maximum time for the valve to close.
|
|
*
|
|
* @param seconds The timeout in seconds.
|
|
*/
|
|
void valve_set_max_close_time(uint16_t seconds);
|
|
|
|
/**
|
|
* @brief Gets the configured maximum opening time.
|
|
*
|
|
* @return The timeout in seconds.
|
|
*/
|
|
uint16_t valve_get_max_open_time(void);
|
|
|
|
/**
|
|
* @brief Gets the configured maximum closing time.
|
|
*
|
|
* @return The timeout in seconds.
|
|
*/
|
|
uint16_t valve_get_max_close_time(void);
|
|
|
|
#endif // VALVE_H
|