示例#1
0
/*! Enables GPIO transmitter and receiver and the Brennenstuhl Lan Gateway.
 *  Returns true, if the GPIO's are available and set up correctly. The status of the gateway will be emited asynchronous. */
bool Radio433::enable()
{
    m_brennenstuhlTransmitter->enable();

#ifdef GPIO433
    // check if GPIOs are available
    QFileInfo gpioFile("/sys/class/gpio/export");
    if (gpioFile.exists()) {
//        bool receiverAvailable = m_receiver->startReceiver();
//        if (!receiverAvailable) {
//            //qCWarning(dcHardware) << "ERROR: radio 433 MHz receiver not available on GPIO's";
//        }

//        bool transmitterAvailable = m_transmitter->startTransmitter();
//        if (!transmitterAvailable) {
//            //qCWarning(dcHardware) << "ERROR: radio 433 MHz transmitter not available on GPIO's";
//        }

//        if (!receiverAvailable && !transmitterAvailable) {
//            qCWarning(dcHardware) << "--> Radio 433 MHz GPIO's not available.";
//            return false;
//        }
    }
    qCDebug(dcDeviceManager) << "--> Radio 433 MHz GPIO's enabled.";
#endif

    return true;
}
示例#2
0
bool SysfsGPIO::writeGPIO(GPIO_Pin gpionr, GPIO_State value)
{
    if(GPIO_UNDEF == value)
    {
        //What did you plan to do?
        return false;
    }

    //Open and write 1/0 to value file
    QFile gpioFile(QString("/sys/class/gpio/gpio%1/value").arg(gpionr));

    if (!gpioFile.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        myErr() << "FAILURE can't open gpio file gpioPath:" << gpioFile.fileName();
        return false;
    }

    QTextStream out(&gpioFile);
    out << value << "\n";
    gpioFile.close();

    return true;
}