Add gpio button settings and minor fixes
parent
b296346945
commit
506a14ea10
|
|
@ -50,6 +50,7 @@ void IntegrationPluginGpio::init()
|
|||
m_gpioParamTypeIds.insert(gpioOutputBbbThingClassId, gpioOutputBbbThingGpioParamTypeId);
|
||||
m_gpioParamTypeIds.insert(gpioInputBbbThingClassId, gpioInputBbbThingGpioParamTypeId);
|
||||
m_gpioParamTypeIds.insert(counterBbbThingClassId, counterBbbThingGpioParamTypeId);
|
||||
m_gpioParamTypeIds.insert(gpioButtonBbbThingClassId, gpioButtonBbbThingGpioParamTypeId);
|
||||
|
||||
// Raspberry pi
|
||||
m_activeLowParamTypeIds.insert(gpioOutputRpiThingClassId, gpioOutputRpiThingActiveLowParamTypeId);
|
||||
|
|
@ -61,6 +62,7 @@ void IntegrationPluginGpio::init()
|
|||
m_activeLowParamTypeIds.insert(gpioOutputBbbThingClassId, gpioOutputBbbThingActiveLowParamTypeId);
|
||||
m_activeLowParamTypeIds.insert(gpioInputBbbThingClassId, gpioInputBbbThingActiveLowParamTypeId);
|
||||
m_activeLowParamTypeIds.insert(counterBbbThingClassId, counterBbbThingActiveLowParamTypeId);
|
||||
m_activeLowParamTypeIds.insert(gpioButtonBbbThingClassId, gpioButtonBbbThingActiveLowParamTypeId);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -122,14 +124,17 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info)
|
|||
}
|
||||
|
||||
if (thing->thingClassId() == gpioInputRpiThingClassId || thing->thingClassId() == gpioInputBbbThingClassId) {
|
||||
|
||||
GpioMonitor *monitor = new GpioMonitor(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this);
|
||||
monitor->setActiveLow(thing->paramValue(m_activeLowParamTypeIds.value(thing->thingClassId())).toBool());
|
||||
if (!monitor->enable()) {
|
||||
qCWarning(dcGpioController()) << "Could not enable gpio monitor for thing" << thing->name();
|
||||
//: Error setting up GPIO thing
|
||||
monitor->deleteLater();
|
||||
return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO monitor failed."));
|
||||
}
|
||||
|
||||
|
||||
|
||||
connect(monitor, &GpioMonitor::enabledChanged, thing, [this, thing](bool enabled){
|
||||
if (thing->thingClassId() == gpioInputRpiThingClassId) {
|
||||
thing->setStateValue(gpioInputRpiPowerStateTypeId, enabled);
|
||||
|
|
@ -156,8 +161,10 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info)
|
|||
// Counter
|
||||
if (thing->thingClassId() == counterRpiThingClassId || thing->thingClassId() == counterBbbThingClassId) {
|
||||
GpioMonitor *monitor = new GpioMonitor(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this);
|
||||
monitor->setActiveLow(thing->paramValue(m_activeLowParamTypeIds.value(thing->thingClassId())).toBool());
|
||||
if (!monitor->enable()) {
|
||||
qCWarning(dcGpioController()) << "Could not enable gpio monitor for thing" << thing->name();
|
||||
monitor->deleteLater();
|
||||
//: Error setting up GPIO thing
|
||||
return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO monitor failed."));
|
||||
}
|
||||
|
|
@ -183,14 +190,40 @@ void IntegrationPluginGpio::setupThing(ThingSetupInfo *info)
|
|||
}
|
||||
|
||||
// Button
|
||||
if (thing->thingClassId() == gpioButtonRpiThingClassId) {
|
||||
if (thing->thingClassId() == gpioButtonRpiThingClassId || thing->thingClassId() == gpioButtonBbbThingClassId) {
|
||||
GpioButton *button = new GpioButton(thing->paramValue(m_gpioParamTypeIds.value(thing->thingClassId())).toInt(), this);
|
||||
button->setActiveLow(thing->paramValue(m_activeLowParamTypeIds.value(thing->thingClassId())).toBool());
|
||||
if (thing->thingClassId() == gpioButtonRpiThingClassId) {
|
||||
button->setLongPressedTimeout(thing->setting(gpioButtonRpiSettingsLongPressedTimeoutParamTypeId).toUInt());
|
||||
button->setRepeateLongPressed(thing->setting(gpioButtonRpiSettingsRepeateLongPressedParamTypeId).toBool());
|
||||
} else if (thing->thingClassId() == gpioButtonBbbThingClassId) {
|
||||
button->setLongPressedTimeout(thing->setting(gpioButtonBbbSettingsLongPressedTimeoutParamTypeId).toUInt());
|
||||
button->setRepeateLongPressed(thing->setting(gpioButtonBbbSettingsRepeateLongPressedParamTypeId).toBool());
|
||||
}
|
||||
|
||||
if (!button->enable()) {
|
||||
qCWarning(dcGpioController()) << "Could not enable button" << button;
|
||||
button->deleteLater();
|
||||
return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Enabling GPIO button failed."));
|
||||
}
|
||||
|
||||
connect(thing, &Thing::settingChanged, this, [button, thing](const ParamTypeId ¶mTypeId, const QVariant &value){
|
||||
qCDebug(dcGpioController()) << button << "settings changed" << paramTypeId.toString() << value;
|
||||
if (thing->thingClassId() == gpioButtonRpiThingClassId) {
|
||||
if (paramTypeId == gpioButtonRpiSettingsRepeateLongPressedParamTypeId) {
|
||||
button->setRepeateLongPressed(value.toBool());
|
||||
} else if (paramTypeId == gpioButtonRpiSettingsLongPressedTimeoutParamTypeId) {
|
||||
button->setLongPressedTimeout(value.toUInt());
|
||||
}
|
||||
} else if (thing->thingClassId() == gpioButtonBbbThingClassId) {
|
||||
if (paramTypeId == gpioButtonBbbSettingsRepeateLongPressedParamTypeId) {
|
||||
button->setRepeateLongPressed(value.toBool());
|
||||
} else if (paramTypeId == gpioButtonBbbSettingsLongPressedTimeoutParamTypeId) {
|
||||
button->setLongPressedTimeout(value.toUInt());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(button, &GpioButton::clicked, this, [this, thing, button](){
|
||||
qCDebug(dcGpioController()) << button << "clicked";
|
||||
if (thing->thingClassId() == gpioButtonRpiThingClassId) {
|
||||
|
|
|
|||
|
|
@ -142,6 +142,23 @@
|
|||
"defaultValue": "-"
|
||||
}
|
||||
],
|
||||
"settingsTypes": [
|
||||
{
|
||||
"id": "d826f02e-7528-4ad5-ac71-f49df988114d",
|
||||
"name": "repeateLongPressed",
|
||||
"displayName": "Repeat long pressed",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"id": "46a25783-3e96-4489-a3f0-15236d938f17",
|
||||
"name": "longPressedTimeout",
|
||||
"displayName": "Long pressed timeout [ms]",
|
||||
"type": "uint",
|
||||
"minValue": 200,
|
||||
"defaultValue": 250
|
||||
}
|
||||
],
|
||||
"eventTypes": [
|
||||
{
|
||||
"id": "28330833-158c-4f99-9f6e-407ee8f29a4e",
|
||||
|
|
@ -344,6 +361,23 @@
|
|||
"defaultValue": "-"
|
||||
}
|
||||
],
|
||||
"settingsTypes": [
|
||||
{
|
||||
"id": "292bf500-b7ab-428b-908c-2fedae295ee2",
|
||||
"name": "repeateLongPressed",
|
||||
"displayName": "Repeat long pressed",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"id": "007be75a-bfcd-4039-b8ab-9bce25421894",
|
||||
"name": "longPressedTimeout",
|
||||
"displayName": "Long pressed timeout [ms]",
|
||||
"type": "uint",
|
||||
"minValue": 200,
|
||||
"defaultValue": 250
|
||||
}
|
||||
],
|
||||
"eventTypes": [
|
||||
{
|
||||
"id": "d02b16a8-a242-41f5-b4e0-d3209849f25e",
|
||||
|
|
|
|||
Loading…
Reference in New Issue