alors voici une réponse pas très élégante : bonne lecture
# Du code avec coloration syntaxique#include <QFile>#include <syslog.h>#ifndef QT_NO_DEBUG#define BASE_SYSFS "/tmp"#else#define BASE_SYSFS ""#endifintwrite(constQString&filename,constQString&message);intreadyGPIO(intnumber,QFile&file,boolreadOnly){//http://falsinsoft.blogspot.fr/2012/11/access-gpio-from-linux-user-space.html//echo XX > /sys/class/gpio/export//echo "out" > /sys/class/gpio/gpioXX/direction//echo 1 > /sys/class/gpio/gpioXX/value//cat /sys/class/gpio/gpioXX/valueintresult=write(BASE_SYSFS"/sys/class/gpio/export",QString::number(number));if(result==EXIT_FAILURE)returnresult;result=write(BASE_SYSFS"/sys/class/gpio/gpio"+QString::number(number)+"/direction",readOnly?"in":"out");if(result==EXIT_FAILURE)returnresult;#ifndef QT_NO_DEBUGif(file.isOpen())//should not be necessary but ...{syslog(LOG_WARNING,QObject::tr("[WARNING][%1:%2] %3: Internal error ! Please report it !").arg(__LINE__).arg(__FILE__).arg(__FUNCTION__).toUtf8().data());file.close();}#endiffile.setFileName(BASE_SYSFS"/sys/class/gpio/gpio"+QString::number(number)+"/value");if(readOnly)result=file.open(QIODevice::ReadOnly);elseresult=file.open(QIODevice::WriteOnly);if(!result){syslog(LOG_ERR,QObject::tr("[ERROR][%1:%2] %3: Couldn't achieve to open %4 in %5 ! Here the error message: %6").arg(__LINE__).arg(__FILE__).arg(__FUNCTION__).arg(file.fileName()).arg(readOnly?"read_only":"write_only").toUtf8().data());returnEXIT_FAILURE;}returnEXIT_SUCCESS;}intcloseGPIO(intnumber,QFile&file){intresult;file.close();result=write(BASE_SYSFS"/sys/class/gpio/unexport",QString::number(number));if(result==EXIT_FAILURE)returnresult;returnEXIT_SUCCESS;}intwrite(constQString&filename,constQString&message){intresult;QFiletmp;QByteArraymsg=message.toUtf8().data();tmp.setFileName(filename);if(!tmp.open(QIODevice::WriteOnly)){syslog(LOG_ERR,QObject::tr("[CRITICAL][%1:%2] %3: Impossible to open %4 ! Here is the error message: %5").arg(__LINE__).arg(__FILE__).arg(__FUNCTION__).arg(filename).arg(tmp.errorString()).toUtf8().data());returnEXIT_FAILURE;}result=tmp.write(msg);if(result!=msg.size()||!tmp.flush()){syslog(LOG_ERR,QObject::tr("[CRITICAL][%1:%2] %3: Impossible to write >%4< into %5 ! Here is the error message: %6").arg(__LINE__).arg(__FILE__).arg(__FUNCTION__).arg(QString(msg)).arg(filename).arg(tmp.errorString()).toUtf8().data());returnEXIT_FAILURE;}tmp.close();returnEXIT_SUCCESS;}
# question pas très élégante
Posté par lem__mel . En réponse au message Shell script-->langage C. Évalué à 1.
alors voici une réponse pas très élégante : bonne lecture