int ProgramSenoko::prepGPIO(void) { QFile exportFile("/sys/class/gpio/export"); if (!exportFile.open(QIODevice::WriteOnly)) { testError(QString() + "Unable to open GPIO export file: " + exportFile.errorString()); return 1; } exportFile.write("149"); exportFile.close(); QFile directionFile("/sys/class/gpio/gpio149/direction"); if (!directionFile.open(QIODevice::WriteOnly)) { testError(QString() + "Unable to open GPIO149 direction file: " + directionFile.errorString()); return 1; } directionFile.write("out\n"); directionFile.close(); QFile valueFile("/sys/class/gpio/gpio149/value"); if (!valueFile.open(QIODevice::WriteOnly)) { testError(QString() + "Unable to open GPIO149 value file: " + valueFile.errorString()); return 1; } valueFile.write("0\n"); valueFile.close(); return 0; }
void Pin::setValue(int value) { ofstream valueFile(this->m_valuePath); if(!valueFile) { throw("SET VALUE FAILED : " + string(strerror(errno))); } valueFile << value; valueFile.close(); }
int Pin::getValue() const { string value; ifstream valueFile(this->m_valuePath); if(!valueFile) { throw("GET VALUE FAILED : " + string(strerror(errno))); } valueFile >> value; valueFile.close(); if(value != "0") { return(HIGH); } return(LOW); }
int ProgramSenoko::resetGPIO(void) { QFile valueFile("/sys/class/gpio/gpio149/value"); if (!valueFile.open(QIODevice::WriteOnly)) { testError(QString() + "Unable to open GPIO149 value file: " + valueFile.errorString()); return 1; } valueFile.write("0\n"); valueFile.close(); sleep(1); if (!valueFile.open(QIODevice::WriteOnly)) { testError(QString() + "Unable to open GPIO149 value file: " + valueFile.errorString()); return 1; } valueFile.write("1\n"); valueFile.close(); return 0; }