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)
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/>.
27 #if defined(USE_HOTT_TEXTMODE) && defined(USE_CMS)
29 #include "common/utils.h"
31 #include "telemetry/hott.h"
33 displayPort_t hottDisplayPort
;
35 static bool hottDrawScreen(displayPort_t
*displayPort
)
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
)
51 hottTextmodeWriteChar(col
, row
, c
);
55 static int hottWriteString(displayPort_t
*displayPort
, uint8_t col
, uint8_t row
, uint8_t attr
, const char *s
)
60 hottWriteChar(displayPort
, col
++, row
, DISPLAYPORT_SEVERITY_NORMAL
, *(s
++));
65 static int hottClearScreen(displayPort_t
*displayPort
, displayClearOption_e 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
, ' ');
77 static bool hottIsTransferInProgress(const displayPort_t
*displayPort
)
83 static int hottHeartbeat(displayPort_t
*displayPort
)
85 if (!hottTextmodeIsAlive()) {
86 cmsMenuExit(displayPort
, (void*)CMS_EXIT_SAVE
);
92 static void hottRedraw(displayPort_t
*displayPort
)
97 static uint32_t hottTxBytesFree(const displayPort_t
*displayPort
)
103 static int hottGrab(displayPort_t
*displayPort
)
106 return displayPort
->grabCount
= 1;
109 static int hottRelease(displayPort_t
*displayPort
)
111 int cnt
= displayPort
->grabCount
= 0;
112 hottClearScreen(displayPort
, DISPLAY_CLEAR_WAIT
);
117 static const displayPortVTable_t hottVTable
= {
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
,
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)
152 cmsDisplayPortSelect(&hottDisplayPort
);
157 void hottSetCmsKey(uint8_t hottKey
, bool keepCmsOpen
)
160 case HOTTV4_BUTTON_DEC
:
161 cmsSetExternKey(CMS_KEY_UP
);
163 case HOTTV4_BUTTON_INC
:
164 cmsSetExternKey(CMS_KEY_DOWN
);
166 case HOTTV4_BUTTON_SET
:
168 cmsMenuExit(pCurrentDisplay
, (void*)CMS_EXIT_SAVE
);
170 cmsSetExternKey(CMS_KEY_NONE
);
172 case HOTTV4_BUTTON_NEXT
:
173 cmsSetExternKey(CMS_KEY_RIGHT
);
175 case HOTTV4_BUTTON_PREV
:
176 cmsSetExternKey(CMS_KEY_LEFT
);
177 if (keepCmsOpen
) { // Make sure CMS is open until textmode is closed.
182 cmsSetExternKey(CMS_KEY_NONE
);