WaspPWR Class Reference

WaspPWR Class. More...

#include <WaspPWR.h>


Public Member Functions

 WaspPWR ()
 class constructor
void setSensorPower (uint8_t type, uint8_t mode)
 It sets ON/OFF 3V3 or 5V switches.
void setWatchdog (uint8_t mode, uint8_t timer)
 It enables or disables watchdog interruption.
void switchesOFF (uint8_t option)
 It switches off the specified Waspmote switches.
void switchesON (uint8_t option)
 It switches on the specified Waspmote switches.
void clearInts ()
 It clears all the captured interrupts to allow new interrupts on that modules.
void sleep (uint8_t option)
 It sets the microcontroller to the lowest consumption sleep mode.
void sleep (uint8_t timer, uint8_t option)
 It sets the microcontroller to the lowest consumption sleep mode enabling the watchdog.
void deepSleep (const char *time2wake, uint8_t offset, uint8_t mode, uint8_t option)
 It sets the microcontroller to the lowest consumption sleep mode enabling RTC interruption.
void hibernate (const char *time2wake, uint8_t offset, uint8_t mode)
 It switches off the general switch enabling RTC interruption.
uint8_t getBatteryLevel ()
 It gets the remaining battery %.
void closeI2C ()
 It closes I2C bus.
void setLowBatteryThreshold (float threshold)
 It inits the value of the digipot used in the battery detector.
void ifHibernate ()
 It checks if Hibernate has generated the reset.

Data Fields

uint8_t IPRA
uint8_t IPRB

Private Member Functions

void setIPF (uint8_t peripheral)
 It sets a certain internal peripheral on.
void resetIPF (uint8_t peripheral)
 It sets a certain internal peripheral off.
uint8_t getIPF ()
 It gets the whole IPR.


Detailed Description

WaspPWR Class.

WaspPWR Class defines all the variables and functions used for managing Waspmote Energy and Power Modes

Definition at line 170 of file WaspPWR.h.


Constructor & Destructor Documentation

WaspPWR::WaspPWR (  ) 

class constructor

It does nothing

Parameters:
void 
Returns:
void

Definition at line 45 of file WaspPWR.cpp.

00046 {
00047   // nothing to do when constructing
00048 }


Member Function Documentation

void WaspPWR::setIPF ( uint8_t  peripheral  )  [private]

It sets a certain internal peripheral on.

Parameters:
uint8_t peripheral : the peripheral to set on
Returns:
void
See also:
resetIPF(uint8_t peripheral), getIPF()

Definition at line 58 of file WaspPWR.cpp.

References intIPRA, IPRA, and setIPF_().

00059 {
00060         setIPF_(peripheral);
00061         intIPRA = IPRA;
00062 }

Here is the call graph for this function:

void WaspPWR::resetIPF ( uint8_t  peripheral  )  [private]

It sets a certain internal peripheral off.

Parameters:
uint8_t peripheral : the peripheral to set off
Returns:
void
See also:
setIPF(uint8_t peripheral), getIPF()

Definition at line 70 of file WaspPWR.cpp.

References intIPRA, IPRA, and resetIPF_().

00071 {
00072         resetIPF_(peripheral);
00073         intIPRA = IPRA;
00074 }

Here is the call graph for this function:

uint8_t WaspPWR::getIPF (  )  [private]

It gets the whole IPR.

Parameters:
void 
Returns:
the IPRA flag
See also:
setIPF(uint8_t peripheral), resetIPF(uint8_t peripheral)

Definition at line 79 of file WaspPWR.cpp.

References intIPRA.

00080 {
00081         return intIPRA;
00082 }

void WaspPWR::setSensorPower ( uint8_t  type,
uint8_t  mode 
)

It sets ON/OFF 3V3 or 5V switches.

Parameters:
uint8_t type : SENS_3V3 or SENS_5V
uint8_t mode : SENS_ON or SENS_OFF
Returns:
void

Definition at line 161 of file WaspPWR.cpp.

References digitalWrite(), HIGH, LOW, OUTPUT, pinMode(), SENS_3V3, SENS_5V, SENS_OFF, SENS_ON, SENS_PW_3V3, and SENS_PW_5V.

00162 {
00163         pinMode(SENS_PW_3V3,OUTPUT);
00164         pinMode(SENS_PW_5V,OUTPUT);
00165         
00166         switch( type )
00167         {
00168                 case SENS_3V3:  if(mode==SENS_ON) digitalWrite(SENS_PW_3V3,HIGH);
00169                 else if(mode==SENS_OFF) digitalWrite(SENS_PW_3V3,LOW);
00170                 break;
00171                 case SENS_5V:   if(mode==SENS_ON) digitalWrite(SENS_PW_5V,HIGH);
00172                 else if(mode==SENS_OFF) digitalWrite(SENS_PW_5V,LOW);
00173                 break;
00174         }
00175 }

