⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setpointregion.c

📁 cypress cy3721做的外部无线结点。感知温度后将温度值反给中心结点。
💻 C
字号:
//
//  SetPointRegion.c
//
//     determines a region based on a setpoint
//     Set points are ordered from low to high SP1 to SPN
//     Regions are output as follows from 1 to N+1
//        0 = nValue < (SP1 - Hysteresis)
//        1 = (SP1 + Hysteresis) < nValue < (SP2 - Hysteresis)
//        i = (SPi + Hysteresis) < nValue < (SPi+1 - Hysteresis)
//        N = (SPN + Hysteresis) < nValue 
//     If nValue falls between any hysteresis bands, then the old valued is output

#include "CMXSystem.h"
#include "CMXSystemFunction.h"
#include "CMXSystemExtern.h"
#include "FunctionParamDecl.h"
#include "SetPointRegion.h"

BYTE SetPointRegion( SETPOINT_REGION_PB const * pParamBlk, int nValue)
{
	BYTE nRegion = 255;
	SETPOINT_REGION_PB setPointParam = *pParamBlk;
	BYTE nSetPointCount = (BYTE)setPointParam.SetPointCount;
	SETPOINT_ELEM_STRUC const * setPointArray = setPointParam.SetPointArray;
	BYTE nInnerIndex;
	int nTempIndex, nOuterIndex;
	signed char nDirection = 0;
	SETPOINT_ELEM_STRUC lowerSetPoint;
	SETPOINT_ELEM_STRUC setPoint;

	// assume that the thresholds are ordered lowest to highest
	// find the region
	// test for the lowest region
	lowerSetPoint = setPointArray[0];
	nTempIndex = *(lowerSetPoint.Threshold) -  *(lowerSetPoint.Hysteresis);
	if (nValue < nTempIndex)
	{
		nRegion = 0;
	}	//ENDIF in lowest region
	else
	{
		lowerSetPoint = setPointArray[nSetPointCount - 1];
		nTempIndex = *(lowerSetPoint.Threshold) +  *(lowerSetPoint.Hysteresis);
		if (nValue > nTempIndex)
		{
			// test for the highest region
			nRegion = nSetPointCount;
		}
		else
		{
			// determine direction
			if (*(setPointParam.pOldValue) == nSetPointCount)
			{
				setPoint = setPointArray[nSetPointCount-1];
				if (nValue < *(setPoint.Threshold) - *(setPoint.Hysteresis))
				{
					nDirection = -1;
				}	//ENDIF out of region decreasing
			}	//ENDIF in highest region
			else if (*(setPointParam.pOldValue) == 0)
			{
				setPoint = setPointArray[0];
				if (nValue > *(setPoint.Threshold) + *(setPoint.Hysteresis))
				{
					nDirection = 1;
				}	//ENDIF out of region increasing
			}	//ENDELSEIF in lowest region
			else
			{
				setPoint = setPointArray[*(setPointParam.pOldValue)];
				lowerSetPoint = setPointArray[*(setPointParam.pOldValue)-1];
				if (nValue > (*(setPoint.Threshold) + *(setPoint.Hysteresis)))
				{
					nDirection = 1;
				}	//ENDIF increasing
				else if (nValue < (*(lowerSetPoint.Threshold) - *(lowerSetPoint.Hysteresis)))
				{
					nDirection = -1;
				}	//ENDELSEIF decreasing
			}	//ENDELSE in between
			if (nDirection != 0)
			{
				// test for intermediate regions
				if (nDirection == 1)
				{
					for (nInnerIndex = nSetPointCount - 1;(nInnerIndex >= *(setPointParam.pOldValue)) && (nRegion == 255);nInnerIndex--)
					{
						// check value above threshold
						setPoint = setPointArray[nInnerIndex];
						nTempIndex = *(setPoint.Threshold) + *(setPoint.Hysteresis);
						if (nValue > nTempIndex)
						{
							nRegion = nInnerIndex+1;
						}	//ENDIF found region
					}	//ENDFOR loop going down
				}	//ENDIF increasing
				else
				{
					for (nInnerIndex = 1;(nInnerIndex < *(setPointParam.pOldValue)) && (nRegion == 255);nInnerIndex++)
					{
						// check value below threshold
						setPoint = setPointArray[nInnerIndex];
						nTempIndex = *(setPoint.Threshold) - *(setPoint.Hysteresis);
						if (nValue < nTempIndex)
						{
							nRegion = nInnerIndex;
						}	//ENDIF found region
					}	//ENDFOR loop going up
				}	//ENDELSE decreasing
			}	//ENDIF changing direction
			else
			{
				// still at the old region value
				nRegion = *(setPointParam.pOldValue);
			}	//ENDELSE no change
		}
	} 
	
	return nRegion;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -