WindowCovering.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2023 Project CHIP Authors
  3. * All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #pragma once
  18. #include "LEDWidget.h"
  19. #include "PWMDevice.h"
  20. #include <app/clusters/window-covering-server/window-covering-delegate.h>
  21. #include <app/clusters/window-covering-server/window-covering-server.h>
  22. #include <cstdint>
  23. using namespace chip::app::Clusters::WindowCovering;
  24. class WindowCovering
  25. {
  26. public:
  27. struct AttributeUpdateData
  28. {
  29. chip::EndpointId mEndpoint;
  30. chip::AttributeId mAttributeId;
  31. };
  32. WindowCovering();
  33. static WindowCovering & Instance()
  34. {
  35. static WindowCovering sInstance;
  36. return sInstance;
  37. }
  38. PWMDevice & GetLiftIndicator() { return mLiftIndicator; }
  39. PWMDevice & GetTiltIndicator() { return mTiltIndicator; }
  40. void StartMove(WindowCoveringType aMoveType);
  41. void SetSingleStepTarget(OperationalState aDirection);
  42. void SetMoveType(WindowCoveringType aMoveType) { mCurrentUIMoveType = aMoveType; }
  43. WindowCoveringType GetMoveType() { return mCurrentUIMoveType; }
  44. void PositionLEDUpdate(WindowCoveringType aMoveType);
  45. static void SchedulePostAttributeChange(chip::EndpointId aEndpoint, chip::AttributeId aAttributeId);
  46. static constexpr chip::EndpointId Endpoint() { return 1; };
  47. private:
  48. void SetBrightness(WindowCoveringType aMoveType, uint16_t aPosition);
  49. void SetTargetPosition(OperationalState aDirection, chip::Percent100ths aPosition);
  50. uint8_t PositionToBrightness(uint16_t aPosition, WindowCoveringType aMoveType);
  51. static void UpdateOperationalStatus(WindowCoveringType aMoveType, OperationalState aDirection);
  52. static bool TargetCompleted(WindowCoveringType aMoveType, NPercent100ths aCurrent, NPercent100ths aTarget);
  53. static void StartTimer(WindowCoveringType aMoveType, uint32_t aTimeoutMs);
  54. static chip::Percent100ths CalculateSingleStep(WindowCoveringType aMoveType);
  55. static void DriveCurrentLiftPosition(intptr_t);
  56. static void DriveCurrentTiltPosition(intptr_t);
  57. static void MoveTimerTimeoutCallback(chip::System::Layer * systemLayer, void * appState);
  58. static void DoPostAttributeChange(intptr_t aArg);
  59. WindowCoveringType mCurrentUIMoveType;
  60. PWMDevice mLiftIndicator;
  61. PWMDevice mTiltIndicator;
  62. bool mInLiftMove{ false };
  63. bool mInTiltMove{ false };
  64. };