diff --git a/plugins/deviceplugins/gpio/deviceplugingpio.cpp b/plugins/deviceplugins/gpio/deviceplugingpio.cpp index 2e5f36d9..561a13de 100644 --- a/plugins/deviceplugins/gpio/deviceplugingpio.cpp +++ b/plugins/deviceplugins/gpio/deviceplugingpio.cpp @@ -30,6 +30,10 @@ \image Raspberry-Pi-2-GPIO.png "Raspberry Pi 2 GPIOs" + \chapter Beaglebone Black + + \image Beaglebone-Black-GPIO.png "Beaglebone Black GPIOs" + \chapter Plugin properties Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses} and \l{Vendor}{Vendors} of this \l{DevicePlugin}. @@ -151,6 +155,43 @@ DeviceManager::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId emit devicesDiscovered(deviceClassId, deviceDescriptors); } + if (deviceClass.vendorId() == beagleboneBlackVendorId) { + + // Create the list of available gpios + QList deviceDescriptors; + + QList gpioDescriptors = beagleboneBlackGpioDescriptors(); + for (int i = 0; i < gpioDescriptors.count(); i++) { + const GpioDescriptor gpioDescriptor = gpioDescriptors.at(i); + + // Offer only gpios which arn't in use already + if (m_beagleboneBlackGpios.keys().contains(gpioDescriptor.gpio())) + continue; + + if (m_beagleboneBlackGpioMoniors.keys().contains(gpioDescriptor.gpio())) + continue; + + QString description; + if (gpioDescriptor.description().isEmpty()) { + description = QString("Pin %1").arg(gpioDescriptor.pin()); + } else { + description = QString("Pin %1 | %2").arg(gpioDescriptor.pin()).arg(gpioDescriptor.description()); + } + + DeviceDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description); + ParamList parameters; + parameters.append(Param(gpioParamTypeId, gpioDescriptor.gpio())); + parameters.append(Param(pinParamTypeId, gpioDescriptor.pin())); + parameters.append(Param(descriptionParamTypeId, gpioDescriptor.description())); + descriptor.setParams(parameters); + + deviceDescriptors.append(descriptor); + } + + emit devicesDiscovered(deviceClassId, deviceDescriptors); + } + + return DeviceManager::DeviceErrorAsync; } @@ -171,6 +212,9 @@ void DevicePluginGpio::deviceRemoved(Device *device) if (m_raspberryPiGpios.values().contains(gpio)) m_raspberryPiGpios.remove(gpio->gpioNumber()); + if (m_beagleboneBlackGpios.values().contains(gpio)) + m_beagleboneBlackGpios.remove(gpio->gpioNumber()); + delete gpio; } @@ -184,6 +228,9 @@ void DevicePluginGpio::deviceRemoved(Device *device) if (m_raspberryPiGpioMoniors.values().contains(monitor)) m_raspberryPiGpios.remove(monitor->gpio()->gpioNumber()); + if (m_beagleboneBlackGpioMoniors.values().contains(monitor)) + m_beagleboneBlackGpioMoniors.remove(monitor->gpio()->gpioNumber()); + delete monitor; } @@ -218,6 +265,9 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const return DeviceManager::DeviceErrorHardwareFailure; } + // Set the current state + device->setStateValue(powerValueStateTypeId, action.param(powerValueStateParamTypeId).value()); + return DeviceManager::DeviceErrorNoError; } @@ -228,7 +278,8 @@ void DevicePluginGpio::postSetupDevice(Device *device) { if (device->deviceClassId() == gpioSwitchDeviceClassId) { Gpio *gpio = m_gpioDevices.key(device); - device->setStateValue(powerValueStateTypeId, (bool)gpio->value()); + gpio->setValue(Gpio::ValueLow); + device->setStateValue(powerValueStateTypeId, false); } if (device->deviceClassId() == gpioButtonDeviceClassId) { @@ -270,18 +321,87 @@ QList DevicePluginGpio::raspberryPiGpioDescriptors() return gpioDescriptors; } +QList DevicePluginGpio::beagleboneBlackGpioDescriptors() +{ + // Note: https://www.mathworks.com/help/examples/beaglebone_product/beaglebone_black_gpio_pinmap.png + QList gpioDescriptors; + gpioDescriptors << GpioDescriptor(30, 11, "P9"); + gpioDescriptors << GpioDescriptor(31, 13, "P9"); + gpioDescriptors << GpioDescriptor(48, 15, "P9"); + gpioDescriptors << GpioDescriptor(5, 17, "P9 - I2C1_SCL"); + gpioDescriptors << GpioDescriptor(13, 19, "P9 - I2C2_SCL"); + gpioDescriptors << GpioDescriptor(3, 21, "P9"); + gpioDescriptors << GpioDescriptor(49, 23, "P9"); + gpioDescriptors << GpioDescriptor(117, 25, "P9"); + gpioDescriptors << GpioDescriptor(121, 29, "P9"); + gpioDescriptors << GpioDescriptor(120, 31, "P9"); + gpioDescriptors << GpioDescriptor(20, 41, "P9"); + gpioDescriptors << GpioDescriptor(60, 12, "P9"); + gpioDescriptors << GpioDescriptor(50, 14, "P9"); + gpioDescriptors << GpioDescriptor(51, 16, "P9"); + gpioDescriptors << GpioDescriptor(4, 18, "P9 - I2C1_SDA"); + gpioDescriptors << GpioDescriptor(12, 20, "P9 - I2C2_SDA"); + gpioDescriptors << GpioDescriptor(2, 22, "P9"); + gpioDescriptors << GpioDescriptor(15, 24, "P9"); + gpioDescriptors << GpioDescriptor(14, 26, "P9"); + gpioDescriptors << GpioDescriptor(123, 28, "P9"); + gpioDescriptors << GpioDescriptor(122, 30, "P9"); + gpioDescriptors << GpioDescriptor(7, 42, "P9"); + gpioDescriptors << GpioDescriptor(38, 3, "P8 - MMC1_DAT6"); + gpioDescriptors << GpioDescriptor(34, 5, "P8 - MMC1_DAT2"); + gpioDescriptors << GpioDescriptor(66, 7, "P8"); + gpioDescriptors << GpioDescriptor(69, 9, "P8"); + gpioDescriptors << GpioDescriptor(45, 11, "P8"); + gpioDescriptors << GpioDescriptor(23, 13, "P8"); + gpioDescriptors << GpioDescriptor(47, 15, "P8"); + gpioDescriptors << GpioDescriptor(27, 17, "P8"); + gpioDescriptors << GpioDescriptor(22, 19, "P8"); + gpioDescriptors << GpioDescriptor(62, 21, "P8 - MMC1-CLK"); + gpioDescriptors << GpioDescriptor(36, 23, "P8 - MMC1-DAT4"); + gpioDescriptors << GpioDescriptor(32, 25, "P8 - MMC1-DAT0"); + gpioDescriptors << GpioDescriptor(86, 27, "P8 - LCD_VSYNC"); + gpioDescriptors << GpioDescriptor(87, 29, "P8 - LCD_HSYNC"); + gpioDescriptors << GpioDescriptor(10, 31, "P8 - LCD_DATA14"); + gpioDescriptors << GpioDescriptor(9, 33, "P8 - LCD_DATA13"); + gpioDescriptors << GpioDescriptor(8, 35, "P8 - LCD_DATA12"); + gpioDescriptors << GpioDescriptor(78, 37, "P8 - LCD_DATA8"); + gpioDescriptors << GpioDescriptor(76, 39, "P8 - LCD_DATA6"); + gpioDescriptors << GpioDescriptor(74, 41, "P8 - LCD_DATA4"); + gpioDescriptors << GpioDescriptor(72, 43, "P8 - LCD_DATA2"); + gpioDescriptors << GpioDescriptor(70, 45, "P8 - LCD_DATA0"); + gpioDescriptors << GpioDescriptor(39, 4, "P8 - MMC1_DAT7"); + gpioDescriptors << GpioDescriptor(35, 6, "P8 - MMC1_DAT3"); + gpioDescriptors << GpioDescriptor(67, 8, "P8"); + gpioDescriptors << GpioDescriptor(68, 10, "P8"); + gpioDescriptors << GpioDescriptor(44, 12, "P8"); + gpioDescriptors << GpioDescriptor(26, 14, "P8"); + gpioDescriptors << GpioDescriptor(46, 16, "P8"); + gpioDescriptors << GpioDescriptor(65, 18, "P8"); + gpioDescriptors << GpioDescriptor(63, 20, "P8 - MMC1_CMD"); + gpioDescriptors << GpioDescriptor(37, 22, "P8 - MMC1_DAT5"); + gpioDescriptors << GpioDescriptor(33, 24, "P8 - MMC1_DAT1"); + gpioDescriptors << GpioDescriptor(61, 26, "P8"); + gpioDescriptors << GpioDescriptor(88, 28, "P8 - LCD_PCLK"); + gpioDescriptors << GpioDescriptor(89, 30, "P8 - LCD_AC_BIAS_E"); + gpioDescriptors << GpioDescriptor(11, 32, "P8 - LCD_DATA15"); + gpioDescriptors << GpioDescriptor(81, 34, "P8 - LCD_DATA11"); + gpioDescriptors << GpioDescriptor(80, 36, "P8 - LCD_DATA10"); + gpioDescriptors << GpioDescriptor(79, 38, "P8 - LCD_DATA9"); + gpioDescriptors << GpioDescriptor(77, 40, "P8 - LCD_DATA7"); + gpioDescriptors << GpioDescriptor(75, 42, "P8 - LCD_DATA5"); + gpioDescriptors << GpioDescriptor(73, 44, "P8 - LCD_DATA3"); + gpioDescriptors << GpioDescriptor(71, 46, "P8 - LCD_DATA1"); + return gpioDescriptors; +} + void DevicePluginGpio::onGpioValueChanged(const bool &value) { GpioMonitor *monitor = static_cast(sender()); - // Get device and set state value - if (m_raspberryPiGpioMoniors.values().contains(monitor)) { - Device *device = m_monitorDevices.value(monitor); - if (!device) - return; - - device->setStateValue(pressedStateTypeId, value); - } + Device *device = m_monitorDevices.value(monitor); + if (!device) + return; + device->setStateValue(pressedStateTypeId, value); } diff --git a/plugins/deviceplugins/gpio/deviceplugingpio.h b/plugins/deviceplugins/gpio/deviceplugingpio.h index 8ba29d67..5dde2f6a 100644 --- a/plugins/deviceplugins/gpio/deviceplugingpio.h +++ b/plugins/deviceplugins/gpio/deviceplugingpio.h @@ -36,7 +36,6 @@ class DevicePluginGpio : public DevicePlugin public: explicit DevicePluginGpio(); - ~DevicePluginGpio(); DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override; @@ -48,12 +47,16 @@ public: private: QHash m_gpioDevices; - QHash m_raspberryPiGpios; - QHash m_monitorDevices; + + QHash m_raspberryPiGpios; QHash m_raspberryPiGpioMoniors; + QHash m_beagleboneBlackGpios; + QHash m_beagleboneBlackGpioMoniors; + QList raspberryPiGpioDescriptors(); + QList beagleboneBlackGpioDescriptors(); private slots: void onGpioValueChanged(const bool &value); diff --git a/plugins/deviceplugins/gpio/deviceplugingpio.json b/plugins/deviceplugins/gpio/deviceplugingpio.json index 2ad45784..fb11ae1d 100644 --- a/plugins/deviceplugins/gpio/deviceplugingpio.json +++ b/plugins/deviceplugins/gpio/deviceplugingpio.json @@ -107,6 +107,111 @@ ] } ] + }, + { + "name": "Beaglebone Black", + "idName": "beagleboneBlack", + "id": "7835d14b-b455-49bd-9f31-72c6e8c3033d", + "deviceClasses": [ + { + "id": "3885c520-e202-4435-88f6-3c35c362b2e6", + "name": "GPIO Switch", + "idName": "gpioSwitch", + "deviceIcon": "Switch", + "basicTags": [ + "Device", + "Actuator" + ], + "createMethods": ["discovery"], + "paramTypes": [ + { + "id": "9eda783f-6d9f-4d39-986d-d2cbfff5a7dd", + "idName": "gpio", + "name": "GPIO", + "type": "int", + "index": 0, + "defaultValue": -1 + }, + { + "id": "2204d278-7bc7-407f-ac82-ce3ae1d5779c", + "idName": "pin", + "name": "Pin number", + "type": "int", + "index": 1, + "defaultValue": -1 + }, + { + "id": "504798eb-1faa-4703-a57a-2778e4bf9a67", + "idName": "description", + "name": "Description", + "type": "QString", + "index": 2, + "defaultValue": "-" + } + ], + "stateTypes": [ + { + "id": "06843766-358e-44b0-8d52-2b46ef98459a", + "idName": "powerValue", + "name": "Power", + "index": 0, + "type": "bool", + "defaultValue": false, + "writable": true, + "eventTypeName": "Power changed", + "actionTypeName": "Set power" + } + ] + }, + { + "id": "6aff228b-0410-4ef9-9593-51e8639aacea", + "name": "GPIO Button", + "idName": "gpioButton", + "deviceIcon": "Power", + "basicTags": [ + "Device", + "Sensor" + ], + "createMethods": ["discovery"], + "paramTypes": [ + { + "id": "9eda783f-6d9f-4d39-986d-d2cbfff5a7dd", + "idName": "gpio", + "name": "GPIO", + "type": "int", + "index": 0, + "defaultValue": -1 + }, + { + "id": "2204d278-7bc7-407f-ac82-ce3ae1d5779c", + "idName": "pin", + "name": "Pin number", + "type": "int", + "index": 1, + "defaultValue": -1 + }, + { + "id": "504798eb-1faa-4703-a57a-2778e4bf9a67", + "idName": "description", + "name": "Description", + "type": "QString", + "index": 2, + "defaultValue": "-" + } + ], + "stateTypes": [ + { + "id": "57f1b7cc-26c8-434b-ba04-d3077dc886c8", + "idName": "pressed", + "name": "Pressed", + "index": 0, + "type": "bool", + "defaultValue": false, + "eventTypeName": "Pressed changed" + } + ] + } + ] } ] } diff --git a/plugins/deviceplugins/gpio/translations/de_DE.ts b/plugins/deviceplugins/gpio/translations/de_DE.ts index a1967f1c..62720933 100644 --- a/plugins/deviceplugins/gpio/translations/de_DE.ts +++ b/plugins/deviceplugins/gpio/translations/de_DE.ts @@ -4,76 +4,82 @@ GpioController - + Gpio Controller The name of the plugin Gpio Controller (127ead55-996a-44ac-ba82-fc3c634e018a) - + Raspberry Pi 2 The name of the vendor (f0d00b66-bbd8-4a07-8591-ea48a61b229e) - + GPIO Switch The name of the DeviceClass (3885c520-e202-4435-88f6-3c35c362b2e6) - + GPIO The name of the paramType (9eda783f-6d9f-4d39-986d-d2cbfff5a7dd) of GPIO Switch - + Pin number The name of the paramType (2204d278-7bc7-407f-ac82-ce3ae1d5779c) of GPIO Switch - + Description The name of the paramType (504798eb-1faa-4703-a57a-2778e4bf9a67) of GPIO Switch - + Power changed The name of the autocreated EventType (06843766-358e-44b0-8d52-2b46ef98459a) - + Power The name of the ParamType of StateType (06843766-358e-44b0-8d52-2b46ef98459a) of DeviceClass GPIO Switch - + Set power The name of the autocreated ActionType (06843766-358e-44b0-8d52-2b46ef98459a) - + GPIO Button The name of the DeviceClass (6aff228b-0410-4ef9-9593-51e8639aacea) - + Pressed changed The name of the autocreated EventType (57f1b7cc-26c8-434b-ba04-d3077dc886c8) - + Pressed The name of the ParamType of StateType (57f1b7cc-26c8-434b-ba04-d3077dc886c8) of DeviceClass GPIO Button + + + Beaglebone Black + The name of the vendor (7835d14b-b455-49bd-9f31-72c6e8c3033d) + + diff --git a/plugins/deviceplugins/gpio/translations/en_US.ts b/plugins/deviceplugins/gpio/translations/en_US.ts index eb9546e0..1ab459d2 100644 --- a/plugins/deviceplugins/gpio/translations/en_US.ts +++ b/plugins/deviceplugins/gpio/translations/en_US.ts @@ -4,76 +4,82 @@ GpioController - + Gpio Controller The name of the plugin Gpio Controller (127ead55-996a-44ac-ba82-fc3c634e018a) - + Raspberry Pi 2 The name of the vendor (f0d00b66-bbd8-4a07-8591-ea48a61b229e) - + GPIO Switch The name of the DeviceClass (3885c520-e202-4435-88f6-3c35c362b2e6) - + GPIO The name of the paramType (9eda783f-6d9f-4d39-986d-d2cbfff5a7dd) of GPIO Switch - + Pin number The name of the paramType (2204d278-7bc7-407f-ac82-ce3ae1d5779c) of GPIO Switch - + Description The name of the paramType (504798eb-1faa-4703-a57a-2778e4bf9a67) of GPIO Switch - + Power changed The name of the autocreated EventType (06843766-358e-44b0-8d52-2b46ef98459a) - + Power The name of the ParamType of StateType (06843766-358e-44b0-8d52-2b46ef98459a) of DeviceClass GPIO Switch - + Set power The name of the autocreated ActionType (06843766-358e-44b0-8d52-2b46ef98459a) - + GPIO Button The name of the DeviceClass (6aff228b-0410-4ef9-9593-51e8639aacea) - + Pressed changed The name of the autocreated EventType (57f1b7cc-26c8-434b-ba04-d3077dc886c8) - + Pressed The name of the ParamType of StateType (57f1b7cc-26c8-434b-ba04-d3077dc886c8) of DeviceClass GPIO Button + + + Beaglebone Black + The name of the vendor (7835d14b-b455-49bd-9f31-72c6e8c3033d) + +