Removed assumption that object instance and object index are one and the same. Added in missing Analog_Input_Instance_To_Index() function.

This commit is contained in:
petermcs
2010-03-11 16:57:55 +00:00
parent baec022ecd
commit bfd3920698
+31 -7
View File
@@ -86,7 +86,10 @@ void Analog_Input_Property_Lists(
bool Analog_Input_Valid_Instance( bool Analog_Input_Valid_Instance(
uint32_t object_instance) uint32_t object_instance)
{ {
if (object_instance < MAX_ANALOG_INPUTS) unsigned int index;
index = Analog_Input_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_INPUTS)
return true; return true;
return false; return false;
@@ -109,13 +112,29 @@ uint32_t Analog_Input_Index_To_Instance(
return index; return index;
} }
/* we simply have 0-n object instances. Yours might be */
/* more complex, and then you need to return the index */
/* that correlates to the correct instance number */
unsigned Analog_Input_Instance_To_Index(
uint32_t object_instance)
{
unsigned index = MAX_ANALOG_INPUTS;
if (object_instance < MAX_ANALOG_INPUTS)
index = object_instance;
return index;
}
float Analog_Input_Present_Value( float Analog_Input_Present_Value(
uint32_t object_instance) uint32_t object_instance)
{ {
float value = 0.0; float value = 0.0;
unsigned int index;
if (object_instance < MAX_ANALOG_INPUTS) { index = Analog_Input_Instance_To_Index(object_instance);
value = Present_Value[object_instance]; if (index < MAX_ANALOG_INPUTS) {
value = Present_Value[index];
} }
return value; return value;
@@ -125,8 +144,11 @@ void Analog_Input_Present_Value_Set(
uint32_t object_instance, uint32_t object_instance,
float value) float value)
{ {
if (object_instance < MAX_ANALOG_INPUTS) { unsigned int index;
Present_Value[object_instance] = value;
index = Analog_Input_Instance_To_Index(object_instance);
if (index < MAX_ANALOG_INPUTS) {
Present_Value[index] = value;
} }
} }
@@ -134,9 +156,11 @@ char *Analog_Input_Name(
uint32_t object_instance) uint32_t object_instance)
{ {
static char text_string[32] = ""; /* okay for single thread */ static char text_string[32] = ""; /* okay for single thread */
unsigned int index;
if (object_instance < MAX_ANALOG_INPUTS) { index = Analog_Input_Instance_To_Index(object_instance);
sprintf(text_string, "ANALOG INPUT %lu", (unsigned long)object_instance); if (index < MAX_ANALOG_INPUTS) {
sprintf(text_string, "ANALOG INPUT %lu", (unsigned long)index);
return text_string; return text_string;
} }