-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAppTaskCommon.h
137 lines (109 loc) · 3.94 KB
/
AppTaskCommon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
*
* Copyright (c) 2022-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "AppConfig.h"
#include "AppEventCommon.h"
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <platform/CHIPDeviceLayer.h>
#if CONFIG_CHIP_FACTORY_DATA
#include <platform/telink/FactoryDataProvider.h>
#endif
#ifdef CONFIG_CHIP_PW_RPC
#include "Rpc.h"
#endif
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <cstdint>
using namespace ::chip;
using namespace ::chip::app;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;
namespace {
inline constexpr EndpointId kExampleEndpointId = 1;
inline constexpr uint8_t kDefaultMinLevel = 0;
inline constexpr uint8_t kDefaultMaxLevel = 254;
inline constexpr uint8_t kButtonPushEvent = 1;
inline constexpr uint8_t kButtonReleaseEvent = 0;
} // namespace
class LedManager;
class PwmManager;
class ButtonManager;
struct Identify;
class AppTaskCommon
{
public:
#ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET
void PowerOnFactoryReset(void);
#endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */
CHIP_ERROR StartApp();
void PostEvent(AppEvent * event);
static void IdentifyEffectHandler(Clusters::Identify::EffectIdentifierEnum aEffect);
static void IdentifyStartHandler(Identify *);
static void IdentifyStopHandler(Identify *);
#ifdef CONFIG_CHIP_PW_RPC
enum ButtonId_t
{
kButtonId_ExampleAction = 1,
kButtonId_FactoryReset,
kButtonId_StartWiFi,
kButtonId_StartThread,
kButtonId_StartBleAdv
} ButtonId;
#endif
protected:
CHIP_ERROR InitCommonParts(void);
void PrintFirmwareInfo(void);
void DispatchEvent(AppEvent * event);
void GetEvent(AppEvent * aEvent);
void InitLeds();
virtual void LinkLeds(LedManager & ledManager);
void InitPwms();
virtual void LinkPwms(PwmManager & pwmManager);
void InitButtons(void);
virtual void LinkButtons(ButtonManager & buttonManager);
static void FactoryResetTimerTimeoutCallback(k_timer * timer);
static void FactoryResetTimerEventHandler(AppEvent * aEvent);
static void FactoryResetButtonEventHandler(void);
static void FactoryResetHandler(AppEvent * aEvent);
static void StartBleAdvButtonEventHandler(void);
static void StartBleAdvHandler(AppEvent * aEvent);
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
static void StartThreadButtonEventHandler(void);
static void StartThreadHandler(AppEvent * aEvent);
#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI
static void StartWiFiButtonEventHandler(void);
static void StartWiFiHandler(AppEvent * aEvent);
#endif
#if CONFIG_TELINK_OTA_BUTTON_TEST
static void TestOTAButtonEventHandler(void);
static void TestOTAHandler(AppEvent * aEvent);
#endif
static void ExampleActionButtonEventHandler(void);
void SetExampleButtonCallbacks(EventHandler aAction_CB);
EventHandler ExampleActionEventHandler;
static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
static void UpdateStatusLED(void);
#if CONFIG_CHIP_FACTORY_DATA
chip::DeviceLayer::FactoryDataProvider<chip::DeviceLayer::ExternalFlashFactoryData> mFactoryDataProvider;
#endif
#ifdef CONFIG_CHIP_PW_RPC
friend class chip::rpc::TelinkButton;
static void ButtonEventHandler(ButtonId_t btnId, bool btnPressed);
#endif
};