123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //
- // Created by DELL on 2025/2/10.
- //
- #include "fan.h"
- #include "main.h"
- #include "tim.h"
- uint8_t dipBuf[3];
- uint8_t dipNum;
- /**
- * 排风风机控制
- * @param speed
- */
- PWMComParam_t PWMComParam[3]=
- {
- {
- .htim=&htim8,
- .timChannel=TIM_CHANNEL_1,
- },
- {
- .htim=&htim8,
- .timChannel=TIM_CHANNEL_2,
- },
- {
- .htim=&htim8,
- .timChannel=TIM_CHANNEL_3,
- },
- };
- dipComParam_t dipComParam[5]=
- {
- {
- .GPIOx=GPIOB,
- .GPIO_Pin=GPIO_PIN_5,
- },
- {
- .GPIOx=GPIOB,
- .GPIO_Pin=GPIO_PIN_6,
- },
- {
- .GPIOx=GPIOB,
- .GPIO_Pin=GPIO_PIN_7,
- },
- {
- .GPIOx=GPIOB,
- .GPIO_Pin=GPIO_PIN_8,
- },
- {
- .GPIOx=GPIOB,
- .GPIO_Pin=GPIO_PIN_9,
- }
- };
- uint8_t read_dip5()
- {
- int n=0;
- for(int i=0;i<5;i++)
- {
- if(n>2)
- {
- break;
- }
- if(HAL_GPIO_ReadPin(dipComParam[i].GPIOx, dipComParam[i].GPIO_Pin)==GPIO_PIN_RESET)
- {
- dipBuf[n]=i;
- n++;
- }
- }
- if(n==0)
- {
- n=3;
- dipBuf[0]=0;
- dipBuf[1]=1;
- dipBuf[2]=2;
- }
- return n;
- }
- void fan_control(PWMComParam_t PWMParam,uint8_t speed) {
- __HAL_TIM_SetCompare(PWMParam.htim, PWMParam.timChannel, speed);
- }
|