Hi Robin,
you could save the last pin number in an additional global variable (just call it ‘unsigned char last_pin;’)
Alternatively you could declare the variable within the function, and make it static (‘static unsigned char last_pin;’) - static variables don’t loose their value when the function is called again, and the variable name is only in the scope of this function, which means, that you can use simple names without the danger for conflicts with other global variables.
On each Din I reset all array_index in the group. Then set the current array index by using the stored current pin # or array_index.
Thats perfect, I wouldn’t do it on a different way
I realise that it would be possible to use a conditional ‘for loop’ using break and/or continue.
This leads only to additional execution time (due to the if condition), and to larger code.
If however the same Din in the group is pressed twice in succession (using Last_ pin_pressed) then each array_index is set to zero prob by using the XOR toggle.
Something that isn’t clear to me is the relation between the XOR toggle and the subject “Radio group button behaviour”.
So long you only want to set a certain pin, and clear the others, then I would suggest following solution:
unsigned char group1_selected;
void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value) __wparam
{
unsigned char i;
// DIN 16..31 is one "radio group"
if( pin >= 16 && pin <= 31 ) {
// save the selected button function of the group
group1_selected = pin - 16;
// the LEDs of this group are connected to DOUT Pin 0..15, clear them
for(i=0; i<=15; ++i)
MIOS_DOUT_PinSet0(i);
// set the LED which is related to the selected function
MIOS_DOUT_PinSet1(group1_selected);
} else {
// this branch handles DIN 0..15 and DIN 32..127
}
}
[/code]
So, as you can see, for a group of LEDs, where only one lits, you don't need to store the information in an array, you only need to store a reference to the selected function
Best Regards, Thorsten.