Here is the call graph for this function:

void WaspPWR::setWatchdog ( uint8_t  mode,
uint8_t  timer 
)

It enables or disables watchdog interruption.

Parameters:
uint8_t mode : WTD_ON or WTD_OFF
uint8_t timer : WTD_16MS, WTD_32MS, WTD_64MS, WTD_128MS, WTD_250MS, WTD_500MS, WTD_1S, WTD_2S, WTD_4S or WTD_8S
Returns:
void

Definition at line 197 of file WaspPWR.cpp.

References disableInterrupts(), enableInterrupts(), off_watchdog(), setup_watchdog(), WTD_INT, WTD_OFF, and WTD_ON.

Referenced by sleep().

00198 {
00199         if(mode==WTD_ON)
00200         {
00201                 enableInterrupts(WTD_INT);
00202                 setup_watchdog(timer); // set watchdog interrupt to wake up from Sleep Power Down Mode
00203         }
00204         
00205         if(mode==WTD_OFF)
00206         {
00207                 disableInterrupts(WTD_INT);
00208                 off_watchdog();
00209         }
00210 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspPWR::switchesOFF ( uint8_t  option  ) 

It switches off the specified Waspmote switches.

Parameters:
uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF
Returns:
void
See also:
switchesON(uint8_t option)

Definition at line 217 of file WaspPWR.cpp.

References BAT_MONITOR_PW, BAT_OFF, cbi, closeSerial(), digitalWrite(), GPS_PW, LOW, MEM_PW, MUX_PW, OUTPUT, pinMode(), RTC_OFF, RTC_PW, SENS_OFF, SENS_PW_3V3, SENS_PW_5V, SERID_PW, WaspXBee::setMode(), UART0_OFF, UART1_OFF, XBee, and XBEE_OFF.

Referenced by deepSleep(), sleep(), and WaspSensorAgr::sleepAgr().

00218 {
00219         cbi(ADCSRA,ADEN);               // switch Analog to Digital Converter OFF
00220         pinMode(SERID_PW,OUTPUT);
00221         digitalWrite(SERID_PW,LOW);
00222         pinMode(MEM_PW,OUTPUT);
00223         digitalWrite(MEM_PW,LOW);
00224         
00225         if( option & SENS_OFF )
00226         {
00227                 pinMode(SENS_PW_3V3,OUTPUT);
00228                 digitalWrite(SENS_PW_3V3,LOW);  
00229                 pinMode(SENS_PW_5V,OUTPUT);
00230                 digitalWrite(SENS_PW_5V,LOW);
00231         }
00232         
00233         if( option & UART0_OFF )
00234         {
00235                 XBee.setMode(XBEE_OFF);
00236         }
00237         
00238         if( option & UART1_OFF )
00239         {
00240                 closeSerial(1);
00241                 pinMode(MUX_PW, OUTPUT);
00242                 digitalWrite(MUX_PW, LOW);
00243                 pinMode(GPS_PW, OUTPUT);
00244                 digitalWrite(GPS_PW, LOW);
00245 
00246         }
00247         
00248         if( option & RTC_OFF )
00249         {
00250                 pinMode(RTC_PW,OUTPUT);
00251                 digitalWrite(RTC_PW,LOW);
00252                 
00253         }
00254         
00255         if( option & BAT_OFF )
00256         {
00257                 pinMode(BAT_MONITOR_PW,OUTPUT);
00258                 digitalWrite(BAT_MONITOR_PW,LOW);
00259         }       
00260 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspPWR::switchesON ( uint8_t  option  ) 

It switches on the specified Waspmote switches.

Parameters:
uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF
Returns:
void
See also:
switchesOFF(uint8_t option)

Definition at line 267 of file WaspPWR.cpp.

References sbi.

Referenced by deepSleep(), sleep(), and WaspSensorAgr::sleepAgr().

00268 {
00269         sbi(ADCSRA,ADEN);                       // switch Analog to Digital Converter OFF
00270         /*
00271         digitalWrite(SERID_PW,HIGH);
00272         digitalWrite(MEM_PW,HIGH);
00273         
00274         if( option & SENS_OFF )
00275         {
00276                 digitalWrite(SENS_PW_3V3,HIGH); 
00277                 digitalWrite(SENS_PW_5V,HIGH);
00278         }
00279         
00280         if( option & RTC_OFF )
00281         {
00282                 digitalWrite(RTC_PW,HIGH);
00283         }
00284         
00285         if( option & BAT_OFF )
00286         {
00287                 digitalWrite(BAT_MONITOR_PW,HIGH);
00288         }       
00289         */
00290         
00291 }

Here is the caller graph for this function:

void WaspPWR::clearInts (  ) 

It clears all the captured interrupts to allow new interrupts on that modules.

Returns:
void

Definition at line 298 of file WaspPWR.cpp.

References ACC, ACC_INT, BAT_INT, WaspRTC::clearAlarmFlag(), enableInterrupts(), intFlag, RTC, RTC_INT, SENS_INT, WaspACC::setFF(), UART1_INT, and WTD_INT.

00299 {
00300         if( intFlag & ACC_INT )
00301         {
00302                 ACC.setFF();
00303         }
00304         if( intFlag & BAT_INT )
00305         {
00306         }
00307         if( intFlag & RTC_INT ) // hay que mirar si está inicializado el I2C
00308         {
00309                 RTC.clearAlarmFlag();
00310         }
00311         if( intFlag & UART1_INT )
00312         {
00313                 enableInterrupts(UART1_INT);
00314         }
00315         if( intFlag & WTD_INT )
00316         {
00317         }
00318         if( intFlag & SENS_INT )
00319         {
00320         }
00321 }

Here is the call graph for this function:

void WaspPWR::sleep ( uint8_t  option  ) 

It sets the microcontroller to the lowest consumption sleep mode.

Parameters:
uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF
Returns:
void
See also:
sleep(uint8_t timer, uint8_t option), deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option), hibernate(const char* time2wake, uint8_t offset, uint8_t mode)

Definition at line 332 of file WaspPWR.cpp.

References delay(), switchesOFF(), and switchesON().

00333 {
00334         switchesOFF(option);
00335         set_sleep_mode(SLEEP_MODE_PWR_DOWN);
00336         sleep_enable();
00337         delay(10);
00338         sleep_mode();
00339         sleep_disable();
00340         switchesON(option);
00341 }

Here is the call graph for this function:

void WaspPWR::sleep ( uint8_t  timer,
uint8_t  option 
)

It sets the microcontroller to the lowest consumption sleep mode enabling the watchdog.

Parameters:
uint8_t timer : WTD_16MS, WTD_32MS, WTD_64MS, WTD_128MS, WTD_250MS, WTD_500MS, WTD_1S, WTD_2S, WTD_4S or WTD_8S
uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF
Returns:
void
See also:
sleep(uint8_t option), deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option), hibernate(const char* time2wake, uint8_t offset, uint8_t mode)

