1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2014/01/24
|
---|
6 | // filename: BatteryMonitor.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Base class for battery monitor
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 |
|
---|
19 | #include "BatteryMonitor.h"
|
---|
20 | #include <Layout.h>
|
---|
21 | #include <Label.h>
|
---|
22 | #include <DoubleSpinBox.h>
|
---|
23 |
|
---|
24 | using std::string;
|
---|
25 | using namespace flair::core;
|
---|
26 | using namespace flair::gui;
|
---|
27 |
|
---|
28 | namespace flair { namespace sensor {
|
---|
29 |
|
---|
30 | BatteryMonitor::BatteryMonitor(const gui::LayoutPosition* position,string name) : GroupBox(position,name) {
|
---|
31 | battery=new Label(this->NewRow(),"battery");
|
---|
32 | battery_thresh=new DoubleSpinBox(this->LastRowLastCol(),"threshold"," V",0,24,.1,1);
|
---|
33 | }
|
---|
34 |
|
---|
35 | BatteryMonitor::~BatteryMonitor() {
|
---|
36 |
|
---|
37 | }
|
---|
38 |
|
---|
39 | float BatteryMonitor::GetVoltage(void) const {
|
---|
40 | return batteryvalue;
|
---|
41 | }
|
---|
42 |
|
---|
43 | bool BatteryMonitor::IsBatteryLow(void) const {
|
---|
44 | if(batteryvalue<battery_thresh->Value())
|
---|
45 | return true;
|
---|
46 | else
|
---|
47 | return false;
|
---|
48 | }
|
---|
49 |
|
---|
50 | void BatteryMonitor::SetBatteryValue(float value) {
|
---|
51 | batteryvalue=value;
|
---|
52 | if(value>0) {
|
---|
53 | battery->SetText("battery: %.1fV",value);
|
---|
54 | } else {
|
---|
55 | battery->SetText("battery: unreadable");
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | } // end namespace sensor
|
---|
60 | } // end namespace flair
|
---|