source: flair-src/tags/0.3/lib/FlairSensorActuator/src/BatteryMonitor.cpp

Last change on this file was 164, checked in by Sanahuja Guillaume, 7 years ago

batterie

File size: 1.8 KB
Line 
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
24using std::string;
25using namespace flair::core;
26using namespace flair::gui;
27
28namespace flair {
29namespace sensor {
30
31BatteryMonitor::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
39BatteryMonitor::~BatteryMonitor() {}
40
41float BatteryMonitor::GetVoltage(void) const { return batteryvalue; }
42
43bool 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
58void 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
Note: See TracBrowser for help on using the repository browser.