Go Down

Topic: library definition (Read 1 time) previous topic - next topic

newhobby

#10
Jan 12, 2012, 04:38 pm Last Edit: Jan 12, 2012, 05:18 pm by newhobby Reason: 1
I think it worked!!!!
You are a genius!!!
Definitely owe you a beer :)
I'll make some more tests later, gotta go to a meeting atm.
Thank you so much!!!

RI

mromani

Glad to hear that. Thanks for the beer. La berrĂ² alla tua salute ;-)

newhobby

Ok, I've done some tests, but I'm still getting somewhat of a problem.
So, I need to add another level of difficulty.
I have a very complex set of libraries.
The solution provided works if the function is called from withint the INO file itself, but does not work if another library is calling it.
What do I need to do so the define becomes globally visible by all libraries?
Let explain a little of what I'm trying to achieve and maybe you could point me to a better solution.
I have a very large code that I'd like to fit on a UNO board.
If I add all features of the code, it won't fit.
So, I have right now a header file located on Arduino\libraries folder that I can edit and #define which features should be included on the compiled code.
Everything is working really good, except that it makes it really hard to know which features you had uploaded a month ago after you have changed this header file and picked different features.
So, I'm trying to make it so I can pick features within the INO itself and making as simple as possible for the user and at the same time, saving the file would also keep track of which features that code was using.

Here is what my test stuff looks like:
INO file:
Code: [Select]

#define TESTING
#include <TestClass.h>
#include <ParentTestClass.h>

void setup()
{
  Serial.begin(57600);
  //p.DoSomething();
  p.t.TestFunction();
}


void loop()
{
}

In the code above, it works if I call p.t.TestFunction(), but not if I use p.DoSomething().
Even though the DoSomething() function calls the same t.TestFunction()
Here are the supporting libraries:
TestClass.h
Code: [Select]

#ifndef _TESTCLASS_H
#define _TESTCLASS_H

#include <Arduino.h>

class TestClass {
public:
    TestClass();
    byte TestFunction() {
#ifdef TESTING
    Serial.println("Test");
#endif
    };
};


#endif


TestClass.cpp
Code: [Select]

#include "TestClass.h"

TestClass::TestClass()
{
}



ParentTestClass.h
Code: [Select]

#ifndef _PARENTTESTCLASS_H
#define _PARENTTESTCLASS_H

#include <Arduino.h>
#include "TestClass.h"

class ParentTestClass {
public:
TestClass t;
ParentTestClass();
void DoSomething();
};

extern ParentTestClass p;
#endif


ParentTestClass.cpp
Code: [Select]

#include "ParentTestClass.h"

ParentTestClass::ParentTestClass()
{
}

void ParentTestClass::DoSomething()
{
t.TestFunction();
}
ParentTestClass p = ParentTestClass() ;



WizenedEE

What about looking into const global variables? They'll get optimized away no problem, and you'll be able to see them from every file in your project.

newhobby

I think need defs.
I have stuff like this:
Code: [Select]

#if defined FEATURE1
#include <Feature1.h>
#endif  // defined FEATURE1


And this:
Code: [Select]

#ifdef FEATURE1
const prog_char feature1menu_5_label[] PROGMEM = "Feature 1";
#endif  // FEATURE1


And this:
Code: [Select]

#ifdef FEATURE1
case Feature1Menu_Option1:
{
SetupFeature1();
break;
}
#endif  // FEATURE1


So, by just not using one single #define, I can strip a lot of code that won't be used and reduce the code size.
Is there a way to do that with Const too? Could Const be declared inside the INO file and be seem by all libraries?

Go Up