WaspACC Class Reference

WaspACC Class. More...

#include <WaspACC.h>


Public Member Functions

 WaspACC ()
 class constructor
void ON ()
 It opens I2C bus and powers the accelerometer.
void begin ()
 It opens I2C bus.
void boot ()
 It reboots the accelerometer.
void close ()
 It closes I2C bus.
uint8_t getStatus ()
 It gets the accelerometer status.
uint8_t check ()
 It checks if accelerometer is working properly.
uint8_t getCTRL1 ()
 It gets the CTRL1 register.
uint8_t setCTRL1 (uint8_t val)
 It sets the CTRL1 register.
uint8_t getCTRL2 ()
 It gets the CTRL2 register.
uint8_t setCTRL2 (uint8_t val)
 It sets the CTRL2 register.
uint8_t getCTRL3 ()
 It gets the CTRL3 register.
uint8_t setCTRL3 (uint8_t val)
 It sets the CTRL3 register.
int16_t readRegister (uint8_t address)
 It reads a register from the accelerometer.
int16_t writeRegister (uint8_t address, uint8_t val)
 It writes a register to the accelerometer.
uint8_t getADCmode ()
 It gets the accelerometer's ADC mode.
uint8_t setADCmode (uint8_t val)
 It sets the accelerometer's ADC mode.
uint8_t setSamplingRate (uint8_t rate)
 It sets the accelerometer's sampling rate.
int16_t getX ()
 It gets the acceleration on OX.
int16_t getY ()
 It gets the acceleration on OY.
int16_t getZ ()
 It gets the acceleration on OZ.
uint8_t setFF (void)
 It sets the Free Fall interrupt using the parameters previously defined.
uint8_t unsetFF (void)
 It unsets the Free Fall interrupt.
uint8_t setDD (uint8_t directions)
 It sets the Direction Change interrupt using the input parameter.
uint8_t setDD (void)
 It sets the Direction Change interrupt using the parameters previously defined.
uint8_t unsetDD (void)
 It unsets the Direction Change interrupt.
uint8_t getMode ()
 It gets the accelerometer's work mode.
uint8_t setMode (uint8_t val)
 It sets the accelerometer's work mode.
uint8_t getAccEvent ()
 It gets the accelerometer's event type.
uint8_t setAccEvent (uint8_t val)
 It sets the accelerometer's event type.
void attachInt (void)
 It configures the specific hardware interrupt for the acc.
void detachInt (void)
 It unsets the specific hardware interrupt for the acc.
void clearAlarmFlag ()
 It clears the Accelerometer's alarm flag.

Data Fields

volatile uint8_t flag
 Variable : status flag, used to see if there has been an error while reading/writing or if there has been a hardware interrupt.
uint8_t flagInt
 Variable : interrupt flag, used to check which interrupt got active.

Private Attributes

uint8_t accMode
 Variable : Accelerometer Operation Mode.
uint8_t AccEventMode
 Variable : Accelerometer Event Mode.


Detailed Description

WaspACC Class.

WaspACC Class defines all the variables and functions used to manage LIS3LV02DL accelerometer

Definition at line 476 of file WaspACC.h.


Constructor & Destructor Documentation

WaspACC::WaspACC (  ) 

class constructor

It does nothing

Parameters:
void 
Returns:
void

Definition at line 32 of file WaspACC.cpp.

00033 {
00034     // nothing to do
00035 }


Member Function Documentation

void WaspACC::ON ( void   ) 

It opens I2C bus and powers the accelerometer.

Parameters:
void 
Returns:
void
See also:
boot(), close(), begin()

Definition at line 48 of file WaspACC.cpp.

References ACC_ON, begin(), and setMode().

00049 {
00050         begin();
00051         setMode(ACC_ON);
00052 }

Here is the call graph for this function:

void WaspACC::begin ( void   ) 

It opens I2C bus.

Parameters:
void 
Returns:
void
See also:
boot(), close()

Definition at line 62 of file WaspACC.cpp.

References ACC_ON, accMode, TwoWire::begin(), RTC, RTC_ON, WaspRTC::setMode(), and Wire.

Referenced by ON().

