-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathlcd.h
129 lines (110 loc) · 3.56 KB
/
lcd.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
/*
*
* Copyright (c) 2020 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 "glib.h"
#ifdef QR_CODE_ENABLED
#include "qrcodegen.h"
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#endif // QR_CODE_ENABLED
#include "demo-ui.h"
#ifdef SL_ENABLE_ICD_LCD
#include <sl_sleeptimer.h>
#endif // SL_ENABLE_ICD_LCD
#include <lib/core/CHIPError.h>
#include <platform/internal/DeviceNetworkInfo.h>
class SilabsLCD
{
public:
typedef enum screen
{
DemoScreen = 0,
StatusScreen,
#ifdef QR_CODE_ENABLED
QRCodeScreen,
#endif
InvalidScreen,
} Screen_e;
typedef enum icdMode
{
NotICD = 0,
SIT,
LIT,
} ICDMode_e;
typedef struct dStatus
{
uint8_t nbFabric = 0;
bool connected = false;
char networkName[chip::DeviceLayer::Internal::kMaxWiFiSSIDLength] = { 0 };
bool advertising = false;
ICDMode_e icdMode = NotICD;
} DisplayStatus_t;
#ifdef SL_ENABLE_ICD_LCD
static const uint32_t kDefaultLCDTimeout = 3000;
static const uint32_t kActivityLCDTimeout = 5000;
static const uint32_t kQRCodeScreenTimeout = 10000;
#endif // SL_ENABLE_ICD_LCD
typedef void (*customUICB)(GLIB_Context_t * context);
CHIP_ERROR Init(uint8_t * name = nullptr, bool initialState = false);
void * Context();
int Clear(void);
int DrawPixel(void * pContext, int32_t x, int32_t y);
int Update(void);
void WriteDemoUI(bool state);
void WriteDemoUI();
void SetCustomUI(customUICB cb);
void GetScreen(Screen_e & screen);
void SetScreen(Screen_e screen);
void CycleScreens(void);
void SetStatus(DisplayStatus_t & status);
void WriteStatus();
CHIP_ERROR TurnOn(void);
CHIP_ERROR TurnOff(void);
#ifdef SL_ENABLE_ICD_LCD
CHIP_ERROR TurnOff(uint32_t delayInMs);
#endif // SL_ENABLE_ICD_LCD
#ifdef QR_CODE_ENABLED
void SetQRCode(uint8_t * str, uint32_t size);
void ShowQRCode(bool show);
#endif
private:
typedef struct demoState
{
bool mainState = false;
bool protocol1 = false; /* data */
} DemoState_t;
#ifdef QR_CODE_ENABLED
void WriteQRCode();
void LCDFillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h);
char mQRCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1];
#endif
GLIB_Context_t glibContext;
#ifdef SL_DEMO_NAME
uint8_t mName[] = SL_DEMO_NAME;
#else
uint8_t mName[APP_NAME_MAX_LENGTH + 1];
#endif
customUICB customUI = nullptr;
DemoState_t dState;
DisplayStatus_t mStatus;
uint8_t mCurrentScreen = DemoScreen;
#ifdef SL_ENABLE_ICD_LCD
sl_sleeptimer_timer_handle_t lcdTimerHandle;
static void LcdTimeoutCallback(sl_sleeptimer_timer_handle_t * handle, void * data);
#endif // SL_ENABLE_ICD_LCD
};