Update navigation_fixedwing.c
[inav.git] / src / main / io / displayport_hott.c
blob68aaed5d93d6da0f3c4fd7f3507b6b2f2c3a381d
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
20 #include <string.h>
22 #include "platform.h"
23 #if defined (USE_HOTT_TEXTMODE) && defined (USE_CMS)
25 #include "common/utils.h"
26 #include "cms/cms.h"
27 #include "telemetry/hott.h"
29 displayPort_t hottDisplayPort;
31 static int hottDrawScreen(displayPort_t *displayPort)
33 UNUSED(displayPort);
34 return 0;
37 static int hottScreenSize(const displayPort_t *displayPort)
39 return displayPort->rows * displayPort->cols;
42 static int hottWriteChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint16_t c, textAttributes_t attr)
44 UNUSED(displayPort);
45 UNUSED(attr);
47 hottTextmodeWriteChar(col, row, (uint8_t)c);
48 return 0;
51 static int hottWriteString(displayPort_t *displayPort, uint8_t col, uint8_t row, const char *s, textAttributes_t attr)
53 while (*s) {
54 hottWriteChar(displayPort, col++, row, *(s++), attr);
56 return 0;
59 static int hottClearScreen(displayPort_t *displayPort)
61 for (int row = 0; row < displayPort->rows; row++) {
62 for (int col= 0; col < displayPort->cols; col++) {
63 hottWriteChar(displayPort, col, row, ' ', 0);
66 return 0;
69 static bool hottIsTransferInProgress(const displayPort_t *displayPort)
71 UNUSED(displayPort);
72 return false;
75 static int hottHeartbeat(displayPort_t *displayPort)
77 if (!hottTextmodeIsAlive()) {
78 cmsMenuExit(displayPort, (void*)CMS_EXIT_SAVE);
81 return 0;
84 static void hottResync(displayPort_t *displayPort)
86 UNUSED(displayPort);
89 static uint32_t hottTxBytesFree(const displayPort_t *displayPort)
91 UNUSED(displayPort);
92 return UINT32_MAX;
95 static int hottGrab(displayPort_t *displayPort)
97 hottTextmodeGrab();
98 return displayPort->grabCount = 1;
101 static int hottRelease(displayPort_t *displayPort)
103 int cnt = displayPort->grabCount = 0;
104 hottClearScreen(displayPort);
105 hottTextmodeExit();
106 return cnt;
109 static const displayPortVTable_t hottVTable = {
110 .grab = hottGrab,
111 .release = hottRelease,
112 .clearScreen = hottClearScreen,
113 .drawScreen = hottDrawScreen,
114 .screenSize = hottScreenSize,
115 .writeString = hottWriteString,
116 .writeChar = hottWriteChar,
117 .isTransferInProgress = hottIsTransferInProgress,
118 .heartbeat = hottHeartbeat,
119 .resync = hottResync,
120 .txBytesFree = hottTxBytesFree
123 displayPort_t *displayPortHottInit(void)
125 hottDisplayPort.device = NULL;
126 displayInit(&hottDisplayPort, &hottVTable);
127 hottDisplayPort.useFullscreen = true;
128 hottDisplayPort.rows = HOTT_TEXTMODE_DISPLAY_ROWS;
129 hottDisplayPort.cols = HOTT_TEXTMODE_DISPLAY_COLUMNS;
130 return &hottDisplayPort;
133 void hottDisplayportRegister(void)
135 cmsDisplayPortRegister(displayPortHottInit());
138 void hottCmsOpen(void)
140 if (!cmsInMenu) {
141 cmsDisplayPortSelect(&hottDisplayPort);
142 cmsMenuOpen();
146 void hottSetCmsKey(uint8_t hottKey, bool keepCmsOpen)
148 switch (hottKey) {
149 case HOTTV4_BUTTON_DEC:
150 cmsSetExternKey(CMS_KEY_UP);
151 break;
152 case HOTTV4_BUTTON_INC:
153 cmsSetExternKey(CMS_KEY_DOWN);
154 break;
155 case HOTTV4_BUTTON_SET:
156 if (cmsInMenu) {
157 cmsMenuExit(cmsDisplayPortGetCurrent(), (void*)CMS_EXIT_SAVE);
159 cmsSetExternKey(CMS_KEY_NONE);
160 break;
161 case HOTTV4_BUTTON_NEXT:
162 cmsSetExternKey(CMS_KEY_RIGHT);
163 break;
164 case HOTTV4_BUTTON_PREV:
165 cmsSetExternKey(CMS_KEY_LEFT);
166 if (keepCmsOpen) { // Make sure CMS is open until textmode is closed.
167 cmsMenuOpen();
169 break;
170 default:
171 cmsSetExternKey(CMS_KEY_NONE);
172 break;
176 #endif