150 if (wiringPiSetup() > -1)
158 static bool debugged =
false;
166 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"wiringPi is not initialised"));
170 int revision = piBoardRev();
172 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Revision 1 board - 7 pins available (0-6)"));
173 else if (revision == 2)
174 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Revision 2 board - 22 pins available (0-6 and 17-31)"));
176 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Unknown board revision..."));
180 QVariantMap::const_iterator i = GPIO.constBegin();
181 for ( ; i != GPIO.constEnd(); ++i)
189 QVariantMap gpio = i.value().toMap();
190 QVariantMap::const_iterator it = gpio.begin();
191 for ( ; it != gpio.end(); ++it)
197 QVariantMap pins = it.value().toMap();
198 QVariantMap::const_iterator it2 = pins.constBegin();
199 for ( ; it2 != pins.constEnd(); ++it2)
201 QString type = it2.key();
202 QVariantMap pin = it2.value().toMap();
204 if (!pin.contains(QStringLiteral(
"gpiopinnumber")))
206 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"GPIO device '%1' does not specify pin <number>").arg(pin.value(QStringLiteral(
"name")).toString()));
210 if (!pin.contains(QStringLiteral(
"default")) && output)
212 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"GPIO device '%1' does not specify <default> value").arg(pin.value(QStringLiteral(
"name")).toString()));
217 int number = pin.value(QStringLiteral(
"gpiopinnumber")).toInt(&ok);
218 if (!ok || (wpiPinToGpio(number) < 0))
220 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to parse valid pin from '%1'").arg(pin.value(
"pin").toString()));
224 if (m_inputs.contains(number) || m_outputs.contains(number) || m_pwmOutputs.contains(number))
226 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"GPIO Pin #%1 is already in use").arg(number));
230 if (type == QStringLiteral(
"switch"))
235 m_outputs.insert(number, out);
240 m_inputs.insert(number, in);
243 else if (type == QStringLiteral(
"pwm") && output)
246 m_pwmOutputs.insert(number, out);
250 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Unknown GPIO device type"));
262 QMap<int,TorcPiSwitchInput*>::iterator it = m_inputs.begin();
263 for ( ; it != m_inputs.end(); ++it)
265 TorcInputs::gInputs->RemoveInput(it.value());
266 it.value()->DownRef();
270 QMap<int,TorcPiSwitchOutput*>::iterator it2 = m_outputs.begin();
271 for ( ; it2 != m_outputs.end(); ++it2)
273 TorcOutputs::gOutputs->RemoveOutput(it2.value());
274 it2.value()->DownRef();
278 QMap<int,TorcPiPWMOutput*>::iterator it3 = m_pwmOutputs.begin();
279 for ( ; it3 != m_pwmOutputs.end(); ++it3)
281 TorcOutputs::gOutputs->RemoveOutput(it3.value());
282 it3.value()->DownRef();
284 m_pwmOutputs.clear();
294 "<xs:simpleType name='gpioPinNumberType'>\r\n" 295 " <xs:restriction base='xs:integer'>\r\n" 296 " <xs:minInclusive value='0'/>\r\n" 297 " <xs:maxInclusive value='6'/>\r\n" 298 " </xs:restriction>\r\n" 299 "</xs:simpleType>\r\n");
305 "<xs:simpleType name='gpioPinNumberType'>\r\n" 306 " <xs:restriction base='xs:integer'>\r\n" 307 " <xs:enumeration value='0'/>\r\n" 308 " <xs:enumeration value='1'/>\r\n" 309 " <xs:enumeration value='2'/>\r\n" 310 " <xs:enumeration value='3'/>\r\n" 311 " <xs:enumeration value='4'/>\r\n" 312 " <xs:enumeration value='5'/>\r\n" 313 " <xs:enumeration value='6'/>\r\n" 314 " <xs:enumeration value='17'/>\r\n" 315 " <xs:enumeration value='18'/>\r\n" 316 " <xs:enumeration value='19'/>\r\n" 317 " <xs:enumeration value='20'/>\r\n" 318 " <xs:enumeration value='21'/>\r\n" 319 " <xs:enumeration value='22'/>\r\n" 320 " <xs:enumeration value='23'/>\r\n" 321 " <xs:enumeration value='24'/>\r\n" 322 " <xs:enumeration value='25'/>\r\n" 323 " <xs:enumeration value='26'/>\r\n" 324 " <xs:enumeration value='27'/>\r\n" 325 " <xs:enumeration value='28'/>\r\n" 326 " <xs:enumeration value='29'/>\r\n" 327 " <xs:enumeration value='30'/>\r\n" 328 " <xs:enumeration value='31'/>\r\n" 329 " </xs:restriction>\r\n" 330 "</xs:simpleType>\r\n");
334 "<xs:complexType name='gpioInputSwitchType'>\r\n" 336 " <xs:element name='name' type='deviceNameType'/>\r\n" 337 " <xs:element name='username' type='userNameType' minOccurs='0' maxOccurs='1'/>\r\n" 338 " <xs:element name='userdescription' type='userDescriptionType' minOccurs='0' maxOccurs='1'/>\r\n" 339 " <xs:element name='gpiopinnumber' type='gpioPinNumberType'/>\r\n" 341 "</xs:complexType>\r\n" 343 "<xs:complexType name='gpioInputType'>\r\n" 345 " <xs:element minOccurs='1' maxOccurs='unbounded' name='switch' type='gpioInputSwitchType'/>\r\n" 346 " </xs:sequence>\r\n" 347 "</xs:complexType>\r\n");
350 " <xs:element minOccurs='0' maxOccurs='1' name='gpio' type='gpioInputType'/>\r\n");
353 "<xs:complexType name='gpioOutputSwitchType'>\r\n" 355 " <xs:element name='name' type='deviceNameType'/>\r\n" 356 " <xs:element name='username' type='userNameType' minOccurs='0' maxOccurs='1'/>\r\n" 357 " <xs:element name='userdescription' type='userDescriptionType' minOccurs='0' maxOccurs='1'/>\r\n" 358 " <xs:element name='gpiopinnumber' type='gpioPinNumberType'/>\r\n" 359 " <xs:element name='default' type='switchNumberType'/>\r\n" 361 "</xs:complexType>\r\n" 363 "<xs:complexType name='gpioOutputPWMType'>\r\n" 365 " <xs:element name='name' type='deviceNameType'/>\r\n" 366 " <xs:element name='username' type='userNameType' minOccurs='0' maxOccurs='1'/>\r\n" 367 " <xs:element name='userdescription' type='userDescriptionType' minOccurs='0' maxOccurs='1'/>\r\n" 368 " <xs:element name='gpiopinnumber' type='gpioPinNumberType'/>\r\n" 369 " <xs:element name='default' type='pwmNumberType'/>\r\n" 371 "</xs:complexType>\r\n" 373 "<xs:complexType name='gpioOutputType'>\r\n" 374 " <xs:choice minOccurs='1' maxOccurs='unbounded'>\r\n" 375 " <xs:element name='switch' type='gpioOutputSwitchType'/>\r\n" 376 " <xs:element name='pwm' type='gpioOutputPWMType'/>\r\n" 378 "</xs:complexType>\r\n");
381 " <xs:element minOccurs='0' maxOccurs='1' name='gpio' type='gpioOutputType'/>\r\n");
384 " <!-- enforce unique GPIO pin numbers -->\r\n" 385 " <xs:unique name='uniqueGPIOPinNumber'>\r\n" 386 " <xs:selector xpath='.//gpiopinnumber' />\r\n" 387 " <xs:field xpath='.' />\r\n" 388 " </xs:unique>\r\n");
395 #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) 396 QCoreApplication::setSetuidAllowed(
true);
400 void GetXSD(QMultiMap<QString,QString> &XSD) {
401 bool rev1 = piBoardRev() == 1;
static const QString pigpioInputs
static const QString pigpioUnique
void GetXSD(QMultiMap< QString, QString > &XSD)
A device to output PWM signals on the Raspberry Pi.
static const QString pigpioOutputs
#define OUTPUTS_DIRECTORY
static const QString gpioPinNumberTypeRev1
static const QString gpioPinNumberTypeRev2
static const QString pigpioOutputTypes
static const QString pigpioInputTypes
static TorcPiGPIO * gPiGPIO
void Create(const QVariantMap &GPIO)
#define LOG(_MASK_, _LEVEL_, _STRING_)
QReadWriteLock m_handlerLock
TorcPiGPIOXSDFactory TorcPiGPIOXSDFactory