Jump to content

[solved] How to send initial AIN state to MIDI OUT at startup?


Recommended Posts

Posted

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

Posted
Should I call in the Init(void) function (within a loop) the function above

yup, 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...

Posted

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

Posted

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 0

if not, decrement it. Check again if it is 0 - yes: set the POT_SNAPSHOT_REQ flag

Once 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.

  • 1 month later...
  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...