MW22-02A/APP/Device/device_Other/device_heatresistor.c

153 lines
4.9 KiB
C
Raw Normal View History

2025-05-21 01:55:40 +00:00
#include "ptz_header_file.h"
#include "device_heatresistor.h"
#include "tmp75.h"
#include "agent_hyt.h"
///<2F><><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD>
HeatResistor heat_resistor;
//<2F><><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><E8BFAA>
void ptz_heat_resistor_switch(PTZ_DATA_PACK *pack)
{
if(pack->command[1] == 1)
{//<2F>򿪵<EFBFBD><F2BFAAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
heat_resistor.pwm_duty_cycle = ((float)((pack->data[0] << 8) | pack->data[1])) / 100.0;
heat_resistor.heat_switch = PTZ_HEAT_RESISTOR_ON;
}
else
{
heat_resistor.pwm_duty_cycle = 0;
heat_resistor.heat_switch = PTZ_HEAT_RESISTOR_OFF_1;
}
}
//<2F><><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
static void ptz_heat_resistor_init()
{
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʹ<EFBFBD><CAB9>
rcu_periph_clock_enable(RCU_GPIOE);
gpio_mode_set(GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_0| GPIO_PIN_1);
gpio_output_options_set(GPIOE, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, GPIO_PIN_0| GPIO_PIN_1);
PTZ_HEAT_RESISTOR_A_OFF;
PTZ_HEAT_RESISTOR_B_OFF;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static void ptz_heat_resistor_task()
{
while(1)
{
switch(heat_resistor.heat_switch)
{
case PTZ_HEAT_RESISTOR_ON:
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>0
heat_resistor.heat_timer_ms = 0;
heat_resistor.heat_timer_s = 0;
heat_resistor.heat_timer_min = 0;
//PWM<57><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
heat_resistor.pwm_t = PTZ_HEAT_RESISTOR_PWM_T;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>ձ<EFBFBD>
heat_resistor.pwm_duty_cycle_max =
PTZ_HEAT_RESISTOR_I_MAX * PTZ_HEAT_RESISTOR_R / PTZ_HEAT_RESISTOR_V_MAX;
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>ձ<EFBFBD><D5B1>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>
if(heat_resistor.pwm_duty_cycle > heat_resistor.pwm_duty_cycle_max)
{
heat_resistor.pwm_duty_cycle = heat_resistor.pwm_duty_cycle_max;
}
//<2F><><EFBFBD><EFBFBD>ռ<EFBFBD>ձȼ<D5B1><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>͹ص<CDB9><D8B5><EFBFBD>ʱ<EFBFBD><CAB1>
heat_resistor.pwm_power_on_t =
(unsigned short int)(heat_resistor.pwm_duty_cycle * heat_resistor.pwm_t + 0.5);
heat_resistor.pwm_power_off_t = heat_resistor.pwm_t - heat_resistor.pwm_power_on_t;
//<2F><><EFBFBD><EFBFBD>ռ<EFBFBD>ձȼ<D5B1><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵ<EFBFBD>ѹ
heat_resistor.resistor_v =
heat_resistor.pwm_duty_cycle * PTZ_HEAT_RESISTOR_V_MAX;
//<2F><><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵ<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
heat_resistor.resistor_i = heat_resistor.resistor_v / PTZ_HEAT_RESISTOR_R;
heat_resistor.heat_switch = PTZ_HEAT_RESISTOR_ON_PWM;
OSTimeDlyHMSM(0u, 0u, 0u, 20u);
break;
case PTZ_HEAT_RESISTOR_ON_PWM:
//<2F><><EFBFBD><EFBFBD>PWM<57><4D><EFBFBD><EFBFBD>
PTZ_HEAT_RESISTOR_A_ON;
PTZ_HEAT_RESISTOR_B_ON;
OSTimeDlyHMSM(0u, 0u, 0u, heat_resistor.pwm_power_on_t);
PTZ_HEAT_RESISTOR_A_OFF;
PTZ_HEAT_RESISTOR_B_OFF;
OSTimeDlyHMSM(0u, 0u, 0u, heat_resistor.pwm_power_off_t);
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
heat_resistor.heat_timer_ms =
heat_resistor.heat_timer_ms + heat_resistor.pwm_t;
if(heat_resistor.heat_timer_ms >= 1000)
{
heat_resistor.heat_timer_s ++;
heat_resistor.heat_timer_ms = heat_resistor.heat_timer_ms - 1000;
}
if(heat_resistor.heat_timer_s >= 60)
{
heat_resistor.heat_timer_min ++;
heat_resistor.heat_timer_s = heat_resistor.heat_timer_s - 60;
}
//<2F><><EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD>¶Ⱦͺ<C8BE><CDBA>ʣ<EFBFBD><CAA3><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><E8B1BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(g_ptz.temperature >= PTZ_HEAT_RESISTOR_TEMP)
{
heat_resistor.heat_switch = PTZ_HEAT_RESISTOR_OFF_1;//<2F>رռ<D8B1><D5BC><EFBFBD>
}
break;
case PTZ_HEAT_RESISTOR_OFF_1:
PTZ_HEAT_RESISTOR_A_OFF;
PTZ_HEAT_RESISTOR_B_OFF;
heat_resistor.heat_timer_ms = 0;
heat_resistor.heat_timer_s = 0;
heat_resistor.heat_timer_min = 0;
heat_resistor.heat_switch = PTZ_HEAT_RESISTOR_OFF_0;
OSTimeDlyHMSM(0u, 0u, 0u, 20u);
break;
default://PTZ_HEAT_RESISTOR_OFF_0
OSTimeDlyHMSM(0u, 0u, 0u, 1000u);
break;
}
OSTimeDlyHMSM(0u, 0u, 0u, 50u);
}
}
static OS_STK task_heat_resistor_stk[TASK_PTZ_HEAT_RESISTOR_STK_SIZE];
static void creat_task_heat_resistor(void)
{
CPU_INT08U task_err;
CPU_INT08U name_err;
task_err = OSTaskCreateExt((void (*)(void *)) ptz_heat_resistor_task,
(void *) 0,
(OS_STK *)&task_heat_resistor_stk[TASK_PTZ_HEAT_RESISTOR_STK_SIZE - 1],
(INT8U ) TASK_PTZ_HEAT_RESISTOR_PRIO,
(INT16U ) TASK_PTZ_HEAT_RESISTOR_PRIO,
(OS_STK *)&task_heat_resistor_stk[0],
(INT32U ) TASK_PTZ_HEAT_RESISTOR_STK_SIZE,
(void *) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
#if (OS_TASK_NAME_EN > 0)
OSTaskNameSet(TASK_PTZ_HEAT_RESISTOR_PRIO, "ptz_heat_resistor_task", &name_err);
#endif
if ((task_err == OS_ERR_NONE) && (name_err == OS_ERR_NONE)) {
pdebug(DEBUG_LEVEL_INFO,"create ptz_heat_resistor_task success...\n\r");
} else {
pdebug(DEBUG_LEVEL_FATAL,"create ptz_heat_resistor_task failed...\n\r");
}
}
void init_heat_resistor_module()
{
ptz_heat_resistor_init();
creat_task_heat_resistor();
}