Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
wollewald authored Mar 12, 2023
1 parent 4c185d1 commit 8251c51
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/ADXL345_WE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,20 +462,20 @@ void ADXL345_WE::setLinkBit(bool link){
}

void ADXL345_WE::setFreeFallThresholds(float ffg, float fft){
regVal = static_cast<uint16_t>(round(ffg / 0.0625));
regVal = static_cast<uint8_t>(round(ffg / 0.0625));
if(regVal<1){
regVal = 1;
}
writeRegister(ADXL345_THRESH_FF, regVal);
regVal = static_cast<uint16_t>(round(fft / 5));
regVal = static_cast<uint8_t>(round(fft / 5));
if(regVal<1){
regVal = 1;
}
writeRegister(ADXL345_TIME_FF, regVal);
}

void ADXL345_WE::setActivityParameters(adxl345_dcAcMode mode, adxl345_actTapSet axes, float threshold){
regVal = static_cast<uint16_t>(round(threshold / 0.0625));
regVal = static_cast<uint8_t>(round(threshold / 0.0625));
if(regVal<1){
regVal = 1;
}
Expand All @@ -484,20 +484,20 @@ void ADXL345_WE::setActivityParameters(adxl345_dcAcMode mode, adxl345_actTapSet

regVal = readRegister8(ADXL345_ACT_INACT_CTL);
regVal &= 0x0F;
regVal |= (static_cast<uint16_t>(mode) + static_cast<uint16_t>(axes))<<4;
regVal |= (static_cast<uint8_t>(mode) + static_cast<uint8_t>(axes))<<4;
writeRegister(ADXL345_ACT_INACT_CTL, regVal);
}

void ADXL345_WE::setInactivityParameters(adxl345_dcAcMode mode, adxl345_actTapSet axes, float threshold, uint8_t inactTime){
regVal = static_cast<uint16_t>(round(threshold / 0.0625));
regVal = static_cast<uint8_t>(round(threshold / 0.0625));
if(regVal<1){
regVal = 1;
}
writeRegister(ADXL345_THRESH_INACT, regVal);

regVal = readRegister8(ADXL345_ACT_INACT_CTL);
regVal &= 0xF0;
regVal |= static_cast<uint16_t>(mode) + static_cast<uint16_t>(axes);
regVal |= static_cast<uint8_t>(mode) + static_cast<uint16_t>(axes);
writeRegister(ADXL345_ACT_INACT_CTL, regVal);

writeRegister(ADXL345_TIME_INACT, inactTime);
Expand All @@ -506,22 +506,22 @@ void ADXL345_WE::setInactivityParameters(adxl345_dcAcMode mode, adxl345_actTapSe
void ADXL345_WE::setGeneralTapParameters(adxl345_actTapSet axes, float threshold, float duration, float latent){
regVal = readRegister8(ADXL345_TAP_AXES);
regVal &= 0b11111000;
regVal |= static_cast<uint16_t>(axes);
regVal |= static_cast<uint8_t>(axes);
writeRegister(ADXL345_TAP_AXES, regVal);

regVal = static_cast<uint16_t>(round(threshold / 0.0625));
regVal = static_cast<uint8_t>(round(threshold / 0.0625));
if(regVal<1){
regVal = 1;
}
writeRegister(ADXL345_THRESH_TAP,regVal);

regVal = static_cast<uint16_t>(round(duration / 0.625));
regVal = static_cast<uint8_t>(round(duration / 0.625));
if(regVal<1){
regVal = 1;
}
writeRegister(ADXL345_DUR, regVal);

regVal = static_cast<uint16_t>(round(latent / 1.25));
regVal = static_cast<uint8_t>(round(latent / 1.25));
if(regVal<1){
regVal = 1;
}
Expand All @@ -538,7 +538,7 @@ void ADXL345_WE::setAdditionalDoubleTapParameters(bool suppress, float window){
}
writeRegister(ADXL345_TAP_AXES, regVal);

regVal = static_cast<uint16_t>(round(window / 1.25));
regVal = static_cast<uint8_t>(round(window / 1.25));
writeRegister(ADXL345_WINDOW, regVal);
}

Expand Down Expand Up @@ -622,7 +622,7 @@ uint8_t ADXL345_WE::readRegister8(uint8_t reg){
_wire->beginTransmission(i2cAddress);
_wire->write(reg);
_wire->endTransmission(false);
_wire->requestFrom(i2cAddress, static_cast<uint16_t>(1));
_wire->requestFrom(i2cAddress, static_cast<uint8_t>(1));
if(_wire->available()){
regValue = _wire->read();
}
Expand Down

0 comments on commit 8251c51

Please sign in to comment.