Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpSyntax › example with Wiring and C++ code?

Page Index Toggle Pages: 1
example with Wiring and C++ code? (Read 5825 times)
09/19/06 at 02:11:28

djones   Offline
YaBB Newbies
Wiring / Processing user
Hamilton, Ontario, CANADA

Posts: 15
*
 
Hi,

With Processing, besides your "setup()" and "draw()" functions,
you can add a "tab" called "myclass.java" in the
development enviroment, and your main code gets linked up with the Java code.

I am guessing it might be possible in Wiring to do something similar,
except the added "tab" would be "mycode.c" or "myclass.cpp".
I am looking for an example that might illustrate the details of how
to write some separate C or C++ code that can be called
from the "setup()" or "loop()" functions.
I wasn't sure how to deal with things like header files to include, etc.

Also, ... if there is online documentation for how to write/install a "library",
please let me know where to find it.

thanks!
  djones
 
IP Logged
 
Reply #1 - 09/19/06 at 04:03:48

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
There's a seperate forum-entry for library writers that has an example.

But what I did was to copy the directory libraries/Servo to
a directory libraries/Gyro and I changed all the Servo to Gyro in the
filenames and the contents of the files, and after I did that I could use
Gyro mygyro;
mygyro,attach(0);

to call the methods in my library.
Then I started changing the code to do what I wanted it to do.

I must admit, I was confused trying to figure out how to compile the
library since there are no Makefiles, but then I realized that when I
"Verified" my Wiring sketch that it compiled the library for me.
(It's hard to rememver to remove the library .o file every time you
edit the library .cpp file though. There should be a dependency
built in so it compiles when you update the source, but there isn't.)
 
IP Logged
 
Reply #2 - 09/19/06 at 22:20:40

djones   Offline
YaBB Newbies
Wiring / Processing user
Hamilton, Ontario, CANADA

Posts: 15
*
 
Thanks Alan.

The Wiring "engine" (if I can call it that) must be doing some kind of dependency checking anyway, since it knows enough to create the ".o" file from the ".cpp" file when necessary.  I would hope it would be relatively easy for them to update Wiring to make sure the ".o" is "up-to-date" relative to the corresponding source ".cpp" file.  Even if we had to add our own Makefile in the "libraries/Gyro" folder, that would be a welcome convenience.

So, ... from what you described, it sounds like I can just create a subfolder in "libraries" and it will auto-magically discover it, and references to new symbols (like "Gyro") will be found, with no headers, includes, or other steps.

thanks a bunch!!

-- djones
 
IP Logged
 
Reply #3 - 09/20/06 at 02:25:14

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
I bet that everything has to have the same name though.
Directory Alan contains Alan.cpp and Alan.h and all the classes and methods are Alan.something().

Let us know if you suceed in writing a library!
 
IP Logged
 
Reply #4 - 09/24/06 at 19:36:12

zambetti   Offline
YaBB Newbies

Posts: 21
*
 
A library named Alan doesn't need files called Alan.cpp and Alan.h ... take a look at the Wire or Serial libraries for examples of this. Those libraries feature preinstantiated instances (Serial and Wire) at the end of their .h files which necessitate their being named in such a way.

The point about the library system knowing when files are out of date is a good point. That is a good idea for an improvement in the next version. Until then, you are correct to delete the .o file to force a rebuild.

The sample libraries in the "library writers" thread are a nice way to start out. They are pretty barebones and illustrate how to use most/all of the library system's features.
 
IP Logged
 
Page Index Toggle Pages: 1