Fix button code handling

This commit is contained in:
Michael Zanetti 2020-04-01 15:37:37 +02:00
parent 3a750ad640
commit ab61e93eae
2 changed files with 78 additions and 75 deletions

View File

@ -44,23 +44,6 @@ class HueRemote : public HueDevice
{ {
Q_OBJECT Q_OBJECT
public: public:
enum ButtonCode {
SmartButtonPressed = 1000,
OnLongPressed = 1001,
OnPressed = 1002,
SmartButtonLongPressed = 1003,
DimUpLongPressed = 2001,
DimUpPressed = 2002,
DimDownLongPressed = 3001,
DimDownPressed = 3002,
OffLongPressed = 4001,
OffPressed = 4002,
TapButton1Pressed = 34,
TapButton2Pressed = 16,
TapButton3Pressed = 17,
TapButton4Pressed = 18
};
explicit HueRemote(QObject *parent = nullptr); explicit HueRemote(QObject *parent = nullptr);
int battery() const; int battery() const;
@ -74,7 +57,7 @@ private:
signals: signals:
void stateChanged(); void stateChanged();
void buttonPressed(const int &buttonCode); void buttonPressed(int buttonCode);
}; };

View File

@ -1018,67 +1018,87 @@ void IntegrationPluginPhilipsHue::remoteStateChanged()
void IntegrationPluginPhilipsHue::onRemoteButtonEvent(int buttonCode) void IntegrationPluginPhilipsHue::onRemoteButtonEvent(int buttonCode)
{ {
HueRemote *remote = static_cast<HueRemote *>(sender()); HueRemote *remote = static_cast<HueRemote *>(sender());
Thing *thing = m_remotes.value(remote);
if (!thing) {
qCWarning(dcPhilipsHue()) << "Received a button press event for a thing we don't know!";
return;
}
EventTypeId id; EventTypeId id;
Param param; Param param;
switch (buttonCode) { if (thing->thingClassId() == remoteThingClassId) {
case HueRemote::OnPressed: switch (buttonCode) {
param = Param(remotePressedEventButtonNameParamTypeId, "ON"); case 1002:
id = remotePressedEventTypeId; param = Param(remotePressedEventButtonNameParamTypeId, "ON");
break; id = remotePressedEventTypeId;
case HueRemote::OnLongPressed: break;
param = Param(remoteLongPressedEventButtonNameParamTypeId, "ON"); case 1001:
id = remoteLongPressedEventTypeId; param = Param(remoteLongPressedEventButtonNameParamTypeId, "ON");
break; id = remoteLongPressedEventTypeId;
case HueRemote::DimUpPressed: break;
param = Param(remotePressedEventButtonNameParamTypeId, "DIM UP"); case 2002:
id = remotePressedEventTypeId; param = Param(remotePressedEventButtonNameParamTypeId, "DIM UP");
break; id = remotePressedEventTypeId;
case HueRemote::DimUpLongPressed: break;
param = Param(remoteLongPressedEventButtonNameParamTypeId, "DIM UP"); case 2001:
id = remoteLongPressedEventTypeId; param = Param(remoteLongPressedEventButtonNameParamTypeId, "DIM UP");
break; id = remoteLongPressedEventTypeId;
case HueRemote::DimDownPressed: break;
param = Param(remotePressedEventButtonNameParamTypeId, "DIM DOWN"); case 3002:
id = remotePressedEventTypeId; param = Param(remotePressedEventButtonNameParamTypeId, "DIM DOWN");
break; id = remotePressedEventTypeId;
case HueRemote::DimDownLongPressed: break;
param = Param(remoteLongPressedEventButtonNameParamTypeId, "DIM DOWN"); case 3001:
id = remoteLongPressedEventTypeId; param = Param(remoteLongPressedEventButtonNameParamTypeId, "DIM DOWN");
break; id = remoteLongPressedEventTypeId;
case HueRemote::OffPressed: break;
param = Param(remotePressedEventButtonNameParamTypeId, "OFF"); case 4002:
id = remotePressedEventTypeId; param = Param(remotePressedEventButtonNameParamTypeId, "OFF");
break; id = remotePressedEventTypeId;
case HueRemote::OffLongPressed: break;
param = Param(remoteLongPressedEventButtonNameParamTypeId, "OFF"); case 4001:
id = remoteLongPressedEventTypeId; param = Param(remoteLongPressedEventButtonNameParamTypeId, "OFF");
break; id = remoteLongPressedEventTypeId;
case HueRemote::TapButton1Pressed: break;
param = Param(tapPressedEventButtonNameParamTypeId, ""); default:
id = tapPressedEventTypeId; qCDebug(dcPhilipsHue()) << "Unhandled button code received from Hue Remoote:" << buttonCode;
break; return;
case HueRemote::TapButton2Pressed: }
param = Param(tapPressedEventButtonNameParamTypeId, "••"); } else if (thing->thingClassId() == tapThingClassId) {
id = tapPressedEventTypeId; switch (buttonCode) {
break; case 34:
case HueRemote::TapButton3Pressed: param = Param(tapPressedEventButtonNameParamTypeId, "");
param = Param(tapPressedEventButtonNameParamTypeId, "•••"); id = tapPressedEventTypeId;
id = tapPressedEventTypeId; break;
break; case 16:
case HueRemote::TapButton4Pressed: param = Param(tapPressedEventButtonNameParamTypeId, "••");
param = Param(tapPressedEventButtonNameParamTypeId, "••••"); id = tapPressedEventTypeId;
id = tapPressedEventTypeId; break;
break; case 17:
case HueRemote::SmartButtonPressed: param = Param(tapPressedEventButtonNameParamTypeId, "•••");
id = smartButtonPressedEventTypeId; id = tapPressedEventTypeId;
break; break;
case HueRemote::SmartButtonLongPressed: case 18:
id = smartButtonLongPressedEventTypeId; param = Param(tapPressedEventButtonNameParamTypeId, "••••");
break; id = tapPressedEventTypeId;
default: break;
break; default:
qCDebug(dcPhilipsHue()) << "Received unhandled button code from Hue Tap:" << buttonCode;
return;
}
} else if (thing->thingClassId() == smartButtonThingClassId) {
switch (buttonCode) {
case 1000:
id = smartButtonPressedEventTypeId;
break;
case 1003:
id = smartButtonLongPressedEventTypeId;
break;
default:
qCDebug(dcPhilipsHue()) << "Received unhandled button code from Hue Smart Button:" << buttonCode;
return;
}
} }
emitEvent(Event(id, m_remotes.value(remote)->id(), ParamList() << param)); emitEvent(Event(id, m_remotes.value(remote)->id(), ParamList() << param));
} }