robinfawell Posted March 6, 2006 Report Share Posted March 6, 2006 Dear ThorstenI have been trying without success to produce a function which will reduce the amount of code considerably. I understand the concept, I think, but cannot implement it. I will show below a section of code derived from your previous suggestion. This is repeated about 10 times with changes of pin numbers and groupxselected ///////////////////////////////////////////////////////////////////////////// // This function is called by MIOS when an button has been toggled // pin_value is 1 when button released, and 0 when button pressed ///////////////////////////////////////////////////////////////////////////// unsigned char group1_selected;//Pedal group, Pins 19-25 unsigned char group2_selected;//Tremelo Fast, Pin 28 unsigned char group3_selected;//Sw_P Group, Pins 33-34 unsigned char group4_selected;//Sw_M Group, Pins 36-38 unsigned char group5_selected;//Sw_R Group, Pin 40 unsigned char group6_selected;//Gt_P Group, Pins 42-47 unsigned char group7_selected;//Gt_M Group, Pin 49 unsigned char group8_selected;//Gt_R Group, Pins 51-57 unsigned char group9_selected;// Pedal couplers pins 16 & 17 unsigned char group10_selected;// Pedal Sub-Octave pin 18 unsigned char group11_selected;// Tremelo Swell Select unsigned char group12_selected;// Tremelo Great Select void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value) __wparam { unsigned char i;// used for MIOS_DOUT_PinSet0 //////// Pedal Radio Group/////// if( (pin >= 19 && pin <= 25) && (pin_value == 0)){ //if button already selected, turn off LED's //this is identified with group1_selected = 0xFF if(group1_selected == pin) { group1_selected = 0xFF;// all LED's Off }else{ //save the selected button function of the group group1_selected = pin ;} //LED's should be cleared for(i=19; i<= 25; i++) MIOS_DOUT_PinSet0(i); //set the LED which relates to the selected function if(group1_selected != 0xFF) MIOS_DOUT_PinSet1(group1_selected); }else{ //////////Tremelo Fast/ Slow Push Button///////// if( (pin >= 28 && pin <= 28) && (pin_value == 0)){ //if button already selected, turn off LED's //this is identified with group2_selected = 0xFF if(group2_selected == pin) etc etc I think that it should be possible to add a function "ControlGroupLed" immediately after the line. if( (pin >= 19 && pin <= 25) && (pin_value == 0)){in each repeated section. There are 3 variables associated with each group, "lowest pin", " highest pin" and "group'x'connected".From the different sections of DIN_NotifyToggle I would call ControlGroupLed (r,s,x) corresponding to the pins and identifying the relevant group'x'connected After the "ControlGroupLed" I could call the "SendDump2 function.I will be very grateful for your help.Regards RobinPS After sending this message it occurred to me that my Function "ControlGroupLed" needs only to be called with one variable ie groupxselected and that the other parameters could be loaded from an constant array above the function statement. Does this make sense? Quote Link to comment Share on other sites More sharing options...
TK. Posted March 6, 2006 Report Share Posted March 6, 2006 Hi Robin,using tables (const arrays) always improve the oversight, I would go this wayBest Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
robinfawell Posted March 10, 2006 Author Report Share Posted March 10, 2006 Dear ThorstenI sent a question to you yesterday regarding my SendNote function. I had spent a lot of time trying various changes and could not get it to work. I then read one of my C references this morning that states that it is good practice to prototpe the function by placing the function after the include statements.It now works! I have theref0re deleted my query.I have now prototyped the SendTremelo function as well.I did get an error concerning the fact that the prototype differed from the function (later in the program). This was due to the "__wparam"at the end of the function. I deleted it fom the function. The error was removed.What is the purpose of this function ending and should I have deleted it?Regards Robin Quote Link to comment Share on other sites More sharing options...
Synapsys Posted March 10, 2006 Report Share Posted March 10, 2006 Hi Robin,The wparam modifier causes the first byte of the arguments to be passed to the function in the WREG. This makes for more effiecient processing.The use of prototypes is necessary so that the C preprocessor can determine the number of arguments a function requires. All modern C compilers will give at least a warning if a prototype is not present. Some C compilers will generate an error and force the inclusion of a prototype prior to calling a function.Hope this helps.Regards,Synapsys Quote Link to comment Share on other sites More sharing options...
robinfawell Posted March 13, 2006 Author Report Share Posted March 13, 2006 Thanks SynapsysI will keep the modifier in the prototype and the function statements.Regards Robin Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.