Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support to enabled/disable each sensor input #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/CAP1293.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,4 +979,32 @@ void CAP1293::writeRegisters(CAP1293_Register reg, byte *buffer, byte len)
for (int i = 0; i < len; i++)
_i2cPort->write(buffer[i]);
_i2cPort->endTransmission(); // Stop transmitting
}
}

// === Begin by Andri ===
void CAP1293::setSensorInputEnabled(uint8_t inputNo, bool enabled) {
SENSOR_INPUT_ENABLE_REG reg;
reg.SENSOR_INPUT_ENABLE_COMBINED = readRegister(SENSOR_INPUT_ENABLE);
if (inputNo == 0) {
reg.SENSOR_INPUT_ENABLE_FIELDS.CS1_EN = enabled? 0x01: 0x00;
}
else if (inputNo == 1) {
reg.SENSOR_INPUT_ENABLE_FIELDS.CS2_EN = enabled? 0x01: 0x00;
}
else if (inputNo == 2) {
reg.SENSOR_INPUT_ENABLE_FIELDS.CS3_EN = enabled? 0x01: 0x00;
}
writeRegister(SENSOR_INPUT_ENABLE, reg.SENSOR_INPUT_ENABLE_COMBINED);
}

void CAP1293::setSensorInputsEnabled(const bool inputEnables[], uint8_t num) {
SENSOR_INPUT_ENABLE_REG reg;
reg.SENSOR_INPUT_ENABLE_COMBINED = readRegister(SENSOR_INPUT_ENABLE);
if (num == 3) {
reg.SENSOR_INPUT_ENABLE_FIELDS.CS1_EN = inputEnables[0]? 0x01: 0x00;
reg.SENSOR_INPUT_ENABLE_FIELDS.CS2_EN = inputEnables[1]? 0x01: 0x00;
reg.SENSOR_INPUT_ENABLE_FIELDS.CS3_EN = inputEnables[2]? 0x01: 0x00;
}
writeRegister(SENSOR_INPUT_ENABLE, reg.SENSOR_INPUT_ENABLE_COMBINED);
}
// === End by Andri ===
31 changes: 31 additions & 0 deletions src/CAP1293.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ typedef union
uint8_t MULTIPLE_TOUCH_PATTERN_COMBINED;
} MULTIPLE_TOUCH_PATTERN_REG;


// === Begin by Andri ===
// Sensor Monitor Enable Register 0x27
typedef union
{
struct
{
uint8_t CS1_EN : 1;
uint8_t CS2_EN : 1;
uint8_t CS3_EN : 1;
uint8_t EMPTY_1 : 5;
} SENSOR_INPUT_ENABLE_FIELDS;
uint8_t SENSOR_INPUT_ENABLE_COMBINED;
} SENSOR_INPUT_ENABLE_REG;
// === End by Andri ===

////////////////////////////////
// CAP1293 Class Declaration //
////////////////////////////////
Expand Down Expand Up @@ -291,6 +307,21 @@ class CAP1293
void setReleaseInterruptEnabled();
bool isReleaseInterruptEnabled();

// === Begin by Andri ===
/**
* Set sensor input monitoring enablement
* @param inputNo - Sensor input number, starts from 0
* @param enabled - true means enabled
*/
void setSensorInputEnabled(uint8_t inputNo, bool enabled);
/**
* Set sensor input monitoring enablement in one go
* @param inputEnables - Sensor input states
* @param num - Should be 3
*/
void setSensorInputsEnabled(const bool inputEnables[], uint8_t num = 3);
// === End by Andri ===

private:
TwoWire *_i2cPort = NULL; //The generic connection to user's chosen I2C hardware
uint8_t _deviceAddress; //Keeps track of I2C address. setI2CAddress changes this.
Expand Down