Loading...
  Show Posts
Pages: 1 [2] 3 4 ... 7
16  Using Arduino / Programming Questions / Re: library definition on: January 13, 2012, 04:15:49 pm
The first option is exactly what we are doing, except the libraries don't need to be moved around. Just the features.h file that needs to be updated.
The second option will not work for someone that has not knowledge of computers nor programming.
My target user is the one that has no knowledge of programming and thus the simple INO code.
Editing a features.h file works, but it gets very confusing and hard to troubleshoot problems, because you never know what the user has inside the features.h file.
17  Using Arduino / Programming Questions / Re: library definition on: January 13, 2012, 03:42:18 pm
Sorry, I didn't re-read you original question before posting my last comment.

What you have is a bounch of libraries and a sketch that can produce different programs based on which features the user enabled. If you want the compiled code to report its particular set of feature to the user once the build configuration is gone, you should find a way to compile in some sort of value that uniquely identifies each feature. (Cfr. e.g. squid or samba, whose binaries can print the list of the features the user selected at compile-time via the configure script.)
Off of top of my head, you could have a "features" unsigned int whose bits represent a particular feature. 1 = feature is present 0 = not compiled in.
You'd have a dump_features() function that would simply Serial.println(features, HEX) or, if you don't mind wasting some space, could print out the feature name for each '1' bit.
I agree that this solution would work for the code currently loaded on the board, but it would still not be enough.
What if I need to know which features I had enabled a month ago after uploading several codes.
Also, if one user wants to share the code with another user, simply giving out the INO file would not be sufficient.
And this is the biggest problem of them all.
If you simply post the INO file, the ending result is totally different from one user to another because what one user has inside the features.h file is different than the other one might have.
To be really honest, the INO file has nothing more than a couple of lines in it.
something like this:
Code:

<include TestClass1.h>
<include TestClass2.h>
<include TestClass3.h>
<include TestClass4.h>
<include TestClass5.h>
<include ParentTestClass.h>
<include features.h>

void setup()
{
  ParentTest.init();
}

void loop()
{
  ParentTest.DisplayScreen();
}

All the features are chosen from within the features.h
The best scenario would be to include the defines inside the INO file, which doesn't seem to be possible or in a file inside the same folder as the ino file, which would not really solve the problem 100%, but it would at least create history of codes if you saved the INO files with different names.

18  Using Arduino / Programming Questions / Re: library definition on: January 13, 2012, 03:10:26 pm
Yeah, I realized that after I posted. I use those to burn bootloaders.
But, how would I get to do that within the IDE?
19  Using Arduino / Programming Questions / Re: library definition on: January 13, 2012, 11:43:08 am
Can you please lead me to the right direction on how to do that?
20  Using Arduino / Programming Questions / Re: library definition on: January 13, 2012, 11:09:20 am
You are in Dependency Hell (tm) ;-)

What about a features.h that gest included both by the .ino file and by all library header files ?

That's what I have been doing so far, and the whole purpose of this thread. I wanted to get rid of it.
The reason why is that to enable/disable features, the user has to actually edit a file features.h that has to be located on "Documents\Arduino\libraries\features", correct?
I would think any other place would make it invisible to all other libraries.
If so, let's suppose you enabled one feature today and uploaded. Then, you changed you mind and decided to go and use 3 other features and uploaded.
The INO code is the same for both and the only thing that was changed was 2 more defines on the features.h file.
A month from now, how would you know which features were compiled on the first code?
I wanted to place the defines inside INO to carry the history of features and make both INO codes different from one another.
Would you be able to explain a little better what the -D flag does and how to get it incorporated on the IDE, if you could?
21  Using Arduino / Programming Questions / Re: library definition on: January 12, 2012, 09:56:58 pm
I think need defs.
I have stuff like this:
Code:
#if defined FEATURE1
#include <Feature1.h>
#endif  // defined FEATURE1

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

And this:
Code:
#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?
22  Using Arduino / Programming Questions / Re: library definition on: January 12, 2012, 09:35:20 pm
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:
#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:
#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:
#include "TestClass.h"

TestClass::TestClass()
{
}


ParentTestClass.h
Code:
#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:
#include "ParentTestClass.h"

ParentTestClass::ParentTestClass()
{
}

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

23  Using Arduino / Programming Questions / Re: library definition on: January 12, 2012, 10:38:53 am
I think it worked!!!!
You are a genius!!!
Definitely owe you a beer smiley
I'll make some more tests later, gotta go to a meeting atm.
Thank you so much!!!

