Commit e93e2a46 authored by luz's avatar luz

ButtonBehaviour: now allows restricting mode (LTMODE) to default derived from...

ButtonBehaviour: now allows restricting mode (LTMODE) to default derived from hardware (and inactive).

This is to avoid making 2-way switches useless by accidental mode change to 0 due to dSS not knowing the exact button type.
parent 640a131b
......@@ -38,6 +38,7 @@ ButtonBehaviour::ButtonBehaviour(Device &aDevice) :
// persistent settings
buttonGroup(group_yellow_light),
buttonMode(buttonMode_inactive), // none by default, hardware should set a default matching the actual HW capabilities
fixedButtonMode(buttonMode_inactive), // by default, mode can be set. Hardware may fix the possible mode
buttonChannel(channeltype_default), // by default, buttons act on default channel
buttonFunc(buttonFunc_room_preset0x), // act as room button by default
setsLocalPriority(false),
......@@ -48,13 +49,13 @@ ButtonBehaviour::ButtonBehaviour(Device &aDevice) :
callsPresent(false)
{
// set default hrdware configuration
setHardwareButtonConfig(0, buttonType_single, buttonElement_center, false, 0);
setHardwareButtonConfig(0, buttonType_single, buttonElement_center, false, 0, false);
// reset the button state machine
resetStateMachine();
}
void ButtonBehaviour::setHardwareButtonConfig(int aButtonID, DsButtonType aType, DsButtonElement aElement, bool aSupportsLocalKeyMode, int aCounterPartIndex)
void ButtonBehaviour::setHardwareButtonConfig(int aButtonID, DsButtonType aType, DsButtonElement aElement, bool aSupportsLocalKeyMode, int aCounterPartIndex, bool aButtonModeFixed)
{
buttonID = aButtonID;
buttonType = aType;
......@@ -73,6 +74,10 @@ void ButtonBehaviour::setHardwareButtonConfig(int aButtonID, DsButtonType aType,
buttonMode = (DsButtonMode)((int)buttonMode_rockerDown_pairWith0+aCounterPartIndex);
}
}
if (aButtonModeFixed) {
// limit settings to this mode
fixedButtonMode = buttonMode;
}
}
......@@ -586,10 +591,16 @@ bool ButtonBehaviour::accessField(PropertyAccessMode aMode, ApiValuePtr aPropVal
buttonGroup = (DsGroup)aPropValue->int32Value();
markDirty();
return true;
case mode_key+settings_key_offset:
buttonMode = (DsButtonMode)aPropValue->int32Value();
case mode_key+settings_key_offset: {
DsButtonMode m = (DsButtonMode)aPropValue->int32Value();
if (m!=buttonMode_inactive && fixedButtonMode!=buttonMode_inactive) {
// only one particular mode (aside from inactive) is allowed.
m = fixedButtonMode;
}
buttonMode = m;
markDirty();
return true;
}
case function_key+settings_key_offset:
buttonFunc = (DsButtonFunc)aPropValue->int32Value();
markDirty();
......
......@@ -50,6 +50,7 @@ namespace p44 {
int buttonID; ///< the ID grouping all inputs of a hardware button (which can have multiple elements)
DsButtonType buttonType; ///< type of button
DsButtonElement buttonElementID; ///< identifies element of a multi-input button hardware-button
DsButtonMode fixedButtonMode; ///< if not buttonMode_inactive, then this is the only mode that can be set
/// @}
/// @name persistent settings
......@@ -82,9 +83,10 @@ namespace p44 {
/// @param aElement the element of the physical button this input represents (like: up or down for a 2-way rocker)
/// @param aSupportsLocalKeyMode true if this button can be local key
/// @param aCounterPartIndex for 2-way buttons, this identifies the index of the counterpart input (needed for dS 1.0 LTMODE compatibility only)
/// @param aButtonModeFixed if set, buttonMode can only be switched between hardware-derived default mode and disabled
/// @note this must be called once before the device gets added to the device container. Implementation might
/// also derive default values for settings from this information.
void setHardwareButtonConfig(int aButtonID, DsButtonType aType, DsButtonElement aElement, bool aSupportsLocalKeyMode, int aCounterPartIndex);
void setHardwareButtonConfig(int aButtonID, DsButtonType aType, DsButtonElement aElement, bool aSupportsLocalKeyMode, int aCounterPartIndex, bool aButtonModeFixed);
/// set group
virtual void setGroup(DsGroup aGroup) { buttonGroup = aGroup; };
......
......@@ -86,7 +86,7 @@ EnoceanDevicePtr EnoceanRpsHandler::newDevice(
buttonHandler->switchIndex = aSubDeviceIndex>>1; // each switch HALF has its own subdevice
buttonHandler->isRockerUp = isUp;
ButtonBehaviourPtr buttonBhvr = ButtonBehaviourPtr(new ButtonBehaviour(*newDev.get()));
buttonBhvr->setHardwareButtonConfig(0, buttonType_2way, isUp ? buttonElement_up : buttonElement_down, false, isUp ? 0 : 1);
buttonBhvr->setHardwareButtonConfig(0, buttonType_2way, isUp ? buttonElement_up : buttonElement_down, false, isUp ? 0 : 1, true); // fixed mode
buttonBhvr->setGroup(group_yellow_light); // pre-configure for light
buttonBhvr->setHardwareName(isUp ? "Up key" : "Down key");
buttonHandler->behaviour = buttonBhvr;
......@@ -117,7 +117,7 @@ EnoceanDevicePtr EnoceanRpsHandler::newDevice(
downHandler->switchIndex = aSubDeviceIndex; // each switch gets its own subdevice
downHandler->isRockerUp = false;
ButtonBehaviourPtr downBhvr = ButtonBehaviourPtr(new ButtonBehaviour(*newDev.get()));
downBhvr->setHardwareButtonConfig(0, buttonType_2way, buttonElement_down, false, 1); // counterpart up-button has index 1
downBhvr->setHardwareButtonConfig(0, buttonType_2way, buttonElement_down, false, 1, true); // counterpart up-button has index 1, fixed mode
downBhvr->setGroup(group_yellow_light); // pre-configure for light
downBhvr->setHardwareName("down key");
downHandler->behaviour = downBhvr;
......@@ -128,7 +128,7 @@ EnoceanDevicePtr EnoceanRpsHandler::newDevice(
upHandler->isRockerUp = true;
ButtonBehaviourPtr upBhvr = ButtonBehaviourPtr(new ButtonBehaviour(*newDev.get()));
upBhvr->setGroup(group_yellow_light); // pre-configure for light
upBhvr->setHardwareButtonConfig(0, buttonType_2way, buttonElement_up, false, 0); // counterpart down-button has index 0
upBhvr->setHardwareButtonConfig(0, buttonType_2way, buttonElement_up, false, 0, true); // counterpart down-button has index 0, fixed mode
upBhvr->setHardwareName("up key");
upHandler->behaviour = upBhvr;
newDev->addChannelHandler(upHandler);
......
......@@ -70,7 +70,7 @@ ConsoleDevice::ConsoleDevice(StaticDeviceContainer *aClassContainerP, const stri
consoleKey->setConsoleKeyHandler(boost::bind(&ConsoleDevice::buttonHandler, this, _1, _2));
// - create one button input
ButtonBehaviourPtr b = ButtonBehaviourPtr(new ButtonBehaviour(*this));
b->setHardwareButtonConfig(0, buttonType_single, buttonElement_center, false, 0);
b->setHardwareButtonConfig(0, buttonType_single, buttonElement_center, false, 0, false); // mode not restricted
b->setHardwareName(string_format("console key '%c'",name[0]));
addBehaviour(b);
}
......
......@@ -66,7 +66,7 @@ DigitalIODevice::DigitalIODevice(StaticDeviceContainer *aClassContainerP, const
buttonInput->setButtonHandler(boost::bind(&DigitalIODevice::buttonHandler, this, _1, _2), true);
// - create one button input
ButtonBehaviourPtr b = ButtonBehaviourPtr(new ButtonBehaviour(*this));
b->setHardwareButtonConfig(0, buttonType_single, buttonElement_center, false, 0);
b->setHardwareButtonConfig(0, buttonType_single, buttonElement_center, false, 0, false); // mode not restricted
addBehaviour(b);
}
else if (digitalIoType==digitalio_input) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment