?? setpointregion.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 + -