Starting methods
cavelamb
Posts: 720
in Propeller 1
My question is about starting a method using Start and Stop...
I assume this only works with an external file?
Comments
No, those method names can be used anywhere, but are usually found in class files to configure an instance of the class.
Since Spin uses dot notation, you could use these method names in your parent (application) file.
cavelamb,
Your main program can have a Start and Stop method in it.
One of the main purposes for these methods is to control Cog usage, since Start will send code to a Cog to run and Stop will shut it down.
Since the Propeller only has 8 Cogs, your program should only have an Object running when it's needed, unless you have Cogs to spare.
It's up for 5 cogs and I'd like to add another one
My experience predates dot notation.
By a couple of centuries.
Just plain didn't think of it.
So
how to write/declare that?
`Pub Drive
Con
Var
.start?
.end?
`
Wait, what? Crack open any Spin object file and have a look. Typically, the first method will be called pub start. Most of the time the second method will be called pub stop. In your application you declare them the same way, but you don't need to use the object.method_name style to access them.
I've attached an archive with my P1 template and some common objects. Have a look -- it should clarify things.
Oh.
Sorry Jon. I was in too big of a hurry and didn't elaborate.
The method needs to run in a own cog by itself.
All the examples that do so that I have found so far do that via an external file.
It's based on your ez_dual_motor.spin, but for the TB6612FNG chip, which uses
a different control pin arrangement.
I'm working on that, but really would like all the code in a single file.
So what I am really asking is how to launch a new method, in a new cog,
with .start, .stop, etc - from my main Spin file. That kind of thing?
I do want to use ** object.method_name **to access them
Or?
Pub Drive
Pub Drive.Start
Pub Drive.stop
I see how it works when using an external file, but - ???
Forgive me for being backwards?
I don't know much about classes and such.
The dot notation is only for calling functions from different files - it's how you indicate which file the function you want is from. Calling them
start
andstop
are only conventions. If you want to start a cog from within the same file, just do what's done inside thestart
method of a typical object.EDIT: typo
Okay, got it. There is no name for this, but I sometimes call this an embedded object as the code for the other cog is embedded in the main application.
Real-world example: For the EFX-TEK HC-8+, I have a background Spin cog that is special to that board, so it's built into the application template. I've attached the code. You'll see this line:
This starts my background cog. You can do this with PASM cogs, too -- you just need to put that code into your message and call the cognew() function appropriately.
You can do that, but you make re-using code that really should be general purpose harder.
Now that's a fact.
But I doubt this code will be used for anything else.
Thanks, Jon.
@Electrodude
Yeah. That's kinds what I expected, but wasn't sure.