RI
24  Using Arduino / Programming Questions / Re: library definition on: January 11, 2012, 01:25:11 pm
I tried your code, but it didn't print "Test".
25  Using Arduino / Programming Questions / Re: library definition on: January 11, 2012, 12:16:30 pm
In this example, all I wanted to do was to print "Test" if TESTING was defined on either the PDE or in a header file in the same folder as the PDE file:
Code:
#ifdef TESTING
Serial.println("Test");
#endif

I tried what you recommended and my code turned out to be:
Code:
byte r;
#define TESTING
#include "TestClass.h"

TestClass  t;

void setup()
{
  Serial.begin(57600);
  Serial.println("Start");
  t.TestFunction();
  Serial.println("End");
}

void loop()
{
}

But it still does not run what's indide the ifdef smiley-sad
26  Using Arduino / Programming Questions / Re: library definition on: January 11, 2012, 10:53:17 am
Doesn't work.
Here is what I have.
Well, it's pde cause I'm still using 0022
TestClass.pde:
Code:

#define TESTING
#include "TestClass.h"

TestClass  t;

void setup()
{
  Serial.begin(57600);
  Serial.println("Start");
  t.TestFunction();
  Serial.println("End");
}

void loop()
{
}


TestClass.h
Code:
#ifndef __TESTCLASS_H__
#define __TESTCLASS_H__

#include <TestClass.h>

class TestClass
{
public:
TestClass();
void TestFunction();
};

#endif  // __TESTCLASS_H__

TestClass.cpp
Code:
#include "TestClass.h"

TestClass::TestClass()
{
}

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

When I comment or uncomment the define on the PDE file, I get no change on the compiled code.
I tried adding new file on the same folder as the PDE called TestH.h:
Code:
#define TESTING

It still does not do anything.

Any other ideas?
27  Using Arduino / Programming Questions / library definition on: January 11, 2012, 01:03:48 am
Hi,

If I have something like this on my custom library:
Code:
void TestClass::TestFunction()
{
// Doing Something
#ifdef TESTING
// Do something else
#endif
// Continue doing something
}
Which are the places I could define TESTING, besides TestClass.h or TestClass.cpp?
Could I use a separate .h file on the same folder as INO file?
Could I define somehow inside the INO file?

Thank you,
RI
28  Using Arduino / Programming Questions / Re: PROGMEM and Serial on: January 08, 2012, 11:47:45 am
Code:
#define MyTestVar F("Test")

void setup()
{
  Serial.begin(57600);
  Serial.print(MyTestVar);

}

void loop()
{
}
Binary sketch size: 1914 bytes (of a 32256 byte maximum)

Code:
const prog_char MyTestVar[] PROGMEM = "Test";

void setup()
{
  Serial.begin(57600);
  PROGMEMprint(MyTestVar);
}

void loop()
{
}

void PROGMEMprint(const prog_char str[])
{
    char c;
    if(!str) return;
    while((c = pgm_read_byte(str++)))
        Serial.write(c);
}
Binary sketch size: 1868 bytes (of a 32256 byte maximum)


Maybe I'm doing something wrong.
29  Using Arduino / Programming Questions / Re: PROGMEM and Serial on: January 08, 2012, 11:14:07 am
Well, I don't really understand much the difference of the two you mentioned, but actually the PROGMEM code is the one that was smaller not the F().
The end result is the same for both. I wanted to print from flash and they both do that, right?
So, you seem to understand it much more than me. Which is the best approach?
30  Using Arduino / Programming Questions / Re: PROGMEM and Serial on: January 08, 2012, 10:47:28 am
Flash is PROGMEM.

Well, I know that much smiley
 I've been using this for quite a while:
Code:
void PROGMEMprint(const prog_char str[])
{
    char c;
    if(!str) return;
    while((c = pgm_read_byte(str++)))
        Serial.write(c);
}

The reason I wanted to know about the F() printing PROGMEM arrays too is that my code has several PROGMEM variables defined on my custom library header file that I can use on any of my other library files.
So, my questions now is:
Instead of using this:
Code:
const prog_char MyTestVar[] PROGMEM = "Test";
PROGMEMprint(MyTestVar);
If I started using this:
Code:
#define MyTestVar F("Test")
Serial.print(MyTestVar);
Which one is the best alternative, keeping in mind that I have code size issues?
I did a simple run test and the PROGMEM route used less code size.
Pages: 1 [2] 3 4 ... 7