Καλησπέρα,
Θέλω να μεταφέρω κάποιες functions σε ένα ξεχωριστό cpp file και κάποια declarations σε ένα ξεχωριστό h file, ώστε να μπορώ να τα χρησιμοποιώ σε διαφορετικά pde files (arduino source)...
AGGen.h file:
#ifndef AGGen_h
#define AGGen_h
#include "WProgram.h"
#define AG_CONFIG_ID "a@g" // ID of the settings block
#define AG_CONFIG_Ver 1 // 0..255 with the version of the config structure
#define AG_CONFIG_START 0 // Tell it where to store your config data in EEPROM
struct AG_ConfigStruct { // AG settings structure
char id[4]; // This is for mere detection if they are your settings
byte ver;
char len;
} AG_Config = {AG_CONFIG_ID, AG_CONFIG_Ver,32};
#endif
AGGen.cpp file:
#include "WProgram.h"
#include <AGGen.h>
#include <EEPROM.h>
bool AG_LoadConfig_from_EEPROM() {
// To make sure there are settings, and they are YOURS!
// If nothing is found it will use the default settings.
if (EEPROM.read(AG_CONFIG_START + 0) == AG_CONFIG_ID[0] &&
EEPROM.read(AG_CONFIG_START + 1) == AG_CONFIG_ID[1] &&
EEPROM.read(AG_CONFIG_START + 2) == AG_CONFIG_ID[2]) {
for (unsigned int t=0; t<sizeof(AG_Config); t++)
*((char*)&AG_Config + t) = EEPROM.read(AG_CONFIG_START + t);
Serial.println("loadConfig.....");
Serial.print("storage.len: ");
Serial.print(AG_Config.len, DEC);
Serial.println("----------");
return true;
}
return false;
}
void AG_LoadConfig() {
// To make sure there are settings, and they are YOURS!
// If nothing is found it will use the default settings.
if (not AG_LoadConfig_from_EEPROM()){
AG_SaveConfig();
AG_LoadConfig_from_EEPROM();
}
}
Στο pde file:
#include <AGGen.h>
...
void setup () {
Serial.begin(57600);
...
AG_LoadConfig();
}
Όταν προσπαθώ να κάνω compile, μου βγάζει μήνυμα:
JeeTest_EEPROM.cpp: In function 'void setup()':
JeeTest_EEPROM:189: error: 'AG_LoadConfig' was not declared in this scope
Εάν προσθέσω το declaration στο AGGen.h:
#ifndef AGGen_h
#define AGGen_h
#include "WProgram.h"
#define AG_CONFIG_ID "a@g" // ID of the settings block
#define AG_CONFIG_Ver 1 // 0..255 with the version of the config structure
#define AG_CONFIG_START 0 // Tell it where to store your config data in EEPROM
struct AG_ConfigStruct { // AG settings structure
char id[4]; // This is for mere detection if they are your settings
byte ver;
char len;
} AG_Config = {AG_CONFIG_ID, AG_CONFIG_Ver,32};
void AG_LoadConfig();
#endif
ο compiler μου βγάζει:
AGLib\AGGen.cpp.o:(.data.AG_Config+0x0): multiple definition of `AG_Config'
JeeTest_EEPROM.cpp.o:(.data.AG_Config+0x0): first defined here
Μπορεί κάποιος να μου πει πως το κάνω αυτό? Δηλαδή πως μπορώ να μεταφέρω κάποιο κώδικα σε ένα cpp/h files...? και να το χρησιμοποιώ σε διαφορετικά pde files?
Τι κάνω λάθος στο παραπάνω κώδικα?
Θέλω να μεταφέρω κάποιες functions σε ένα ξεχωριστό cpp file και κάποια declarations σε ένα ξεχωριστό h file, ώστε να μπορώ να τα χρησιμοποιώ σε διαφορετικά pde files (arduino source)...
AGGen.h file:
#ifndef AGGen_h
#define AGGen_h
#include "WProgram.h"
#define AG_CONFIG_ID "a@g" // ID of the settings block
#define AG_CONFIG_Ver 1 // 0..255 with the version of the config structure
#define AG_CONFIG_START 0 // Tell it where to store your config data in EEPROM
struct AG_ConfigStruct { // AG settings structure
char id[4]; // This is for mere detection if they are your settings
byte ver;
char len;
} AG_Config = {AG_CONFIG_ID, AG_CONFIG_Ver,32};
#endif
AGGen.cpp file:
#include "WProgram.h"
#include <AGGen.h>
#include <EEPROM.h>
bool AG_LoadConfig_from_EEPROM() {
// To make sure there are settings, and they are YOURS!
// If nothing is found it will use the default settings.
if (EEPROM.read(AG_CONFIG_START + 0) == AG_CONFIG_ID[0] &&
EEPROM.read(AG_CONFIG_START + 1) == AG_CONFIG_ID[1] &&
EEPROM.read(AG_CONFIG_START + 2) == AG_CONFIG_ID[2]) {
for (unsigned int t=0; t<sizeof(AG_Config); t++)
*((char*)&AG_Config + t) = EEPROM.read(AG_CONFIG_START + t);
Serial.println("loadConfig.....");
Serial.print("storage.len: ");
Serial.print(AG_Config.len, DEC);
Serial.println("----------");
return true;
}
return false;
}
void AG_LoadConfig() {
// To make sure there are settings, and they are YOURS!
// If nothing is found it will use the default settings.
if (not AG_LoadConfig_from_EEPROM()){
AG_SaveConfig();
AG_LoadConfig_from_EEPROM();
}
}
Στο pde file:
#include <AGGen.h>
...
void setup () {
Serial.begin(57600);
...
AG_LoadConfig();
}
Όταν προσπαθώ να κάνω compile, μου βγάζει μήνυμα:
JeeTest_EEPROM.cpp: In function 'void setup()':
JeeTest_EEPROM:189: error: 'AG_LoadConfig' was not declared in this scope
Εάν προσθέσω το declaration στο AGGen.h:
#ifndef AGGen_h
#define AGGen_h
#include "WProgram.h"
#define AG_CONFIG_ID "a@g" // ID of the settings block
#define AG_CONFIG_Ver 1 // 0..255 with the version of the config structure
#define AG_CONFIG_START 0 // Tell it where to store your config data in EEPROM
struct AG_ConfigStruct { // AG settings structure
char id[4]; // This is for mere detection if they are your settings
byte ver;
char len;
} AG_Config = {AG_CONFIG_ID, AG_CONFIG_Ver,32};
void AG_LoadConfig();
#endif
ο compiler μου βγάζει:
AGLib\AGGen.cpp.o:(.data.AG_Config+0x0): multiple definition of `AG_Config'
JeeTest_EEPROM.cpp.o:(.data.AG_Config+0x0): first defined here
Μπορεί κάποιος να μου πει πως το κάνω αυτό? Δηλαδή πως μπορώ να μεταφέρω κάποιο κώδικα σε ένα cpp/h files...? και να το χρησιμοποιώ σε διαφορετικά pde files?
Τι κάνω λάθος στο παραπάνω κώδικα?