You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.4 KiB

/*
* pump_control.cpp
*
* Created on: Jul 27, 2021
* Author: Andreas Berthoud
*/
#include "pump_control.h"
#include "pump_control.hpp"
#include "main.h"
#include "stm32wbxx_hal.h"
#include "hw_if.h"
#include "LogCommand.hpp"
namespace pump {
typedef struct {
bool is_on;
uint8_t timer_id;
} pump_state_t;
pump_state_t pump_state {
.is_on=false
};
void turn_on(uint16_t timeout) {
uint32_t ticks = (timeout*1000*1000/CFG_TS_TICK_VAL);
if (ticks > 0xFFFF0000) {
log_error("pump::turn_on", "max timout exceeded", 0);
return;
}
HW_TS_Start(pump_state.timer_id, ticks);
HAL_GPIO_WritePin(RELAY_12V_OUT1_GPIO_Port, RELAY_12V_OUT1_Pin, GPIO_PIN_SET);
pump_state.is_on = true;
log_debug("pump", "turned on", 0);
}
uint8_t is_on() {
return (uint8_t)pump_state.is_on;
}
void turn_off() {
pump_state.is_on = false;
HAL_GPIO_WritePin(RELAY_12V_OUT1_GPIO_Port, RELAY_12V_OUT1_Pin, GPIO_PIN_RESET);
HW_TS_Stop(pump_state.timer_id);
log_debug("pump", "turned off", 0);
}
uint8_t init() {
HW_TS_ReturnStatus_t return_status = HW_TS_Create(CFG_TIM_PROC_ID_ISR, &(pump_state.timer_id), hw_ts_SingleShot, turn_off);
if (return_status == hw_ts_Failed) {
log_error("pump::init", "Creating hardware timer failed", 0);
return 1;
}
return 0;
}
}
uint8_t pump_init() {
return pump::init();
}