AppTask.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "timers.h" // provides FreeRTOS timer support
  29. #include <ble/BLEEndPoint.h>
  30. #include <lib/core/CHIPError.h>
  31. #include <platform/CHIPDeviceLayer.h>
  32. /**********************************************************
  33. * Defines
  34. *********************************************************/
  35. // Application-defined error codes in the CHIP_ERROR space.
  36. #define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
  37. #define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
  38. #define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03)
  39. #define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04)
  40. #define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
  41. #define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)
  42. /**********************************************************
  43. * AppTask Declaration
  44. *********************************************************/
  45. class AppTask : public BaseApplication
  46. {
  47. public:
  48. AppTask() = default;
  49. static AppTask & GetAppTask() { return sAppTask; }
  50. /**
  51. * @brief AppTask task main loop function
  52. *
  53. * @param pvParameter FreeRTOS task parameter
  54. */
  55. static void AppTaskMain(void * pvParameter);
  56. CHIP_ERROR StartAppTask();
  57. /**
  58. * @brief Event handler when a button is pressed
  59. * Function posts an event for button processing
  60. *
  61. * @param buttonHandle APP_LIGHT_SWITCH or APP_FUNCTION_BUTTON
  62. * @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED,
  63. * SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
  64. */
  65. static void ButtonEventHandler(uint8_t button, uint8_t btnAction) override;
  66. private:
  67. static AppTask sAppTask;
  68. /**
  69. * @brief AppTask initialisation function
  70. *
  71. * @return CHIP_ERROR
  72. */
  73. CHIP_ERROR Init();
  74. /**
  75. * @brief PB0 Button event processing function
  76. * Press and hold will trigger a factory reset timer start
  77. * Press and release will restart BLEAdvertising if not commisionned
  78. *
  79. * @param aEvent button event being processed
  80. */
  81. static void ButtonHandler(AppEvent * aEvent);
  82. /**
  83. * @brief PB1 Button event processing function
  84. * Function triggers a switch action sent to the CHIP task
  85. *
  86. * @param aEvent button event being processed
  87. */
  88. static void SwitchActionEventHandler(AppEvent * aEvent);
  89. };