Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BatteryCheckControl.cc

Go to the documentation of this file.
00001 #include "Shared/RobotInfo.h"
00002 #ifdef TGT_HAS_POWER_STATUS
00003 
00004 #include "BatteryCheckControl.h"
00005 #include "Shared/WorldState.h"
00006 #include "Motion/MMAccessor.h"
00007 #include "Motion/LedMC.h"
00008 #include "NullControl.h"
00009 #include "Events/EventRouter.h"
00010 #include "Wireless/Wireless.h"
00011 
00012 ControlBase * BatteryCheckControl::activate(MC_ID display, Socket * gui) {
00013   erouter->addListener(this,EventBase::powerEGID);
00014   return ControlBase::activate(display,gui);
00015 }
00016 
00017 void BatteryCheckControl::pause() {
00018   erouter->removeListener(this);
00019   display_id=invalid_MC_ID;
00020 }
00021 
00022 void BatteryCheckControl::refresh() {
00023   report();
00024   if(gui_comm!=NULL && wireless->isConnected(gui_comm->sock)) {
00025     char tmp[20];
00026     sprintf(tmp,"%d",(unsigned int)(state->sensors[PowerRemainOffset]*100));
00027     //    pushSlot(new NullControl(std::string("Power remain: ")+tmp+std::string("%"),"See console output for details"));
00028     std::string s("refresh\n");
00029     s+=getName()+"\n1\n0\n0\nPower remain: ";
00030     s+=tmp;
00031     s+="%\n0\nSee console output for details\n";
00032     s+="status\n1\nPower remaining: ";
00033     s+=tmp;
00034     s+="%\n";
00035     gui_comm->write((const byte*)s.c_str(),s.size());
00036   }
00037 }
00038 
00039 void BatteryCheckControl::deactivate() {
00040   erouter->removeListener(this);
00041   display_id=invalid_MC_ID;
00042 }
00043 
00044 void BatteryCheckControl::processEvent(const EventBase& event) {
00045   if(event.getSourceID()!=PowerSrcID::VibrationSID)
00046     refresh();
00047 }
00048 
00049 void BatteryCheckControl::report() {
00050   unsigned int tmp;
00051   sout->printf("BATTERY REPORT:\n");
00052   
00053   tmp = capabilities.findSensorOffset("PowerRemain");
00054   if(tmp!=-1U)
00055     sout->printf("\tPower Remain:\t%d%%\n",(int)(state->sensors[tmp]*100));
00056   
00057   tmp = capabilities.findSensorOffset("PowerCapacity");
00058   if(tmp!=-1U)
00059     sout->printf("\tCapacity:\t%g\n",state->sensors[tmp]);
00060   
00061   tmp = capabilities.findSensorOffset("PowerVoltage");
00062   if(tmp!=-1U)
00063     sout->printf("\tVoltage:\t%g\n",state->sensors[tmp]);
00064   
00065   tmp = capabilities.findSensorOffset("PowerCurrent");
00066   if(tmp!=-1U)
00067     sout->printf("\tCurrent:\t%g\n",state->sensors[tmp]);
00068   
00069   tmp = capabilities.findSensorOffset("PowerThermo");
00070   if(tmp!=-1U)
00071     sout->printf("\tTemperature:\t%g\n",state->sensors[tmp]);
00072   
00073   sout->printf("\tFlags:\t");
00074   if(state->powerFlags[PowerSrcID::BatteryConnectSID])
00075     sout->printf("BatteryConnect ");
00076   if(state->powerFlags[PowerSrcID::DischargingSID])
00077     sout->printf("Discharging ");
00078   if(state->powerFlags[PowerSrcID::ChargingSID])
00079     sout->printf("Charging ");
00080   if(state->powerFlags[PowerSrcID::ExternalPowerSID])
00081     sout->printf("ExternalPower ");
00082   if(state->powerFlags[PowerSrcID::PowerGoodSID])
00083     sout->printf("PowerGood ");
00084   if(state->powerFlags[PowerSrcID::LowPowerWarnSID])
00085     sout->printf("LowPowerWarn ");
00086   if(state->powerFlags[PowerSrcID::BatteryEmptySID])
00087     sout->printf("BatteryEmpty ");
00088   sout->printf("\n");
00089   
00090   tmp = capabilities.findSensorOffset("PowerRemain");
00091   if(tmp!=-1U && display_id!=invalid_MC_ID) {
00092     MMAccessor<LedMC> disp(display_id);
00093     disp->displayPercent(state->sensors[tmp],LedEngine::major,LedEngine::major);
00094   }
00095 }
00096 
00097 REGISTER_CONTROL(BatteryCheckControl,"Status Reports");
00098 
00099 #endif
00100 
00101 /*! @file
00102  * @brief Implements BatteryCheckControl, which will spew a power report to stdout upon activation
00103  * @author ejt (Creator)
00104  */

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:36 2016 by Doxygen 1.6.3