Definition at line 365 of file WaspPWR.cpp.

References setWatchdog(), switchesOFF(), switchesON(), and WTD_ON.

00366 {
00367         switchesOFF(option);
00368         set_sleep_mode(SLEEP_MODE_PWR_DOWN);
00369         sleep_enable();
00370         
00371         setWatchdog(WTD_ON,timer);
00372         sleep_mode();
00373         sleep_disable();
00374         switchesON(option);
00375         
00376 }

Here is the call graph for this function:

void WaspPWR::deepSleep ( const char *  time2wake,
uint8_t  offset,
uint8_t  mode,
uint8_t  option 
)

It sets the microcontroller to the lowest consumption sleep mode enabling RTC interruption.

Parameters:
const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss"
uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE
uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5
uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF
Returns:
void
See also:
sleep(uint8_t option), sleep(uint8_t timer, uint8_t option), hibernate(const char* time2wake, uint8_t offset, uint8_t mode)

Definition at line 395 of file WaspPWR.cpp.

References WaspRTC::close(), RTC, WaspRTC::setAlarm1(), switchesOFF(), and switchesON().

00396 {
00397         // Set RTC alarme to wake up from Sleep Power Down Mode
00398         RTC.setAlarm1(time2wake,offset,mode);
00399         RTC.close();
00400         switchesOFF(option);
00401         set_sleep_mode(SLEEP_MODE_PWR_DOWN);
00402         sleep_enable();
00403         sleep_mode();
00404         sleep_disable();
00405         switchesON(option);
00406 }

Here is the call graph for this function:

void WaspPWR::hibernate ( const char *  time2wake,
uint8_t  offset,
uint8_t  mode 
)

It switches off the general switch enabling RTC interruption.

Parameters:
const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss"
uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE
uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5
Returns:
void
See also:
sleep(uint8_t option), sleep(uint8_t timer, uint8_t option), deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option)

Definition at line 428 of file WaspPWR.cpp.

