Index: firmware/App/Monitors/Switches.c =================================================================== diff -u -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a -ra0d405d152c0f451ebf3c25e3c2cfa49a4db17cd --- firmware/App/Monitors/Switches.c (.../Switches.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) +++ firmware/App/Monitors/Switches.c (.../Switches.c) (revision a0d405d152c0f451ebf3c25e3c2cfa49a4db17cd) @@ -33,18 +33,12 @@ #define SWITCHES_DEBOUNCE_TIME_MS ( MS_PER_SECOND / 4 ) ///< Switches FPGA status check interval. #define DATA_PUBLISH_COUNTER_START_COUNT 90 ///< Data publish counter start count. -/// Switch status structure -typedef struct -{ - OVERRIDE_U32_T status; ///< Switch status. - U32 debounceStartTime; ///< Debounce start time. -} SWITCH_STATUS_T; - // ********** private data ********** static U32 switchesDataPublicationCounter; ///< Switches data publication counter. static OVERRIDE_U32_T switchesDataPublishInterval; ///< Interval (in ms) at which to publish switches data to CAN bus. -static SWITCH_STATUS_T switchesStatus[ NUM_OF_SWITCHES ]; ///< Switches status array. +static OVERRIDE_U32_T switchesStatus[ NUM_OF_SWITCHES ]; ///< Debounced switch states. +static U32 switchDebounceStartTimes[ NUM_OF_SWITCHES ]; ///< Switch debounce start times. static BOOL requireDoorClosed; ///< Flag indicates whether door is required to be closed in current state. // ********** private function prototypes ********** @@ -74,11 +68,11 @@ // Initialize all the switches for ( i = 0; i < NUM_OF_SWITCHES; i++ ) { - switchesStatus[ i ].status.data = (U32)STATE_CLOSED; - switchesStatus[ i ].status.ovData = (U32)STATE_CLOSED; - switchesStatus[ i ].status.ovInitData = (U32)STATE_CLOSED; - switchesStatus[ i ].status.override = OVERRIDE_RESET; - switchesStatus[ i ].debounceStartTime = 0; + switchesStatus[ i ].data = (U32)STATE_CLOSED; + switchesStatus[ i ].ovData = (U32)STATE_CLOSED; + switchesStatus[ i ].ovInitData = (U32)STATE_CLOSED; + switchesStatus[ i ].override = OVERRIDE_RESET; + switchDebounceStartTimes[ i ] = 0; } } @@ -109,24 +103,24 @@ #endif { // Check if the current switch status is not the same as the recorded data - if ( (U32)currentSwitchStates[ i ] != switchesStatus[ i ].status.data ) + if ( (U32)currentSwitchStates[ i ] != switchesStatus[ i ].data ) { // If the debounce time is 0, start the timer - if ( 0 == switchesStatus[ i ].debounceStartTime ) + if ( 0 == switchDebounceStartTimes[ i ] ) { - switchesStatus[ i ].debounceStartTime = getMSTimerCount(); + switchDebounceStartTimes[ i ] = getMSTimerCount(); } // If the debounce time has been elapsed, update the switch status to the new status - else if ( TRUE == didTimeout( switchesStatus[ i ].debounceStartTime, SWITCHES_DEBOUNCE_TIME_MS ) ) + else if ( TRUE == didTimeout( switchDebounceStartTimes[ i ], SWITCHES_DEBOUNCE_TIME_MS ) ) { // If the bit is 0, the door switch is open, because it is normally open switch - switchesStatus[ i ].debounceStartTime = 0; - switchesStatus[ i ].status.data = currentSwitchStates[ i ]; + switchDebounceStartTimes[ i ] = 0; + switchesStatus[ i ].data = currentSwitchStates[ i ]; } } else { - switchesStatus[ i ].debounceStartTime = 0; + switchDebounceStartTimes[ i ] = 0; } } } @@ -185,11 +179,11 @@ if ( switchId < NUM_OF_SWITCHES ) { - state = switchesStatus[ switchId ].status.data; + state = switchesStatus[ switchId ].data; - if ( OVERRIDE_KEY == switchesStatus[ switchId ].status.override ) + if ( OVERRIDE_KEY == switchesStatus[ switchId ].override ) { - state = switchesStatus[ switchId ].status.ovData; + state = switchesStatus[ switchId ].ovData; } } else