Update FrSky SPI RX.md
[betaflight.git] / src / main / io / displayport_hott.c
blob96ac13276c680f748bbb9b6fb11dd074d2a01924
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, uint8_t c)
44 UNUSED(displayPort);
46 hottTextmodeWriteChar(col, row, c);
47 return 0;
50 static int hottWriteString(displayPort_t *displayPort, uint8_t col, uint8_t row, const char *s)
52 while (*s) {
53 hottWriteChar(displayPort, col++, row, *(s++));
55 return 0;
58 static int hottClearScreen(displayPort_t *displayPort)
60 for (int row = 0; row < displayPort->rows; row++) {
61 for (int col= 0; col < displayPort->cols; col++) {
62 hottWriteChar(displayPort, col, row, ' ');
65 return 0;
68 static bool hottIsTransferInProgress(const displayPort_t *displayPort)
70 UNUSED(displayPort);
71 return false;
74 static int hottHeartbeat(displayPort_t *displayPort)
76 if (!hottTextmodeIsAlive()) {
77 cmsMenuExit(displayPort, (void*)CMS_EXIT_SAVE);
80 return 0;
83 static void hottResync(displayPort_t *displayPort)
85 UNUSED(displayPort);
88 static uint32_t hottTxBytesFree(const displayPort_t *displayPort)
90 UNUSED(displayPort);
91 return UINT32_MAX;
94 static int hottGrab(displayPort_t *displayPort)
96 hottTextmodeGrab();
97 return displayPort->grabCount = 1;
100 static int hottRelease(displayPort_t *displayPort)
102 int cnt = displayPort->grabCount = 0;
103 hottClearScreen(displayPort);
104 hottTextmodeExit();
105 return cnt;
108 static const displayPortVTable_t hottVTable = {
109 .grab = hottGrab,
110 .release = hottRelease,
111 .clearScreen = hottClearScreen,
112 .drawScreen = hottDrawScreen,
113 .screenSize = hottScreenSize,
114 .writeString = hottWriteString,
115 .writeChar = hottWriteChar,
116 .isTransferInProgress = hottIsTransferInProgress,
117 .heartbeat = hottHeartbeat,
118 .resync = hottResync,
119 .txBytesFree = hottTxBytesFree
122 displayPort_t *displayPortHottInit()
124 hottDisplayPort.device = NULL;
125 displayInit(&hottDisplayPort, &hottVTable);
126 hottDisplayPort.useFullscreen = true;
127 hottDisplayPort.rows = HOTT_TEXTMODE_DISPLAY_ROWS;
128 hottDisplayPort.cols = HOTT_TEXTMODE_DISPLAY_COLUMNS;
129 return &hottDisplayPort;
132 void hottDisplayportRegister()
134 cmsDisplayPortRegister(displayPortHottInit());
137 void hottCmsOpen()
139 if (!cmsInMenu) {
140 cmsDisplayPortSelect(&hottDisplayPort);
141 cmsMenuOpen();
145 void hottSetCmsKey(uint8_t hottKey, bool keepCmsOpen)
147 switch (hottKey) {
148 case HOTTV4_BUTTON_DEC:
149 cmsSetExternKey(CMS_KEY_UP);
150 break;
151 case HOTTV4_BUTTON_INC:
152 cmsSetExternKey(CMS_KEY_DOWN);
153 break;
154 case HOTTV4_BUTTON_SET:
155 if (cmsInMenu) {
156 cmsMenuExit(pCurrentDisplay, (void*)CMS_EXIT_SAVE);
158 cmsSetExternKey(CMS_KEY_NONE);
159 break;
160 case HOTTV4_BUTTON_NEXT:
161 cmsSetExternKey(CMS_KEY_RIGHT);
162 break;
163 case HOTTV4_BUTTON_PREV:
164 cmsSetExternKey(CMS_KEY_LEFT);
165 if (keepCmsOpen) { // Make sure CMS is open until textmode is closed.
166 cmsMenuOpen();
168 break;
169 default:
170 cmsSetExternKey(CMS_KEY_NONE);
171 break;
175 #endif