Puzzled that child values are changed by parent
lardom
Posts: 1,659
in Propeller 1
I modified a 'joystick' object from "rctime" which gave me 7 X-axis values and 7 Y-axis values to mcp3208 which gave me 17 x-axis and 17 y-axis values. The 'joystick' object works fine. When I call that object from the top object some of those values change. Before I rewrite the object to have fewer values I'd like some advice on what I should look for.
I did not have that problem with the lower resolution 'rctime'.
I did not have that problem with the lower resolution 'rctime'.
Comments
From "Buggy joystick" I get the correct values.
You're assigning F_B to a value, then using a case statement to re-assign it to a different value. Because this is running in a cog, the caller may be accessing the variable F_B between when you first set it and when you change it.
I'd alter the code to this:
I can't say for sure that's your issue, but it's a possibility. It might also be that the ADC method you're calling needs more stack space than you're providing, though 50 longs seems like it should be plenty. As a test, bump that up to 100 longs and see if you still have the problem.
I added a variable "temp" because it was clearly the correct thing to do but I got the same result. Then I tried raising the stack from 50 to 400 longs which had no effect so I took another look at the top object.
I commented the CASE loop and "Button press" then called the "Joystick" object directly. That worked.
It appears I should call for the joystick values before I call "Mode_select. If that doesn't work I'll start another cog.
Much thanks to you and Kwinn because I was completely out of ideas.
The pst.Dec() call should just display Fwd_Bkwd instead of calling the function again. Minor, and not going to be your bug, but it's a little odd and will be slower.
I don't understand what you mean by "before I call Mode_select" - it's a variable, not a function - I don't see a call to it anywhere, unless the code is different than what I'm looking at. Do you mean before you execute the case statement? I see no reason you should have to call the JS.GetFB function first.
I do think the case statement (which is what I meant) is the culprit but I'm not sure. I'll pinpoint it tomorrow.
The code compiles, but I haven't actually run it.
There are many roads that lead to Rome. As we say here in Hollywood, this code is "for your consideration."
I actually spent the morning modifying my code and testing different approaches. I decided to accept the values that the CASE statement in the parent object is changing because "Mode_select" is a necessary part of my project.