Hier was ich bisher gemacht habe:
Die IOs
bbbgpio.h:
Code: Alles auswählen
#ifndef BBBGPIO_H
#define BBBGPIO_H
#include <QObject>
class bbbgpio : public QObject
{
Q_OBJECT
private:
bool wert;
char command[255];
unsigned int adresse;
std::string io;
public:
bbbgpio(QObject *parent = 0, unsigned int uebergabe =0,bool output= true);
bool zustand();
signals:
void valChanged(bool w);
public slots:
void setVal(bool w);
};
#endif // BBBGPIO_H
bbbgpio.cpp: (etwas wirr tut aber seine Aufgabe bisher recht zuverlässig)
Code: Alles auswählen
#include "bbbgpio.h"
#include <QDebug>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <fstream>
using namespace std;
const char sysPath[23] ="/sys/class/gpio";
char command[256];
bbbgpio::bbbgpio(QObject *parent, unsigned int uebergabe, bool output) :
QObject(parent)
{wert = false;
adresse=uebergabe;
qDebug() << adresse <<"PIO";
snprintf(command,256,"echo %d > %s/export",adresse,sysPath);
system(command);
//usleep(10);
if (!output) {
snprintf(command,256, "echo in > %s/gpio%d/direction",sysPath,adresse);
system(command);
//usleep(10);
}
else {
snprintf(command,256, "echo out > %s/gpio%d/direction",sysPath,adresse);
system(command);
//usleep(10);
}
}
void bbbgpio::setVal(bool w){
if (w != wert){
if (w){
snprintf(command,256, "echo 1 > %s/gpio%d/value",sysPath,adresse);
system(command);
qDebug("true");
}
else {
qDebug("false");
snprintf(command,256, "echo 0 > %s/gpio%d/value",sysPath,adresse);
system(command);}//else
emit valChanged(w);
wert = w;}//if
}
bool bbbgpio::zustand(){
bool back;
snprintf(command,256, "%s/gpio%d/value",sysPath,adresse);
ifstream Quelldatei;
//ifstream Quelldatei; // neuen Lese-Stream erzeugen
Quelldatei.open(command, ios_base::in); // Datei öffnen
if (!Quelldatei) // Fehler beim Öffnen?
qDebug() << "Eingabe-Datei kann nicht geöffnet werden\n";
else { // falls es geklappt hat
char c;
Quelldatei.get(c);
if (c != '1') {back = false;}
else {back =true;};
}
qDebug() << "WERT: "<<adresse << " " << back << endl;
Quelldatei.close();
if (back != wert){emit valChanged(back);wert = back;}
return(back);
}
die Klasse Wert mit die einfach meine Parameter speichern soll:
wert.h
Code: Alles auswählen
#ifndef WERT_H
#define WERT_H
#include <QObject>
class wert : public QObject
{
Q_OBJECT
public:
explicit wert(QObject *parent = 0, int startVal = 0);
int value;
signals:
void valChanged(int vw);
public slots:
void setVal(int val);
void setVal();
};
#endif // WERT_H
wert.cpp
Code: Alles auswählen
#include "wert.h"
wert::wert(QObject *parent, int startVal) :
QObject(parent)
{value = startVal;
setVal(value);
}
void wert::setVal(int val)
{if (val != value)
{value = val;
emit valChanged(value);}
}
void wert::setVal()
{ emit valChanged(value);}
mainwindow.h
Code: Alles auswählen
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code: Alles auswählen
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "bbbgpio.h"
#include "wert.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Initialisierung der Variablen zeit in 1/10s
wert *bbbwarteSchieberF = new wert(this,20);
connect(ui->warteSchieberF,SIGNAL(valueChanged(int)),bbbwarteSchieberF,SLOT(setVal(int)));
connect(bbbwarteSchieberF,SIGNAL(valChanged(int)),ui->warteSchieberF,SLOT(setValue(int)));
bbbwarteSchieberF->setVal();
//natürlich noch mehr...
// Initialisierung der IOs
bbbgpio *bbbstopper1= new bbbgpio(this,48);
//noch einige mehr hab der Übersichtlichkeit weggelassen
connect(ui->stopper1,SIGNAL(clicked(bool)),bbbstopper1,SLOT(setVal(bool)));
connect(bbbstopper1,SIGNAL(valChanged(bool)),ui->stopper1,SLOT(setChecked(bool)));
}
MainWindow::~MainWindow()
{
delete ui;
}
nun möchte ich nicht nur die Werte Ändern können und die IOs abfragen bzw ansteuern können sondern jetzt soll die Steuerung laufen die mit den Werten und IOs arbeitet. Leider hab ich jetzt keinen Plan wo ich die hinpacke damit das klappt(das mit den IOs und werten) Wäre echt super wenn mir da jemand helfen würde!!!
Danke Wolf
PS: bin natürlich auch dankbar über sonstige Anregungen