Format code with cpplint

Signed-off-by: Mickael Gaillard <mickael.gaillard@tactfactory.com>
This commit is contained in:
Mickael Gaillard 2020-04-18 20:45:31 +02:00 committed by Mickael Gaillard
parent eab612871c
commit 94ca074b59

View File

@ -294,9 +294,9 @@ typedef struct gesture_data_type {
uint8_t APDS9960_aTime = DEFAULT_ATIME;
/*******************************************************************************
/******************************************************************************\
* Helper functions
******************************************************************************/
\******************************************************************************/
/**
* @brief Writes a single byte to the I2C device (no register)
@ -304,8 +304,7 @@ typedef struct gesture_data_type {
* @param[in] val the 1-byte value to write to the I2C device
* @return True if successful write operation. False otherwise.
*/
bool wireWriteByte(uint8_t val)
{
bool wireWriteByte(uint8_t val) {
Wire.beginTransmission(APDS9960_I2C_ADDR);
Wire.write(val);
if ( Wire.endTransmission() != 0 ) {
@ -314,6 +313,7 @@ typedef struct gesture_data_type {
return true;
}
/**
* @brief Reads a block (array) of bytes from the I2C device and register
*
@ -322,11 +322,9 @@ typedef struct gesture_data_type {
* @param[in] len number of bytes to read
* @return Number of bytes read. -1 on read error.
*/
int8_t wireReadDataBlock(uint8_t reg,
uint8_t *val,
uint16_t len)
{
uint16_t len) {
unsigned char i = 0;
/* Indicate which register we want to read from */
@ -352,9 +350,7 @@ int8_t wireReadDataBlock( uint8_t reg,
* @brief Converts the raw R/G/B values to color temperature in degrees
* Kelvin
*/
void calculateColorTemperature(void)
{
void calculateColorTemperature(void) {
float X, Y, Z; /* RGB to XYZ correlation */
float xc, yc; /* Chromaticity co-ordinates */
float n; /* McCamy's formula */
@ -366,7 +362,7 @@ void calculateColorTemperature(void)
/* Note: Y = Illuminance or lux */
X = (-0.14282F * color_data.r) + (1.54924F * color_data.g) + (-0.95641F * color_data.b);
Y = (-0.32466F * color_data.r) + (1.57837F * color_data.g) + (-0.73191F * color_data.b); // this is Lux ... under certain circumstances
Z = (-0.68202F * color_data.r) + (0.77073F * color_data.g) + ( 0.56332F * color_data.b);
Z = (-0.68202F * color_data.r) + (0.77073F * color_data.g) + (+0.56332F * color_data.b);
/* 2. Calculate the chromaticity co-ordinates */
xc = (X) / (X + Y + Z);
@ -390,8 +386,7 @@ void calculateColorTemperature(void)
*
* @return lower threshold
*/
uint8_t getProxIntLowThresh(void)
{
uint8_t getProxIntLowThresh(void) {
uint8_t val;
/* Read value from PILT register */
@ -404,8 +399,7 @@ void calculateColorTemperature(void)
*
* @param[in] threshold the lower proximity threshold
*/
void setProxIntLowThresh(uint8_t threshold)
{
void setProxIntLowThresh(uint8_t threshold) {
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PILT, threshold);
}
@ -414,8 +408,7 @@ void calculateColorTemperature(void)
*
* @return high threshold
*/
uint8_t getProxIntHighThresh(void)
{
uint8_t getProxIntHighThresh(void) {
uint8_t val;
/* Read value from PIHT register */
@ -428,13 +421,10 @@ void calculateColorTemperature(void)
*
* @param[in] threshold the high proximity threshold
*/
void setProxIntHighThresh(uint8_t threshold)
{
void setProxIntHighThresh(uint8_t threshold) {
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PIHT, threshold);
}
/**
* @brief Returns LED drive strength for proximity and ALS
*
@ -446,8 +436,7 @@ void calculateColorTemperature(void)
*
* @return the value of the LED drive strength. 0xFF on failure.
*/
uint8_t getLEDDrive(void)
{
uint8_t getLEDDrive(void) {
uint8_t val;
/* Read value from CONTROL register */
@ -469,8 +458,7 @@ void calculateColorTemperature(void)
*
* @param[in] drive the value (0-3) for the LED drive strength
*/
void setLEDDrive(uint8_t drive)
{
void setLEDDrive(uint8_t drive) {
uint8_t val;
/* Read value from CONTROL register */
@ -486,7 +474,6 @@ void calculateColorTemperature(void)
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_CONTROL, val);
}
/**
* @brief Returns receiver gain for proximity detection
*
@ -498,8 +485,7 @@ void calculateColorTemperature(void)
*
* @return the value of the proximity gain. 0xFF on failure.
*/
uint8_t getProximityGain(void)
{
uint8_t getProximityGain(void) {
uint8_t val;
/* Read value from CONTROL register */
@ -521,8 +507,7 @@ void calculateColorTemperature(void)
*
* @param[in] drive the value (0-3) for the gain
*/
void setProximityGain(uint8_t drive)
{
void setProximityGain(uint8_t drive) {
uint8_t val;
/* Read value from CONTROL register */
@ -538,7 +523,6 @@ void calculateColorTemperature(void)
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_CONTROL, val);
}
/**
* @brief Returns receiver gain for the ambient light sensor (ALS)
*
@ -562,8 +546,7 @@ void calculateColorTemperature(void)
*
* @param[in] drive the value (0-3) for the gain
*/
void setAmbientLightGain(uint8_t drive)
{
void setAmbientLightGain(uint8_t drive) {
uint8_t val;
/* Read value from CONTROL register */
@ -589,8 +572,7 @@ void calculateColorTemperature(void)
*
* @return The LED boost value. 0xFF on failure.
*/
uint8_t getLEDBoost(void)
{
uint8_t getLEDBoost(void) {
uint8_t val;
/* Read value from CONFIG2 register */
@ -613,8 +595,7 @@ void calculateColorTemperature(void)
*
* @param[in] drive the value (0-3) for current boost (100-300%)
*/
void setLEDBoost(uint8_t boost)
{
void setLEDBoost(uint8_t boost) {
uint8_t val;
/* Read value from CONFIG2 register */
@ -634,8 +615,7 @@ void calculateColorTemperature(void)
*
* @return 1 if compensation is enabled. 0 if not. 0xFF on error.
*/
uint8_t getProxGainCompEnable(void)
{
uint8_t getProxGainCompEnable(void) {
uint8_t val;
/* Read value from CONFIG3 register */
@ -652,8 +632,7 @@ void calculateColorTemperature(void)
*
* @param[in] enable 1 to enable compensation. 0 to disable compensation.
*/
void setProxGainCompEnable(uint8_t enable)
{
void setProxGainCompEnable(uint8_t enable) {
uint8_t val;
/* Read value from CONFIG3 register */
@ -681,8 +660,7 @@ void calculateColorTemperature(void)
*
* @return Current proximity mask for photodiodes. 0xFF on error.
*/
uint8_t getProxPhotoMask(void)
{
uint8_t getProxPhotoMask(void) {
uint8_t val;
/* Read value from CONFIG3 register */
@ -706,8 +684,7 @@ void calculateColorTemperature(void)
*
* @param[in] mask 4-bit mask value
*/
void setProxPhotoMask(uint8_t mask)
{
void setProxPhotoMask(uint8_t mask) {
uint8_t val;
/* Read value from CONFIG3 register */
@ -727,8 +704,7 @@ void calculateColorTemperature(void)
*
* @return Current entry proximity threshold.
*/
uint8_t getGestureEnterThresh(void)
{
uint8_t getGestureEnterThresh(void) {
uint8_t val;
/* Read value from GPENTH register */
@ -742,10 +718,8 @@ void calculateColorTemperature(void)
*
* @param[in] threshold proximity value needed to start gesture mode
*/
void setGestureEnterThresh(uint8_t threshold)
{
void setGestureEnterThresh(uint8_t threshold) {
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GPENTH, threshold);
}
/**
@ -753,8 +727,7 @@ void calculateColorTemperature(void)
*
* @return Current exit proximity threshold.
*/
uint8_t getGestureExitThresh(void)
{
uint8_t getGestureExitThresh(void) {
uint8_t val;
/* Read value from GEXTH register */
@ -768,8 +741,7 @@ void calculateColorTemperature(void)
*
* @param[in] threshold proximity value needed to end gesture mode
*/
void setGestureExitThresh(uint8_t threshold)
{
void setGestureExitThresh(uint8_t threshold) {
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GEXTH, threshold);
}
@ -784,8 +756,7 @@ void calculateColorTemperature(void)
*
* @return the current photodiode gain. 0xFF on error.
*/
uint8_t getGestureGain(void)
{
uint8_t getGestureGain(void) {
uint8_t val;
/* Read value from GCONF2 register */
@ -808,8 +779,7 @@ void calculateColorTemperature(void)
*
* @param[in] gain the value for the photodiode gain
*/
void setGestureGain(uint8_t gain)
{
void setGestureGain(uint8_t gain) {
uint8_t val;
/* Read value from GCONF2 register */
@ -836,8 +806,7 @@ void calculateColorTemperature(void)
*
* @return the LED drive current value. 0xFF on error.
*/
uint8_t getGestureLEDDrive(void)
{
uint8_t getGestureLEDDrive(void) {
uint8_t val;
/* Read value from GCONF2 register */
@ -860,8 +829,7 @@ void calculateColorTemperature(void)
*
* @param[in] drive the value for the LED drive current
*/
void setGestureLEDDrive(uint8_t drive)
{
void setGestureLEDDrive(uint8_t drive) {
uint8_t val;
/* Read value from GCONF2 register */
@ -892,8 +860,7 @@ void calculateColorTemperature(void)
*
* @return the current wait time between gestures. 0xFF on error.
*/
uint8_t getGestureWaitTime(void)
{
uint8_t getGestureWaitTime(void) {
uint8_t val;
/* Read value from GCONF2 register */
@ -920,8 +887,7 @@ void calculateColorTemperature(void)
*
* @param[in] the value for the wait time
*/
void setGestureWaitTime(uint8_t time)
{
void setGestureWaitTime(uint8_t time) {
uint8_t val;
/* Read value from GCONF2 register */
@ -941,8 +907,7 @@ void calculateColorTemperature(void)
*
* @param[out] threshold current low threshold stored on the APDS-9960
*/
void getLightIntLowThreshold(uint16_t &threshold)
{
void getLightIntLowThreshold(uint16_t &threshold) {
uint8_t val_byte;
threshold = 0;
@ -960,9 +925,7 @@ void calculateColorTemperature(void)
*
* @param[in] threshold low threshold value for interrupt to trigger
*/
void setLightIntLowThreshold(uint16_t threshold)
{
void setLightIntLowThreshold(uint16_t threshold) {
uint8_t val_low;
uint8_t val_high;
@ -975,17 +938,14 @@ void calculateColorTemperature(void)
/* Write high byte */
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_AILTH, val_high);
}
/**
* @brief Gets the high threshold for ambient light interrupts
*
* @param[out] threshold current low threshold stored on the APDS-9960
*/
void getLightIntHighThreshold(uint16_t &threshold)
{
void getLightIntHighThreshold(uint16_t &threshold) {
uint8_t val_byte;
threshold = 0;
@ -1003,8 +963,7 @@ void calculateColorTemperature(void)
*
* @param[in] threshold high threshold value for interrupt to trigger
*/
void setLightIntHighThreshold(uint16_t threshold)
{
void setLightIntHighThreshold(uint16_t threshold) {
uint8_t val_low;
uint8_t val_high;
@ -1019,19 +978,16 @@ void calculateColorTemperature(void)
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_AIHTH, val_high);
}
/**
* @brief Gets the low threshold for proximity interrupts
*
* @param[out] threshold current low threshold stored on the APDS-9960
*/
void getProximityIntLowThreshold(uint8_t &threshold)
{
void getProximityIntLowThreshold(uint8_t &threshold) {
threshold = 0;
/* Read value from proximity low threshold register */
threshold = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PILT);
}
/**
@ -1039,27 +995,21 @@ void calculateColorTemperature(void)
*
* @param[in] threshold low threshold value for interrupt to trigger
*/
void setProximityIntLowThreshold(uint8_t threshold)
{
void setProximityIntLowThreshold(uint8_t threshold) {
/* Write threshold value to register */
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PILT, threshold);
}
/**
* @brief Gets the high threshold for proximity interrupts
*
* @param[out] threshold current low threshold stored on the APDS-9960
*/
void getProximityIntHighThreshold(uint8_t &threshold)
{
void getProximityIntHighThreshold(uint8_t &threshold) {
threshold = 0;
/* Read value from proximity low threshold register */
threshold = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PIHT);
}
/**
@ -1067,9 +1017,7 @@ void calculateColorTemperature(void)
*
* @param[in] threshold high threshold value for interrupt to trigger
*/
void setProximityIntHighThreshold(uint8_t threshold)
{
void setProximityIntHighThreshold(uint8_t threshold) {
/* Write threshold value to register */
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PIHT, threshold);
}
@ -1079,8 +1027,7 @@ void calculateColorTemperature(void)
*
* @return 1 if interrupts are enabled, 0 if not. 0xFF on error.
*/
uint8_t getAmbientLightIntEnable(void)
{
uint8_t getAmbientLightIntEnable(void) {
uint8_t val;
/* Read value from ENABLE register */
@ -1097,8 +1044,7 @@ void calculateColorTemperature(void)
*
* @param[in] enable 1 to enable interrupts, 0 to turn them off
*/
void setAmbientLightIntEnable(uint8_t enable)
{
void setAmbientLightIntEnable(uint8_t enable) {
uint8_t val;
/* Read value from ENABLE register */
@ -1119,8 +1065,7 @@ void calculateColorTemperature(void)
*
* @return 1 if interrupts are enabled, 0 if not. 0xFF on error.
*/
uint8_t getProximityIntEnable(void)
{
uint8_t getProximityIntEnable(void) {
uint8_t val;
/* Read value from ENABLE register */
@ -1137,8 +1082,7 @@ void calculateColorTemperature(void)
*
* @param[in] enable 1 to enable interrupts, 0 to turn them off
*/
void setProximityIntEnable(uint8_t enable)
{
void setProximityIntEnable(uint8_t enable) {
uint8_t val;
/* Read value from ENABLE register */
@ -1159,8 +1103,7 @@ void calculateColorTemperature(void)
*
* @return 1 if interrupts are enabled, 0 if not. 0xFF on error.
*/
uint8_t getGestureIntEnable(void)
{
uint8_t getGestureIntEnable(void) {
uint8_t val;
/* Read value from GCONF4 register */
@ -1177,8 +1120,7 @@ void calculateColorTemperature(void)
*
* @param[in] enable 1 to enable interrupts, 0 to turn them off
*/
void setGestureIntEnable(uint8_t enable)
{
void setGestureIntEnable(uint8_t enable) {
uint8_t val;
/* Read value from GCONF4 register */
@ -1198,8 +1140,7 @@ void calculateColorTemperature(void)
* @brief Clears the ambient light interrupt
*
*/
void clearAmbientLightInt(void)
{
void clearAmbientLightInt(void) {
uint8_t throwaway;
throwaway = I2cRead8(APDS9960_I2C_ADDR, APDS9960_AICLEAR);
}
@ -1208,11 +1149,9 @@ void calculateColorTemperature(void)
* @brief Clears the proximity interrupt
*
*/
void clearProximityInt(void)
{
void clearProximityInt(void) {
uint8_t throwaway;
throwaway = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PICLEAR);
}
/**
@ -1220,8 +1159,7 @@ void calculateColorTemperature(void)
*
* @return 1 if gesture state machine is running, 0 if not. 0xFF on error.
*/
uint8_t getGestureMode(void)
{
uint8_t getGestureMode(void) {
uint8_t val;
/* Read value from GCONF4 register */
@ -1238,8 +1176,7 @@ void calculateColorTemperature(void)
*
* @param[in] mode 1 to enter gesture state machine, 0 to exit.
*/
void setGestureMode(uint8_t mode)
{
void setGestureMode(uint8_t mode) {
uint8_t val;
/* Read value from GCONF4 register */
@ -1255,65 +1192,42 @@ void calculateColorTemperature(void)
}
bool APDS9960_init(void)
{
bool APDS9960_init(void) {
/* Set default values for ambient light and proximity registers */
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_ATIME, DEFAULT_ATIME);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, DEFAULT_WTIME);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PPULSE, DEFAULT_PROX_PPULSE);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_POFFSET_UR, DEFAULT_POFFSET_UR);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_POFFSET_DL, DEFAULT_POFFSET_DL);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_CONFIG1, DEFAULT_CONFIG1);
setLEDDrive(DEFAULT_LDRIVE);
setProximityGain(DEFAULT_PGAIN);
setAmbientLightGain(DEFAULT_AGAIN);
setProxIntLowThresh(DEFAULT_PILT);
setProxIntHighThresh(DEFAULT_PIHT);
setLightIntLowThreshold(DEFAULT_AILT);
setLightIntHighThreshold(DEFAULT_AIHT);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PERS, DEFAULT_PERS);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_CONFIG2, DEFAULT_CONFIG2);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_CONFIG3, DEFAULT_CONFIG3);
/* Set default values for gesture sense registers */
setGestureEnterThresh(DEFAULT_GPENTH);
setGestureExitThresh(DEFAULT_GEXTH);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GCONF1, DEFAULT_GCONF1);
setGestureGain(DEFAULT_GGAIN);
setGestureLEDDrive(DEFAULT_GLDRIVE);
setGestureWaitTime(DEFAULT_GWTIME);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GOFFSET_U, DEFAULT_GOFFSET);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GOFFSET_D, DEFAULT_GOFFSET);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GOFFSET_L, DEFAULT_GOFFSET);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GOFFSET_R, DEFAULT_GOFFSET);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GPULSE, DEFAULT_GPULSE);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_GCONF3, DEFAULT_GCONF3);
setGestureIntEnable(DEFAULT_GIEN);
@ -1322,17 +1236,18 @@ bool APDS9960_init(void)
return true;
}
/*******************************************************************************
/******************************************************************************\
* Public methods for controlling the APDS-9960
******************************************************************************/
\******************************************************************************/
/**
* @brief Reads and returns the contents of the ENABLE register
*
* @return Contents of the ENABLE register. 0xFF if error.
*/
uint8_t getMode(void)
{
uint8_t getMode(void) {
uint8_t enable_value;
/* Read current ENABLE register */
@ -1347,14 +1262,12 @@ uint8_t getMode(void)
* @param[in] mode which feature to enable
* @param[in] enable ON (1) or OFF (0)
*/
void setMode(uint8_t mode, uint8_t enable)
{
void setMode(uint8_t mode, uint8_t enable) {
uint8_t reg_val;
/* Read current ENABLE register */
reg_val = getMode();
/* Change bit(s) in ENABLE register */
enable = enable & 0x01;
if (mode >= 0 && mode <= 6) {
@ -1380,8 +1293,7 @@ void setMode(uint8_t mode, uint8_t enable)
*
* no interrupts
*/
void enableLightSensor(void)
{
void enableLightSensor(void) {
/* Set default gain, interrupts, enable power, and enable sensor */
setAmbientLightGain(DEFAULT_AGAIN);
setAmbientLightIntEnable(0);
@ -1393,8 +1305,7 @@ void enableLightSensor(void)
* @brief Ends the light sensor on the APDS-9960
*
*/
void disableLightSensor(void)
{
void disableLightSensor(void) {
setAmbientLightIntEnable(0);
setMode(AMBIENT_LIGHT, 0);
}
@ -1404,8 +1315,7 @@ void disableLightSensor(void)
*
* no interrupts
*/
void enableProximitySensor(void)
{
void enableProximitySensor(void) {
/* Set default gain, LED, interrupts, enable power, and enable sensor */
setProximityGain(DEFAULT_PGAIN);
setLEDDrive(DEFAULT_LDRIVE);
@ -1418,8 +1328,7 @@ void enableProximitySensor(void)
* @brief Ends the proximity sensor on the APDS-9960
*
*/
void disableProximitySensor(void)
{
void disableProximitySensor(void) {
setProximityIntEnable(0);
setMode(PROXIMITY, 0);
}
@ -1429,8 +1338,7 @@ void disableProximitySensor(void)
*
* no interrupts
*/
void enableGestureSensor(void)
{
void enableGestureSensor(void) {
/* Enable gesture mode
Set ENABLE to 0 (power off)
Set WTIME to 0xFF
@ -1454,8 +1362,7 @@ void enableGestureSensor(void)
* @brief Ends the gesture recognition engine on the APDS-9960
*
*/
void disableGestureSensor(void)
{
void disableGestureSensor(void) {
resetGestureParameters();
setGestureIntEnable(0);
setGestureMode(0);
@ -1467,8 +1374,7 @@ void disableGestureSensor(void)
*
* @return True if gesture available. False otherwise.
*/
bool isGestureAvailable(void)
{
bool isGestureAvailable(void) {
uint8_t val;
/* Read value from GSTATUS register */
@ -1478,11 +1384,7 @@ bool isGestureAvailable(void)
val &= APDS9960_GVALID;
/* Return true/false based on GVALID bit */
if( val == 1) {
return true;
} else {
return false;
}
return (val == 1);
}
/**
@ -1490,8 +1392,7 @@ bool isGestureAvailable(void)
*
* @return Number corresponding to gesture. -1 on error.
*/
int16_t readGesture(void)
{
int16_t readGesture(void) {
uint8_t fifo_level = 0;
uint8_t bytes_read = 0;
uint8_t fifo_data[128];
@ -1521,15 +1422,12 @@ int16_t readGesture(void)
/* If we have valid data, read in FIFO */
if ((gstatus & APDS9960_GVALID) == APDS9960_GVALID) {
/* Read the current FIFO level */
fifo_level = I2cRead8(APDS9960_I2C_ADDR, APDS9960_GFLVL);
/* If there's stuff in the FIFO, read it into our data block */
if (fifo_level > 0) {
bytes_read = wireReadDataBlock( APDS9960_GFIFO_U,
(uint8_t*)fifo_data,
(fifo_level * 4) );
bytes_read = wireReadDataBlock(APDS9960_GFIFO_U, (uint8_t*)fifo_data, (fifo_level * 4));
if (bytes_read == -1) {
return APDS9960_ERROR;
}
@ -1548,10 +1446,11 @@ int16_t readGesture(void)
gesture_data_.index++;
gesture_data_.total_gestures++;
}
/* Filter and process gesture data. Decode near/far state */
if (processGestureData()) {
if (decodeGesture()) {
//***TODO: U-Turn Gestures
// TODO(xx): U-Turn Gestures
}
}
/* Reset data */
@ -1560,7 +1459,6 @@ int16_t readGesture(void)
}
}
} else {
/* Determine best guessed gesture and clean up */
delay(FIFO_PAUSE_TIME);
decodeGesture();
@ -1575,8 +1473,7 @@ int16_t readGesture(void)
* Turn the APDS-9960 on
*
*/
void enablePower(void)
{
void enablePower(void) {
setMode(POWER, 1);
}
@ -1584,38 +1481,34 @@ void enablePower(void)
* Turn the APDS-9960 off
*
*/
void disablePower(void)
{
void disablePower(void) {
setMode(POWER, 0);
}
/*******************************************************************************
/******************************************************************************\
* Ambient light and color sensor controls
******************************************************************************/
\******************************************************************************/
/**
* @brief Reads the ARGB-Data and fills color_data
*
*/
void readAllColorAndProximityData(void)
{
if (I2cReadBuffer(APDS9960_I2C_ADDR, APDS9960_CDATAL, (uint8_t *) &color_data, (uint16_t)9))
{
void readAllColorAndProximityData(void) {
if (I2cReadBuffer(APDS9960_I2C_ADDR, APDS9960_CDATAL, (uint8_t *) &color_data, (uint16_t)9)) {
// not absolutely shure, if this is a correct way to do this, but it is very short
// we fill the struct byte by byte
}
}
/*******************************************************************************
/******************************************************************************\
* High-level gesture controls
******************************************************************************/
\******************************************************************************/
/**
* @brief Resets all the parameters in the gesture data member
*/
void resetGestureParameters(void)
{
void resetGestureParameters(void) {
gesture_data_.index = 0;
gesture_data_.total_gestures = 0;
@ -1634,8 +1527,7 @@ void resetGestureParameters(void)
*
* @return True if near or far state seen. False otherwise.
*/
bool processGestureData(void)
{
bool processGestureData(void) {
uint8_t u_first = 0;
uint8_t d_first = 0;
uint8_t l_first = 0;
@ -1660,14 +1552,12 @@ bool processGestureData(void)
/* Check to make sure our data isn't out of bounds */
if ((gesture_data_.total_gestures <= 32) && \
(gesture_data_.total_gestures > 0)) {
/* Find the first value in U/D/L/R above the threshold */
for (i = 0; i < gesture_data_.total_gestures; i++) {
if ((gesture_data_.u_data[i] > GESTURE_THRESHOLD_OUT) &&
(gesture_data_.d_data[i] > GESTURE_THRESHOLD_OUT) &&
(gesture_data_.l_data[i] > GESTURE_THRESHOLD_OUT) &&
(gesture_data_.r_data[i] > GESTURE_THRESHOLD_OUT) ) {
u_first = gesture_data_.u_data[i];
d_first = gesture_data_.d_data[i];
l_first = gesture_data_.l_data[i];
@ -1677,19 +1567,16 @@ bool processGestureData(void)
}
/* If one of the _first values is 0, then there is no good data */
if( (u_first == 0) || (d_first == 0) || \
(l_first == 0) || (r_first == 0) ) {
if ((u_first == 0) || (d_first == 0) || (l_first == 0) || (r_first == 0)) {
return false;
}
/* Find the last value in U/D/L/R above the threshold */
for (i = gesture_data_.total_gestures - 1; i >= 0; i--) {
if ((gesture_data_.u_data[i] > GESTURE_THRESHOLD_OUT) &&
(gesture_data_.d_data[i] > GESTURE_THRESHOLD_OUT) &&
(gesture_data_.l_data[i] > GESTURE_THRESHOLD_OUT) &&
(gesture_data_.r_data[i] > GESTURE_THRESHOLD_OUT)) {
u_last = gesture_data_.u_data[i];
d_last = gesture_data_.d_data[i];
l_last = gesture_data_.l_data[i];
@ -1738,9 +1625,7 @@ bool processGestureData(void)
*
* @return True if near/far event. False otherwise.
*/
bool decodeGesture(void)
{
bool decodeGesture(void) {
/* Determine swipe direction */
if ((gesture_ud_count_ == -1) && (gesture_lr_count_ == 0)) {
gesture_motion_ = DIR_UP;
@ -1801,38 +1686,34 @@ void handleGesture(void) {
snprintf_P(currentGesture, sizeof(currentGesture), PSTR("Right"));
break;
default:
if(APDS9960_overload)
{
if (APDS9960_overload) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("LONG"));
snprintf_P(currentGesture, sizeof(currentGesture), PSTR("Long"));
}
else{
} else {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NONE"));
snprintf_P(currentGesture, sizeof(currentGesture), PSTR("None"));
}
break;
}
MqttPublishSensor();
}
}
void APDS9960_adjustATime(void) // not really used atm
{
void APDS9960_adjustATime(void) { // not really used atm
// readAllColorAndProximityData();
I2cValidRead16LE(&color_data.a, APDS9960_I2C_ADDR, APDS9960_CDATAL);
// disablePower();
if (color_data.a < (uint16_t)20) {
APDS9960_aTime = 0x40;
}
else if (color_data.a < (uint16_t)40){
} else if (color_data.a < (uint16_t)40) {
APDS9960_aTime = 0x80;
}
else if (color_data.a < (uint16_t)50){
} else if (color_data.a < (uint16_t)50) {
APDS9960_aTime = DEFAULT_ATIME;
}
else if (color_data.a < (uint16_t)70){
} else if (color_data.a < (uint16_t)70) {
APDS9960_aTime = 0xc0;
}
if (color_data.a < 200) {
APDS9960_aTime = 0xe9;
}
@ -1850,12 +1731,11 @@ void APDS9960_adjustATime(void) // not really used atm
delay(20);
}
void APDS9960_loop(void)
{
void APDS9960_loop(void) {
if (recovery_loop_counter > 0) {
recovery_loop_counter -= 1;
}
if (recovery_loop_counter == 1 && APDS9960_overload) { // restart sensor just before the end of recovery from long press
enableGestureSensor();
APDS9960_overload = false;
@ -1868,8 +1748,7 @@ void APDS9960_loop(void)
if (recovery_loop_counter == 0) {
handleGesture();
if (APDS9960_overload)
{
if (APDS9960_overload) {
disableGestureSensor();
recovery_loop_counter = APDS9960_LONG_RECOVERY; // long pause after overload/long press - number of stateloops
Response_P(PSTR("{\"Gesture\":\"Off\"}"));
@ -1880,8 +1759,7 @@ void APDS9960_loop(void)
}
}
void APDS9960_detect(void)
{
void APDS9960_detect(void) {
if (APDS9960type || I2cActive(APDS9960_I2C_ADDR)) { return; }
APDS9960type = I2cRead8(APDS9960_I2C_ADDR, APDS9960_ID);
@ -1897,6 +1775,7 @@ void APDS9960_detect(void)
} else {
APDS9960type = 0;
}
currentGesture[0] = '\0';
}
@ -1904,8 +1783,7 @@ void APDS9960_detect(void)
* Presentation
\*********************************************************************************************/
void APDS9960_show(bool json)
{
void APDS9960_show(bool json) {
if (!APDS9960type) { return; }
if (!gesture_mode && !APDS9960_overload) {
@ -1939,8 +1817,7 @@ void APDS9960_show(bool json)
WSContentSend_PD(HTTP_APDS_9960_SNS, red_chr, green_chr, blue_chr, ambient_chr, cct_chr, prox_chr);
#endif // USE_WEBSERVER
}
}
else {
} else {
if (json && (currentGesture[0] != '\0' )) {
ResponseAppend_P(PSTR(",\"%s\":{\"%s\":1}"), APDS9960stype, currentGesture);
currentGesture[0] = '\0';
@ -1959,8 +1836,7 @@ void APDS9960_show(bool json)
* Sensor27 | 2 / On | Enable gesture mode with half gain
\*********************************************************************************************/
bool APDS9960CommandSensor(void)
{
bool APDS9960CommandSensor(void) {
bool serviced = true;
switch (XdrvMailbox.payload) {
@ -2007,16 +1883,14 @@ bool APDS9960CommandSensor(void)
* Interface
\*********************************************************************************************/
bool Xsns27(uint8_t function)
{
bool Xsns27(uint8_t function) {
if (!I2cEnabled(XI2C_21)) { return false; }
bool result = false;
if (FUNC_INIT == function) {
APDS9960_detect();
}
else if (APDS9960type) {
} else if (APDS9960type) {
switch (function) {
case FUNC_EVERY_50_MSECOND:
APDS9960_loop();
@ -2038,5 +1912,6 @@ bool Xsns27(uint8_t function)
}
return result;
}
#endif // USE_APDS9960
#endif // USE_I2C