Sorry guys, this was left out due to my haste and was added here later...
Hello everyone!
The procedural spaghetti code's complexity has reached my threshold. With little time and even less experience, I "moved the critical parts onto the OOP plate."
With the brilliant manageability of OOP came the issue of communication between the "OOP plates," i.e., the instances of individual (custom and 3rd-party) classes.
Unfortunately, even after a week of gathering information (forums, tutorials), I couldn't solve the problem...
The project:
A serial display is divided into 7 parts, of which 6 are equal. I made 2 classes to write the values on the display. The display has a factory library (class with public methods), at start must make 1 object.
There are buttons on the display, which are also treated by the display class (other) method.
I made two classes (in stand-alone .cpp/.h files), and I would like to use the (factory) methods of display.
Naturally (due to different translation units), my own class instances cannot see the methods of a class instantiated in another file.
I tried to use a namespace, but every attempt ends with the namespace created in one file not being visible in other files.
allDisplays.h
// display factory class
#include <genieArduino.h>
Genie uLCD90DCT;
// my classes
#include "InvDisplay.h"
InvDisplay* invDisplays = new InvDisplay[6];
#include "smallDisplay.h"
smallDisplay display;
allDisplays.ino
#include "allDisplays.h"
void setup() {
Serial1.begin(9600);
uLCD90DCT.Begin(Serial1);
uLCD90DCT.AttachEventHandler(displayEventHandler); // Attach the user function Event Handler for processing events
.
.
}
void displayEventHandler() {
genieFrame Event;
uLCD90DCT.DequeueEvent(&Event);
.
.
}
void loop() {
uLCD90DCT.DoEvents(); // This calls the library each loop to process the queued responses from the display
}
my classes
smallDisplay.h
#ifndef smallDisplay_h
#define smallDisplay_h
#include <Arduino.h>
#include <String.h>
class smallDisplay {
public:
smallDisplay();
.
.
private:
void _setGENIE_OBJ_LED_DIGITS(uint8_t _LeddigitsID, uint16_t value);
.
};
#endif
smallDisplay.cpp
#include "smallDisplay.h"
smallDisplay::smallDisplay() {
}
.
.
void smallDisplay::_setGENIE_OBJ_LED_DIGITS(uint8_t _LeddigitsID, uint16_t value) {
uLCD90DCT.WriteObject(GENIE_OBJ_LED_DIGITS, _LeddigitsID, value);
} // without any namespace, (of course) this error message: Compilation error: 'uLCD90DCT' was not declared in this scope
The other class works almost the same way (but with 6 instances). For the sake of clarity, I didn't copy the entire code; I omitted the non-relevant parts.
I tried to use a namespace,
// in allDisplays.h
.
namespace nsGenie{
Genie uLCD90DCT;
}
.
// smallDisplay.cpp
.
void smallDisplay::_setGENIE_OBJ_LED_DIGITS(uint8_t _LeddigitsID, uint16_t value) {
nsGenie::uLCD90DCT.WriteObject(GENIE_OBJ_LED_DIGITS, _LeddigitsID, value);
}
.
but the error message is always this: Compilation error: 'uLCD90DCT' was not declared in this scope