Pages: [1]   Go Down
Author Topic: [SOLVED] Referencing define in another file  (Read 443 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 145
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got a project that I would like to publish on google code. The problem is that the code contains a api key which obviously I dont want to publish. I could remove it from the local source code but then everytime I rest the code I would need to put the key back in.

Currently the key is defined at the top of my program as
Code:
#define apikey "my key here"

What I would like to do just include the key in a separate file and then not sync that to google code. I've tried adding in a new file called key.ino but I think at compile time the key then gets added to the bottom of the main program so that it fails to compile.

I can't use it in a #include as its only a define.

Any suggestions, or is there a simple solution I'm over looking?

« Last Edit: July 30, 2013, 12:25:36 pm by GregM » Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1478
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"I can't use it in a #include as its only a define."

In traditional C, that is exactly where #defines are supposed to go!

If you are worried about name space collision you can make them "idimpotent":

# ifndefined(API_KEY_FILE)
#define API_KEY_FILE
#define my_api_key
#endif
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26626
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Better still, make them "idempotent"
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Full Member
***
Karma: 0
Posts: 145
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"I can't use it in a #include as its only a define."

In traditional C, that is exactly where #defines are supposed to go!

If you are worried about name space collision you can make them "idimpotent":

# ifndefined(API_KEY_FILE)
#define API_KEY_FILE
#define my_api_key
#endif


I'm afraid you've completely lost me. smiley-sad

Should I create a file, say "api_key_file" and it in put the apikey. Then use the above code in my main program?
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1478
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You create a .h file with the commands I used and then #include it.
Logged

Atlanta, USA
Offline Offline
Edison Member
*
Karma: 56
Posts: 1848
AKA: Ray Burne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Edit to Bold, Italicize, and Underline stuff!

Quote
What I would like to do just include the key in a separate file and then not sync that to google code. I've tried adding in a new file called key.ino

Use the Arduino GUI to create a new tab called key.h, put your defines there.  In your main module,
Code:
#include "Defines.h"

"Defines.h" for different LCD pinouts that looks like:

Code:
// defines associated specifically with Nokia 5110 LCD ScrnFuncts
#define PIN_SCE   7
#define PIN_RESET 6
#define PIN_DC    5
#define PIN_SDIN  4
#define PIN_SCLK  3

#define LCD_C     LOW
#define LCD_D     HIGH
#define LCD_X     84
#define LCD_Y     48
« Last Edit: July 30, 2013, 10:58:47 am by mrburnette » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or even better
Code:
#include "key.h"
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

0
Offline Offline
Full Member
***
Karma: 0
Posts: 145
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys - working perfectly now.
Logged

Pages: [1]   Go Up
Jump to: