source: flair-src/trunk/lib/FlairSensorActuator/src/BatteryMonitor.cpp

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

batterie

File size: 1.8 KB
RevLine 
[3]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[3]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>
[164]22#include <SpinBox.h>
[3]23
24using std::string;
25using namespace flair::core;
26using namespace flair::gui;
27
[15]28namespace flair {
29namespace sensor {
[3]30
[15]31BatteryMonitor::BatteryMonitor(const gui::LayoutPosition *position, string name)
32    : GroupBox(position, name) {
33  battery = new Label(this->NewRow(), "battery");
[164]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;
[3]37}
38
[15]39BatteryMonitor::~BatteryMonitor() {}
[3]40
[15]41float BatteryMonitor::GetVoltage(void) const { return batteryvalue; }
[3]42
[164]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) {
[15]52    return true;
[164]53  }
54   
55  return false;
[3]56}
57
58void BatteryMonitor::SetBatteryValue(float value) {
[15]59  batteryvalue = value;
60  if (value > 0) {
61    battery->SetText("battery: %.1fV", value);
62  } else {
63    battery->SetText("battery: unreadable");
64  }
[3]65}
66
67} // end namespace sensor
68} // end namespace flair
Note: See TracBrowser for help on using the repository browser.