Go Down

Topic: Use #define from .ino in library (Read 1 time) previous topic - next topic

MaxBec

Hey guys,

i have a question concerning using a #define made in the sketch file in my library.
I want the user of my lib be able to set a debug #define which decides if he wants debug output or not.
(eg. #define DEBUGGING true)

To achieve this i have the following code:

.ino file:
Code: [Select]
/// PRE DEFINES
/// ============================================================================
///
#define INOMATION_AUTH_KEY "bWF4OjhBdHJKRk5hbXBMYzhpOEpURQ=="
#define INOMATION_DEBUGGING true

/// Webduino Settings. Decomment to activate
#define WEBDUINO_SERIAL_DEBUGGING 2
// #define WEBDUINO_READ_TIMEOUT_IN_MS 1000
// #define WEBDUINO_COMMANDS_COUNT 8
// #define WEBDUINO_URL_PATH_COMMAND_LENGTH 8
// #define WEBDUINO_FAIL_MESSAGE "<h1>EPIC FAIL</h1>"
// #define WEBDUINO_AUTH_REALM "Webduino"
// #define WEBDUINO_AUTH_MESSAGE "<h1>401 Unauthorized</h1>"
// #define WEBDUINO_SERVER_ERROR_MESSAGE "<h1>500 Internal Server Error</h1>"
// #define WEBDUINO_OUTPUT_BUFFER_SIZE 32
// #define WEBDUINO_FAVICON_DATA { 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x10, \
//                                 0x10, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, \
//                                 0xb0, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, \
//                                 0x00, 0x28, 0x00, 0x00, 0x00, 0x10, 0x00, \
//                                 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, \
//                                 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, \
//                                 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, \
//                                 0x00, 0xff, 0xff, 0x00, 0x00, 0xcf, 0xbf, \
//                                 0x00, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0xc3, \
//                                 0xbf, 0x00, 0x00, 0xc1, 0xbf, 0x00, 0x00, \
//                                 0xc0, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0xc0, 0xbf, 0x00, 0x00, 0xc1, 0xbf, \
//                                 0x00, 0x00, 0xc3, 0xbf, 0x00, 0x00, 0xc7, \
//                                 0xbf, 0x00, 0x00, 0xcf, 0xbf, 0x00, 0x00, \
//                                 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
//                                 0x00, 0x00 }


/// INCLUDES
/// ============================================================================
///
/// Standrad Arduino Libraries
#include <VirtualWire.h>
#include <Ethernet.h>
#include <SPI.h>
#include <RCSwitch.h>
#include <WebServer.h>

/// Non-Standard Arduino Libraries. If you dont have them, download them.
#include "Inomation.h"


.h lib file:
Code: [Select]
/// Check if the Inomation Library is already included
#ifndef INOMATION_H_
#define INOMATION_H_
/// Needed for non -multiple integration of webduino implementation
#define WEBDUINO_NO_IMPLEMENTATION


///
/// INCLUDES and STRUCTS
/// ============================================================================
///
/// Include the main Arduino library.
#include "Arduino.h"

/// Including standard Arduino libraries needed in the project.
#include "SPI.h"
#include "VirtualWire.h"
#include "Ethernet.h"
#include "RCSwitch.h"
#include "WebServer.h"


/// DEFINITIONS
/// ============================================================================
///
#ifndef INOMATION_DEBUGGING
#define INOMATION_DEBUGGING false
#endif


The thing is, it isnt working. The output option always is set to false... so he does not overtake the true from the ino file.

Thanks for your help.

PaulS

Quote
so he does not overtake the true from the ino file.

Correct. The #define in the sketch has nothing to do with the name in the library.

There have been many attempts to do what you want to do with #defines. None of them have worked.
The art of getting good answers lies in asking good questions.

MaxBec

Ok. I already thought that there may be no solution for that. That was my last try :D

But maybe you guys have another neat solution for passing library settings to a library by the user ;)

Hackscribble

How about adding a second constructor with an additional boolean argument.  User sets it to true if they want debug on.

Or add a setDebug method to the class.
Hackscribble.  Writing about making things
hackscribble@outlook.com

MaxBec

I will have a lot of settings. That would be a big and ugly constructor :D

Hackscribble

Ah, ok, so it is not just debug on or off?
Hackscribble.  Writing about making things
hackscribble@outlook.com

MaxBec

Nope.
Mac-Address, IP, Debug, txPin, rxPin, etc. :D

PaulS


Nope.
Mac-Address, IP, Debug, txPin, rxPin, etc. :D


It sounds like you need a different approach. Using #defines for all that is not the correct approach.

Have methods in your class that can be called to set that stuff.
The art of getting good answers lies in asking good questions.

Go Up