AppTask.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. *
  3. * Copyright (c) 2020 Project CHIP Authors
  4. * Copyright (c) 2019 Google LLC.
  5. * All rights reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. #pragma once
  20. /**********************************************************
  21. * Includes
  22. *********************************************************/
  23. #include <stdbool.h>
  24. #include <stdint.h>
  25. #include "AppEvent.h"
  26. #include "BaseApplication.h"
  27. #include "FreeRTOS.h"
  28. #include "PumpManager.h"
  29. #include "timers.h" // provides FreeRTOS timer support
  30. #include <ble/BLEEndPoint.h>
  31. #include <lib/core/CHIPError.h>
  32. #include <platform/CHIPDeviceLayer.h>
  33. /**********************************************************
  34. * AppTask Declaration
  35. *********************************************************/
  36. class AppTask : public BaseApplication
  37. {
  38. public:
  39. AppTask() = default;
  40. static AppTask & GetAppTask() { return sAppTask; }
  41. /**
  42. * @brief AppTask task main loop function
  43. *
  44. * @param pvParameter FreeRTOS task parameter
  45. */
  46. static void AppTaskMain(void * pvParameter);
  47. CHIP_ERROR StartAppTask();
  48. /**
  49. * @brief Event handler when a button is pressed
  50. * Function posts an event for button processing
  51. *
  52. * @param buttonHandle APP_LIGHT_SWITCH or APP_FUNCTION_BUTTON
  53. * @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED,
  54. * SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
  55. */
  56. static void ButtonEventHandler(uint8_t button, uint8_t btnAction);
  57. private:
  58. static AppTask sAppTask;
  59. static void ActionInitiated(PumpManager::Action_t aAction, int32_t aActor);
  60. static void ActionCompleted(PumpManager::Action_t aAction, int32_t aActor);
  61. static void PumpActionEventHandler(AppEvent * aEvent);
  62. static void UpdateClusterState(intptr_t context);
  63. /**
  64. * @brief AppTask initialisation function
  65. *
  66. * @return CHIP_ERROR
  67. */
  68. CHIP_ERROR Init();
  69. /**
  70. * @brief PB0 Button event processing function
  71. * Press and hold will trigger a factory reset timer start
  72. * Press and release will restart BLEAdvertising if not commisionned
  73. *
  74. * @param aEvent button event being processed
  75. */
  76. static void ButtonHandler(AppEvent * aEvent);
  77. /**
  78. * @brief PB1 Button event processing function
  79. * Function triggers a switch action sent to the CHIP task
  80. *
  81. * @param aEvent button event being processed
  82. */
  83. static void SwitchActionEventHandler(AppEvent * aEvent);
  84. };