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/>.
26 #if defined (USE_HOTT_TEXTMODE) && defined (USE_CMS)
28 #include "common/utils.h"
30 #include "telemetry/hott.h"
32 displayPort_t hottDisplayPort
;
34 static bool hottDrawScreen(displayPort_t
*displayPort
)
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
)
50 hottTextmodeWriteChar(col
, row
, c
);
54 static int hottWriteString(displayPort_t
*displayPort
, uint8_t col
, uint8_t row
, uint8_t attr
, const char *s
)
59 hottWriteChar(displayPort
, col
++, row
, DISPLAYPORT_SEVERITY_NORMAL
, *(s
++));
64 static int hottClearScreen(displayPort_t
*displayPort
, displayClearOption_e 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
, ' ');
76 static bool hottIsTransferInProgress(const displayPort_t
*displayPort
)
82 static int hottHeartbeat(displayPort_t
*displayPort
)
84 if (!hottTextmodeIsAlive()) {
85 cmsMenuExit(displayPort
, (void*)CMS_EXIT_SAVE
);
91 static void hottRedraw(displayPort_t
*displayPort
)
96 static uint32_t hottTxBytesFree(const displayPort_t
*displayPort
)
102 static int hottGrab(displayPort_t
*displayPort
)
105 return displayPort
->grabCount
= 1;
108 static int hottRelease(displayPort_t
*displayPort
)
110 int cnt
= displayPort
->grabCount
= 0;
111 hottClearScreen(displayPort
, DISPLAY_CLEAR_WAIT
);
116 static const displayPortVTable_t hottVTable
= {
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
,
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)
151 cmsDisplayPortSelect(&hottDisplayPort
);
156 void hottSetCmsKey(uint8_t hottKey
, bool keepCmsOpen
)
159 case HOTTV4_BUTTON_DEC
:
160 cmsSetExternKey(CMS_KEY_UP
);
162 case HOTTV4_BUTTON_INC
:
163 cmsSetExternKey(CMS_KEY_DOWN
);
165 case HOTTV4_BUTTON_SET
:
167 cmsMenuExit(pCurrentDisplay
, (void*)CMS_EXIT_SAVE
);
169 cmsSetExternKey(CMS_KEY_NONE
);
171 case HOTTV4_BUTTON_NEXT
:
172 cmsSetExternKey(CMS_KEY_RIGHT
);
174 case HOTTV4_BUTTON_PREV
:
175 cmsSetExternKey(CMS_KEY_LEFT
);
176 if (keepCmsOpen
) { // Make sure CMS is open until textmode is closed.
181 cmsSetExternKey(CMS_KEY_NONE
);