#include "xc.h"
#include "../CommonCode/types.h"
#include "../CommonCode/CRSAL.h"


/*Sets value field of tCRSAL structure with SetPt after comparing to upper and lower limits
 * If setpoint is outside allowable range, it is set to the min or max depending on which side it is outside of the window.
 *    This is a decision that seems to make sense for how this function is used, and reduces the chance something will be un-set at initialization.
 *    If a "don't set if out of range" behavior is also needed, a behavior flag can be added to the argument list.
 * Returns  0 on success, 
*/
int Set_CRSALValue(fractional SetPt,volatile tCRSAL *var)
{
    if(SetPt < var->LowerLimit)
          SetPt = var->LowerLimit;  // return -1;
    if(SetPt > var->UpperLimit)
        SetPt = var->UpperLimit; //return 1;
    
    var->Value = SetPt;
    return 0;
    
}

