static-supported-temperature-levels.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <app/util/config.h>
  19. #include <static-supported-temperature-levels.h>
  20. #include <zap-generated/gen_config.h>
  21. using namespace std;
  22. using namespace chip;
  23. using namespace chip::app::Clusters;
  24. using namespace chip::app::Clusters::TemperatureControl;
  25. using chip::Protocols::InteractionModel::Status;
  26. // TODO: Configure your options for each endpoint
  27. CharSpan AppSupportedTemperatureLevelsDelegate::temperatureLevelOptions[] = { CharSpan("Hot", 3), CharSpan("Warm", 4),
  28. CharSpan("Cold", 4) };
  29. const AppSupportedTemperatureLevelsDelegate::EndpointPair AppSupportedTemperatureLevelsDelegate::supportedOptionsByEndpoints
  30. [EMBER_AF_TEMPERATURE_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT] = {
  31. EndpointPair(1, AppSupportedTemperatureLevelsDelegate::temperatureLevelOptions, 3) // Options for Endpoint 1
  32. };
  33. uint8_t AppSupportedTemperatureLevelsDelegate::Size()
  34. {
  35. for (auto & endpointPair : AppSupportedTemperatureLevelsDelegate::supportedOptionsByEndpoints)
  36. {
  37. if (endpointPair.mEndpointId == mEndpoint)
  38. {
  39. return endpointPair.mSize;
  40. }
  41. }
  42. return 0;
  43. }
  44. CHIP_ERROR AppSupportedTemperatureLevelsDelegate::Next(MutableCharSpan & item)
  45. {
  46. for (auto & endpointPair : AppSupportedTemperatureLevelsDelegate::supportedOptionsByEndpoints)
  47. {
  48. if (endpointPair.mEndpointId == mEndpoint)
  49. {
  50. if (endpointPair.mSize > mIndex)
  51. {
  52. CHIP_ERROR err = CopyCharSpanToMutableCharSpan(endpointPair.mTemperatureLevels[mIndex], item);
  53. if (err != CHIP_NO_ERROR)
  54. {
  55. ChipLogError(Zcl, "Error copying char span to mutable char span %s", ErrorStr(err));
  56. return err;
  57. }
  58. mIndex++;
  59. return CHIP_NO_ERROR;
  60. }
  61. }
  62. }
  63. return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
  64. }