blob: 8ca4a69e91c0f057f571534037dd1cf2049e3125 [file] [log] [blame]
Thomas Lykkeberg47181962021-05-08 05:34:34 +02001/*
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 Kasperczykb06b55c2021-10-20 22:07:10 +020023#include "LEDWidget.h"
Thomas Lykkeberg47181962021-05-08 05:34:34 +020024#include "PumpManager.h"
25
26#include <platform/CHIPDeviceLayer.h>
27
Kamil Kasperczykcf4beb52022-06-23 12:55:11 +020028#if CONFIG_CHIP_FACTORY_DATA
29#include <platform/nrfconnect/FactoryDataProvider.h>
Arkadiusz Bałysbab40de2023-04-25 17:25:52 +020030#else
31#include <platform/nrfconnect/DeviceInstanceInfoProviderImpl.h>
Kamil Kasperczykcf4beb52022-06-23 12:55:11 +020032#endif
33
Kamil Kasperczyk4c7f38d2023-06-06 20:46:29 +020034#ifdef CONFIG_MCUMGR_TRANSPORT_BT
Mathias K. Garbus2418eb72021-08-21 02:10:59 +020035#include "DFUOverSMP.h"
36#endif
37
Thomas Lykkeberg47181962021-05-08 05:34:34 +020038struct k_timer;
39
40class AppTask
41{
42public:
Arkadiusz Bałyse6a1e8e2022-11-25 15:50:18 +010043 static AppTask & Instance(void)
44 {
45 static AppTask sAppTask;
46 return sAppTask;
47 };
48
Damian Królik944425f2022-02-22 05:04:12 +010049 CHIP_ERROR StartApp();
Thomas Lykkeberg47181962021-05-08 05:34:34 +020050
Arkadiusz Bałyse6a1e8e2022-11-25 15:50:18 +010051 static void PostStartActionRequest(int32_t actor, PumpManager::Action_t action);
52 static void UpdateClusterState();
53 static void PostEvent(const AppEvent & event);
Thomas Lykkeberg47181962021-05-08 05:34:34 +020054
55private:
Damian Królik944425f2022-02-22 05:04:12 +010056 CHIP_ERROR Init();
Thomas Lykkeberg47181962021-05-08 05:34:34 +020057
Arkadiusz Bałyse6a1e8e2022-11-25 15:50:18 +010058 static void CancelTimer();
59 static void StartTimer(uint32_t timeoutInMs);
Thomas Lykkeberg47181962021-05-08 05:34:34 +020060
Arkadiusz Bałyse6a1e8e2022-11-25 15:50:18 +010061 static void ActionInitiated(PumpManager::Action_t action, int32_t actor);
62 static void ActionCompleted(PumpManager::Action_t action, int32_t actor);
Thomas Lykkeberg47181962021-05-08 05:34:34 +020063
Arkadiusz Bałyse6a1e8e2022-11-25 15:50:18 +010064 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 Lykkeberg47181962021-05-08 05:34:34 +020070
Damian Królik6e96fca2021-07-27 17:21:21 +020071 static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
Arkadiusz Bałyse6a1e8e2022-11-25 15:50:18 +010072 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 Lykkeberg47181962021-05-08 05:34:34 +020076
Arkadiusz Bałyse6a1e8e2022-11-25 15:50:18 +010077 FunctionEvent mFunction = FunctionEvent::NoneSelected;
Mathias K. Garbus2418eb72021-08-21 02:10:59 +020078 bool mFunctionTimerActive = false;
Kamil Kasperczykcf4beb52022-06-23 12:55:11 +020079
80#if CONFIG_CHIP_FACTORY_DATA
81 chip::DeviceLayer::FactoryDataProvider<chip::DeviceLayer::InternalFlashFactoryData> mFactoryDataProvider;
82#endif
Thomas Lykkeberg47181962021-05-08 05:34:34 +020083};