huyongji1.1-system/App/Ozone/Ozone.c

73 lines
2.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "Ozone.h"
// 臭氧控制变量
uint8_t ozone_running = 0; // 默认不运行
uint32_t ozone_timer = 0; // 臭氧计时器
uint32_t OZONE_ON_TIME = 1; // 运行1分钟
uint32_t OZONE_OFF_TIME = 1; // 停止1分钟
void Save_Ozone_Time_To_EEPROM(uint32_t on_time, uint32_t off_time) // 保存
{
Save_Float_To_EEPROM(OZONE_ON_TIME_ADDR, (float)on_time); // 保存运行时间
Save_Float_To_EEPROM(OZONE_OFF_TIME_ADDR, (float)off_time); // 保存停止时间
Inf_AT24C02_WriteByte(OZONE_FLAG_ADDR, OZONE_FLAG_VAL); // 保存标志
}
// 从EEPROM读取臭氧时间参数OZENE_FLAG_ADDR
void Load_Ozone_Time_From_EEPROM(void)
{
uint8_t flag = Inf_AT24C02_ReadByte(OZONE_FLAG_ADDR);
if(flag == OZONE_FLAG_VAL)
{
// 读取时间参数
OZONE_ON_TIME = (uint32_t)Read_Float_From_EEPROM(OZONE_ON_TIME_ADDR);
OZONE_OFF_TIME = (uint32_t)Read_Float_From_EEPROM(OZONE_OFF_TIME_ADDR);
}
else
{
// 如果EEPROM中没有有效数据使用默认值并保存
Save_Ozone_Time_To_EEPROM(OZONE_ON_TIME, OZONE_OFF_TIME);
}
}
void Ozone_Init(void)
{
Load_Ozone_Time_From_EEPROM();
ozone_running = 1; // 上电直接启动
ozone_timer = 0; // 初始化计时器
Ozone_Control(1); // 初始状态直接开启
// printf("Ozone Init OK, starting immediately\n");
}
void Ozone_Control_Update(void)
{
if(ozone_running)
{
// 按1分钟开1分钟关的逻辑运行
if(ozone_timer <= OZONE_ON_TIME)
{
Ozone_Control(1); // 直接控制,不需要中间变量
// printf("臭氧运行中: %d秒\n", ozone_timer);
}
else if(ozone_timer <= (OZONE_ON_TIME + OZONE_OFF_TIME))
{
Ozone_Control(0);
// printf("臭氧暂停中: %d秒\n", ozone_timer);
}
else
{
ozone_timer = 0; // 重置计时器,开始新循环
Ozone_Control(1);
// printf("臭氧开始新循环\n");
}
}
else
{
// 远程控制关闭时,保持关闭状态
Ozone_Control(0);
// printf("臭氧已关闭(远程控制)\n");
}
}