References WaspRTC::close(), delay(), digitalWrite(), HIB_ADDR, HIB_VALUE, HIGH, LOW, OUTPUT, pinMode(), RTC, RTC_OFF, RTC_SLEEP, WaspRTC::setAlarm1(), WaspRTC::setMode(), Utils, and WaspUtils::writeEEPROM().

00429 {       
00430         // Set RTC alarme to wake up from Sleep Power Down Mode
00431         RTC.setAlarm1(time2wake,offset,mode);
00432         RTC.close();
00433         RTC.setMode(RTC_OFF);
00434         
00435         Utils.writeEEPROM(HIB_ADDR,HIB_VALUE);
00436         
00437         pinMode(RTC_SLEEP,OUTPUT);
00438         digitalWrite(RTC_SLEEP,HIGH);
00439         delay(18);
00440         digitalWrite(RTC_SLEEP,LOW);
00441         
00442         // To avoid executing any other function after calling hibernate
00443         while(1);
00444 }

Here is the call graph for this function:

uint8_t WaspPWR::getBatteryLevel (  ) 

It gets the remaining battery %.

Returns:
the remaining battery %

Definition at line 456 of file WaspPWR.cpp.

References analogRead(), BAT_MAX, BAT_MIN, BAT_MONITOR_PW, digitalWrite(), HIGH, LOW, OUTPUT, and pinMode().

00457 {
00458         float aux=0;
00459         uint8_t resul=0;
00460         pinMode(BAT_MONITOR_PW,OUTPUT);
00461         digitalWrite(BAT_MONITOR_PW,HIGH);
00462         aux=analogRead(0);
00463         // it gives a value 1024 for +3V3
00464         // a resistor bridge is put to down max +4V2 battery level around +2V07 on 100% battery charge
00465         // minimum value for good battery +1V5, so with resistor bridge is set to +0V75
00466         // values are from 204 to 567
00467         if(aux<BAT_MIN) aux=0;
00468         else aux=((aux-BAT_MIN)/(BAT_MAX-BAT_MIN))*100;
00469         resul=(uint8_t) aux;
00470         digitalWrite(BAT_MONITOR_PW,LOW);
00471         return resul;
00472 }

Here is the call graph for this function:

void WaspPWR::closeI2C (  ) 

void WaspPWR::setLowBatteryThreshold ( float  threshold  ) 

It inits the value of the digipot used in the battery detector.

Parameters:
float threshold : threshold to init the battery detector (from 3V to 3.4V)
Returns:
void

Definition at line 489 of file WaspPWR.cpp.

References TwoWire::begin(), TwoWire::beginTransmission(), closeI2C(), delay(), TwoWire::endTransmission(), TwoWire::send(), and Wire.

00490 {
00491         uint8_t dig=0;
00492         uint8_t rpot=200;
00493         dig = uint8_t (rpot-(((threshold-1.15)*470/1.15)-806))*255/rpot;
00494         Wire.begin();
00495         delay(200);
00496         Wire.beginTransmission(0x2d);    // Address
00497         Wire.send(0x11);                 // Write command
00498         Wire.send(dig);                 // Data
00499         Wire.endTransmission();
00500         closeI2C();
00501 } 

Here is the call graph for this function:

void WaspPWR::ifHibernate (  ) 

It checks if Hibernate has generated the reset.

Returns:
void

Definition at line 504 of file WaspPWR.cpp.

References delay(), digitalRead(), digitalWrite(), HIB_ADDR, HIB_INT, HIB_VALUE, HIGH, intFlag, LOW, OUTPUT, pinMode(), WaspUtils::readEEPROM(), RST_RTC, RTC_INT_PIN_MON, Utils, and WaspUtils::writeEEPROM().

00505 {
00506         if( digitalRead(RTC_INT_PIN_MON) && (Utils.readEEPROM(HIB_ADDR)==HIB_VALUE) )
00507         {
00508                 intFlag |= HIB_INT;
00509         }
00510         Utils.writeEEPROM(HIB_ADDR,0);
00511         if( !(intFlag & HIB_INT) )
00512         {
00513                 pinMode(RST_RTC, OUTPUT);
00514                 digitalWrite(RST_RTC, HIGH);
00515                 delay(10);
00516                 digitalWrite(RST_RTC, LOW);
00517         }
00518 }

Here is the call graph for this function:


Field Documentation

uint8_t WaspPWR::IPRA

Definition at line 200 of file WaspPWR.h.

Referenced by resetIPF(), and setIPF().

uint8_t WaspPWR::IPRB

Definition at line 201 of file WaspPWR.h.


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

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