RTC Alarm System
Core/Src/AlarmRTC.cpp void alarmRTC::ActionAlarms()
{
HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
if(_config->lightConfig.PowerOnOffLithtAuto == 1 && _config->lightConfig.PowerOnOffLithtManual == 0)
{
if(compareTime(&time, &_config->lightConfig.PowerOnLight) && _config->lightConfig.gpio.Enabled == 0)
{
_config->lightConfig.gpio.Enabled = 1;
HAL_GPIO_WritePin(_config->lightConfig.gpio.port,_config->lightConfig.gpio.pin, GPIO_PIN_RESET);
}
if(compareTime(&time, &_config->lightConfig.PowerOffLight) && _config->lightConfig.gpio.Enabled == 1)
{
_config->lightConfig.gpio.Enabled = 0;
HAL_GPIO_WritePin(_config->lightConfig.gpio.port,_config->lightConfig.gpio.pin, GPIO_PIN_SET);
}
}
if(_config->heaterConfig.PowerOnOffHeaterAuto == 1 && _config->heaterConfig.PowerOnOffHeaterManual == 0)
{
int16_t temp = (int16_t)lroundf(SensorTemp);
if((temp < _config->heaterConfig.TempMinONHeater ) && (_config->heaterConfig.gpio.Enabled == 0))
{
_config->heaterConfig.gpio.Enabled = 1;
HAL_GPIO_WritePin(_config->heaterConfig.gpio.port,_config->heaterConfig.gpio.pin, GPIO_PIN_RESET);
}
if((temp >_config->heaterConfig.TempMaxOffHeater && temp > _config->heaterConfig.TempMinONHeater) && (_config->heaterConfig.gpio.Enabled == 1))
{
_config->heaterConfig.gpio.Enabled = 0;
HAL_GPIO_WritePin(_config->heaterConfig.gpio.port,_config->heaterConfig.gpio.pin, GPIO_PIN_SET);
}
}
}
The ActionAlarms function handles automatic on/off of lights and heaters according to time settings and water temperature. It uses RTC to check the current time.
Menu Configuration
Core/Src/BuildMenu.cpp static MenuItem miLightManualOnOff {"Manual wl/wyl ",[](){
Action_SetOnOff(&aquaConfig.lightConfig.PowerOnOffLithtManual,true);
if(aquaConfig.lightConfig.PowerOnOffLithtManual == 1)
{
aquaConfig.lightConfig.gpio.Enabled = 1;
HAL_GPIO_WritePin(aquaConfig.lightConfig.gpio.port,aquaConfig.lightConfig.gpio.pin, GPIO_PIN_RESET);
}
else
{
aquaConfig.lightConfig.gpio.Enabled = 0;
HAL_GPIO_WritePin(aquaConfig.lightConfig.gpio.port,aquaConfig.lightConfig.gpio.pin, GPIO_PIN_SET);
}
}, {}};
static MenuItem miLightAutoOnOff {"Automat wl/wyl ",[](){Action_SetOnOff(&aquaConfig.lightConfig.PowerOnOffLithtAuto,false);}, {}};
Example menu configuration for light control - handles both manual and automatic modes with functions setting flags and controlling GPIO.
DS18B20 Temperature Control
Core/Src/TemperatureSensors.cpp DS18B20Sensor::DS18B20Sensor(GPIO_TypeDef* dqPort, uint16_t dqPin, TIM_HandleTypeDef* htim)
: dqPort_(dqPort), dqPin_(dqPin), htim_(htim)
{
// Timer do µs powinien już działać (HAL_TIM_Base_Start)
// Linia 1-Wire w spoczynku ma być "puszczona" (input) + podciągnięta rezystorem 4.7k do 3.3V.
LineInput();
}
void DS18B20Sensor::DelayUs(uint16_t us)
{
// Założenie: timer tyka 1 MHz => 1 tick = 1 µs
__HAL_TIM_SET_COUNTER(htim_, 0);
while (__HAL_TIM_GET_COUNTER(htim_) < us) { }
}
The DS18B20Sensor class implements control of DS18B20 temperature sensor using 1-Wire bus and timers for generating delays.