Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmucde committed Jul 9, 2021
1 parent 0adf0a5 commit fca7cf4
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 41 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ https://www.wemos.cc/en/latest/ch340_driver.html

The Arduino SW understands the following commands:

* "D11\n", "D21\n" or "D61\n" Activate Relais connected to pin D1, D2 or D6
* "D10\n", "D20\n" or "D60\n" Deactivate Relais connected to pin D1, D2 or D6
* "D1T\n", "D2T\n" or "D6T\n" Trigger Relais connected to pin D1, D2 or D6 for 500ms
* "R11\n", "R21\n", "R31\n", "R41\n", "R51\n" Activates Relais connected to pin D1, D2, D6, D7 and D8
* "R10\n", "R20\n", "R30\n", "R40\n", "R50\n" Deactivates Relais connected to pin D1, D2, D6, D7 and D8
* "R1T\n", "R2T\n", "R3T\n", "R4T\n", "R5T\n" Trigger Relais connected to pin D1, D2, D6, D7 and D8 for 500ms

The Arduino board sends the status of Relais, when it was triggered with the button with the same command.

The Arduino board sends every second a watchdog signal "WD\n".

## Installation

Expand Down Expand Up @@ -85,6 +89,15 @@ Github Sponsors:

[:heart: Sponsor](https://github.com/sponsors/alexmucde)

## Changes

v0.0.3:

* Support up to 5 Relais
* Changed communication protocol with Arduino board
* Added Watchdog
* Fixed startup problem with Arduino Flash Mode

## Copyright

Alexander Wenzel <[email protected]>
Expand Down
56 changes: 50 additions & 6 deletions dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,34 @@ Dialog::Dialog(QWidget *parent)
{
ui->setupUi(this);

// clear settings
on_pushButtonDefaultSettings_clicked();

// set window title with version information
setWindowTitle(QString("DLTRelais %1").arg(DLT_RELAIS_VERSION));

// disable stop button at startup
ui->pushButtonStop->setDisabled(true);

// connect status slots
connect(&dltRelais, SIGNAL(status(QString)), this, SLOT(statusRelais(QString)));
connect(&dltMiniServer, SIGNAL(status(QString)), this, SLOT(statusDlt(QString)));

/* load global settings */
// load global settings from registry
QSettings settings;
QString filename = settings.value("autoload/filename").toString();
bool autoload = settings.value("autoload/checked").toBool();
bool autostart = settings.value("autostart/checked").toBool();

/* autoload settings */
// autoload settings, when activated in global settings
if(autoload)
{
dltRelais.readSettings(filename);
dltMiniServer.readSettings(filename);
restoreSettings();
}

/* autostart */
// autostart, when activated in global settings
if(autostart)
{
on_pushButtonStart_clicked();
Expand All @@ -62,6 +66,8 @@ Dialog::Dialog(QWidget *parent)

Dialog::~Dialog()
{

// disconnect status slots
disconnect(&dltRelais, SIGNAL(status(QString)), this, SLOT(statusRelais(QString)));
disconnect(&dltMiniServer, SIGNAL(status(QString)), this, SLOT(statusDlt(QString)));

Expand All @@ -70,7 +76,7 @@ Dialog::~Dialog()

void Dialog::restoreSettings()
{
/* DLTRelais */
// update names of Relais
ui->lineEditRelaisName1->setText(dltRelais.getRelaisName(1));
ui->lineEditRelaisName2->setText(dltRelais.getRelaisName(2));
ui->lineEditRelaisName3->setText(dltRelais.getRelaisName(3));
Expand All @@ -85,11 +91,15 @@ void Dialog::updateSettings()

void Dialog::on_pushButtonStart_clicked()
{
// start communication
updateSettings();

// start Relais and DLT communication
dltRelais.start();
dltMiniServer.start();

// disable settings and start button
// enable stop button
ui->pushButtonStart->setDisabled(true);
ui->pushButtonStop->setDisabled(false);
ui->pushButtonDefaultSettings->setDisabled(true);
Expand All @@ -99,9 +109,14 @@ void Dialog::on_pushButtonStart_clicked()

void Dialog::on_pushButtonStop_clicked()
{
// stop communication

// stop Relais and DLT communication
dltRelais.stop();
dltMiniServer.stop();

// enable settings and start button
// disable stop button
ui->pushButtonStart->setDisabled(false);
ui->pushButtonStop->setDisabled(true);
ui->pushButtonDefaultSettings->setDisabled(false);
Expand All @@ -111,6 +126,9 @@ void Dialog::on_pushButtonStop_clicked()

void Dialog::statusRelais(QString text)
{
// status from Relais

// Relais status changed on Arduino board
if(text=="R10\r\n")
{
ui->checkBoxRelais1->setChecked(false);
Expand Down Expand Up @@ -165,6 +183,8 @@ void Dialog::statusRelais(QString text)
ui->checkBoxRelais5->setChecked(true);
return;
}

// status of Relais communication changed
else if(text == "" || text == "stopped")
{
QPalette palette;
Expand All @@ -190,8 +210,10 @@ void Dialog::statusRelais(QString text)

void Dialog::statusDlt(QString text)
{
// status from DLT Mini Server
ui->lineEditStatusDLT->setText(text);

// status of DLT communication changed
if(text == "" || text == "stopped")
{
QPalette palette;
Expand All @@ -218,6 +240,9 @@ void Dialog::statusDlt(QString text)
}
}

// The following functions are called, when the Relais Checkboxes are triggered or the Trigger
// button is pressed

void Dialog::on_checkBoxRelais1_clicked(bool checked)
{
if(checked)
Expand Down Expand Up @@ -322,8 +347,10 @@ void Dialog::on_checkBoxRelais5_clicked(bool checked)
dltMiniServer.sendValue2(dltRelais.getRelaisName(5),"Off");
}
}

void Dialog::on_pushButtonDefaultSettings_clicked()
{
// Reset settings to default
dltRelais.clearSettings();
dltMiniServer.clearSettings();

Expand All @@ -332,14 +359,18 @@ void Dialog::on_pushButtonDefaultSettings_clicked()

void Dialog::on_pushButtonLoadSettings_clicked()
{
// Load settings from XML file

QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Settings"), "", tr("DLTRelais Settings (*.xml);;All files (*.*)"));

if(fileName.isEmpty())
{
// No file was selected or cancel was pressed
return;
}

// read the settings from XML file
dltRelais.readSettings(fileName);
dltMiniServer.readSettings(fileName);

Expand All @@ -348,40 +379,52 @@ void Dialog::on_pushButtonLoadSettings_clicked()

void Dialog::on_pushButtonSaveSettings_clicked()
{
// Save settings into XML file

updateSettings();

QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Settings"), "", tr("DLTRelais Settings (*.xml);;All files (*.*)"));

if(fileName.isEmpty())
{
// No file was selected or cancel was pressed
return;
}

// read the settings from XML file
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text))
return;
{
// Cannot open the file for writing
return;
}

QXmlStreamWriter xml(&file);
xml.setAutoFormatting(true);

// FIXME: Cannot read data from XML file, which contains a start document
// So currently do not call StartDocument
//xml.writeStartDocument();

xml.writeStartElement("DLTRelaisSettings");
dltRelais.writeSettings(xml);
dltMiniServer.writeSettings(xml);
xml.writeEndElement(); // DLTRelaisSettings

// FIXME: Cannot read data from XML file, which contains a end document
// So currently do not call EndDocument
//xml.writeEndDocument();
file.close();

}

void Dialog::on_pushButtonSettings_clicked()
{
// Open settings dialog
SettingsDialog dlg(this);

dlg.restoreSettings(&dltRelais, &dltMiniServer);

if(dlg.exec()==QDialog::Accepted)
{
dlg.backupSettings(&dltRelais, &dltMiniServer);
Expand All @@ -391,6 +434,7 @@ void Dialog::on_pushButtonSettings_clicked()

void Dialog::on_pushButtonInfo_clicked()
{
// Open information window
QMessageBox msgBox(this);

msgBox.setWindowTitle("Info DLTRelais");
Expand Down
17 changes: 9 additions & 8 deletions dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,40 @@ class Dialog : public QDialog

private slots:

// Relais control
void on_checkBoxRelais1_clicked(bool checked);
void on_pushButtonRelais1Trigger_clicked();
void on_checkBoxRelais2_clicked(bool checked);
void on_pushButtonRelais2Trigger_clicked();
void on_checkBoxRelais3_clicked(bool checked);
void on_pushButtonRelais3Trigger_clicked();
void on_checkBoxRelais4_clicked(bool checked);
void on_pushButtonRelais4Trigger_clicked();
void on_checkBoxRelais5_clicked(bool checked);
void on_pushButtonRelais5Trigger_clicked();

// Status of Relais and DLT connection
void statusRelais(QString text);
void statusDlt(QString text);

// Settings and Info
void on_pushButtonSettings_clicked();
void on_pushButtonDefaultSettings_clicked();
void on_pushButtonLoadSettings_clicked();
void on_pushButtonSaveSettings_clicked();
void on_pushButtonInfo_clicked();

// Start and stop communication
void on_pushButtonStart_clicked();
void on_pushButtonStop_clicked();

void on_pushButtonRelais4Trigger_clicked();

void on_pushButtonRelais5Trigger_clicked();

void on_checkBoxRelais4_clicked(bool checked);

void on_checkBoxRelais5_clicked(bool checked);

private:
Ui::Dialog *ui;

DLTRelais dltRelais;
DLTMiniServer dltMiniServer;

// Settings
void restoreSettings();
void updateSettings();
};
Expand Down
Loading

0 comments on commit fca7cf4

Please sign in to comment.