/
displayport_hott.c
175 lines (152 loc) · 4.28 KB
/
displayport_hott.c
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "platform.h"
#if defined (USE_HOTT_TEXTMODE) && defined (USE_CMS)
#include "common/utils.h"
#include "cms/cms.h"
#include "telemetry/hott.h"
displayPort_t hottDisplayPort;
static int hottDrawScreen(displayPort_t *displayPort)
{
UNUSED(displayPort);
return 0;
}
static int hottScreenSize(const displayPort_t *displayPort)
{
return displayPort->rows * displayPort->cols;
}
static int hottWriteChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t c)
{
UNUSED(displayPort);
hottTextmodeWriteChar(col, row, c);
return 0;
}
static int hottWriteString(displayPort_t *displayPort, uint8_t col, uint8_t row, const char *s)
{
while (*s) {
hottWriteChar(displayPort, col++, row, *(s++));
}
return 0;
}
static int hottClearScreen(displayPort_t *displayPort)
{
for (int row = 0; row < displayPort->rows; row++) {
for (int col= 0; col < displayPort->cols; col++) {
hottWriteChar(displayPort, col, row, ' ');
}
}
return 0;
}
static bool hottIsTransferInProgress(const displayPort_t *displayPort)
{
UNUSED(displayPort);
return false;
}
static int hottHeartbeat(displayPort_t *displayPort)
{
if (!hottTextmodeIsAlive()) {
cmsMenuExit(displayPort, (void*)CMS_EXIT_SAVE);
}
return 0;
}
static void hottResync(displayPort_t *displayPort)
{
UNUSED(displayPort);
}
static uint32_t hottTxBytesFree(const displayPort_t *displayPort)
{
UNUSED(displayPort);
return UINT32_MAX;
}
static int hottGrab(displayPort_t *displayPort)
{
hottTextmodeGrab();
return displayPort->grabCount = 1;
}
static int hottRelease(displayPort_t *displayPort)
{
int cnt = displayPort->grabCount = 0;
hottClearScreen(displayPort);
hottTextmodeExit();
return cnt;
}
static const displayPortVTable_t hottVTable = {
.grab = hottGrab,
.release = hottRelease,
.clearScreen = hottClearScreen,
.drawScreen = hottDrawScreen,
.screenSize = hottScreenSize,
.writeString = hottWriteString,
.writeChar = hottWriteChar,
.isTransferInProgress = hottIsTransferInProgress,
.heartbeat = hottHeartbeat,
.resync = hottResync,
.txBytesFree = hottTxBytesFree
};
displayPort_t *displayPortHottInit()
{
hottDisplayPort.device = NULL;
displayInit(&hottDisplayPort, &hottVTable);
hottDisplayPort.useFullscreen = true;
hottDisplayPort.rows = HOTT_TEXTMODE_DISPLAY_ROWS;
hottDisplayPort.cols = HOTT_TEXTMODE_DISPLAY_COLUMNS;
return &hottDisplayPort;
}
void hottDisplayportRegister()
{
cmsDisplayPortRegister(displayPortHottInit());
}
void hottCmsOpen()
{
if (!cmsInMenu) {
cmsDisplayPortSelect(&hottDisplayPort);
cmsMenuOpen();
}
}
void hottSetCmsKey(uint8_t hottKey, bool keepCmsOpen)
{
switch (hottKey) {
case HOTTV4_BUTTON_DEC:
cmsSetExternKey(CMS_KEY_UP);
break;
case HOTTV4_BUTTON_INC:
cmsSetExternKey(CMS_KEY_DOWN);
break;
case HOTTV4_BUTTON_SET:
if (cmsInMenu) {
cmsMenuExit(pCurrentDisplay, (void*)CMS_EXIT_SAVE);
}
cmsSetExternKey(CMS_KEY_NONE);
break;
case HOTTV4_BUTTON_NEXT:
cmsSetExternKey(CMS_KEY_RIGHT);
break;
case HOTTV4_BUTTON_PREV:
cmsSetExternKey(CMS_KEY_LEFT);
if (keepCmsOpen) { // Make sure CMS is open until textmode is closed.
cmsMenuOpen();
}
break;
default:
cmsSetExternKey(CMS_KEY_NONE);
break;
}
}
#endif