Skip to content

Commit

Permalink
Add a bridged switched device to the bridge app (project-chip#10703)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjzander-signify authored and PSONALl committed Dec 2, 2021
1 parent e53f6d3 commit e0dbb22
Show file tree
Hide file tree
Showing 27 changed files with 1,025 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9323,7 +9323,7 @@
"code": 2,
"mfgCode": null,
"side": "server",
"included": 0,
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
Expand All @@ -9333,6 +9333,21 @@
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
Expand Down
112 changes: 112 additions & 0 deletions examples/bridge-app/bridge-common/bridge-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3936,6 +3936,118 @@
}
]
},
{
"name": "Switch",
"code": 59,
"mfgCode": null,
"define": "SWITCH_CLUSTER",
"side": "client",
"enabled": 0,
"commands": [],
"attributes": [
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "client",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0001",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
}
]
},
{
"name": "Switch",
"code": 59,
"mfgCode": null,
"define": "SWITCH_CLUSTER",
"side": "server",
"enabled": 1,
"commands": [],
"attributes": [
{
"name": "number of positions",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "2",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "current position",
"code": 1,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "multi press max",
"code": 2,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "2",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0001",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
}
]
},
{
"name": "Fixed Label",
"code": 64,
Expand Down
135 changes: 99 additions & 36 deletions examples/bridge-app/linux/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,15 @@ Device::Device(const char * szDeviceName, const char * szLocation)
{
strncpy(mName, szDeviceName, sizeof(mName));
strncpy(mLocation, szLocation, sizeof(mLocation));
mState = kState_Off;
mReachable = false;
mEndpointId = 0;
mChanged_CB = nullptr;
}

bool Device::IsOn()
{
return mState == kState_On;
}

bool Device::IsReachable()
{
return mReachable;
}

void Device::SetOnOff(bool aOn)
{
bool changed;

if (aOn)
{
changed = (mState != kState_On);
mState = kState_On;
ChipLogProgress(DeviceLayer, "Device[%s]: ON", mName);
}
else
{
changed = (mState != kState_Off);
mState = kState_Off;
ChipLogProgress(DeviceLayer, "Device[%s]: OFF", mName);
}

if ((changed) && (mChanged_CB))
{
mChanged_CB(this, kChanged_State);
}
}

void Device::SetReachable(bool aReachable)
{
bool changed = (mReachable != aReachable);
Expand All @@ -82,9 +52,9 @@ void Device::SetReachable(bool aReachable)
ChipLogProgress(DeviceLayer, "Device[%s]: OFFLINE", mName);
}

if ((changed) && (mChanged_CB))
if (changed)
{
mChanged_CB(this, kChanged_Reachable);
HandleDeviceChange(this, kChanged_Reachable);
}
}

Expand All @@ -96,9 +66,9 @@ void Device::SetName(const char * szName)

strncpy(mName, szName, sizeof(mName));

if ((changed) && (mChanged_CB))
if (changed)
{
mChanged_CB(this, kChanged_Name);
HandleDeviceChange(this, kChanged_Name);
}
}

Expand All @@ -110,13 +80,106 @@ void Device::SetLocation(const char * szLocation)

ChipLogProgress(DeviceLayer, "Device[%s]: Location=\"%s\"", mName, mLocation);

if (changed)
{
HandleDeviceChange(this, kChanged_Location);
}
}

DeviceOnOff::DeviceOnOff(const char * szDeviceName, const char * szLocation) : Device(szDeviceName, szLocation)
{
mOn = false;
}

bool DeviceOnOff::IsOn()
{
return mOn;
}

void DeviceOnOff::SetOnOff(bool aOn)
{
bool changed;

changed = aOn ^ mOn;
mOn = aOn;
ChipLogProgress(DeviceLayer, "Device[%s]: %s", mName, aOn ? "ON" : "OFF");

if ((changed) && (mChanged_CB))
{
mChanged_CB(this, kChanged_Location);
mChanged_CB(this, kChanged_OnOff);
}
}

void Device::SetChangeCallback(DeviceCallback_fn aChanged_CB)
void DeviceOnOff::SetChangeCallback(DeviceCallback_fn aChanged_CB)
{
mChanged_CB = aChanged_CB;
}

void DeviceOnOff::HandleDeviceChange(Device * device, Device::Changed_t changeMask)
{
if (mChanged_CB)
{
mChanged_CB(this, (DeviceOnOff::Changed_t) changeMask);
}
}

DeviceSwitch::DeviceSwitch(const char * szDeviceName, const char * szLocation, uint32_t aFeatureMap) :
Device(szDeviceName, szLocation)
{
mNumberOfPositions = 2;
mCurrentPosition = 0;
mMultiPressMax = 2;
mFeatureMap = aFeatureMap;
}

void DeviceSwitch::SetNumberOfPositions(uint8_t aNumberOfPositions)
{
bool changed;

changed = aNumberOfPositions != mNumberOfPositions;
mNumberOfPositions = aNumberOfPositions;

if ((changed) && (mChanged_CB))
{
mChanged_CB(this, kChanged_NumberOfPositions);
}
}

void DeviceSwitch::SetCurrentPosition(uint8_t aCurrentPosition)
{
bool changed;

changed = aCurrentPosition != mCurrentPosition;
mCurrentPosition = aCurrentPosition;

if ((changed) && (mChanged_CB))
{
mChanged_CB(this, kChanged_CurrentPosition);
}
}

void DeviceSwitch::SetMultiPressMax(uint8_t aMultiPressMax)
{
bool changed;

changed = aMultiPressMax != mMultiPressMax;
mMultiPressMax = aMultiPressMax;

if ((changed) && (mChanged_CB))
{
mChanged_CB(this, kChanged_MultiPressMax);
}
}

void DeviceSwitch::SetChangeCallback(DeviceCallback_fn aChanged_CB)
{
mChanged_CB = aChanged_CB;
}

void DeviceSwitch::HandleDeviceChange(Device * device, Device::Changed_t changeMask)
{
if (mChanged_CB)
{
mChanged_CB(this, (DeviceSwitch::Changed_t) changeMask);
}
}
Loading

0 comments on commit e0dbb22

Please sign in to comment.