If this is too off-topic and someone can point to a resource elsewhere I will be grateful. I have googled and tried a number of approaches so far to no success. I am needing to call one constructor from another. Here's what I am trying to do. I have an I2C register class (PCA9557) since on our board there are multiple of these. Each one generates a complex bit stream to talk to an off-board chain of shift registers which are part of legacy hardware we are controlling. So the PCA9557 class gets instantiated passing it the I2C base address. That all works fine and an example program (all in the Github repo) works well.
Now I also want to have a higher layer library of functions and data which generates a complex 32-bit stream to be sent to one of these coreJ2, coreJ3, coreJ4. Each instance of that higher level library is associated with one of the PCA9557 registers.
So the higher library has a constructor, I can also pass it the PCA9557 base address which it could pass on and create the appropriate instance of the PCA9557. But every way I try to do that fails. Due to my ignorance of how C++ does this (I've most recently been a Java guy) these probably look laughable. The higher library class def looks like this
This must be a common question but googling has not led me to the answer. Thanks in advance for any help!
BTW if anyone out there is a C++ guru and can spare a few hours of consulting time I am more than happy to pay you for some oversight and assistance either PayPal $$ or I have too many Raspi and Beaglebone Black, and could send you some hardware.
Code:
/**
* These are the addresses of the I2C devices which drive the related Core DB15 connector
*/
#define I2C_J2 0x1B
#define I2C_J3 0x1A
#define I2C_J4 0x19
// and later in the example .ino file, outside of the scope of setup() and loop(), where other data is declared, I declare these class instances:
Systronix_PCA9557 coreJ2(I2C_J2);
Systronix_PCA9557 coreJ3(I2C_J3);
Systronix_PCA9557 coreJ4(I2C_J4);
// now I have coreJ2, coreJ3, coreJ4 which can drive their own appropriate PCA9557
Now I also want to have a higher layer library of functions and data which generates a complex 32-bit stream to be sent to one of these coreJ2, coreJ3, coreJ4. Each instance of that higher level library is associated with one of the PCA9557 registers.
So the higher library has a constructor, I can also pass it the PCA9557 base address which it could pass on and create the appropriate instance of the PCA9557. But every way I try to do that fails. Due to my ignorance of how C++ does this (I've most recently been a Java guy) these probably look laughable. The higher library class def looks like this
Code:
class SALT_JX
{
protected:
uint32_t _DC_data_in; // data the update() is reading from the DC board '165 shift register
//Systronix_PCA9557 coreJXreg; // the instance of PCA_9557 which is tied to this SALT_JX instance, this is not right, I need to pass base address
Systronix_PCA9557 coreJXreg(uint8_t); // nope this doesn't work either
public:
SALT_JX (uint8_t); // constructor, I2C base address
void begin (void);
void init (void);
void update(void); // this is the function which will send a long bitstream eventually out the pins on the PCA9557 to downstream shift registers
// more class def
This must be a common question but googling has not led me to the answer. Thanks in advance for any help!
BTW if anyone out there is a C++ guru and can spare a few hours of consulting time I am more than happy to pay you for some oversight and assistance either PayPal $$ or I have too many Raspi and Beaglebone Black, and could send you some hardware.
Last edited: