bool lineInLevel(uint8_t n) { return lineInLevel(n, n); }
bool lineInLevel(uint8_t left, uint8_t right) {return lineInLevel(left, right, 0);}
bool lineInLevel(uint8_t left, uint8_t right, uint8_t att);
bool AudioControlSGTL5000::lineInLevel(uint8_t left, uint8_t right, uint8_t att)
{
if (left > 15) left = 15;
if (right > 15) right = 15;
return write(CHIP_ANA_ADC_CTRL, (left << 4) | right | (att & 1) <<8);
}
sgtl5000.lineInLevel(level);
sgtl5000.lineInLevel(left,right);
sgtl5000.lineInLevel(left,right,att);
modify "control_sgtl5000.h"
#include "control_sgtl5000.h"
class mSGTL5000: public AudioControlSGTL5000
{
public:
bool lineInLevel(uint8_t left, uint8_t right, uint8_t att)
{
if (reg == CHIP_ANA_CTRL) ana_ctrl = val;
Wire.beginTransmission(i2c_addr);
Wire.write(reg >> 8);
Wire.write(reg);
Wire.write(val >> 8);
Wire.write(val);
if (Wire.endTransmission() == 0) return true;
return false;
}
};
[B]#include "control_sgtl5000.cpp"[/B]
class Bat_SGTL5000: public AudioControlSGTL5000
{ uint16_t reg=CHIP_ANA_ADC_CTRL;
public:
void attGAIN(uint8_t att)
{ uint16_t input_gain=AudioControlSGTL5000::read(reg);
write(reg, (input_gain << 4) | input_gain | (att & 1) <<8);
}
};
And using only the include the compiler (platformio ) was complaining about CHIP_ANA_ADC_CTRL as that is decllared in the .cpp
#include "control_sgtl5000.h"
#define CHIP_ANA_ADC_CTRL 0x0020
class mSGTL5000: public AudioControlSGTL5000
{
public:
bool AudioControlSGTL5000::lineInLevel(uint8_t left, uint8_t right, uint8_t att)
{
if (left > 15) left = 15;
if (right > 15) right = 15;
return write(CHIP_ANA_ADC_CTRL, (left << 4) | right | (att & 1) <<8);
}
};
That should also work, in my case I opted to read the current gain settings and simply switch the bit on/off.
EDIT: Tested and that works fine.
void attGAIN(uint8_t att)
{ uint16_t input_gain=AudioControlSGTL5000::read(reg);
write(reg, (input_gain << 4) | input_gain | (att & 1) <<8);
}
void attGAIN(uint8_t att) { modify(reg, (att & 1) <<8, 1<<8); }