Files
BinderBeispielRegler/app/main.cpp
Uwe Jakobeit c220df2df9 comment added
2026-04-06 00:50:27 +02:00

67 lines
1.4 KiB
C++
Executable File

#include <QCoreApplication>
#include <QDebug>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include "datamodel.h"
#include "Controller.h"
// evaluate keyboard hits
// return 0 - no keyboard hit detected
// return 1 - keyboard hit detected
int kbhit() {
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if (ch != EOF) {
ungetc(ch, stdin);
return 1;
}
return 0;
}
// entry point for controller app
// no arguments used (yet)
// program stops on any keyboard hit
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
DataModel model; // create data model instance
Controller bbr; // create controller instance
bbr.initialize(&model);
// loop endlessly until keybord hit
qDebug() << "Press any key to stop ...";
while(!kbhit())
{
qDebug() << "Perform 'temperature is rising'";
bbr.step();
usleep(200000); // 200ms delay
model.getInputs()->data()->analog.Istwert_Temperatur += 0.1;
}
return 0;
// todo uj 30.03.26 - uncomment if needed
// return QCoreApplication::exec();
}