Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle write on identifyTime attribute on esp32 side #13536

Merged
merged 2 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "esp_log.h"
#include "route_hook/esp_route_hook.h"
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/CommandHandler.h>
#include <app/clusters/identify-server/identify-server.h>
Expand All @@ -49,6 +50,7 @@ using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::System;
using namespace ::chip::DeviceLayer;
using namespace chip::app;

constexpr uint32_t kIdentifyTimerDelayMS = 250;

Expand Down Expand Up @@ -120,10 +122,10 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
{
// MDNS server restart on any ip assignment: if link local ipv6 is configured, that
// will not trigger a 'internet connectivity change' as there is no internet
// connectivity. MDNS still wants to refresh its listening interfaces to include the
// newly selected address.
// MDNS server restart on any ip assignment: if link local ipv6 is
// configured, that will not trigger a 'internet connectivity change' as
// there is no internet connectivity. MDNS still wants to refresh its
// listening interfaces to include the newly selected address.
chip::app::DnssdServer::Instance().StartServer();
}
if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)
Expand All @@ -139,23 +141,28 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
uint8_t type, uint16_t size, uint8_t * value)
{
ESP_LOGI(TAG, "PostAttributeChangeCallback - Cluster ID: '0x%04x', EndPoint ID: '0x%02x', Attribute ID: '0x%04x'", clusterId,
endpointId, attributeId);
ESP_LOGI(TAG,
"PostAttributeChangeCallback - Cluster ID: '0x%04x', EndPoint ID: "
"'0x%02x', Attribute ID: '0x%04x'",
clusterId, endpointId, attributeId);

switch (clusterId)
{
case ZCL_ON_OFF_CLUSTER_ID:
case Clusters::OnOff::Id:
OnOnOffPostAttributeChangeCallback(endpointId, attributeId, value);
break;

case ZCL_LEVEL_CONTROL_CLUSTER_ID:
case Clusters::LevelControl::Id:
OnLevelControlAttributeChangeCallback(endpointId, attributeId, value);
break;
#if CONFIG_DEVICE_TYPE_ESP32_C3_DEVKITM
case ZCL_COLOR_CONTROL_CLUSTER_ID:
case Clusters::ColorControl::Id:
OnColorControlAttributeChangeCallback(endpointId, attributeId, value);
break;
#endif
case Clusters::Identify::Id:
OnIdentifyPostAttributeChangeCallback(endpointId, attributeId, size, value);
break;
default:
ESP_LOGI(TAG, "Unhandled cluster ID: %d", clusterId);
break;
Expand Down Expand Up @@ -224,7 +231,8 @@ void DeviceCallbacks::OnLevelControlAttributeChangeCallback(EndpointId endpointI
return;
}

// Currently we only support ColorControl cluster for ESP32C3_DEVKITM which has an on-board RGB-LED
// Currently we only support ColorControl cluster for ESP32C3_DEVKITM which has
// an on-board RGB-LED
#if CONFIG_DEVICE_TYPE_ESP32_C3_DEVKITM
void DeviceCallbacks::OnColorControlAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value)
{
Expand Down Expand Up @@ -254,6 +262,28 @@ void DeviceCallbacks::OnColorControlAttributeChangeCallback(EndpointId endpointI
}
#endif

void DeviceCallbacks::OnIdentifyPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint16_t size,
uint8_t * value)
{
if (attributeId == Clusters::Identify::Attributes::IdentifyTime::Id && size == 2)
{
uint16_t identifyTime;
memcpy(&identifyTime, value, size);
if (identifyTime)
{
// Currently we have no separate indicator LEDs on each endpoints.
// We are using LED1 for endpoint 0,1 and LED2 for endpoint 2
endpointId == 2 ? statusLED2.Blink(kIdentifyTimerDelayMS * 2) : statusLED1.Blink(kIdentifyTimerDelayMS * 2);
}
else
{
bool onOffState;
endpointId == 0 ? onOffState = mEndpointOnOffState[0] : onOffState = mEndpointOnOffState[endpointId - 1];
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
endpointId == 2 ? statusLED2.Set(onOffState) : statusLED1.Set(onOffState);
}
}
}

bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::CommandHandler * commandObj)
{
emberAfSendDefaultResponse(emberAfCurrentCommand(), EMBER_ZCL_STATUS_SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ class DeviceCallbacks : public chip::DeviceManager::CHIPDeviceManagerCallbacks
#if CONFIG_DEVICE_TYPE_ESP32_C3_DEVKITM
void OnColorControlAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value);
#endif
void OnIdentifyPostAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint16_t size,
uint8_t * value);
bool mEndpointOnOffState[2];
};