PumpManager.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. *
  3. * Copyright (c) 2019 Google LLC.
  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. #pragma once
  19. #include <stdbool.h>
  20. #include <stdint.h>
  21. #include "AppEvent.h"
  22. #include <lib/core/CHIPError.h>
  23. #include <FreeRTOS.h>
  24. #include <timers.h>
  25. #define PCC_CLUSTER_ENDPOINT 1
  26. class PumpManager
  27. {
  28. public:
  29. enum Action_t
  30. {
  31. START_ACTION = 0,
  32. STOP_ACTION,
  33. INVALID_ACTION
  34. } Action;
  35. enum State_t
  36. {
  37. kState_StartInitiated = 0,
  38. kState_StartCompleted,
  39. kState_StopInitiated,
  40. kState_StopCompleted,
  41. } State;
  42. CHIP_ERROR Init();
  43. bool IsStopped();
  44. void SetAutoStartDuration(uint32_t aDurationInSecs);
  45. bool IsActionInProgress();
  46. bool InitiateAction(int32_t aActor, Action_t aAction);
  47. typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor);
  48. typedef void (*Callback_fn_completed)(Action_t, int32_t aActor);
  49. void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
  50. private:
  51. friend PumpManager & PumpMgr(void);
  52. State_t mState;
  53. Callback_fn_initiated mActionInitiated_CB;
  54. Callback_fn_completed mActionCompleted_CB;
  55. TimerHandle_t mTimerHandle;
  56. int32_t mCurrentActor;
  57. void CancelTimer(void);
  58. void PumpTimer(uint32_t aTimeoutMs);
  59. static void TimerEventHandler(TimerHandle_t aTimer);
  60. static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
  61. static PumpManager sPump;
  62. };
  63. inline PumpManager & PumpMgr(void)
  64. {
  65. return PumpManager::sPump;
  66. }