Bump workflow action (#13355)
[betaflight.git] / src / main / io / displayport_hott.c
blob8b163f537eb1596da8694a04bebe2e524c5630b6
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"
27 #if defined(USE_HOTT_TEXTMODE) && defined(USE_CMS)
29 #include "common/utils.h"
30 #include "cms/cms.h"
31 #include "telemetry/hott.h"
33 displayPort_t hottDisplayPort;
35 static bool hottDrawScreen(displayPort_t *displayPort)
37 UNUSED(displayPort);
38 return 0;
41 static int hottScreenSize(const displayPort_t *displayPort)
43 return displayPort->rows * displayPort->cols;
46 static int hottWriteChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t attr, uint8_t c)
48 UNUSED(displayPort);
49 UNUSED(attr);
51 hottTextmodeWriteChar(col, row, c);
52 return 0;
55 static int hottWriteString(displayPort_t *displayPort, uint8_t col, uint8_t row, uint8_t attr, const char *s)
57 UNUSED(attr);
59 while (*s) {
60 hottWriteChar(displayPort, col++, row, DISPLAYPORT_SEVERITY_NORMAL, *(s++));
62 return 0;
65 static int hottClearScreen(displayPort_t *displayPort, displayClearOption_e options)
67 UNUSED(options);
69 for (int row = 0; row < displayPort->rows; row++) {
70 for (int col= 0; col < displayPort->cols; col++) {
71 hottWriteChar(displayPort, col, row, DISPLAYPORT_SEVERITY_NORMAL, ' ');
74 return 0;
77 static bool hottIsTransferInProgress(const displayPort_t *displayPort)
79 UNUSED(displayPort);
80 return false;
83 static int hottHeartbeat(displayPort_t *displayPort)
85 if (!hottTextmodeIsAlive()) {
86 cmsMenuExit(displayPort, (void*)CMS_EXIT_SAVE);
89 return 0;
92 static void hottRedraw(displayPort_t *displayPort)
94 UNUSED(displayPort);
97 static uint32_t hottTxBytesFree(const displayPort_t *displayPort)
99 UNUSED(displayPort);
100 return UINT32_MAX;
103 static int hottGrab(displayPort_t *displayPort)
105 hottTextmodeGrab();
106 return displayPort->grabCount = 1;
109 static int hottRelease(displayPort_t *displayPort)
111 int cnt = displayPort->grabCount = 0;
112 hottClearScreen(displayPort, DISPLAY_CLEAR_WAIT);
113 hottTextmodeExit();
114 return cnt;
117 static const displayPortVTable_t hottVTable = {
118 .grab = hottGrab,
119 .release = hottRelease,
120 .clearScreen = hottClearScreen,
121 .drawScreen = hottDrawScreen,
122 .screenSize = hottScreenSize,
123 .writeString = hottWriteString,
124 .writeChar = hottWriteChar,
125 .isTransferInProgress = hottIsTransferInProgress,
126 .heartbeat = hottHeartbeat,
127 .redraw = hottRedraw,
128 .txBytesFree = hottTxBytesFree,
129 .layerSupported = NULL,
130 .layerSelect = NULL,
131 .layerCopy = NULL,
134 static displayPort_t *displayPortHottInit(void)
136 hottDisplayPort.device = NULL;
137 displayInit(&hottDisplayPort, &hottVTable, DISPLAYPORT_DEVICE_TYPE_HOTT);
138 hottDisplayPort.useFullscreen = true;
139 hottDisplayPort.rows = HOTT_TEXTMODE_DISPLAY_ROWS;
140 hottDisplayPort.cols = HOTT_TEXTMODE_DISPLAY_COLUMNS;
141 return &hottDisplayPort;
144 void hottDisplayportRegister(void)
146 cmsDisplayPortRegister(displayPortHottInit());
149 void hottCmsOpen(void)
151 if (!cmsInMenu) {
152 cmsDisplayPortSelect(&hottDisplayPort);
153 cmsMenuOpen();
157 void hottSetCmsKey(uint8_t hottKey, bool keepCmsOpen)
159 switch (hottKey) {
160 case HOTTV4_BUTTON_DEC:
161 cmsSetExternKey(CMS_KEY_UP);
162 break;
163 case HOTTV4_BUTTON_INC:
164 cmsSetExternKey(CMS_KEY_DOWN);
165 break;
166 case HOTTV4_BUTTON_SET:
167 if (cmsInMenu) {
168 cmsMenuExit(pCurrentDisplay, (void*)CMS_EXIT_SAVE);
170 cmsSetExternKey(CMS_KEY_NONE);
171 break;
172 case HOTTV4_BUTTON_NEXT:
173 cmsSetExternKey(CMS_KEY_RIGHT);
174 break;
175 case HOTTV4_BUTTON_PREV:
176 cmsSetExternKey(CMS_KEY_LEFT);
177 if (keepCmsOpen) { // Make sure CMS is open until textmode is closed.
178 cmsMenuOpen();
180 break;
181 default:
182 cmsSetExternKey(CMS_KEY_NONE);
183 break;
187 #endif