Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
void DigitalButton_Process(HalDigitalButton* const pThis)
{
    
    bool isState;
    uint32_t filteredValue;
    uint32_t isDiagnosticStable;
    uint32_t pinVal;
   
    Expect_FatalObjConstructedAndInitialized(pThis);
   
	pinVal = (pThis->pCfg->pFunGetDigitalPinStatus)()? DIGITAL_BUTTON_PIN_STATE_HIGH : DIGITAL_BUTTON_PIN_STATE_LOW;
    MiscFilter_StableFilter_PushValue(pThis->pCfg->pFilter, pinVal);
    isState = MiscFilter_StableFilter_GetFilteredValue(pThis->pCfg->pFilter, &filteredValue);
     
             

    if (isState)
    {
        pThis->data.currentStatus = DigitalButtonStatus_stable;
        /*if the Button is Active low state*/
        if (pThis->pCfg->halDigitalButtonMode)
        {
            if (filteredValue == DIGITAL_BUTTON_PIN_STATE_HIGH)
            {
                pThis->data.currentState = DigitalButtonState_released;
            }
            else if (filteredValue == DIGITAL_BUTTON_PIN_STATE_LOW)
            {
                pThis->data.currentState = DigitalButtonState_pushed;
            }
            else /* invalid value */
            {
                pThis->data.currentState = DigitalButtonState_error;
            }
        }
        else
        {    /*if the Button is Active high state*/
            if (filteredValue == DIGITAL_BUTTON_PIN_STATE_HIGH)
            {
                pThis->data.currentState = DigitalButtonState_pushed;
            }
            else if (filteredValue == DIGITAL_BUTTON_PIN_STATE_LOW)
            {
                pThis->data.currentState = DigitalButtonState_released;
            }
            else /* invalid value */
            {
                pThis->data.currentState = DigitalButtonState_error;
            }
        }
    }
    else
    {  
        pThis->data.currentStatus = DigitalButtonStatus_unstable;
        
    }


What I have tried:

TEST_F(HAL_DigitalButton_c, HAL_DigitalButton_Process___isInitialized_is_High)
{
    ConstructAndInit()
    obj->isInitialized = false;
    HAL_DigitalButton_Process(obj);
    EXPECT_EQ(DigitalButtonStatus_unstable, obj->data.currentStatus);
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900