9 changed files with 176 additions and 30 deletions
-
56app/MDK-ARM/app.uvguix.h_zha
-
12app/MDK-ARM/app.uvoptx
-
5app/MDK-ARM/app.uvprojx
-
2dep/libiflytop_micro
-
11src/device_io_service.cpp
-
10src/device_io_service.hpp
-
58src/fan_state_monitor.cpp
-
47src/fan_state_monitor.hpp
-
5src/umain.cpp
56
app/MDK-ARM/app.uvguix.h_zha
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1 +1 @@ |
|||
Subproject commit bf2d8c1c5d3ab028b17d61e3dd6906231115bd82 |
|||
Subproject commit 8a21b347ee6436e79cdc404bd3082946deade41f |
@ -0,0 +1,58 @@ |
|||
#include "fan_state_monitor.hpp"
|
|||
|
|||
#include "libiflytop_micro/stm32/basic/basic.h"
|
|||
|
|||
using namespace iflytop; |
|||
|
|||
#define TAG "FAN_STATE_MONITOR"
|
|||
void FanStateMonitor::initialize(IflytopMicroOS* os, GPIO_TypeDef* FB_GPIOx, uint16_t FB_GPIO_Pin, bool* fanstate) { |
|||
//
|
|||
m_fanstate = fanstate; |
|||
} |
|||
void FanStateMonitor::doFanStateCheckPeriodicJob() { |
|||
/**
|
|||
* @brief 捕获风扇异常反馈信号 |
|||
*/ |
|||
GPIO_PinState pinState = HAL_GPIO_ReadPin(m_FB_GPIOx, m_FB_GPIO_Pin); |
|||
if (HAL_GPIO_ReadPin(m_FB_GPIOx, m_FB_GPIO_Pin) != m_lastPinState) { |
|||
m_fanFBCount++; |
|||
m_lastPinState = pinState; |
|||
} |
|||
|
|||
/**
|
|||
* @brief 电机工作超过2秒,且2秒内没有反馈信号,判断电机不工作 |
|||
*/ |
|||
if (m_os->hasPassedMS(m_fanOpenTicket) > 2000 && m_os->hasPassedMS(m_lastCallTicket) > 2000) { |
|||
if (m_fanFBCount == 0) { |
|||
ZLOGE(TAG, "Fan is not working!"); |
|||
m_fanError = true; |
|||
} |
|||
m_lastCallTicket = m_os->getTicket(); |
|||
m_fanFBCount = 0; |
|||
} |
|||
} |
|||
void FanStateMonitor::periodicJob() { |
|||
//
|
|||
bool& fanstate = *m_fanstate; |
|||
|
|||
if (fanstate != m_lastFanState) { |
|||
m_lastFanState = fanstate; |
|||
if (fanstate) { |
|||
/**
|
|||
* @brief 风扇有关到开 |
|||
*/ |
|||
// 启动检查
|
|||
m_fanOpenTicket = m_os->getTicket(); |
|||
m_lastCallTicket = m_os->getTicket(); |
|||
m_fanFBCount = 0; |
|||
m_fanError = false; |
|||
} |
|||
} |
|||
|
|||
/**
|
|||
* @brief 如果当前风扇正在工作,则周期性检查风扇状态 |
|||
*/ |
|||
if (fanstate) { |
|||
doFanStateCheckPeriodicJob(); |
|||
} |
|||
} |
@ -0,0 +1,47 @@ |
|||
#pragma once
|
|||
#include "libiflytop_micro/stm32/basic/iflytop_micro_os.hpp"
|
|||
#include "main.h"
|
|||
namespace iflytop { |
|||
class FanStateMonitor { |
|||
GPIO_TypeDef* m_FB_GPIOx; // 风扇反馈引脚
|
|||
uint16_t m_FB_GPIO_Pin; // 风扇反馈引脚
|
|||
bool* m_fanstate; // 风扇当前是否正在工作
|
|||
IflytopMicroOS* m_os; // 系统基础方法
|
|||
uint16_t m_fanFBCount; // 风扇反馈计数
|
|||
GPIO_PinState m_lastPinState; // 上次风扇反馈引脚状态,用来实现风扇反馈计数逻辑
|
|||
uint32_t m_lastCallTicket = 0; // 上次调用周期性任务的时间戳
|
|||
uint32_t m_fanOpenTicket = 0; // 风扇打开的时间戳
|
|||
bool m_lastFanState = false; // 上次风扇状态,用来实现捕获风扇打开事件
|
|||
|
|||
bool m_fanError; // 风扇故障标志位
|
|||
|
|||
public: |
|||
FanStateMonitor(/* args */){}; |
|||
~FanStateMonitor(){}; |
|||
|
|||
void initialize(IflytopMicroOS* os, GPIO_TypeDef* FB_GPIOx, uint16_t FB_GPIO_Pin, bool* fanstate); |
|||
|
|||
/**
|
|||
* @brief 读取风扇故障状态 |
|||
* 风扇故障异常会在以下两种情况被清除 |
|||
* 1. 风扇关闭后又重新启动 |
|||
* 2. 上层代码调用clearFanError()清除 |
|||
* @return true |
|||
* @return false |
|||
*/ |
|||
bool getFanError() { return m_fanError; } |
|||
bool clearFanError() { m_fanError = false; } |
|||
|
|||
/*******************************************************************************
|
|||
* 周期性调度任务 * |
|||
*******************************************************************************/ |
|||
|
|||
/**
|
|||
* @brief 周期性调度任务,需要上层代码尽可能的频繁调度 |
|||
*/ |
|||
void periodicJob(); |
|||
|
|||
private: |
|||
void doFanStateCheckPeriodicJob(); |
|||
}; |
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue