7 #define _USE_MATH_DEFINES
16#include <QGraphicsPixmapItem>
40void MainWindow::updateMain()
53 sprintf(buff,
"%s", info.c_str());
61 yError(
"TIMEOUT: unable to receive data from battery manager ");
65 scene->setSceneRect(0, 0, 200, 180);
74 if (connected && charge > 12)
76 QRect rect(0, 0, 200, 180);
77 QPixmap qpm = img_background1.copy(rect);
78 QGraphicsPixmapItem *p1 =
scene->addPixmap(qpm);
84 QRect rect(0, 0, 200, 180);
85 QPixmap qpm = img_background2.copy(rect);
86 QGraphicsPixmapItem *p1 =
scene->addPixmap(qpm);
95 QRect rect(0, 8, 48, 8);
96 QPixmap qpm = img_charge.copy(rect);
97 QGraphicsPixmapItem *p1 =
scene->addPixmap(qpm);
103 QRect rect(0, 0, 48, 8);
104 QPixmap qpm = img_charge.copy(rect);
105 QGraphicsPixmapItem *p1 =
scene->addPixmap(qpm);
113 QRect rect0(0, 0, 14, 7);
114 QRect rect1(0, 15, 14, 7);
115 QRect rect2(0, 30, 14, 7);
116 QPixmap qpm0 = img_blocks.copy(rect0);
117 QPixmap qpm1 = img_blocks.copy(rect1);
118 QPixmap qpm2 = img_blocks.copy(rect2);
119 QPixmap* qpp = &qpm2;
120 int n_blocks = int(charge * 11 / 100.0);
121 for (
int i = 0; i < n_blocks; i++)
123 if (current < -0.3) {
130 int ypos = 135 - i * 6;
132 QGraphicsPixmapItem *p1 =
scene->addPixmap(*qpp);
134 p1->setPos(xpos, ypos);
141 sprintf(buff,
"%4.1f", voltage);
142 int len = strlen(buff);
144 for (
int i = 0; i < len; i++)
146 if (buff[i] ==
'.') {
149 if (buff[i] >=
'0' && buff[i] <=
'9')
151 QRect rect((buff[i] -
'0') * 29, 0, 29, 52);
152 QPixmap qpm = img_numbers.copy(rect);
153 QGraphicsPixmapItem *p1 =
scene->addPixmap(qpm);
155 p1->setPos(19 + i * 29 - point_off, 21);
163 sprintf(buff,
"%4.1f", fabs(current));
164 int len = strlen(buff);
166 for (
int i = 0; i < len; i++)
168 if (buff[i] ==
'.') {
171 if (buff[i] >=
'0' && buff[i] <=
'9')
173 QRect rect((buff[i] -
'0') * 29, 0, 29, 52);
174 QPixmap qpm = img_numbers.copy(rect);
175 QGraphicsPixmapItem *p1 =
scene->addPixmap(qpm);
177 p1->setPos(19 + i * 29 - point_off, 88);
181 ui->graphicsView->setScene(
scene);
191 enable_ask_info(false),
197 mainTimer =
new QTimer(
this);
198 connect(mainTimer,
SIGNAL(timeout()),
this, SLOT(updateMain()));
199 mainTimer->start(1000*refresh_period);
203 this->setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);
207 bool ret_load =
true;
208 ret_load &= img_background1.load(
":/images/background.bmp");
209 ret_load &= img_background2.load(
":/images/background2.bmp");
210 ret_load &= img_blocks.load(
":/images/batt_blocks.bmp");
211 ret_load &= img_charge.load(
":/images/charge.bmp");
212 ret_load &= img_numbers.load(
":/images/numbers.bmp");
213 if (ret_load ==
false)
215 yError(
"Failed loading graphics");
218 img_blocks.setMask(img_blocks.createMaskFromColor(QColor(255,0,255)));
219 img_charge.setMask(img_charge.createMaskFromColor(QColor(255, 0, 255)));
220 img_numbers.setMask(img_numbers.createMaskFromColor(QColor(255, 0, 255)));
222 scene =
new QGraphicsScene;
223 QTimer::singleShot(0,
this, &MainWindow::updateMain);
int SIGNAL(int pid, int signum)
yarp::dev::IBattery * ibat
MainWindow(const yarp::os::ResourceFinder &rf, yarp::dev::IBattery *ibat, QWidget *parent=0, double refresh_period=10.0)
A generic battery interface.
virtual yarp::dev::ReturnValue getBatteryInfo(std::string &battery_info)=0
get the battery hardware characteristics (e.g.
virtual yarp::dev::ReturnValue getBatteryCharge(double &charge)=0
get the battery status of charge
virtual yarp::dev::ReturnValue getBatteryCurrent(double ¤t)=0
Get the instantaneous current measurement.
virtual yarp::dev::ReturnValue getBatteryVoltage(double &voltage)=0
Get the instantaneous voltage measurement.
Helper class for finding config files and other external resources.