00063 {
00064 
00065         // Sets RTC on to enable I2C
00066         RTC.setMode(RTC_ON);
00067         
00068   accMode = ACC_ON;         // by default the accelerometer will be in continuous mode
00069                             // this should be changed once Wasp is released, by default
00070                             // the system should be in standby, and with the communication 
00071                             // disabled
00072 
00073   Wire.begin(); // join i2c bus (address optional for master)
00074   
00075         
00076   // start the communication by
00077   // making sure we have the right data in
00078   // the control registers
00079 
00080   // register 2 takes care rebooting, and turning on/off
00081   // the free fall filters
00082   // writeRegister(ctrlReg2, B00000000);
00083   /*
00084    *      MSB - fs: full scale selection, 0=2g, 1=6g
00085    *            bdu: block data update, 0=continuous, 1=when MSB/LSB has been read 
00086    *            ble: big little endian, 0=little, 1=big
00087    *            boot: reboot factory defaults
00088    *            ien: interrupt enable, 0=data ready on RDY , 1=int. request on RDY
00089    *            drdy: data ready generation, 0 for 0 on RDY, 1 for 1 on RDY
00090    *            sim: SPI 4/3 wire, 0=4 wires, 1=3 wires
00091    *      LSB - das: 0=12 bit signed, 1=16 bits unsigned
00092    */
00093 
00094   // register 1 will decide upon the different acceleration, sample rate,
00095   // will enable the different axes and will control if the sensor is 
00096   // in power down mode
00097   // writeRegister(ctrlReg1, B01000111);
00098   /*
00099    *      MSB - pd1, pd0: 00 means power down, 01, 10, 11 are power on
00100    *            df1, df0: decimation factor, 00=512, 01=128, 10=32, 11=8
00101    *            sfe: self test enable, 0=normal, 1=active
00102    *            z enable
00103    *            y enable
00104    *      LSB - x enable
00105    */
00106 
00107   // mostly takes care of filter activations and such
00108   // writeRegister(ctrlReg3, B00001000);
00109   // in theory the pin we are trying to write to should be reserved
00110   // therefore this operation should not be needed
00111   /*
00112    *      MSB - eck - External Clock. Default value: 0
00113    *            hpdd - (0: clock from internal oscillator; 1: clock from external pad)
00114    *                   High Pass filter enabled for Direction Detection. Default value: 0
00115    *            hpff - (0: filter bypassed; 1: filter enabled)
00116    *                   High Pass filter enabled for Free-Fall and Wake-Up. Default value: 0
00117    *            fds  - (0: filter bypassed; 1: filter enabled)
00118    *                   Filtered Data Selection. Default value: 0
00119    *            res  - Reserved. These bit are reserved for future enhancements.
00120    *                   Best to be left to their default value (10 binary)
00121    *            res
00122    *            cfs1, cfs0 - (0: internal filter bypassed; 1: data from internal filter)
00123    *                   High-pass filter Cut-off Frequency Selection. Default value: 00
00124    *                   (00: Hpc=512
00125    *                    01: Hpc=1024
00126    *                    10: Hpc=2048
00127    *                    11: Hpc=4096)
00128    */
00129 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspACC::boot ( void   ) 

It reboots the accelerometer.

Parameters:
void 
Returns:
void
See also:
init(), close()

Definition at line 139 of file WaspACC.cpp.

References B00000000, B00010000, ctrlReg2, delay(), and writeRegister().

00140 {
00141   // send reboot command
00142   writeRegister(ctrlReg2, B00010000);
00143 
00144   delay(1);  // make a short pause after rebooting
00145 
00146   writeRegister(ctrlReg2, B00000000);
00147 
00148 }

Here is the call graph for this function:

void WaspACC::close ( void   ) 

It closes I2C bus.

Parameters:
void 
Returns:
void
See also:
init(), boot()

Definition at line 157 of file WaspACC.cpp.

References ACC_HIBERNATE, WaspPWR::closeI2C(), PWR, and setMode().

00158 {
00159         setMode(ACC_HIBERNATE); 
00160         PWR.closeI2C();
00161 }

Here is the call graph for this function:

uint8_t WaspACC::getStatus ( void   ) 

It gets the accelerometer status.

Parameters:
void 
Returns:
a byte containing the accelerometer status as read from the proper register. It won't activate any flags by itself, but activates ACC_COMM_ERROR in case there was an error writing to the register
See also:
check()

Definition at line 174 of file WaspACC.cpp.

References readRegister(), and statusReg.

00175 {
00176   return (uint8_t) readRegister(statusReg);
00177 }

Here is the call graph for this function:

uint8_t WaspACC::check ( void   ) 

It checks if accelerometer is working properly.

Parameters:
void 
Returns:
a byte containing the register value. If this value is different from '0x3A', the accelerometer is not working properly
See also:
getStatus()

Definition at line 192 of file WaspACC.cpp.

References readRegister(), and whoAmIReg.

00193 {
00194   return (uint8_t) readRegister(whoAmIReg);
00195 }

Here is the call graph for this function:

uint8_t WaspACC::getCTRL1 ( void   ) 

It gets the CTRL1 register.

Parameters:
void 
Returns:
a byte containing the register value.
See also:
setCTRL1(uint8_t val)

Definition at line 210 of file WaspACC.cpp.

References ctrlReg1, and readRegister().

00211 {
00212   return (uint8_t) readRegister(ctrlReg1);
00213 }

Here is the call graph for this function:

uint8_t WaspACC::setCTRL1 ( uint8_t  val  ) 

It sets the CTRL1 register.

Parameters:
uint8_t val : value to set the CTRL1 register to
Returns:
'1' if error
See also:
getCTRL1()

Definition at line 224 of file WaspACC.cpp.

References ctrlReg1, and writeRegister().

00225 {
00226   return (uint8_t) writeRegister(ctrlReg1, val);
00227 }

Here is the call graph for this function:

uint8_t WaspACC::getCTRL2 ( void   ) 

It gets the CTRL2 register.

Parameters:
void 
Returns:
a byte containing the register value.
See also:
setCTRL2(uint8_t val)

Definition at line 239 of file WaspACC.cpp.

References ctrlReg2, and readRegister().

00239 {
00240   return (uint8_t) readRegister(ctrlReg2);
00241 }
00242 

Here is the call graph for this function:

uint8_t WaspACC::setCTRL2 ( uint8_t  val  ) 

It sets the CTRL2 register.

Parameters:
uint8_t val : value to set the CTRL2 register to
Returns:
'1' if error
See also:
getCTRL2()

Definition at line 253 of file WaspACC.cpp.

References ctrlReg2, and writeRegister().

00253 {
00254   return (uint8_t) writeRegister(ctrlReg2, val);
00255 }
00256 

Here is the call graph for this function:

uint8_t WaspACC::getCTRL3 ( void   ) 

It gets the CTRL3 register.

Parameters:
void 
Returns:
a byte containing the register value.
See also:
setCTRL3(uint8_t val)

Definition at line 267 of file WaspACC.cpp.

References ctrlReg3, and readRegister().

00267 {
00268   return (uint8_t) readRegister(ctrlReg3);
00269 }
00270 

Here is the call graph for this function:

uint8_t WaspACC::setCTRL3 ( uint8_t  val  ) 

It sets the CTRL3 register.

Parameters:
uint8_t val : value to set the CTRL3 register to
Returns:
'1' if error
See also:
getCTRL3()

Definition at line 281 of file WaspACC.cpp.

References ctrlReg3, and writeRegister().

00281 {
00282   return (uint8_t) writeRegister(ctrlReg3, val);
00283 }
00284 

Here is the call graph for this function:

int16_t WaspACC::readRegister ( uint8_t  address  ) 

It reads a register from the accelerometer.

Parameters:
uint8_t address : register address
Returns:
register value or '-1' if error
See also:
writeRegister(uint8_t address, uint8_t val)

Definition at line 656 of file WaspACC.cpp.

References ACC_ERROR_READING, TwoWire::available(), TwoWire::beginTransmission(), TwoWire::endTransmission(), flag, i2cID, TwoWire::receive(), TwoWire::requestFrom(), TwoWire::send(), and Wire.

Referenced by check(), clearAlarmFlag(), getADCmode(), getCTRL1(), getCTRL2(), getCTRL3(), getStatus(), getX(), getY(), getZ(), setADCmode(), setDD(), setSamplingRate(), unsetDD(), unsetFF(), and writeRegister().

00656 {
00657   // reset the flag
00658   flag &= ~(ACC_ERROR_READING);
00659 
00660   uint8_t aux = 0;
00661   Wire.beginTransmission(i2cID);
00662   Wire.send(regNum);
00663   Wire.endTransmission();
00664 
00665   Wire.requestFrom(i2cID, 1);
00666   if(Wire.available())
00667   {
00668     aux = Wire.receive();
00669     return aux;
00670   }
00671 
00672   // error, activate the reading flag
00673   flag |= ACC_ERROR_READING;
00674 
00675   return -1;
00676 }
00677 

Here is the call graph for this function:

Here is the caller graph for this function:

int16_t WaspACC::writeRegister ( uint8_t  address,
uint8_t  val 
)

It writes a register to the accelerometer.

Parameters:
uint8_t address : register address
uint8_t val : value to write
Returns:
'0' on success, '-1' if error
See also:
readRegister(uint8_t val)

Definition at line 681 of file WaspACC.cpp.

References ACC_ERROR_WRITING, TwoWire::beginTransmission(), TwoWire::endTransmission(), flag, i2cID, readRegister(), TwoWire::send(), and Wire.

Referenced by boot(), clearAlarmFlag(), setADCmode(), setCTRL1(), setCTRL2(), setCTRL3(), setDD(), setFF(), setMode(), setSamplingRate(), unsetDD(), and unsetFF().

00681 {
00682   // reset the flag
00683   flag &= ~(ACC_ERROR_WRITING);
00684 
00685   Wire.beginTransmission(i2cID);
00686   Wire.send(address); 
00687   Wire.send(val);
00688   Wire.endTransmission();
00689 
00690   if (readRegister(address) != val)
00691   {
00692     // error, activate the reading flag
00693     flag |= ACC_ERROR_WRITING;
00694 
00695     return -1;
00696   }
00697 
00698   // exit with no error
00699   return 0;
00700 }
00701 

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspACC::getADCmode ( void   ) 

It gets the accelerometer's ADC mode.

Parameters:
void 
Returns:
'0' for 12 bits right aligned (MSB represents the sign) and '1' for 16 bits left aligned
See also:
setADCmode(uint8_t val)

Definition at line 295 of file WaspACC.cpp.

References B01, ctrlReg2, and readRegister().

00295 {
00296   return readRegister(ctrlReg2) && B01;
00297 }
00298 

Here is the call graph for this function:

uint8_t WaspACC::setADCmode ( uint8_t  val  ) 

It sets the accelerometer's ADC mode.

Parameters:
uint8_t val : '0' for 12 bits right aligned (MSB represents the sign) and '1' for 16 bits left aligned
Returns:
'0' on success, '-1' if error
See also:
getADCmode()

Definition at line 311 of file WaspACC.cpp.

References B11111110, ctrlReg2, readRegister(), and writeRegister().

00311 {
00312   uint8_t aux = readRegister(ctrlReg2);
00313   aux &= B11111110;
00314   aux |= val;
00315   return writeRegister(ctrlReg2, aux);
00316 }
00317 

Here is the call graph for this function:

uint8_t WaspACC::setSamplingRate ( uint8_t  rate  ) 

It sets the accelerometer's sampling rate.

Parameters:
uint8_t rate : ACC_RATE_40, ACC_RATE_160, ACC_RATE_640, ACC_RATE_2560
Returns:
'0' on success, '-1' if error

Definition at line 329 of file WaspACC.cpp.

References ACC_RATE_160, ACC_RATE_2560, ACC_RATE_40, ACC_RATE_640, B00010000, B00100000, B00110000, B11001111, ctrlReg1, readRegister(), and writeRegister().

00329 {
00330         uint8_t aux = readRegister(ctrlReg1);
00331         aux &= B11001111;
00332         
00333         switch( rate )
00334         {
00335                 case ACC_RATE_40        :       aux |= rate;
00336                                                 break;
00337                 case ACC_RATE_160       :       aux |= B00010000;
00338                                                 break;
00339                 case ACC_RATE_640       :       aux |= B00100000;
00340                                                 break;
00341                 case ACC_RATE_2560      :       aux |= B00110000;
00342                                                 break;
00343         }
00344         return writeRegister(ctrlReg1, aux);
00345 }
00346 

Here is the call graph for this function:

int16_t WaspACC::getX ( void   ) 

It gets the acceleration on OX.

Parameters:
void 
Returns:
the combined contents of data registers outXhigh and outXlow as an integer according to ADC's configuration
See also:
getY(), getZ()

Definition at line 363 of file WaspACC.cpp.

References outXhigh, outXlow, and readRegister().

00363 {
00364   int16_t aux = readRegister(outXhigh)*256 + readRegister(outXlow);
00365   return aux;
00366 }
00367 

Here is the call graph for this function:

int16_t WaspACC::getY ( void   ) 

It gets the acceleration on OY.

Parameters:
void 
Returns:
the combined contents of data registers outYhigh and outYlow as an integer according to ADC's configuration
See also:
getX(), getZ()

Definition at line 379 of file WaspACC.cpp.

References outYhigh, outYlow, and readRegister().

00379 {
00380   int16_t aux = readRegister(outYhigh)*256 + readRegister(outYlow);
00381   return aux;
00382 }
00383 

Here is the call graph for this function:

int16_t WaspACC::getZ ( void   ) 

It gets the acceleration on OZ.

Parameters:
void 
Returns:
the combined contents of data registers outZhigh and outZlow as an integer according to ADC's configuration
See also:
getX(), getY()

Definition at line 395 of file WaspACC.cpp.

References outZhigh, outZlow, and readRegister().

00395 {
00396   int16_t aux = readRegister(outZhigh)*256 + readRegister(outZlow);
00397   return aux;
00398 }
00399 

Here is the call graph for this function:

uint8_t WaspACC::setFF ( void   ) 

It sets the Free Fall interrupt using the parameters previously defined.

Parameters:
void 
Returns:
'flag' variable
See also:
unsetFF()

Definition at line 466 of file WaspACC.cpp.

References ACC, ACC_FREE_FALL, AccEventMode, attachInt(), ctrlReg1, ctrlReg2, ctrlReg3, FF_WU_CFG, FF_WU_CFG_val, FF_WU_DURATION, FF_WU_DURATION_val, FF_WU_THS_H, FF_WU_THS_H_val, FF_WU_THS_L, FF_WU_THS_L_val, flag, unsetFF(), and writeRegister().

Referenced by WaspPWR::clearInts().

00466 {
00467   // clear the FF interrupt if active
00468   unsetFF();
00469    
00470   // configure the different registers to 
00471   // handle acceleration detection on the X, Y, or Z axis
00472   ACC.writeRegister(ctrlReg1, 0xC7);
00473   ACC.writeRegister(ctrlReg2, 0x08); 
00474   ACC.writeRegister(ctrlReg3, 0x08);
00475   
00476  // here we have to double-check if we
00477   // are in 12 or 16bit data modes. The 12
00478   // bit data mode is giving away the 4LSBs
00479   // therefore the register needs to be written
00480   // according to that. 0x3C00 is just below 1g
00481   // but the acc will give 0x03C0, beware!
00482   writeRegister(FF_WU_THS_L, FF_WU_THS_L_val);  // threshold L
00483   writeRegister(FF_WU_THS_H, FF_WU_THS_H_val);  // threshold H
00484   writeRegister(FF_WU_DURATION, FF_WU_DURATION_val);  // event duration
00485   // readRegister(HP_FILTER_RESET);   // config the acc. to get current acceleration as initial val
00486   writeRegister(FF_WU_CFG, FF_WU_CFG_val);  // config accelerometer to wake up 
00487 
00488   // assign the ACC_FREE_FALL mode
00489   AccEventMode |= ACC_FREE_FALL;
00490 
00491   // attach the hardware interrupt to the pin
00492   attachInt();
00493 
00494   return flag;
00495 }
00496 

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspACC::unsetFF ( void   ) 

It unsets the Free Fall interrupt.

Parameters:
void 
Returns:
'flag' variable
See also:
setFF()

Definition at line 501 of file WaspACC.cpp.

References ACC_FREE_FALL, AccEventMode, detachInt(), FF_WU_ACK, FF_WU_CFG, flag, readRegister(), and writeRegister().

Referenced by setFF().

00501 {
00502 
00503   writeRegister(FF_WU_CFG, 0x00);  
00504   readRegister(FF_WU_ACK);  // clear the interrupt flag
00505 
00506   // detach the event if there are no flags active
00507   AccEventMode &= ~(ACC_FREE_FALL);
00508   if (!AccEventMode) detachInt();
00509   return flag;
00510 }
00511 

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspACC::setDD ( uint8_t  directions  ) 

It sets the Direction Change interrupt using the input parameter.

Parameters:
uint8_t directions : the axis where enable the interruptions
Returns:
'flag' variable
See also:
setDD()

Definition at line 516 of file WaspACC.cpp.

References ACC_DIRECTION, AccEventMode, attachInt(), ctrlReg1, ctrlReg2, ctrlReg3, DD_CFG, DD_THSE_H, DD_THSE_H_val, DD_THSE_L, DD_THSE_L_val, DD_THSI_H, DD_THSI_H_val, DD_THSI_L, DD_THSI_L_val, flag, HP_FILTER_RESET, IEND, LIR, readRegister(), unsetDD(), and writeRegister().

00516 {
00517   // make sure it gets configured for whatever direction
00518   // people choose like e.g. XHIE or ZLIE
00519   directions |= (IEND | LIR);
00520 
00521   // clear the DD interrupt if active
00522   unsetDD();
00523    
00524   // configure the different registers to 
00525   // handle acceleration detection on the X, Y, or Z axis
00526   writeRegister(ctrlReg1, 0xC7);
00527   writeRegister(ctrlReg2, 0x08); 
00528   writeRegister(ctrlReg3, 0x4B);
00529   
00530   // here we have to double-check if we
00531   // are in 12 or 16bit data modes. The 12
00532   // bit data mode is giving away the 4LSBs
00533   // therefore the register needs to be written
00534   // according to that. 0x3C00 is just below 1g
00535   // but the acc will give 0x03C0, beware!
00536   writeRegister(DD_THSI_L, DD_THSI_L_val);  // threshold L internal
00537   writeRegister(DD_THSI_H, DD_THSI_H_val);  // threshold H internal
00538   writeRegister(DD_THSE_L, DD_THSE_L_val);  // threshold L external
00539   writeRegister(DD_THSE_H, DD_THSE_H_val);  // threshold H external
00540   readRegister(HP_FILTER_RESET);   // config the acc. to get current acceleration as initial val
00541   writeRegister(DD_CFG, directions);  // config accelerometer to wake up 
00542 
00543   // assign the ACC_FREE_FALL mode
00544   AccEventMode |= ACC_DIRECTION;
00545 
00546   // attach the hardware interrupt to the pin
00547   attachInt();
00548 
00549   return flag;
00550 }
00551 

Here is the call graph for this function:

uint8_t WaspACC::setDD ( void   )  [inline]

It sets the Direction Change interrupt using the parameters previously defined.

Parameters:
void 
Returns:
'flag' variable
See also:
setDD(uint8_t directions)

Definition at line 707 of file WaspACC.h.

References DD_CFG_val, and flag.

00707 { setDD(DD_CFG_val); return flag; }

uint8_t WaspACC::unsetDD ( void   ) 

It unsets the Direction Change interrupt.

Parameters:
void 
Returns:
'flag' variable
See also:
setFF()

Definition at line 556 of file WaspACC.cpp.

References ACC_DIRECTION, AccEventMode, DD_ACK, DD_CFG, detachInt(), flag, readRegister(), and writeRegister().

Referenced by setDD().

00556 {
00557 
00558   writeRegister(DD_CFG, 0x00);
00559   readRegister(DD_ACK);  // clear the interrupt flag
00560 
00561   // detach the event if there are no flags active
00562   AccEventMode &= ~(ACC_DIRECTION);
00563   if (!AccEventMode) detachInt();
00564   return flag;
00565 }
00566 

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspACC::getMode (  ) 

It gets the accelerometer's work mode.

Parameters:
void 
Returns:
'accMode' variable
See also:
setMode(uint8_t val)

Definition at line 415 of file WaspACC.cpp.

References accMode.

00415 {
00416   return accMode;
00417 }
00418 

uint8_t WaspACC::setMode ( uint8_t  val  ) 

It sets the accelerometer's work mode.

Parameters:
uint8_t val : the accelerometer's work mode (ACC_ON, ACC_HIBERNATE, ACC_CUSTOM)
Returns:
'0' if no error
See also:
getMode()

Definition at line 433 of file WaspACC.cpp.

References ACC_CUSTOM, ACC_HIBERNATE, ACC_ON, accMode, B00000000, B00000111, B00001000, B01000111, ctrlReg1, ctrlReg2, ctrlReg3, and writeRegister().

Referenced by close(), and ON().

00433 {
00434   accMode = mode;
00435 
00436   if (mode == ACC_HIBERNATE)
00437   {
00438         writeRegister(ctrlReg2,B00000000); // de-activate RDY 
00439         writeRegister(ctrlReg1,B00000111); // turn power off 
00440   }
00441 
00442   if (mode == ACC_ON)
00443   {
00444         writeRegister(ctrlReg2, B00000000);
00445         writeRegister(ctrlReg1, B01000111); // turn power ON
00446         writeRegister(ctrlReg3, B00001000);
00447   }
00448 
00449   if (mode == ACC_CUSTOM)
00450   {
00451         // here the custom mode has to be defined by expert users
00452   }
00453 
00454   // go out with no error, leaves room to implement an error function
00455   return 0;
00456 }
00457 

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspACC::getAccEvent ( void   ) 

It gets the accelerometer's event type.

Parameters:
void 
Returns:
'AccEventMode' variable
See also:
setAccEvent(uint8_t val)

Definition at line 575 of file WaspACC.cpp.

References AccEventMode.

00575 {
00576   return AccEventMode;
00577 }
00578 

uint8_t WaspACC::setAccEvent ( uint8_t  val  ) 

It sets the accelerometer's event type.

Parameters:
uint8_t val : accelerometer's event type (ACC_NONE, ACC_FREE_FALL, ACC_DIRECTION, ACC_THRESHOLD)
Returns:
'0' if no error
See also:
getMode()

Definition at line 590 of file WaspACC.cpp.

References ACC_DIRECTION, ACC_FREE_FALL, ACC_NONE, and AccEventMode.

00590 {
00591   AccEventMode = mode;
00592 
00593   if (mode & ACC_DIRECTION)
00594   {
00595   }
00596 
00597   if (mode == ACC_FREE_FALL)
00598   {
00599   }
00600 
00601   if (mode == ACC_NONE)
00602   {
00603   }
00604 
00605   // go out with no error, leaves room to implement an error function
00606   return 0;
00607 }
00608 

void WaspACC::attachInt ( void   ) 

It configures the specific hardware interrupt for the acc.

Parameters:
void 
Returns:
void
See also:
detachInt()

Definition at line 619 of file WaspACC.cpp.

References ACC_INT, and enableInterrupts().

Referenced by setDD(), and setFF().

00619 {
00620         enableInterrupts(ACC_INT);
00621 }
00622 

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspACC::detachInt ( void   ) 

It unsets the specific hardware interrupt for the acc.

Parameters:
void 
Returns:
void
See also:
attachInt()

Definition at line 627 of file WaspACC.cpp.

References ACC_INT, and disableInterrupts().

Referenced by unsetDD(), and unsetFF().

00627 {
00628   disableInterrupts(ACC_INT);
00629 }
00630 

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspACC::clearAlarmFlag ( void   ) 

It clears the Accelerometer's alarm flag.

Parameters:
void 
Returns:
void

Definition at line 636 of file WaspACC.cpp.

References DD_ACK, DD_CFG, FF_WU_ACK, FF_WU_CFG, readRegister(), and writeRegister().

00636 {
00637         writeRegister(FF_WU_CFG, 0x00);  
00638         readRegister(FF_WU_ACK);  // clear the interrupt flag
00639         
00640         writeRegister(DD_CFG, 0x00);
00641         readRegister(DD_ACK);  // clear the interrupt flag
00642 }
00643 

Here is the call graph for this function:


Field Documentation

uint8_t WaspACC::accMode [private]

Variable : Accelerometer Operation Mode.

Possible values are ACC_ON, ACC_HIBERNATE and ACC_CUSTOM

Definition at line 484 of file WaspACC.h.

Referenced by begin(), getMode(), and setMode().

uint8_t WaspACC::AccEventMode [private]

Variable : Accelerometer Event Mode.

Possible values are ACC_NONE, ACC_FREE_FALL, ACC_DIRECTION, ACC_THRESHOLD

Definition at line 490 of file WaspACC.h.

Referenced by getAccEvent(), setAccEvent(), setDD(), setFF(), unsetDD(), and unsetFF().

volatile uint8_t WaspACC::flag

Variable : status flag, used to see if there has been an error while reading/writing or if there has been a hardware interrupt.

Possible values are ACC_ERROR_READING or ACC_ERROR_WRITING

Definition at line 506 of file WaspACC.h.

Referenced by readRegister(), setDD(), setFF(), unsetDD(), unsetFF(), and writeRegister().

Variable : interrupt flag, used to check which interrupt got active.

Its structure is: (MSB) 7 6 5 4 3 2 1 0 (LSB) XX XX XX XX XX TH DD FF TH - threshold, DD - direction change, FF - free fall

Definition at line 515 of file WaspACC.h.


The documentation for this class was generated from the following files:

Generated on Tue Jul 20 09:31:01 2010 for WaspmoteAPI by  doxygen 1.5.6