Use one Library from another Library?

Hello,

in my code, I would like to use one library from another one.

From a self-developed application library (including application logic, menu logic, etc.), I would like to use the LCD4Bit library, i.e., output text to an LCD. How can I do that?

I tried to hand-over a reference like that:

LCD4Bit myLCD4Bit; APP myApp(myLCD4Bit);

This does not work.

I also tried to use extern LCD4Bit myLCD4Bit; within my application class, but witthout success.

Does anybody have an idea? Any suggestions?

holgr

Sorry, I’m… really confused on what you’re trying to do here.
From your question… sounds like you would just need to #include both libraries.

But if you’re talking about updating a single library, so you won’t have to use the Two #includes, you could edit the .cpp of your library and .h and have them #include <LCD4Bit.h> I believe anyway. I’ve only edited a few libraries.

I’m still not sure what you’re trying to do, so I don’t know where to point you! Are you trying to use a Library you’ve created to implement the menu into the LCD4Bit?

If that’s the case, you’re going to have to write another library, or open it up with VB and do a Search for all your commands, and change them to LCD4Bit compatible commands.

And if none of this is what you’re looking for, sorry for the long post! :smiley:

Hello CaptainObvious,

thank you very much for your reply.

My problem is that I want to use to libraries, LCD4Bit and another self-developed one (say MyApp). Both are implemented as libraries (.h and *.cpp). From within MyApp, I would like to use LCD4Bit via an LCD4Bit, a LCD4Bit& or just as a LCD4Bit.

My problem is that just including LCD4Bit and creating an instance does not work. So when I define LCD4Bit m_LCD within MyApp, nothing happens.

With some libraries (Ethernet), I saw that extern definitions where used, but this doesn't work for me as well.

holgr

Hi.

You can include LCD4Bit to your own library, add a member of LCD4Bit to the library class, create an instance of it in the libraries constructor and if you really need a pointer to this LCD4Bit instance you can add a getter method to your library, that returns this pointer.

(Library != application)

— MyLib.h —

#include <LCD4Bit.h>
class MyLib
{
public:
void init()
{
  lcd.init(); // check LCD4Bit library to see how to init this instance correctly
}

void doSomethingVeryCool()
{
  //do some of your library stuff here
}

LCD4Bit* getLCDPointer()
{
  return &lcd;
}

private:
LCD4Bit lcd;
}

If you want to use the LCD4Bit in your application, you need to include LCD4Bit.h, initialize your library “MyLib”, before you do something with the LCD.

— MyProject.pde —

#include <MyLib.h>
#include <LCD4Bit.h>

MyLib myLib;
LCD4Bit* pLCD = 0;

setup()
{
  myLib.init();
  pLCD = myLib.getLCDPointer();
  pLCD->Write("Hello World");
}

If you want to do the “main stuff” within your library and use the LCD within your application additionally, may be just for textout, then you should add a textOut(…) to your library instead of access the lcd via a pointer from the application. This can avoid mixed output, because you can control within your library, if the application is allowed to textout something at this moment. Otherwise your lib draws the menu and the application could write some other text at the same time.

I had no time to test this, but it should work LIKE this.

rgds,
marleaux

Hello marleaux,

thank you very much for your reply and for the sample code.

I've already tried this approach, but I hasn't worked with me. However, I've found what went wrong.

I put my initialisation code for LCD4Bit into my application library's constructor, but the constructor's code wasn't called when creating an instance using MyApplication class myApp;

When moving the initialisation code to an init method, everyhing works fine.

I'm currently working on extenting the Visual Studio debuggin approach for Arduino and will publish it soon.

Again, thank you very much!

holgr

Hi holgr,

I use Visual Studio every day at work, so I am highly interested in using VS for Arduino development.

Do you have some more information about this?

Did I miss a "Playground entry"?

Best regards, marleaux

Hi marleaux,

under http://www.arduino.cc/playground/Code/VisualStudio, you can find a short description on how to make VS regognising PDE files as CPP files and an *.h and a .cpp file for being able to compile projects (pinMode() function, etc.)

This approach works quite will, but it doesn't allow for reading/writing from/to arduino I/Os. One option may be to use the Firmata protocol (http://firmata.org, similar to the MIDI protocol), but this seems to be like using a sledgehammer to crack a nut.

holgr