PumpManager.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #pragma once
  19. #include <zephyr/kernel.h>
  20. #include <cstdint>
  21. #include "AppEventCommon.h"
  22. struct k_timer;
  23. class PumpManager
  24. {
  25. public:
  26. enum Action_t
  27. {
  28. START_ACTION = 0,
  29. STOP_ACTION,
  30. INVALID_ACTION
  31. };
  32. enum State_t
  33. {
  34. kState_StartInitiated = 0,
  35. kState_StartCompleted,
  36. kState_StopInitiated,
  37. kState_StopCompleted,
  38. };
  39. void Init();
  40. bool IsStopped();
  41. void EnableAutoRestart(bool aOn);
  42. void SetAutoStartDuration(uint32_t aDurationInSecs);
  43. bool IsActionInProgress();
  44. bool InitiateAction(int32_t aActor, Action_t aAction);
  45. int16_t GetMaxPressure();
  46. uint16_t GetMaxSpeed();
  47. uint16_t GetMaxFlow();
  48. int16_t GetMinConstPressure();
  49. int16_t GetMaxConstPressure();
  50. int16_t GetMinCompPressure();
  51. int16_t GetMaxCompPressure();
  52. uint16_t GetMinConstSpeed();
  53. uint16_t GetMaxConstSpeed();
  54. uint16_t GetMinConstFlow();
  55. uint16_t GetMaxConstFlow();
  56. int16_t GetMinConstTemp();
  57. int16_t GetMaxConstTemp();
  58. typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor);
  59. typedef void (*Callback_fn_completed)(Action_t, int32_t aActor);
  60. void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
  61. private:
  62. friend PumpManager & PumpMgr(void);
  63. State_t mState;
  64. Callback_fn_initiated mActionInitiated_CB;
  65. Callback_fn_completed mActionCompleted_CB;
  66. bool mAutoRestart;
  67. uint32_t mAutoStartDuration;
  68. bool mAutoStartTimerArmed;
  69. int32_t mCurrentActor;
  70. void CancelTimer(void);
  71. void StartTimer(uint32_t aTimeoutMs);
  72. static void TimerEventHandler(k_timer * timer);
  73. static void AutoRestartTimerEventHandler(AppEvent * aEvent);
  74. static void PumpStartTimerEventHandler(AppEvent * aEvent);
  75. static PumpManager sPump;
  76. };
  77. inline PumpManager & PumpMgr(void)
  78. {
  79. return PumpManager::sPump;
  80. }