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 | #include "BatteryMonitor.h"
|
---|
19 | #include <Layout.h>
|
---|
20 | #include <Label.h>
|
---|
21 | #include <DoubleSpinBox.h>
|
---|
22 |
|
---|
23 | using std::string;
|
---|
24 | using namespace flair::core;
|
---|
25 | using namespace flair::gui;
|
---|
26 |
|
---|
27 | namespace flair {
|
---|
28 | namespace sensor {
|
---|
29 |
|
---|
30 | BatteryMonitor::BatteryMonitor(const gui::LayoutPosition *position, string name)
|
---|
31 | : GroupBox(position, name) {
|
---|
32 | battery = new Label(this->NewRow(), "battery");
|
---|
33 | battery_thresh = new DoubleSpinBox(this->LastRowLastCol(), "threshold", " V",
|
---|
34 | 0, 24, .1, 1);
|
---|
35 | }
|
---|
36 |
|
---|
37 | BatteryMonitor::~BatteryMonitor() {}
|
---|
38 |
|
---|
39 | float BatteryMonitor::GetVoltage(void) const { return batteryvalue; }
|
---|
40 |
|
---|
41 | bool BatteryMonitor::IsBatteryLow(void) const {
|
---|
42 | if (batteryvalue < battery_thresh->Value())
|
---|
43 | return true;
|
---|
44 | else
|
---|
45 | return false;
|
---|
46 | }
|
---|
47 |
|
---|
48 | void BatteryMonitor::SetBatteryValue(float value) {
|
---|
49 | batteryvalue = value;
|
---|
50 | if (value > 0) {
|
---|
51 | battery->SetText("battery: %.1fV", value);
|
---|
52 | } else {
|
---|
53 | battery->SetText("battery: unreadable");
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | } // end namespace sensor
|
---|
58 | } // end namespace flair
|
---|