nsunier Posted March 23, 2008 Report Share Posted March 23, 2008 Hi,I use the AIN_NotifyChange(unsigned char pin, unsigned int pin_value) function to send MIDI message and update display when a pot is moved. It works quite well.Now, I want, at startup, to do the same thing for each AIN channel in order to send to the PC software the initial AIN channels state. How can I achieve this? Should I call in the Init(void) function (within a loop) the function above or is there another cleaner way to do that?Many thanks in advance for your help.nsunier Quote Link to comment Share on other sites More sharing options...
audiocommander Posted March 23, 2008 Report Share Posted March 23, 2008 Should I call in the Init(void) function (within a loop) the function aboveyup, you can do that ;)Edit:...but of course, you have to read the AIN states, because you don't know what to hand over to this notifier function; so it might be easier, if you read and send the states in the Init() ... or even better: split your functions into useful parts and call those... Quote Link to comment Share on other sites More sharing options...
nsunier Posted March 23, 2008 Author Report Share Posted March 23, 2008 If I understand well, I should use the MIOS_AIN_Pin7bitGet function in order to get the AIN states? I don't know in detail how works the MIOS OS. Is it allowed to run this function in the Init()? I'm not sure that the pots are already read...nsunier Quote Link to comment Share on other sites More sharing options...
TK. Posted March 23, 2008 Report Share Posted March 23, 2008 No, at the time the Init() hook is invoked, the pots haven't been scanned. I would add a request mechanism into Tick() which sends all pot values when a certain flag is set (e.g. POT_SNAPSHOT_REQ, similar handling like the DISPLAY_UPDATE_REQ you will find in many C based applications).This flag has to be set after a certain time (which depends on the number of pots). I guess, that with 30 mS you are at the save side. So, how to add a cheap delay mechanism without sacrificing the Timer() hook: use SR_Service_Prepare() or SR_Service_Finish(), these hooks are called each mS if number of SRIO is > 0 (I guess that you are using DIN/DOUT modules, so SRIO length is probably already initialized?)Then define a 8bit variable as counter, set it to 30 inside Init()Inside SR_Service_Prepare() (or _Finish() - doesn't really matter), check if the counter is already 0if not, decrement it. Check again if it is 0 - yes: set the POT_SNAPSHOT_REQ flagOnce the routine in Tick() is executed (this happens whenever nothing else is to do), it clears POT_SNAPSHOT_REQ (so that this mechanism won't be triggered again), sends the pot values - voila!Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
nsunier Posted May 4, 2008 Author Report Share Posted May 4, 2008 Thank you. ;) Now it works well. This question is solved.Best regards,nsunier Quote Link to comment Share on other sites More sharing options...
dinama Posted May 17, 2012 Report Share Posted May 17, 2012 Can you post a text file with your solution? I want the same thing but i'm not a programmer. thanks Quote Link to comment Share on other sites More sharing options...
TK. Posted May 17, 2012 Report Share Posted May 17, 2012 Duplicate: 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.