REading a value from a Cog???
SailerMan
Posts: 337
Basically I have code to Read a Sony REmote running in an endless loop in a cog ....Call it Cog#0.
I want another cog#1 to be·notifyed that data has been recieved in·Cog#0·and what that data is.
Is there a way to do this?
Thanks,
Eric
PS any people in Pennsylvania out there?
·
I want another cog#1 to be·notifyed that data has been recieved in·Cog#0·and what that data is.
Is there a way to do this?
Thanks,
Eric
PS any people in Pennsylvania out there?
·
Comments
There are multiple ways to do this......depends on if you want to go through the hub or not.
1. Direct method (real fast).......If you have a extra pin you are not using. Make it an output and set it high when the data is ready. You main loop can look at the pin and retreive the data when the pin goes high.
2. If you can't go with that option. Make a byte VAR. Slice it up into 8 bit flags. byte[noparse][[/noparse]0] through byte[noparse][[/noparse]7] and you can set those flags high....and have the main loop see if the bit is high or low. When the bit is high retreive the data.
The data passing is a little different.
Main loop (cog#1)
mypassedinformation *8 /2
Data loop (cog #0)
long[noparse][[/noparse]mypassedinformation] = what ever data to be passed····· (the size can be byte,word,long,)
You can thank Beau, Paul, Mike and a few other to get this through my thick skull.
Hope this helps,
James L
I will try when I get home and ask questions where needed.
Is anything specific with the line above?
Thanks for your help,
Eric
James L
Like I said I can't test this out yet.. I'm just thinking.
I created a SonyIRDecoder Spin Object.
It basically runs in a loop waiting for IR data to come.
When Data arrives it is decoded into Device ID and Button Code.
In my Main program I use the object like normal
How Do I get access to these? I tried the info below but could not get it to work.
Regards,
Eric
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
I'm sure this has been addressed before in the forums, so you might want to struggle with the seach engine to find some of those threads
One approach I recall is to have your IR object communicate with other cogs through a shared variable. Say you want to share the value in the variable "Info". Then have your IR object something like:
in which you pass the address of a variable, probably a global variable in your "main" code. So from your main code you do something like:
The IR object would update the Info variable in the code running as an endless loop in the separate cog, like so:
The "client", perhaps the "main" thread (which instantiated the IRthingie object) will periodically consult the Info variable as usual:
To ensure the data in info is "fresh", you might set it to an "illegal" value (e.g. -1) from your "main" code after reading it, and then poll info until it takes a value different from -1.
I haven't taken into account concurrency problems. If you just update a 32-bit or less variable, there'll be no problem because read/write operations on these are atomic. If it's not the case, you can use semaphores or a buffer approach.
Warning: I haven't tested this code and it might have mistakes. There also might be a better way, I'm mainly translating from a C mental model. I'm sure Mike Green has explained this better somewhere
Best Regards,
Eric