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 | #include <SpinBox.h>
|
---|
23 |
|
---|
24 | using std::string;
|
---|
25 | using namespace flair::core;
|
---|
26 | using namespace flair::gui;
|
---|
27 |
|
---|
28 | namespace flair {
|
---|
29 | namespace sensor {
|
---|
30 |
|
---|
31 | BatteryMonitor::BatteryMonitor(const gui::LayoutPosition *position, string name)
|
---|
32 | : GroupBox(position, name) {
|
---|
33 | battery = new Label(this->NewRow(), "battery");
|
---|
34 | battery_thresh = new DoubleSpinBox(this->LastRowLastCol(), "threshold", " V",0, 24, .1, 1);
|
---|
35 | thresholdTime = new SpinBox(this->LastRowLastCol(), "threshold time", " s",1, 3600, 1, 10);
|
---|
36 | isUnderThershold=false;
|
---|
37 | }
|
---|
38 |
|
---|
39 | BatteryMonitor::~BatteryMonitor() {}
|
---|
40 |
|
---|
41 | float BatteryMonitor::GetVoltage(void) const { return batteryvalue; }
|
---|
42 |
|
---|
43 | bool BatteryMonitor::IsBatteryLow(void) {
|
---|
44 | if (batteryvalue <= battery_thresh->Value() && !isUnderThershold) {
|
---|
45 | isUnderThershold=true;
|
---|
46 | underThersholdStartTime=GetTime();
|
---|
47 | }
|
---|
48 | if (batteryvalue > battery_thresh->Value()) {
|
---|
49 | isUnderThershold=false;
|
---|
50 | }
|
---|
51 | if(isUnderThershold && GetTime() > underThersholdStartTime + (Time)(thresholdTime->Value())*(Time)1000000000) {
|
---|
52 | return true;
|
---|
53 | }
|
---|
54 |
|
---|
55 | return false;
|
---|
56 | }
|
---|
57 |
|
---|
58 | void BatteryMonitor::SetBatteryValue(float value) {
|
---|
59 | batteryvalue = value;
|
---|
60 | if (value > 0) {
|
---|
61 | battery->SetText("battery: %.1fV", value);
|
---|
62 | } else {
|
---|
63 | battery->SetText("battery: unreadable");
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | } // end namespace sensor
|
---|
68 | } // end namespace flair
|
---|