[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / io / displayport_hott.c
blob03161b8188da2d959445f2e027c1d7863a5158ff
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
25 #include "platform.h"
26 #if defined (USE_HOTT_TEXTMODE) && defined (USE_CMS)
28 #include "common/utils.h"
29 #include "cms/cms.h"
30 #include "telemetry/hott.h"
32 displayPort_t hottDisplayPort;
34 static bool hottDrawScreen(displayPort_t *displayPort)
36 UNUSED(displayPort);
37 return 0;
40 static int hottScreenSize(const displayPort_t *displayPort)
42 return displayPort->rows * displayPort->cols;
45 static int hottWriteChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t attr, uint8_t c)
47 UNUSED(displayPort);
48 UNUSED(attr);
50 hottTextmodeWriteChar(col, row, c);
51 return 0;
54 static int hottWriteString(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t attr, const char *s)
56 UNUSED(attr);
58 while (*s) {
59 hottWriteChar(displayPort, col++, row, DISPLAYPORT_SEVERITY_NORMAL, *(s++));
61 return 0;
64 static int hottClearScreen(displayPort_t *displayPort, displayClearOption_e options)
66 UNUSED(options);
68 for (int row = 0; row < displayPort->rows; row++) {
69 for (int col= 0; col < displayPort->cols; col++) {
70 hottWriteChar(displayPort, col, row, DISPLAYPORT_SEVERITY_NORMAL, ' ');
73 return 0;
76 static bool hottIsTransferInProgress(const displayPort_t *displayPort)
78 UNUSED(displayPort);
79 return false;
82 static int hottHeartbeat(displayPort_t *displayPort)
84 if (!hottTextmodeIsAlive()) {
85 cmsMenuExit(displayPort, (void*)CMS_EXIT_SAVE);
88 return 0;
91 static void hottRedraw(displayPort_t *displayPort)
93 UNUSED(displayPort);
96 static uint32_t hottTxBytesFree(const displayPort_t *displayPort)
98 UNUSED(displayPort);
99 return UINT32_MAX;
102 static int hottGrab(displayPort_t *displayPort)
104 hottTextmodeGrab();
105 return displayPort->grabCount = 1;
108 static int hottRelease(displayPort_t *displayPort)
110 int cnt = displayPort->grabCount = 0;
111 hottClearScreen(displayPort, DISPLAY_CLEAR_WAIT);
112 hottTextmodeExit();
113 return cnt;
116 static const displayPortVTable_t hottVTable = {
117 .grab = hottGrab,
118 .release = hottRelease,
119 .clearScreen = hottClearScreen,
120 .drawScreen = hottDrawScreen,
121 .screenSize = hottScreenSize,
122 .writeString = hottWriteString,
123 .writeChar = hottWriteChar,
124 .isTransferInProgress = hottIsTransferInProgress,
125 .heartbeat = hottHeartbeat,
126 .redraw = hottRedraw,
127 .txBytesFree = hottTxBytesFree,
128 .layerSupported = NULL,
129 .layerSelect = NULL,
130 .layerCopy = NULL,
133 static displayPort_t *displayPortHottInit(void)
135 hottDisplayPort.device = NULL;
136 displayInit(&hottDisplayPort, &hottVTable, DISPLAYPORT_DEVICE_TYPE_HOTT);
137 hottDisplayPort.useFullscreen = true;
138 hottDisplayPort.rows = HOTT_TEXTMODE_DISPLAY_ROWS;
139 hottDisplayPort.cols = HOTT_TEXTMODE_DISPLAY_COLUMNS;
140 return &hottDisplayPort;
143 void hottDisplayportRegister(void)
145 cmsDisplayPortRegister(displayPortHottInit());
148 void hottCmsOpen(void)
150 if (!cmsInMenu) {
151 cmsDisplayPortSelect(&hottDisplayPort);
152 cmsMenuOpen();
156 void hottSetCmsKey(uint8_t hottKey, bool keepCmsOpen)
158 switch (hottKey) {
159 case HOTTV4_BUTTON_DEC:
160 cmsSetExternKey(CMS_KEY_UP);
161 break;
162 case HOTTV4_BUTTON_INC:
163 cmsSetExternKey(CMS_KEY_DOWN);
164 break;
165 case HOTTV4_BUTTON_SET:
166 if (cmsInMenu) {
167 cmsMenuExit(pCurrentDisplay, (void*)CMS_EXIT_SAVE);
169 cmsSetExternKey(CMS_KEY_NONE);
170 break;
171 case HOTTV4_BUTTON_NEXT:
172 cmsSetExternKey(CMS_KEY_RIGHT);
173 break;
174 case HOTTV4_BUTTON_PREV:
175 cmsSetExternKey(CMS_KEY_LEFT);
176 if (keepCmsOpen) { // Make sure CMS is open until textmode is closed.
177 cmsMenuOpen();
179 break;
180 default:
181 cmsSetExternKey(CMS_KEY_NONE);
182 break;
186 #endif