Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 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 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include "AppEvent.h" |
Kamil Kasperczyk | b06b55c | 2021-10-20 22:07:10 +0200 | [diff] [blame] | 23 | #include "LEDWidget.h" |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 24 | #include "PumpManager.h" |
| 25 | |
| 26 | #include <platform/CHIPDeviceLayer.h> |
| 27 | |
Kamil Kasperczyk | cf4beb5 | 2022-06-23 12:55:11 +0200 | [diff] [blame] | 28 | #if CONFIG_CHIP_FACTORY_DATA |
| 29 | #include <platform/nrfconnect/FactoryDataProvider.h> |
Arkadiusz Bałys | bab40de | 2023-04-25 17:25:52 +0200 | [diff] [blame] | 30 | #else |
| 31 | #include <platform/nrfconnect/DeviceInstanceInfoProviderImpl.h> |
Kamil Kasperczyk | cf4beb5 | 2022-06-23 12:55:11 +0200 | [diff] [blame] | 32 | #endif |
| 33 | |
Kamil Kasperczyk | 4c7f38d | 2023-06-06 20:46:29 +0200 | [diff] [blame^] | 34 | #ifdef CONFIG_MCUMGR_TRANSPORT_BT |
Mathias K. Garbus | 2418eb7 | 2021-08-21 02:10:59 +0200 | [diff] [blame] | 35 | #include "DFUOverSMP.h" |
| 36 | #endif |
| 37 | |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 38 | struct k_timer; |
| 39 | |
| 40 | class AppTask |
| 41 | { |
| 42 | public: |
Arkadiusz Bałys | e6a1e8e | 2022-11-25 15:50:18 +0100 | [diff] [blame] | 43 | static AppTask & Instance(void) |
| 44 | { |
| 45 | static AppTask sAppTask; |
| 46 | return sAppTask; |
| 47 | }; |
| 48 | |
Damian Królik | 944425f | 2022-02-22 05:04:12 +0100 | [diff] [blame] | 49 | CHIP_ERROR StartApp(); |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 50 | |
Arkadiusz Bałys | e6a1e8e | 2022-11-25 15:50:18 +0100 | [diff] [blame] | 51 | static void PostStartActionRequest(int32_t actor, PumpManager::Action_t action); |
| 52 | static void UpdateClusterState(); |
| 53 | static void PostEvent(const AppEvent & event); |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 54 | |
| 55 | private: |
Damian Królik | 944425f | 2022-02-22 05:04:12 +0100 | [diff] [blame] | 56 | CHIP_ERROR Init(); |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 57 | |
Arkadiusz Bałys | e6a1e8e | 2022-11-25 15:50:18 +0100 | [diff] [blame] | 58 | static void CancelTimer(); |
| 59 | static void StartTimer(uint32_t timeoutInMs); |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 60 | |
Arkadiusz Bałys | e6a1e8e | 2022-11-25 15:50:18 +0100 | [diff] [blame] | 61 | static void ActionInitiated(PumpManager::Action_t action, int32_t actor); |
| 62 | static void ActionCompleted(PumpManager::Action_t action, int32_t actor); |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 63 | |
Arkadiusz Bałys | e6a1e8e | 2022-11-25 15:50:18 +0100 | [diff] [blame] | 64 | static void DispatchEvent(const AppEvent & event); |
| 65 | static void FunctionTimerEventHandler(const AppEvent & event); |
| 66 | static void FunctionHandler(const AppEvent & event); |
| 67 | static void StartBLEAdvertisementHandler(const AppEvent & event); |
| 68 | static void UpdateLedStateEventHandler(const AppEvent & event); |
| 69 | static void StartActionEventHandler(const AppEvent & event); |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 70 | |
Damian Królik | 6e96fca | 2021-07-27 17:21:21 +0200 | [diff] [blame] | 71 | static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); |
Arkadiusz Bałys | e6a1e8e | 2022-11-25 15:50:18 +0100 | [diff] [blame] | 72 | static void ButtonEventHandler(uint32_t buttonState, uint32_t hasChanged); |
| 73 | static void LEDStateUpdateHandler(LEDWidget & ledWidget); |
| 74 | static void FunctionTimerTimeoutCallback(k_timer * timer); |
| 75 | static void UpdateStatusLED(); |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 76 | |
Arkadiusz Bałys | e6a1e8e | 2022-11-25 15:50:18 +0100 | [diff] [blame] | 77 | FunctionEvent mFunction = FunctionEvent::NoneSelected; |
Mathias K. Garbus | 2418eb7 | 2021-08-21 02:10:59 +0200 | [diff] [blame] | 78 | bool mFunctionTimerActive = false; |
Kamil Kasperczyk | cf4beb5 | 2022-06-23 12:55:11 +0200 | [diff] [blame] | 79 | |
| 80 | #if CONFIG_CHIP_FACTORY_DATA |
| 81 | chip::DeviceLayer::FactoryDataProvider<chip::DeviceLayer::InternalFlashFactoryData> mFactoryDataProvider; |
| 82 | #endif |
Thomas Lykkeberg | 4718196 | 2021-05-08 05:34:34 +0200 | [diff] [blame] | 83 | }; |