R
Rohit
Hi,
I am working on a switch module which after reading voltage through a
port pin and caterogizing it into three ranges(open,low or high),
passes this range to a function switch_status() with parameters value
and signal ID. Signal Id is used to get a user configurable parameter
inside a configuration file, which depends on the type of switch.
I have implemented it as under. Please ignore those magic numbers as I
have mimized logic to simplify it. Now I want to optimize it. Somebody
told me that the logical connection between variables: value,
switchconfTable[signal_id].contact and the return value(TRUE or FALSE)
should be solved via preprocessor not code.
I am unclear about what it means. Can anybody suggest an insight what
it means ?
..h file
typedef enum
{
Switch_Low, /*!< 0 - value of digital Input is low */
Switch_High, /*!< 1 - value of digital Input is high */
Switch_Open /*!< 2 - value of digital input being not
connected (break) */
} Switch_value_t;
..c file
/* This function is called after determining that value
is in one of the ranges defined by Switch_value_t */
int static switch_status(Switch_value_t value, signal_id)
{
int retval = 0;
switch(value)
{
case Switch_Low:
{
if(switchconfTable[signal_id].contact==0x01)
retval = 1;
else
retval = 2;
}
case Switch_High:
/* Similar code as Switch_Low case*/
case Switch_Open:
/* Similar code as Switch_Low case*/
}
return retval;
}
Cheers
Rohit
I am working on a switch module which after reading voltage through a
port pin and caterogizing it into three ranges(open,low or high),
passes this range to a function switch_status() with parameters value
and signal ID. Signal Id is used to get a user configurable parameter
inside a configuration file, which depends on the type of switch.
I have implemented it as under. Please ignore those magic numbers as I
have mimized logic to simplify it. Now I want to optimize it. Somebody
told me that the logical connection between variables: value,
switchconfTable[signal_id].contact and the return value(TRUE or FALSE)
should be solved via preprocessor not code.
I am unclear about what it means. Can anybody suggest an insight what
it means ?
..h file
typedef enum
{
Switch_Low, /*!< 0 - value of digital Input is low */
Switch_High, /*!< 1 - value of digital Input is high */
Switch_Open /*!< 2 - value of digital input being not
connected (break) */
} Switch_value_t;
..c file
/* This function is called after determining that value
is in one of the ranges defined by Switch_value_t */
int static switch_status(Switch_value_t value, signal_id)
{
int retval = 0;
switch(value)
{
case Switch_Low:
{
if(switchconfTable[signal_id].contact==0x01)
retval = 1;
else
retval = 2;
}
case Switch_High:
/* Similar code as Switch_Low case*/
case Switch_Open:
/* Similar code as Switch_Low case*/
}
return retval;
}
Cheers
Rohit