Rename gpio devices

This commit is contained in:
Simon Stürz 2018-03-16 09:49:26 +01:00 committed by Michael Zanetti
parent 1dfdca8c89
commit 8a7a24ce97
2 changed files with 65 additions and 77 deletions

View File

@ -68,14 +68,14 @@ DeviceManager::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device)
} }
// GPIO Switch // GPIO Switch
if (device->deviceClassId() == gpioSwitchRpiDeviceClassId || device->deviceClassId() == gpioSwitchBbbDeviceClassId) { if (device->deviceClassId() == gpioOutputRpiDeviceClassId || device->deviceClassId() == gpioOutputBbbDeviceClassId) {
// Create and configure gpio // Create and configure gpio
int gpioId = -1; int gpioId = -1;
if (device->deviceClassId() == gpioSwitchRpiDeviceClassId) if (device->deviceClassId() == gpioOutputRpiDeviceClassId)
gpioId = device->paramValue(gpioSwitchRpiGpioParamTypeId).toInt(); gpioId = device->paramValue(gpioOutputRpiGpioParamTypeId).toInt();
if (device->deviceClassId() == gpioSwitchBbbDeviceClassId) if (device->deviceClassId() == gpioOutputBbbDeviceClassId)
gpioId = device->paramValue(gpioSwitchBbbGpioParamTypeId).toInt(); gpioId = device->paramValue(gpioOutputBbbGpioParamTypeId).toInt();
Gpio *gpio = new Gpio(gpioId, this); Gpio *gpio = new Gpio(gpioId, this);
@ -96,23 +96,23 @@ DeviceManager::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device)
m_gpioDevices.insert(gpio, device); m_gpioDevices.insert(gpio, device);
if (device->deviceClassId() == gpioSwitchRpiDeviceClassId) if (device->deviceClassId() == gpioOutputRpiDeviceClassId)
m_raspberryPiGpios.insert(gpio->gpioNumber(), gpio); m_raspberryPiGpios.insert(gpio->gpioNumber(), gpio);
if (device->deviceClassId() == gpioSwitchBbbDeviceClassId) if (device->deviceClassId() == gpioOutputBbbDeviceClassId)
m_beagleboneBlackGpios.insert(gpio->gpioNumber(), gpio); m_beagleboneBlackGpios.insert(gpio->gpioNumber(), gpio);
return DeviceManager::DeviceSetupStatusSuccess; return DeviceManager::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == gpioButtonRpiDeviceClassId || device->deviceClassId() == gpioButtonBbbDeviceClassId) { if (device->deviceClassId() == gpioInputRpiDeviceClassId || device->deviceClassId() == gpioInputBbbDeviceClassId) {
int gpioId = -1; int gpioId = -1;
if (device->deviceClassId() == gpioButtonRpiDeviceClassId) if (device->deviceClassId() == gpioInputRpiDeviceClassId)
gpioId = device->paramValue(gpioButtonRpiGpioParamTypeId).toInt(); gpioId = device->paramValue(gpioInputRpiGpioParamTypeId).toInt();
if (device->deviceClassId() == gpioButtonBbbDeviceClassId) if (device->deviceClassId() == gpioInputBbbDeviceClassId)
gpioId = device->paramValue(gpioButtonBbbGpioParamTypeId).toInt(); gpioId = device->paramValue(gpioInputBbbGpioParamTypeId).toInt();
GpioMonitor *monior = new GpioMonitor(gpioId, this); GpioMonitor *monior = new GpioMonitor(gpioId, this);
@ -125,10 +125,10 @@ DeviceManager::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device)
m_monitorDevices.insert(monior, device); m_monitorDevices.insert(monior, device);
if (device->deviceClassId() == gpioSwitchRpiDeviceClassId) if (device->deviceClassId() == gpioOutputRpiDeviceClassId)
m_raspberryPiGpioMoniors.insert(monior->gpio()->gpioNumber(), monior); m_raspberryPiGpioMoniors.insert(monior->gpio()->gpioNumber(), monior);
if (device->deviceClassId() == gpioSwitchBbbDeviceClassId) if (device->deviceClassId() == gpioOutputBbbDeviceClassId)
m_beagleboneBlackGpioMoniors.insert(monior->gpio()->gpioNumber(), monior); m_beagleboneBlackGpioMoniors.insert(monior->gpio()->gpioNumber(), monior);
return DeviceManager::DeviceSetupStatusSuccess; return DeviceManager::DeviceSetupStatusSuccess;
@ -174,14 +174,14 @@ DeviceManager::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId
DeviceDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description); DeviceDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description);
ParamList parameters; ParamList parameters;
if (deviceClass.id() == gpioSwitchRpiDeviceClassId) { if (deviceClass.id() == gpioOutputRpiDeviceClassId) {
parameters.append(Param(gpioSwitchRpiGpioParamTypeId, gpioDescriptor.gpio())); parameters.append(Param(gpioOutputRpiGpioParamTypeId, gpioDescriptor.gpio()));
parameters.append(Param(gpioSwitchRpiPinParamTypeId, gpioDescriptor.pin())); parameters.append(Param(gpioOutputRpiPinParamTypeId, gpioDescriptor.pin()));
parameters.append(Param(gpioSwitchRpiDescriptionParamTypeId, gpioDescriptor.description())); parameters.append(Param(gpioOutputRpiDescriptionParamTypeId, gpioDescriptor.description()));
} else if (deviceClass.id() == gpioButtonRpiDeviceClassId) { } else if (deviceClass.id() == gpioInputRpiDeviceClassId) {
parameters.append(Param(gpioButtonRpiGpioParamTypeId, gpioDescriptor.gpio())); parameters.append(Param(gpioInputRpiGpioParamTypeId, gpioDescriptor.gpio()));
parameters.append(Param(gpioButtonRpiPinParamTypeId, gpioDescriptor.pin())); parameters.append(Param(gpioInputRpiPinParamTypeId, gpioDescriptor.pin()));
parameters.append(Param(gpioButtonRpiDescriptionParamTypeId, gpioDescriptor.description())); parameters.append(Param(gpioInputRpiDescriptionParamTypeId, gpioDescriptor.description()));
} }
descriptor.setParams(parameters); descriptor.setParams(parameters);
@ -217,14 +217,14 @@ DeviceManager::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId
DeviceDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description); DeviceDescriptor descriptor(deviceClassId, QString("GPIO %1").arg(gpioDescriptor.gpio()), description);
ParamList parameters; ParamList parameters;
if (deviceClass.id() == gpioSwitchBbbDeviceClassId) { if (deviceClass.id() == gpioOutputBbbDeviceClassId) {
parameters.append(Param(gpioSwitchBbbGpioParamTypeId, gpioDescriptor.gpio())); parameters.append(Param(gpioOutputBbbGpioParamTypeId, gpioDescriptor.gpio()));
parameters.append(Param(gpioSwitchBbbPinParamTypeId, gpioDescriptor.pin())); parameters.append(Param(gpioOutputBbbPinParamTypeId, gpioDescriptor.pin()));
parameters.append(Param(gpioSwitchBbbDescriptionParamTypeId, gpioDescriptor.description())); parameters.append(Param(gpioOutputBbbDescriptionParamTypeId, gpioDescriptor.description()));
} else if (deviceClass.id() == gpioButtonBbbDeviceClassId) { } else if (deviceClass.id() == gpioInputBbbDeviceClassId) {
parameters.append(Param(gpioButtonBbbGpioParamTypeId, gpioDescriptor.gpio())); parameters.append(Param(gpioInputBbbGpioParamTypeId, gpioDescriptor.gpio()));
parameters.append(Param(gpioButtonBbbPinParamTypeId, gpioDescriptor.pin())); parameters.append(Param(gpioInputBbbPinParamTypeId, gpioDescriptor.pin()));
parameters.append(Param(gpioButtonBbbDescriptionParamTypeId, gpioDescriptor.description())); parameters.append(Param(gpioInputBbbDescriptionParamTypeId, gpioDescriptor.description()));
} }
descriptor.setParams(parameters); descriptor.setParams(parameters);
@ -282,10 +282,10 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const
// Find the gpio in the corresponding hash // Find the gpio in the corresponding hash
if (deviceClass.vendorId() == raspberryPiVendorId) if (deviceClass.vendorId() == raspberryPiVendorId)
gpio = m_raspberryPiGpios.value(device->paramValue(gpioSwitchRpiGpioParamTypeId).toInt()); gpio = m_raspberryPiGpios.value(device->paramValue(gpioOutputRpiGpioParamTypeId).toInt());
if (deviceClass.vendorId() == beagleboneBlackVendorId) if (deviceClass.vendorId() == beagleboneBlackVendorId)
gpio = m_beagleboneBlackGpios.value(device->paramValue(gpioSwitchBbbGpioParamTypeId).toInt()); gpio = m_beagleboneBlackGpios.value(device->paramValue(gpioOutputBbbGpioParamTypeId).toInt());
// Check if gpio was found // Check if gpio was found
if (!gpio) { if (!gpio) {
@ -295,9 +295,9 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const
// GPIO Switch power action // GPIO Switch power action
if (deviceClass.vendorId() == raspberryPiVendorId) { if (deviceClass.vendorId() == raspberryPiVendorId) {
if (action.actionTypeId() == gpioSwitchRpiPowerValueActionTypeId) { if (action.actionTypeId() == gpioOutputRpiPowerValueActionTypeId) {
bool success = false; bool success = false;
if (action.param(gpioSwitchRpiPowerValueStateParamTypeId).value().toBool()) { if (action.param(gpioOutputRpiPowerValueStateParamTypeId).value().toBool()) {
success = gpio->setValue(Gpio::ValueHigh); success = gpio->setValue(Gpio::ValueHigh);
} else { } else {
success = gpio->setValue(Gpio::ValueLow); success = gpio->setValue(Gpio::ValueLow);
@ -309,14 +309,14 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const
} }
// Set the current state // Set the current state
device->setStateValue(gpioSwitchRpiPowerValueStateTypeId, action.param(gpioSwitchRpiPowerValueStateParamTypeId).value()); device->setStateValue(gpioOutputRpiPowerValueStateTypeId, action.param(gpioOutputRpiPowerValueStateParamTypeId).value());
return DeviceManager::DeviceErrorNoError; return DeviceManager::DeviceErrorNoError;
} }
} else if (deviceClass.vendorId() == beagleboneBlackVendorId) { } else if (deviceClass.vendorId() == beagleboneBlackVendorId) {
if (action.actionTypeId() == gpioSwitchBbbPowerValueActionTypeId) { if (action.actionTypeId() == gpioOutputBbbPowerValueActionTypeId) {
bool success = false; bool success = false;
if (action.param(gpioSwitchBbbPowerValueStateParamTypeId).value().toBool()) { if (action.param(gpioOutputBbbPowerValueStateParamTypeId).value().toBool()) {
success = gpio->setValue(Gpio::ValueHigh); success = gpio->setValue(Gpio::ValueHigh);
} else { } else {
success = gpio->setValue(Gpio::ValueLow); success = gpio->setValue(Gpio::ValueLow);
@ -328,7 +328,7 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const
} }
// Set the current state // Set the current state
device->setStateValue(gpioSwitchBbbPowerValueStateTypeId, action.param(gpioSwitchBbbPowerValueStateParamTypeId).value()); device->setStateValue(gpioOutputBbbPowerValueStateTypeId, action.param(gpioOutputBbbPowerValueStateParamTypeId).value());
return DeviceManager::DeviceErrorNoError; return DeviceManager::DeviceErrorNoError;
} }
@ -339,29 +339,29 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const
void DevicePluginGpio::postSetupDevice(Device *device) void DevicePluginGpio::postSetupDevice(Device *device)
{ {
if (device->deviceClassId() == gpioSwitchRpiDeviceClassId || device->deviceClassId() == gpioSwitchBbbDeviceClassId) { if (device->deviceClassId() == gpioOutputRpiDeviceClassId || device->deviceClassId() == gpioOutputBbbDeviceClassId) {
Gpio *gpio = m_gpioDevices.key(device); Gpio *gpio = m_gpioDevices.key(device);
if (!gpio) if (!gpio)
return; return;
gpio->setValue(Gpio::ValueLow); gpio->setValue(Gpio::ValueLow);
if (device->deviceClassId() == gpioSwitchRpiDeviceClassId) { if (device->deviceClassId() == gpioOutputRpiDeviceClassId) {
device->setStateValue(gpioSwitchRpiPowerValueStateTypeId, false); device->setStateValue(gpioOutputRpiPowerValueStateTypeId, false);
} }
if (device->deviceClassId() == gpioSwitchBbbDeviceClassId) { if (device->deviceClassId() == gpioOutputBbbDeviceClassId) {
device->setStateValue(gpioSwitchBbbPowerValueStateTypeId, false); device->setStateValue(gpioOutputBbbPowerValueStateTypeId, false);
} }
} }
if (device->deviceClassId() == gpioButtonRpiDeviceClassId || device->deviceClassId() == gpioButtonBbbDeviceClassId) { if (device->deviceClassId() == gpioInputRpiDeviceClassId || device->deviceClassId() == gpioInputBbbDeviceClassId) {
GpioMonitor *monitor = m_monitorDevices.key(device); GpioMonitor *monitor = m_monitorDevices.key(device);
if (!monitor) if (!monitor)
return; return;
if (device->deviceClassId() == gpioButtonRpiDeviceClassId) { if (device->deviceClassId() == gpioInputRpiDeviceClassId) {
device->setStateValue(gpioButtonRpiPressedStateTypeId, monitor->value()); device->setStateValue(gpioInputRpiPressedStateTypeId, monitor->value());
} else if (device->deviceClassId() == gpioButtonBbbDeviceClassId) { } else if (device->deviceClassId() == gpioInputBbbDeviceClassId) {
device->setStateValue(gpioButtonBbbPressedStateTypeId, monitor->value()); device->setStateValue(gpioInputBbbPressedStateTypeId, monitor->value());
} }
} }
} }
@ -481,10 +481,10 @@ void DevicePluginGpio::onGpioValueChanged(const bool &value)
if (!device) if (!device)
return; return;
if (device->deviceClassId() == gpioButtonRpiDeviceClassId) { if (device->deviceClassId() == gpioInputRpiDeviceClassId) {
device->setStateValue(gpioButtonRpiPressedStateTypeId, value); device->setStateValue(gpioInputRpiPressedStateTypeId, value);
} else if (device->deviceClassId() == gpioButtonBbbDeviceClassId) { } else if (device->deviceClassId() == gpioInputBbbDeviceClassId) {
device->setStateValue(gpioButtonBbbPressedStateTypeId, value); device->setStateValue(gpioInputBbbPressedStateTypeId, value);
} }
} }

View File

@ -4,19 +4,16 @@
"id": "127ead55-996a-44ac-ba82-fc3c634e018a", "id": "127ead55-996a-44ac-ba82-fc3c634e018a",
"vendors": [ "vendors": [
{ {
"displayName": "Raspberry Pi 2", "displayName": "Raspberry Pi 2/3",
"name": "raspberryPi", "name": "raspberryPi",
"id": "f0d00b66-bbd8-4a07-8591-ea48a61b229e", "id": "f0d00b66-bbd8-4a07-8591-ea48a61b229e",
"deviceClasses": [ "deviceClasses": [
{ {
"id": "3885c520-e202-4435-88f6-3c35c362b2e6", "id": "3885c520-e202-4435-88f6-3c35c362b2e6",
"displayName": "GPIO Switch", "displayName": "GPIO Output",
"name": "gpioSwitchRpi", "name": "gpioOutputRpi",
"deviceIcon": "Switch", "deviceIcon": "Switch",
"basicTags": [ "basicTags": ["Device", "Actuator"],
"Device",
"Actuator"
],
"createMethods": ["discovery"], "createMethods": ["discovery"],
"paramTypes": [ "paramTypes": [
{ {
@ -56,13 +53,10 @@
}, },
{ {
"id": "6aff228b-0410-4ef9-9593-51e8639aacea", "id": "6aff228b-0410-4ef9-9593-51e8639aacea",
"displayName": "GPIO Button", "displayName": "GPIO Input",
"name": "gpioButtonRpi", "name": "gpioInputRpi",
"deviceIcon": "Power", "deviceIcon": "Power",
"basicTags": [ "basicTags": ["Device", "Sensor"],
"Device",
"Sensor"
],
"createMethods": ["discovery"], "createMethods": ["discovery"],
"paramTypes": [ "paramTypes": [
{ {
@ -107,13 +101,10 @@
"deviceClasses": [ "deviceClasses": [
{ {
"id": "75d54a59-f9b0-4bc4-a86c-6b1fc47e0663", "id": "75d54a59-f9b0-4bc4-a86c-6b1fc47e0663",
"displayName": "GPIO Switch", "displayName": "GPIO Output",
"name": "gpioSwitchBbb", "name": "gpioOutputBbb",
"deviceIcon": "Switch", "deviceIcon": "Switch",
"basicTags": [ "basicTags": ["Device", "Actuator"],
"Device",
"Actuator"
],
"createMethods": ["discovery"], "createMethods": ["discovery"],
"paramTypes": [ "paramTypes": [
{ {
@ -153,13 +144,10 @@
}, },
{ {
"id": "ffd2aa29-55cc-4824-ba95-c311784f7824", "id": "ffd2aa29-55cc-4824-ba95-c311784f7824",
"displayName": "GPIO Button", "displayName": "GPIO Input",
"name": "gpioButtonBbb", "name": "gpioInputBbb",
"deviceIcon": "Power", "deviceIcon": "Power",
"basicTags": [ "basicTags": ["Device", "Sensor"],
"Device",
"Sensor"
],
"createMethods": ["discovery"], "createMethods": ["discovery"],
"paramTypes": [ "paramTypes": [
{ {