Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

BatteryCheckControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_BatteryCheckControl_h_
00003 #define INCLUDED_BatteryCheckControl_h_
00004 
00005 #include "ControlBase.h"
00006 #include "Shared/WorldState.h"
00007 #include "Motion/MMAccessor.h"
00008 #include "Motion/LedMC.h"
00009 #include "NullControl.h"
00010 
00011 //! when activated, this will print a battery report to stdout and light up LEDs to specify power level
00012 /*! The LEDs use the LedEngine::displayPercent() function, with minor/major style.  This means
00013  *  the left column (viewing the dog head on) will show the overall power level, and the
00014  *  right column will show the level within the tick lit up in the left column.  The more geeky
00015  *  among you may prefer to think of this as a two digit base 5 display.
00016  *
00017  *  This gives you pretty precise visual feedback as to remaining power (perhaps more than
00018  *  you really need, but it's as much a demo as a useful tool)
00019  *
00020  *  This is implemented as a Control instead of a Behavior on the assumption you
00021  *  wouldn't want to leave this running while you were doing other things (ie not
00022  *  in e-stop). But it definitely blurs the line between the two.
00023  */
00024 class BatteryCheckControl : public ControlBase, public EventListener {
00025 public:
00026 
00027   //!Constructor
00028   BatteryCheckControl() : ControlBase("Battery Check","Reports % power remaining, and gives details on console") {}
00029 
00030   //!Destructor
00031   virtual ~BatteryCheckControl() {}
00032 
00033   //!Prints a report to stdio and lights up the face to show battery level
00034   /*! keeps running until deactivated - will listen for power events and continue to update display */
00035   virtual ControlBase * activate(MotionManager::MC_ID display, Socket * gui) {
00036     cout << "Press the \"back\" button to leave battery display" << endl;
00037     erouter->addListener(this,EventBase::powerEGID);
00038     return ControlBase::activate(display,gui);
00039   }
00040   //! stops listening for power events and sets display to invalid
00041   virtual void pause() {
00042     erouter->forgetListener(this);
00043     display_id=MotionManager::invalid_MC_ID;
00044   }
00045   //! calls report()
00046   virtual void refresh() {
00047     report();
00048     if(gui_comm!=NULL && wireless->isConnected(gui_comm->sock)) {
00049       char tmp[20];
00050       sprintf(tmp,"%d",(unsigned int)(state->sensors[PowerRemainOffset]*100));
00051       //    pushSlot(new NullControl(std::string("Power remain: ")+tmp+std::string("%"),"See console output for details"));
00052       std::string s("refresh\n");
00053       s+=getName()+"\n1\n0\n0\nPower remain: ";
00054       s+=tmp;
00055       s+="%\nSee console output for details\n";
00056       s+="status\nPower remaining: ";
00057       s+=tmp;
00058       s+="%\n";
00059       gui_comm->write((const byte*)s.c_str(),s.size());
00060     }
00061   }
00062   //! stops listening for power events and sets display to invalid
00063   virtual void deactivate() {
00064     erouter->forgetListener(this);
00065     display_id=MotionManager::invalid_MC_ID;
00066   }
00067   //! calls refresh() to redisplay with new information if it's not a vibration event
00068   virtual void processEvent(const EventBase& event) {
00069     if(event.getSourceID()!=PowerSourceID::VibrationSID)
00070       refresh();
00071   }
00072   virtual ControlBase * doSelect() {
00073     return this;
00074   }
00075   //! redisplay text to cout and refresh LED values
00076   void report() {
00077     cout << "BATTERY REPORT:" << endl;
00078     cout << "\tPower Remain:\t" << (int)(state->sensors[PowerRemainOffset]*100) << "%" << endl;
00079     cout << "\tCapacity:\t" << state->sensors[PowerCapacityOffset] << endl;
00080     cout << "\tVoltage:\t" << state->sensors[PowerVoltageOffset] << endl;
00081     cout << "\tCurrent:\t" << state->sensors[PowerCurrentOffset] << endl;
00082     cout << "\tTemp:\t" << state->sensors[PowerThermoOffset] << endl;
00083     cout << "\tFlags:\t";
00084     if(state->powerFlags[PowerSourceID::BatteryConnectSID])
00085       cout << "BatteryConnect ";
00086     if(state->powerFlags[PowerSourceID::DischargingSID])
00087       cout << "Discharging ";
00088     if(state->powerFlags[PowerSourceID::ChargingSID])
00089       cout << "Charging ";
00090     if(state->powerFlags[PowerSourceID::ExternalPowerSID])
00091       cout << "ExternalPower ";
00092     if(state->powerFlags[PowerSourceID::PowerGoodSID])
00093       cout << "PowerGood ";
00094     if(state->powerFlags[PowerSourceID::LowPowerWarnSID])
00095       cout << "LowPowerWarn ";
00096     if(state->powerFlags[PowerSourceID::BatteryEmptySID])
00097       cout << "BatteryEmpty ";
00098     cout << endl;
00099     if(display_id!=MotionManager::invalid_MC_ID) {
00100       MMAccessor<LedMC> disp(display_id);
00101       disp->displayPercent(state->sensors[PowerRemainOffset],LedEngine::major,LedEngine::major);
00102     }
00103   }
00104 
00105 };
00106 
00107 /*! @file
00108  * @brief Defines BatteryCheckControl, which will spew a power report to stdout upon activation
00109  * @author ejt (Creator)
00110  *
00111  * $Author: ejt $
00112  * $Name: tekkotsu-1_4_1 $
00113  * $Revision: 1.4 $
00114  * $State: Exp $
00115  * $Date: 2003/06/09 08:05:12 $
00116  */
00117 
00118 #endif

Tekkotsu v1.4
Generated Sat Jul 19 00:06:29 2003 by Doxygen 1.3.2