ClusterChangeAttribute.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. *
  3. * Copyright (c) 2023 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "ColorControlManager.h"
  19. #include "DoorLockManager.h"
  20. #include "OnOffManager.h"
  21. #include <app-common/zap-generated/attributes/Accessors.h>
  22. #include <app-common/zap-generated/ids/Attributes.h>
  23. #include <app-common/zap-generated/ids/Clusters.h>
  24. #include <app/ConcreteAttributePath.h>
  25. #include <lib/support/logging/CHIPLogging.h>
  26. using namespace chip;
  27. using namespace ::chip::app::Clusters;
  28. static void OnOffClusterAttributeChangeCallback(const app::ConcreteAttributePath & attributePath, uint16_t size, uint8_t * value)
  29. {
  30. if (attributePath.mAttributeId == OnOff::Attributes::OnOff::Id)
  31. {
  32. bool onoff = static_cast<bool>(*value);
  33. ChipLogProgress(Zcl, "Received on/off command endpoint %d value = %d", static_cast<int>(attributePath.mEndpointId), onoff);
  34. OnOffManager().PostOnOffChanged(attributePath.mEndpointId, onoff);
  35. }
  36. }
  37. static void ColorControlClusterAttributeChangeCallback(const app::ConcreteAttributePath & attributePath, uint16_t size,
  38. uint8_t * value)
  39. {
  40. if (attributePath.mAttributeId == ColorControl::Attributes::CurrentHue::Id)
  41. {
  42. uint8_t currentHue = static_cast<uint8_t>(*value);
  43. ChipLogProgress(Zcl, "Received CurrentHue command endpoint %d value = %d", static_cast<int>(attributePath.mEndpointId),
  44. currentHue);
  45. ColorControlManager().PostCurrentHueChanged(attributePath.mEndpointId, currentHue);
  46. }
  47. else if (attributePath.mAttributeId == ColorControl::Attributes::CurrentSaturation::Id)
  48. {
  49. uint8_t currentSaturation = static_cast<uint8_t>(*value);
  50. ChipLogProgress(Zcl, "Received CurrentSaturation command endpoint %d value = %d",
  51. static_cast<int>(attributePath.mEndpointId), currentSaturation);
  52. ColorControlManager().PostCurrentSaturationChanged(attributePath.mEndpointId, currentSaturation);
  53. }
  54. else if (attributePath.mAttributeId == ColorControl::Attributes::ColorTemperatureMireds::Id)
  55. {
  56. int16_t colorTemperatureMireds = static_cast<int16_t>(*value);
  57. ChipLogProgress(Zcl, "Received ColorTemperatureMireds command endpoint %d value = %d",
  58. static_cast<int>(attributePath.mEndpointId), colorTemperatureMireds);
  59. ColorControlManager().PostColorTemperatureChanged(attributePath.mEndpointId, colorTemperatureMireds);
  60. }
  61. else if (attributePath.mAttributeId == ColorControl::Attributes::ColorMode::Id)
  62. {
  63. uint8_t colorMode = static_cast<uint8_t>(*value);
  64. ChipLogProgress(Zcl, "Received ColorMode command endpoint %d value = %d", static_cast<int>(attributePath.mEndpointId),
  65. colorMode);
  66. ColorControlManager().PostColorModeChanged(attributePath.mEndpointId, colorMode);
  67. }
  68. else if (attributePath.mAttributeId == ColorControl::Attributes::EnhancedColorMode::Id)
  69. {
  70. uint8_t enhancedColorMode = static_cast<uint8_t>(*value);
  71. ChipLogProgress(Zcl, "Received EnhancedColorMode command endpoint %d value = %d",
  72. static_cast<int>(attributePath.mEndpointId), enhancedColorMode);
  73. ColorControlManager().PostEnhancedColorModeChanged(attributePath.mEndpointId, enhancedColorMode);
  74. }
  75. }
  76. static void DoorLockClusterAttributeChangeCallback(const app::ConcreteAttributePath & attributePath, uint16_t size, uint8_t * value)
  77. {
  78. if (attributePath.mAttributeId == DoorLock::Attributes::LockState::Id)
  79. {
  80. uint8_t lockState = *value;
  81. ChipLogProgress(Zcl, "Received lock state command endpoint %d value = %d", static_cast<int>(attributePath.mEndpointId),
  82. lockState);
  83. DoorLockManager().PostLockStateChanged(attributePath.mEndpointId, lockState);
  84. }
  85. }
  86. void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
  87. uint8_t * value)
  88. {
  89. ChipLogProgress(Zcl, "[Device] clusterId:%d,attributeId:%d,endpoint:%d", attributePath.mClusterId, attributePath.mAttributeId,
  90. static_cast<int>(attributePath.mEndpointId));
  91. switch (attributePath.mClusterId)
  92. {
  93. case OnOff::Id:
  94. OnOffClusterAttributeChangeCallback(attributePath, size, value);
  95. break;
  96. case ColorControl::Id:
  97. ColorControlClusterAttributeChangeCallback(attributePath, size, value);
  98. break;
  99. case DoorLock::Id:
  100. DoorLockClusterAttributeChangeCallback(attributePath, size, value);
  101. break;
  102. default:
  103. break;
  104. }
  105. }