Tried that way too. Still the same.
Compilation fails with this result:
In file included from /var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/DBabstraction.h:5:0,
from /var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/Runner.h:5,
from /Users/Thibault/Desktop/CPPtest_v2/CPPTEST_v3/CPPTEST_v3.ino:2:
/Users/Thibault/Documents/Arduino/libraries/EDB/EDB.h:24:25: warning: 'typedef' was ignored in this declaration [enabled by default]
};
In file included from /var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/DBabstraction.h:5:0,
from /var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/DBabstraction.cpp:1:
/Users/Thibault/Documents/Arduino/libraries/EDB/EDB.h:24:25: warning: 'typedef' was ignored in this declaration [enabled by default]
};
^
In file included from /var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/DBabstraction.h:5:0,
from /var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/Runner.h:5,
from /var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/Runner.cpp:1:
/Users/Thibault/Documents/Arduino/libraries/EDB/EDB.h:24:25: warning: 'typedef' was ignored in this declaration [enabled by default]
};
^
and
/var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/DBabstraction.cpp.o: In function `DBabstraction::DBabstraction(HardwareSerial*)':
/var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/DBabstraction.cpp:27: multiple definition of `rec_struct'
/var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/CPPTEST_v3.ino.cpp.o:/Users/Thibault/Desktop/CPPtest_v2/CPPTEST_v3/CPPTEST_v3.ino:29: first defined here
/var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/Runner.cpp.o: In function `Runner::begin()':
/var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/Runner.cpp:9: multiple definition of `rec_struct'
/var/folders/y8/2cf22w216j7cxt1k7g54v1y80000gp/T/arduino_build_82174/sketch/CPPTEST_v3.ino.cpp.o:/Users/Thibault/Desktop/CPPtest_v2/CPPTEST_v3/CPPTEST_v3.ino:29: first defined here
INO:
#include "Arduino.h"
#include "Runner.h"
#include "DBabstraction.h"
//#include <EDB.h>
//#include "LSD.h"
//#include "LStorage.h"
//#include "LFlash.h"
//#include "DBrecord.h"
//#include "DBrecord.h"
// Define variables and constants
#define UsbSerial Serial // rename Serial ports
// Variables
EDB * myDB;
DBabstraction * myAbstraction = myAbstraction->getInstance(&UsbSerial);
Runner myRunner(&UsbSerial, myDB, myAbstraction);
// Add setup code
void setup() {
UsbSerial.begin(115200);
UsbSerial.printf("starting");
myRunner.begin();
}
// Main loo^
void loop() {
delay(500);
myRunner.run();
}
Runner.h:
#ifndef Runner_h
#define Runner_h
#include "Arduino.h"
#include "DBabstraction.h"
#include "HardwareSerial.h"
#include <EDB.h>
class Runner {
public:
Runner(HardwareSerial *serial, EDB *currDB, DBabstraction * DBabs);
static DBabstraction *globalDB;
HardwareSerial * _HardSerial;
void globalConfigWriter( unsigned long address, byte data ) {
globalDB->dbWriter(address, data);
}
byte globalConfigReader( unsigned long address ) {
return globalDB->dbReader(address);
}
void run();
void begin();
};
#endif // Runner_h
Runner.cpp:
#include "Runner.h"
// Code
/**************************************************/
DBabstraction *Runner::globalDB = NULL;
// public functions
Runner::Runner(HardwareSerial *serial, EDB *currDB, DBabstraction * DBabs) {
if (globalDB == NULL) globalDB = DBabs;
_HardSerial = serial;
if(_HardSerial) _HardSerial->printf("[Runner] constructor\n");
//if (globalDB == NULL) globalDB = globalDB->getInstance(_HardSerial);
if (globalDB) globalDB->begin(currDB);
}
void Runner::run() {
if(_HardSerial) _HardSerial->printf("[Runner] run()\n");
}
void Runner::begin() {
if(_HardSerial) _HardSerial->printf("[Runner] begin()\n");
}
DBabstraction.h:
#ifndef DBabstraction_h
#define DBabstraction_h
#include "Arduino.h"
#include <EDB.h>
#include "LSD.h"
#include "LStorage.h"
#include "LFlash.h"
//#include "DBrecord.h"
#include "HardwareSerial.h"
#define Drv LFlash // use Internal 10M Flash
#define TABLE_SIZE 8192 // arbitrary for now
#define FILE_PATH "db.txt"
#define RECORDS_TO_CREATE 10 // This should be less than (TABLE_SIZE - sizeof(EDB_Header)) / sizeof(LogEvent).
struct Record_Struct {
int id;
int temperature;
} rec_struct;
class DBabstraction {
public:
static DBabstraction * getInstance(HardwareSerial *serial);
EDB * myDB;
void begin(EDB *currDB);
static LFile * myFile;
static void dbWriter( unsigned long address, byte data );
static byte dbReader( unsigned long address );
static HardwareSerial * _HardSerial;
private:
static DBabstraction * pInstance; // pointer to the DBabstraction instance NEW:
DBabstraction(HardwareSerial *serial);
};
#endif // DBabstraction_h
DBabstraction.cpp:
#include "DBabstraction.h"
DBabstraction *DBabstraction::pInstance = NULL;
LFile *DBabstraction::myFile = NULL;
HardwareSerial *DBabstraction::_HardSerial = NULL;
/* returns an instance of the object
* If no instance exists, it will create one
*/
DBabstraction * DBabstraction::getInstance(HardwareSerial *serial) {
if (pInstance == NULL) {
pInstance = new DBabstraction(serial);
}
return pInstance;
}
/* private constructor with HardwareSerial object pointer arg */
DBabstraction::DBabstraction(HardwareSerial *serial) {
_HardSerial = serial;
pInstance = this;
}
/* The raw writer function exposed to the EDB library */
void DBabstraction::dbWriter(unsigned long address, byte data ) {
/* nothing */
if(_HardSerial) _HardSerial->printf("[DBabstraction] dbWriter\n");
if (myFile) {
myFile->seek(address);
myFile->write(data);
myFile->flush();
}
}
/* The raw writer function exposed to the EDB library */
byte DBabstraction::dbReader( unsigned long address) {
/* nothing */
if(_HardSerial) _HardSerial->printf("[DBabstraction] dbReader\n");
if (myFile) {
myFile->seek(address);
return myFile->read();
}
}
/* The Arduino Begin() function of the class */
void DBabstraction::begin(EDB *currDB) {
myDB = currDB;
if(_HardSerial) _HardSerial->printf("[DBabstraction] Begin\n");
// start the flash drive
Drv.begin();
// try to open the DB file
*myFile = Drv.open(FILE_PATH, FILE_WRITE);
// if the file opened okay,
if (myFile) {
myFile->close();
} else {
// if the file didn't open, tell it
if(_HardSerial) _HardSerial->printf("[DBabstraction] error opening the db file\n");
}
// retry to open the file for reading:
*myFile = Drv.open(FILE_PATH, FILE_WRITE);
if (myFile) {
if(_HardSerial) _HardSerial->printf("Opening current table\n");
EDB_Status result = myDB->open(0);
if (result == EDB_OK) //
myFile->seek(0);
} else {
// if the file didn't open, print an error:
if(_HardSerial) _HardSerial->printf("[DBabstraction] error opening the db file, aborted\n");
}
// create the EDB instance with the DBabstraction reader/writer
myDB = new EDB(DBabstraction::dbWriter, DBabstraction::dbReader);
}
// Code DBabstraction.cpp
Getting crazy... ![]()