xosview  1.23
About: xosview is an X Windows based system monitor (cpu, memory, swap and network usage; interrupt and serial activities; load average).
  Fossies Dox: xosview-1.23.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

btrymeter.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013 by Tomi Tapper ( tomi.o.tapper@student.jyu.fi )
3 //
4 // Based on linux/btrymeter.cc:
5 // Copyright (c) 1997, 2006 by Mike Romberg ( mike.romberg@noaa.gov )
6 //
7 // This file may be distributed under terms of the GPL
8 //
9 
10 #include "btrymeter.h"
11 #include "kernel.h"
12 #include <stdlib.h>
13 
14 
16  : FieldMeter( parent, 2, "BTRY", "CHRG/USED", 1, 1, 0 ) {
17  old_state_ = 255;
18 }
19 
21 }
22 
25 
26  leftcolor_ = parent_->allocColor( parent_->getResource("batteryLeftColor") );
27  usedcolor_ = parent_->allocColor( parent_->getResource("batteryUsedColor") );
28  chargecolor_ = parent_->allocColor( parent_->getResource("batteryChargeColor") );
29  fullcolor_ = parent_->allocColor( parent_->getResource("batteryFullColor") );
30  lowcolor_ = parent_->allocColor( parent_->getResource("batteryLowColor") );
31  critcolor_ = parent_->allocColor( parent_->getResource("batteryCritColor") );
32  nonecolor_ = parent_->allocColor( parent_->getResource("batteryNoneColor") );
33 
36 
37  priority_ = atoi( parent_->getResource("batteryPriority") );
38  SetUsedFormat( parent_->getResource("batteryUsedFormat") );
39 }
40 
41 void BtryMeter::checkevent( void ) {
42  getstats();
43  drawfields();
44 }
45 
46 void BtryMeter::getstats( void ) {
47  int remaining;
48  unsigned int state;
49 
50  BSDGetBatteryInfo(&remaining, &state);
51 
52  if (state != old_state_) {
53  if (state == XOSVIEW_BATT_NONE) { // no battery present
55  legend("NONE/NONE");
56  }
57  else if (state & XOSVIEW_BATT_FULL) { // full battery
59  legend("CHRG/FULL");
60  }
61  else { // present, not full
62  if (state & XOSVIEW_BATT_CRITICAL) // critical charge
64  else if (state & XOSVIEW_BATT_LOW) // low charge
66  else { // above low, below full
67  if (state & XOSVIEW_BATT_CHARGING) // is charging
69  else
71  }
72  // legend tells if charging or discharging
73  if (state & XOSVIEW_BATT_CHARGING)
74  legend("CHRG/AC");
75  else
76  legend("CHRG/USED");
77  }
78  drawlegend();
79  parent_->draw(); // make sure the field changes colour too
80  old_state_ = state;
81  }
82 
83  total_ = 100.0;
84  fields_[0] = remaining;
85  fields_[1] = total_ - remaining;
86  setUsed(fields_[0], total_);
87 }
unsigned long lowcolor_
Definition: btrymeter.h:31
~BtryMeter(void)
Definition: btrymeter.cc:20
BtryMeter(XOSView *parent)
Definition: btrymeter.cc:15
unsigned long usedcolor_
Definition: btrymeter.h:30
void checkevent(void)
Definition: btrymeter.cc:41
unsigned long chargecolor_
Definition: btrymeter.h:30
void getstats(void)
Definition: btrymeter.cc:46
unsigned long leftcolor_
Definition: btrymeter.h:30
unsigned int old_state_
Definition: btrymeter.h:32
unsigned long fullcolor_
Definition: btrymeter.h:30
unsigned long critcolor_
Definition: btrymeter.h:31
void checkResources(void)
Definition: btrymeter.cc:23
unsigned long nonecolor_
Definition: btrymeter.h:31
double total_
Definition: fieldmeter.h:41
virtual void checkResources(void)
Definition: fieldmeter.cc:54
void setfieldcolor(int field, const char *color)
Definition: fieldmeter.cc:108
void drawlegend(void)
Definition: fieldmeter.cc:136
void setUsed(double val, double total)
Definition: fieldmeter.cc:76
virtual void drawfields(int mandatory=0)
Definition: fieldmeter.cc:221
double * fields_
Definition: fieldmeter.h:40
void SetUsedFormat(const char *const str)
Definition: fieldmeter.cc:60
int priority_
Definition: meter.h:54
const char * legend(void)
Definition: meter.h:27
XOSView * parent_
Definition: meter.h:52
void draw(void)
Definition: xosview.cc:302
unsigned long allocColor(const char *name)
Definition: xwin.cc:383
const char * getResource(const char *name)
Definition: xwin.cc:362
#define XOSVIEW_BATT_CHARGING
Definition: defines.h:50
#define XOSVIEW_BATT_NONE
Definition: defines.h:49
#define XOSVIEW_BATT_LOW
Definition: defines.h:53
#define XOSVIEW_BATT_CRITICAL
Definition: defines.h:54
#define XOSVIEW_BATT_FULL
Definition: defines.h:52
void BSDGetBatteryInfo(int *remaining, unsigned int *state)
Definition: kernel.cc:1585