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/>.
23 #if defined (USE_HOTT_TEXTMODE) && defined (USE_CMS)
25 #include "common/utils.h"
27 #include "telemetry/hott.h"
29 displayPort_t hottDisplayPort
;
31 static int hottDrawScreen(displayPort_t
*displayPort
)
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
)
47 hottTextmodeWriteChar(col
, row
, (uint8_t)c
);
51 static int hottWriteString(displayPort_t
*displayPort
, uint8_t col
, uint8_t row
, const char *s
, textAttributes_t attr
)
54 hottWriteChar(displayPort
, col
++, row
, *(s
++), attr
);
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);
69 static bool hottIsTransferInProgress(const displayPort_t
*displayPort
)
75 static int hottHeartbeat(displayPort_t
*displayPort
)
77 if (!hottTextmodeIsAlive()) {
78 cmsMenuExit(displayPort
, (void*)CMS_EXIT_SAVE
);
84 static void hottResync(displayPort_t
*displayPort
)
89 static uint32_t hottTxBytesFree(const displayPort_t
*displayPort
)
95 static int hottGrab(displayPort_t
*displayPort
)
98 return displayPort
->grabCount
= 1;
101 static int hottRelease(displayPort_t
*displayPort
)
103 int cnt
= displayPort
->grabCount
= 0;
104 hottClearScreen(displayPort
);
109 static const displayPortVTable_t hottVTable
= {
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)
141 cmsDisplayPortSelect(&hottDisplayPort
);
146 void hottSetCmsKey(uint8_t hottKey
, bool keepCmsOpen
)
149 case HOTTV4_BUTTON_DEC
:
150 cmsSetExternKey(CMS_KEY_UP
);
152 case HOTTV4_BUTTON_INC
:
153 cmsSetExternKey(CMS_KEY_DOWN
);
155 case HOTTV4_BUTTON_SET
:
157 cmsMenuExit(cmsDisplayPortGetCurrent(), (void*)CMS_EXIT_SAVE
);
159 cmsSetExternKey(CMS_KEY_NONE
);
161 case HOTTV4_BUTTON_NEXT
:
162 cmsSetExternKey(CMS_KEY_RIGHT
);
164 case HOTTV4_BUTTON_PREV
:
165 cmsSetExternKey(CMS_KEY_LEFT
);
166 if (keepCmsOpen
) { // Make sure CMS is open until textmode is closed.
171 cmsSetExternKey(CMS_KEY_NONE
);