src/DetailFermenter.cpp

changeset 489
4db768aea3df
parent 415
dd4ab5c2a8e5
child 492
c3a781b4d35b
equal deleted inserted replaced
488:dc3091338f9b 489:4db768aea3df
30 30
31 DetailFermenter::DetailFermenter(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailFermenter) 31 DetailFermenter::DetailFermenter(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailFermenter)
32 { 32 {
33 QSqlQuery query; 33 QSqlQuery query;
34 34
35 qDebug() << "DetailFermenter record:" << id;
36 ui->setupUi(this); 35 ui->setupUi(this);
37 this->recno = id; 36 this->recno = id;
38 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); 37 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
39 setWindowTitle(tr("BMSapp - Details Fermenter")); 38 setWindowTitle(tr("BMSapp - Details Fermenter"));
40 39
86 connect(ui->modeButton2, SIGNAL(clicked()), this, SLOT(button2_pressed())); 85 connect(ui->modeButton2, SIGNAL(clicked()), this, SLOT(button2_pressed()));
87 connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::mode_changed); 86 connect(ui->modeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::mode_changed);
88 connect(ui->stageEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::stage_changed); 87 connect(ui->stageEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::stage_changed);
89 connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::code_changed); 88 connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::code_changed);
90 connect(ui->profilePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::profile_changed); 89 connect(ui->profilePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::profile_changed);
91 connect(ui->logButton, SIGNAL(clicked()), this, SLOT(on_ChartButton_clicked()));
92 connect(ui->camButton, SIGNAL(clicked()), this, SLOT(on_WebcamButton_clicked()));
93 connect(parent, SIGNAL(updateFermenter(QString)), this, SLOT(refreshFermenter(QString))); 90 connect(parent, SIGNAL(updateFermenter(QString)), this, SLOT(refreshFermenter(QString)));
94 emit refreshTable(); 91 emit refreshTable();
95 } 92 }
96 93
97 94
188 ui->codePick->hide(); 185 ui->codePick->hide();
189 } 186 }
190 ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false); 187 ui->alarmLED->setChecked((query.value("alarm").toInt() != 0) ? true:false);
191 188
192 ui->tempsetBox->show(); 189 ui->tempsetBox->show();
193 if ((query.value("mode").toString() == "FRIDGE") || (query.value("mode").toString() == "BEER")) { 190 if ((query.value("mode").toString() == "OFF") || (query.value("mode").toString() == "NONE")) {
194 ui->loEdit->setReadOnly(false); 191 ui->loEdit->hide();
195 ui->loEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows); 192 ui->loLabel->hide();
196 ui->hiEdit->setReadOnly(false); 193 ui->hiEdit->hide();
197 ui->hiEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows); 194 ui->hiLabel->hide();
198 } else { 195 } else {
199 ui->loEdit->setReadOnly(true); 196 ui->loEdit->show();
200 ui->loEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); 197 ui->loLabel->show();
201 ui->hiEdit->setReadOnly(true); 198 ui->hiEdit->show();
202 ui->hiEdit->setButtonSymbols(QAbstractSpinBox::NoButtons); 199 ui->hiLabel->show();
203 } 200 if ((query.value("mode").toString() == "FRIDGE") || (query.value("mode").toString() == "BEER")) {
204 lo_set = query.value("setpoint_low").toDouble(); 201 ui->loEdit->setReadOnly(false);
205 hi_set = query.value("setpoint_high").toDouble(); 202 ui->loEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows);
206 ui->loEdit->setValue(lo_set); 203 ui->hiEdit->setReadOnly(false);
207 ui->hiEdit->setValue(hi_set); 204 ui->hiEdit->setButtonSymbols(QAbstractSpinBox::UpDownArrows);
205 } else {
206 ui->loEdit->setReadOnly(true);
207 ui->loEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
208 ui->hiEdit->setReadOnly(true);
209 ui->hiEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
210 }
211 lo_set = query.value("setpoint_low").toDouble();
212 hi_set = query.value("setpoint_high").toDouble();
213 ui->loEdit->setValue(lo_set);
214 ui->hiEdit->setValue(hi_set);
215 }
208 216
209 ui->switchBox->show(); 217 ui->switchBox->show();
210 ui->heatLED->setChecked((query.value("heater_state").toInt() != 0) ? true:false); 218 if (query.value("heater_address").toString().length() == 36) {
211 ui->coolLED->setChecked((query.value("cooler_state").toInt() != 0) ? true:false); 219 ui->heatLED->show();
212 ui->fanLED->setChecked((query.value("fan_state").toInt() != 0) ? true:false); 220 ui->heatLabel->show();
213 221 ui->heatLED->setChecked((query.value("heater_state").toInt() != 0) ? true:false);
214 if (query.value("mode").toString() == "NONE") { 222 if (query.value("mode").toString() == "NONE") {
215 ui->heatSwitch->show(); 223 ui->heatSwitch->show();
216 ui->coolSwitch->show(); 224 heat_state = (query.value("heater_state").toInt()) ? true:false;
217 ui->fanSwitch->show(); 225 ui->heatSwitch->setChecked(heat_state);
218 heat_state = (query.value("heater_state").toInt()) ? true:false; 226 } else {
219 cool_state = (query.value("cooler_state").toInt()) ? true:false; 227 ui->heatSwitch->hide();
220 fan_state = (query.value("fan_state").toInt()) ? true:false; 228 heat_state = false;
221 ui->heatSwitch->setChecked(heat_state); 229 }
222 ui->coolSwitch->setChecked(cool_state); 230 } else {
223 ui->fanSwitch->setChecked(fan_state); 231 ui->heatLED->hide();
224 // Copy state values to variables and set the switches. 232 ui->heatLabel->hide();
225 } else {
226 ui->heatSwitch->hide(); 233 ui->heatSwitch->hide();
227 ui->coolSwitch->hide(); 234 }
228 ui->fanSwitch->hide(); 235 if (query.value("cooler_address").toString().length() == 36) {
229 heat_state = cool_state = fan_state = false; 236 ui->coolLED->show();
237 ui->coolLabel->show();
238 ui->coolLED->setChecked((query.value("cooler_state").toInt() != 0) ? true:false);
239 if (query.value("mode").toString() == "NONE") {
240 ui->coolSwitch->show();
241 cool_state = (query.value("cooler_state").toInt()) ? true:false;
242 ui->coolSwitch->setChecked(cool_state);
243 } else {
244 ui->coolSwitch->hide();
245 cool_state = false;
246 }
247 } else {
248 ui->coolLED->hide();
249 ui->coolLabel->hide();
250 ui->coolSwitch->hide();
251 }
252 if (query.value("fan_address").toString().length() == 36) {
253 ui->fanLED->show();
254 ui->fanLabel->show();
255 ui->fanLED->setChecked((query.value("fan_state").toInt() != 0) ? true:false);
256 if (query.value("mode").toString() == "NONE") {
257 ui->fanSwitch->show();
258 fan_state = (query.value("fan_state").toInt()) ? true:false;
259 ui->fanSwitch->setChecked(fan_state);
260 } else {
261 ui->fanSwitch->hide();
262 fan_state = false;
263 }
264 } else {
265 ui->fanLED->hide();
266 ui->fanLabel->hide();
267 ui->fanSwitch->hide();
230 } 268 }
231 269
232 if (query.value("profile_name").toString() == "") { 270 if (query.value("profile_name").toString() == "") {
233 qobject_cast<QStandardItemModel*>(ui->modeEdit->model())->item(4)->setEnabled(false); 271 qobject_cast<QStandardItemModel*>(ui->modeEdit->model())->item(4)->setEnabled(false);
234 } else { 272 } else {
289 } else { 327 } else {
290 ui->camButton->show(); 328 ui->camButton->show();
291 } 329 }
292 330
293 ui->thermoBox->show(); 331 ui->thermoBox->show();
294 if (query.value("air_state").toString() == "OK") { 332 if (query.value("air_address").toString().length() == 36) {
295 ui->airThermo->setValue(query.value("air_temperature").toDouble()); 333 ui->airThermo->show();
296 } 334 ui->airLabel->show();
297 if (query.value("beer_state").toString() == "OK") { 335 if (query.value("air_state").toString() == "OK") {
298 ui->beerThermo->setValue(query.value("beer_temperature").toDouble()); 336 ui->airThermo->setValue(query.value("air_temperature").toDouble());
299 } 337 }
300 if (query.value("chiller_state").toString() == "OK") { 338 } else {
301 ui->chillerThermo->setValue(query.value("chiller_temperature").toDouble()); 339 ui->airThermo->hide();
340 ui->airLabel->hide();
341 }
342 if (query.value("beer_address").toString().length() == 36) {
343 ui->beerThermo->show();
344 ui->beerLabel->show();
345 if (query.value("beer_state").toString() == "OK") {
346 ui->beerThermo->setValue(query.value("beer_temperature").toDouble());
347 }
348 } else {
349 ui->beerThermo->hide();
350 ui->beerLabel->hide();
351 }
352 if (query.value("chiller_address").toString().length() == 36) {
353 ui->chillerThermo->show();
354 ui->chillerLabel->show();
355 if (query.value("chiller_state").toString() == "OK") {
356 ui->chillerThermo->setValue(query.value("chiller_temperature").toDouble());
357 }
358 } else {
359 ui->chillerThermo->hide();
360 ui->chillerLabel->hide();
302 } 361 }
303 362
304 } else { 363 } else {
305 /* Offline */ 364 /* Offline */
306 ui->statusEdit->setText(tr("Offline")); 365 ui->statusEdit->setText(tr("Offline"));
320 ui->switchBox->hide(); 379 ui->switchBox->hide();
321 ui->camButton->hide(); 380 ui->camButton->hide();
322 ui->logButton->hide(); 381 ui->logButton->hide();
323 } 382 }
324 } 383 }
325
326 } 384 }
327 385
328 386
329 DetailFermenter::~DetailFermenter() 387 DetailFermenter::~DetailFermenter()
330 { 388 {
331 qDebug() << "DetailFermenter done";
332 delete ui; 389 delete ui;
333 emit entry_changed(); 390 emit entry_changed();
334 } 391 }
335 392
336 393
344 emit refreshTable(); 401 emit refreshTable();
345 } 402 }
346 } 403 }
347 404
348 405
349 void DetailFermenter::on_ChartButton_clicked() 406 void DetailFermenter::on_logButton_clicked()
350 { 407 {
351 ChartFermenter dialog(_beercode, _beername, this); 408 ChartFermenter dialog(_beercode, _beername, this);
352 } 409 }
353 410
354 411
355 void DetailFermenter::on_WebcamButton_clicked() 412 void DetailFermenter::on_camButton_clicked()
356 { 413 {
357 QString msg = QString("{\"device\":\"fermenters\",\"node\":\""+_node+"\",\"unit\":\""+_alias+"\",\"light_state\":100}"); 414 if (_webcam_light) {
358 webSocket->sendTextMessage(msg); 415 QString msg = QString("{\"device\":\"fermenters\",\"node\":\""+_node+"\",\"unit\":\""+_alias+"\",\"light_state\":100}");
416 webSocket->sendTextMessage(msg);
417 }
359 Webcam dialog(_webcam_url, this); 418 Webcam dialog(_webcam_url, this);
360 } 419 }
361 420
362 421
363 void DetailFermenter::on_quitButton_clicked() 422 void DetailFermenter::on_quitButton_clicked()
395 454
396 void DetailFermenter::send_switches() 455 void DetailFermenter::send_switches()
397 { 456 {
398 QString msg=QString("{\"device\":\"fermenters\",\"node\":\""+_node+"\",\"unit\":\""+_alias+"\",\"heater_state\":%1,\"cooler_state\":%2,\"fan_state\":%3}") 457 QString msg=QString("{\"device\":\"fermenters\",\"node\":\""+_node+"\",\"unit\":\""+_alias+"\",\"heater_state\":%1,\"cooler_state\":%2,\"fan_state\":%3}")
399 .arg((heat_state)?100:0).arg((cool_state)?100:0).arg((fan_state)?100:0); 458 .arg((heat_state)?100:0).arg((cool_state)?100:0).arg((fan_state)?100:0);
400 //qDebug() << msg;
401 webSocket->sendTextMessage(msg); 459 webSocket->sendTextMessage(msg);
402 } 460 }
403 461
404 462
405 void DetailFermenter::heat_switched() 463 void DetailFermenter::heat_switched()
468 526
469 void DetailFermenter::mode_changed(int val) 527 void DetailFermenter::mode_changed(int val)
470 { 528 {
471 QStringList mode ({ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }); 529 QStringList mode ({ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" });
472 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"mode\":\"" + mode[val] + "\"}"); 530 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"mode\":\"" + mode[val] + "\"}");
473 //qDebug() << "mode_changed" << val << msg;
474 webSocket->sendTextMessage(msg); 531 webSocket->sendTextMessage(msg);
475 } 532 }
476 533
477 534
478 void DetailFermenter::stage_changed(int val) 535 void DetailFermenter::stage_changed(int val)
479 { 536 {
480 QStringList stage ({ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" }); 537 QStringList stage ({ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" });
481 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"stage\":\"" + stage[val] + "\"}"); 538 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",\"stage\":\"" + stage[val] + "\"}");
482 //qDebug() << "stage_changed" << val << msg;
483 webSocket->sendTextMessage(msg); 539 webSocket->sendTextMessage(msg);
484 } 540 }
485 541
486 542
487 void DetailFermenter::code_changed(int val) 543 void DetailFermenter::code_changed(int val)
588 } 644 }
589 } 645 }
590 } 646 }
591 647
592 payload.append(QString("]}")); 648 payload.append(QString("]}"));
593 // qDebug() << query.value("steps").toString();
594 } 649 }
595 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",%1}").arg(payload); 650 QString msg = QString("{\"device\":\"fermenters\",\"node\":\"" + _node + "\",\"unit\":\"" + _alias + "\",%1}").arg(payload);
596 qDebug() << "profile_changed" << val << msg; 651 qDebug() << "profile_changed" << val << msg;
597 webSocket->sendTextMessage(msg); 652 webSocket->sendTextMessage(msg);
598 } 653 }

mercurial