00001
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
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 class BatteryCheckControl : public ControlBase, public EventListener {
00025 public:
00026
00027
00028 BatteryCheckControl() : ControlBase("Battery Check","Reports % power remaining, and gives details on console") {}
00029
00030
00031 virtual ~BatteryCheckControl() {}
00032
00033
00034
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
00041 virtual void pause() {
00042 erouter->forgetListener(this);
00043 display_id=MotionManager::invalid_MC_ID;
00044 }
00045
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
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
00063 virtual void deactivate() {
00064 erouter->forgetListener(this);
00065 display_id=MotionManager::invalid_MC_ID;
00066 }
00067
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
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
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 #endif