APM:Libraries
Display.cpp
Go to the documentation of this file.
1 /*
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License as published by
4  the Free Software Foundation, either version 3 of the License, or
5  (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 /* Notify display driver for 128 x 64 pixel displays */
17 #include "Display.h"
18 #include "Display_SH1106_I2C.h"
19 #include "Display_SSD1306_I2C.h"
20 
21 #include "AP_Notify.h"
22 
23 #include <stdio.h>
24 #include <AP_GPS/AP_GPS.h>
25 
26 #include <utility>
27 
28 extern const AP_HAL::HAL& hal;
29 
30 // Bit Map
31 // Rotate right 90 degrees
32 // Ex: 0x7C, 0x12, 0x11, 0x12, 0x7C, // 'A'
33 // 0XXXXX00
34 // 000X00X0
35 // 000X000X
36 // 000X00X0
37 // 0XXXXX00
38 static const uint8_t _font[] = {
39 #ifdef AP_NOTIFY_DISPLAY_USE_EMOJI
40  // 0x Group
41  0x00, 0x00, 0x00, 0x00, 0x00, // 00
42  0x3E, 0x5B, 0x4F, 0x5B, 0x3E, // 01
43  0x3E, 0x6B, 0x4F, 0x6B, 0x3E, // 02
44  0x1C, 0x3E, 0x7C, 0x3E, 0x1C, // 03
45  0x18, 0x3C, 0x7E, 0x3C, 0x18, // 04
46  0x1C, 0x57, 0x7D, 0x57, 0x1C, // 05
47  0x1C, 0x5E, 0x7F, 0x5E, 0x1C, // 06
48  0x00, 0x18, 0x3C, 0x18, 0x00, // 07
49  0xFF, 0xE7, 0xC3, 0xE7, 0xFF, // 08
50  0x00, 0x18, 0x24, 0x18, 0x00, // 09
51  0xFF, 0xE7, 0xDB, 0xE7, 0xFF, // 0A
52  0x30, 0x48, 0x3A, 0x06, 0x0E, // 0B
53  0x26, 0x29, 0x79, 0x29, 0x26, // 0C
54  0x40, 0x7F, 0x05, 0x05, 0x07, // 0D
55  0x40, 0x7F, 0x05, 0x25, 0x3F, // 0E
56  0x5A, 0x3C, 0xE7, 0x3C, 0x5A, // 0F
57  // 1x Group
58  0x7F, 0x3E, 0x1C, 0x1C, 0x08, // 10
59  0x08, 0x1C, 0x1C, 0x3E, 0x7F, // 11
60  0x14, 0x22, 0x7F, 0x22, 0x14, // 12
61  0x5F, 0x5F, 0x00, 0x5F, 0x5F, // 13
62  0x06, 0x09, 0x7F, 0x01, 0x7F, // 14
63  0x00, 0x66, 0x89, 0x95, 0x6A, // 15
64  0x60, 0x60, 0x60, 0x60, 0x60, // 16
65  0x94, 0xA2, 0xFF, 0xA2, 0x94, // 17
66  0x08, 0x04, 0x7E, 0x04, 0x08, // 18
67  0x10, 0x20, 0x7E, 0x20, 0x10, // 19
68  0x08, 0x08, 0x2A, 0x1C, 0x08, // 1A
69  0x08, 0x1C, 0x2A, 0x08, 0x08, // 1B
70  0x1E, 0x10, 0x10, 0x10, 0x10, // 1C
71  0x0C, 0x1E, 0x0C, 0x1E, 0x0C, // 1D
72  0x30, 0x38, 0x3E, 0x38, 0x30, // 1E
73  0x06, 0x0E, 0x3E, 0x0E, 0x06, // 1F
74 #endif
75  // 2x Group
76  0x00, 0x00, 0x00, 0x00, 0x00, // ' '
77  0x00, 0x00, 0x5F, 0x00, 0x00, // '!'
78  0x00, 0x07, 0x00, 0x07, 0x00, // '"'
79  0x14, 0x7F, 0x14, 0x7F, 0x14, // '#'
80  0x24, 0x2A, 0x7F, 0x2A, 0x12, // '$'
81  0x23, 0x13, 0x08, 0x64, 0x62, // '%'
82  0x36, 0x49, 0x56, 0x20, 0x50, // '&'
83  0x00, 0x08, 0x07, 0x03, 0x00, // '''
84  0x00, 0x1C, 0x22, 0x41, 0x00, // '('
85  0x00, 0x41, 0x22, 0x1C, 0x00, // ')'
86  0x2A, 0x1C, 0x7F, 0x1C, 0x2A, // '*'
87  0x08, 0x08, 0x3E, 0x08, 0x08, // '+'
88  0x00, 0x80, 0x70, 0x30, 0x00, // ','
89  0x08, 0x08, 0x08, 0x08, 0x08, // '-'
90  0x00, 0x00, 0x60, 0x60, 0x00, // '.'
91  0x20, 0x10, 0x08, 0x04, 0x02, // '/'
92  // 3x Group
93  0x3E, 0x51, 0x49, 0x45, 0x3E, // '0'
94  0x00, 0x42, 0x7F, 0x40, 0x00, // '1'
95  0x72, 0x49, 0x49, 0x49, 0x46, // '2'
96  0x21, 0x41, 0x49, 0x4D, 0x33, // '3'
97  0x18, 0x14, 0x12, 0x7F, 0x10, // '4'
98  0x27, 0x45, 0x45, 0x45, 0x39, // '5'
99  0x3C, 0x4A, 0x49, 0x49, 0x31, // '6'
100  0x41, 0x21, 0x11, 0x09, 0x07, // '7'
101  0x36, 0x49, 0x49, 0x49, 0x36, // '8'
102  0x46, 0x49, 0x49, 0x29, 0x1E, // '9'
103  0x00, 0x00, 0x14, 0x00, 0x00, // ':'
104  0x00, 0x40, 0x34, 0x00, 0x00, // ';'
105  0x00, 0x08, 0x14, 0x22, 0x41, // '<'
106  0x14, 0x14, 0x14, 0x14, 0x14, // '='
107  0x00, 0x41, 0x22, 0x14, 0x08, // '>'
108  0x02, 0x01, 0x59, 0x09, 0x06, // '?'
109  // 4x Group
110  0x3E, 0x41, 0x5D, 0x59, 0x4E, // '@'
111  0x7C, 0x12, 0x11, 0x12, 0x7C, // 'A'
112  0x7F, 0x49, 0x49, 0x49, 0x36, // 'B'
113  0x3E, 0x41, 0x41, 0x41, 0x22, // 'C'
114  0x7F, 0x41, 0x41, 0x41, 0x3E, // 'D'
115  0x7F, 0x49, 0x49, 0x49, 0x41, // 'E'
116  0x7F, 0x09, 0x09, 0x09, 0x01, // 'F'
117  0x3E, 0x41, 0x41, 0x51, 0x73, // 'G'
118  0x7F, 0x08, 0x08, 0x08, 0x7F, // 'H'
119  0x00, 0x41, 0x7F, 0x41, 0x00, // 'I'
120  0x20, 0x40, 0x41, 0x3F, 0x01, // 'J'
121  0x7F, 0x08, 0x14, 0x22, 0x41, // 'K'
122  0x7F, 0x40, 0x40, 0x40, 0x40, // 'L'
123  0x7F, 0x02, 0x1C, 0x02, 0x7F, // 'M'
124  0x7F, 0x04, 0x08, 0x10, 0x7F, // 'N'
125  0x3E, 0x41, 0x41, 0x41, 0x3E, // 'O'
126  // 5x Group
127  0x7F, 0x09, 0x09, 0x09, 0x06, // 'P'
128  0x3E, 0x41, 0x51, 0x21, 0x5E, // 'Q'
129  0x7F, 0x09, 0x19, 0x29, 0x46, // 'R'
130  0x26, 0x49, 0x49, 0x49, 0x32, // 'S'
131  0x03, 0x01, 0x7F, 0x01, 0x03, // 'T'
132  0x3F, 0x40, 0x40, 0x40, 0x3F, // 'U'
133  0x1F, 0x20, 0x40, 0x20, 0x1F, // 'V'
134  0x3F, 0x40, 0x38, 0x40, 0x3F, // 'W'
135  0x63, 0x14, 0x08, 0x14, 0x63, // 'X'
136  0x03, 0x04, 0x78, 0x04, 0x03, // 'Y'
137  0x61, 0x59, 0x49, 0x4D, 0x43, // 'Z'
138  0x00, 0x7F, 0x41, 0x41, 0x41, // '['
139  0x02, 0x04, 0x08, 0x10, 0x20, // '\'
140  0x00, 0x41, 0x41, 0x41, 0x7F, // ']'
141  0x04, 0x02, 0x01, 0x02, 0x04, // '^'
142  0x40, 0x40, 0x40, 0x40, 0x40, // '_'
143  // 6x Group
144  0x00, 0x03, 0x07, 0x08, 0x00, // '`'
145  0x20, 0x54, 0x54, 0x78, 0x40, // 'a'
146  0x7F, 0x28, 0x44, 0x44, 0x38, // 'b'
147  0x38, 0x44, 0x44, 0x44, 0x28, // 'c'
148  0x38, 0x44, 0x44, 0x28, 0x7F, // 'd'
149  0x38, 0x54, 0x54, 0x54, 0x18, // 'e'
150  0x00, 0x08, 0x7E, 0x09, 0x02, // 'f'
151  0x18, 0xA4, 0xA4, 0x9C, 0x78, // 'g'
152  0x7F, 0x08, 0x04, 0x04, 0x78, // 'h'
153  0x00, 0x44, 0x7D, 0x40, 0x00, // 'i'
154  0x20, 0x40, 0x40, 0x3D, 0x00, // 'j'
155  0x7F, 0x10, 0x28, 0x44, 0x00, // 'k'
156  0x00, 0x41, 0x7F, 0x40, 0x00, // 'l'
157  0x7C, 0x04, 0x78, 0x04, 0x78, // 'm'
158  0x7C, 0x08, 0x04, 0x04, 0x78, // 'n'
159  0x38, 0x44, 0x44, 0x44, 0x38, // 'o'
160  // 7x Group
161  0xFC, 0x18, 0x24, 0x24, 0x18, // 'p'
162  0x18, 0x24, 0x24, 0x18, 0xFC, // 'q'
163  0x7C, 0x08, 0x04, 0x04, 0x08, // 'r'
164  0x48, 0x54, 0x54, 0x54, 0x24, // 's'
165  0x04, 0x04, 0x3F, 0x44, 0x24, // 't'
166  0x3C, 0x40, 0x40, 0x20, 0x7C, // 'u'
167  0x1C, 0x20, 0x40, 0x20, 0x1C, // 'v'
168  0x3C, 0x40, 0x30, 0x40, 0x3C, // 'w'
169  0x44, 0x28, 0x10, 0x28, 0x44, // 'x'
170  0x4C, 0x90, 0x90, 0x90, 0x7C, // 'y'
171  0x44, 0x64, 0x54, 0x4C, 0x44, // 'z'
172  0x00, 0x08, 0x36, 0x41, 0x00, // '{'
173  0x00, 0x00, 0x77, 0x00, 0x00, // '|'
174  0x00, 0x41, 0x36, 0x08, 0x00, // '}'
175  0x02, 0x01, 0x02, 0x04, 0x02, // '~'
176 #ifdef AP_NOTIFY_DISPLAY_USE_EMOJI
177  0x3C, 0x26, 0x23, 0x26, 0x3C, // 7F
178  // 8x Group
179  0x1E, 0xA1, 0xA1, 0x61, 0x12, // 80
180  0x3A, 0x40, 0x40, 0x20, 0x7A, // 81
181  0x38, 0x54, 0x54, 0x55, 0x59, // 82
182  0x21, 0x55, 0x55, 0x79, 0x41, // 83
183  0x22, 0x54, 0x54, 0x78, 0x42, // 84
184  0x21, 0x55, 0x54, 0x78, 0x40, // 85
185  0x20, 0x54, 0x55, 0x79, 0x40, // 86
186  0x0C, 0x1E, 0x52, 0x72, 0x12, // 87
187  0x39, 0x55, 0x55, 0x55, 0x59, // 88
188  0x39, 0x54, 0x54, 0x54, 0x59, // 89
189  0x39, 0x55, 0x54, 0x54, 0x58, // 8A
190  0x00, 0x00, 0x45, 0x7C, 0x41, // 8B
191  0x00, 0x02, 0x45, 0x7D, 0x42, // 8C
192  0x00, 0x01, 0x45, 0x7C, 0x40, // 8D
193  0x7D, 0x12, 0x11, 0x12, 0x7D, // 8E
194  0xF0, 0x28, 0x25, 0x28, 0xF0, // 8F
195  // 9x Group
196  0x7C, 0x54, 0x55, 0x45, 0x00, // 90
197  0x20, 0x54, 0x54, 0x7C, 0x54, // 91
198  0x7C, 0x0A, 0x09, 0x7F, 0x49, // 92
199  0x32, 0x49, 0x49, 0x49, 0x32, // 93
200  0x3A, 0x44, 0x44, 0x44, 0x3A, // 94
201  0x32, 0x4A, 0x48, 0x48, 0x30, // 95
202  0x3A, 0x41, 0x41, 0x21, 0x7A, // 96
203  0x3A, 0x42, 0x40, 0x20, 0x78, // 97
204  0x00, 0x9D, 0xA0, 0xA0, 0x7D, // 98
205  0x3D, 0x42, 0x42, 0x42, 0x3D, // 99
206  0x3D, 0x40, 0x40, 0x40, 0x3D, // 9A
207  0x3C, 0x24, 0xFF, 0x24, 0x24, // 9B
208  0x48, 0x7E, 0x49, 0x43, 0x66, // 9C
209  0x2B, 0x2F, 0xFC, 0x2F, 0x2B, // 9D
210  0xFF, 0x09, 0x29, 0xF6, 0x20, // 9E
211  0xC0, 0x88, 0x7E, 0x09, 0x03, // 9F
212  // Ax Group
213  0x20, 0x54, 0x54, 0x79, 0x41, // A0
214  0x00, 0x00, 0x44, 0x7D, 0x41, // A1
215  0x30, 0x48, 0x48, 0x4A, 0x32, // A2
216  0x38, 0x40, 0x40, 0x22, 0x7A, // A3
217  0x00, 0x7A, 0x0A, 0x0A, 0x72, // A4
218  0x7D, 0x0D, 0x19, 0x31, 0x7D, // A5
219  0x26, 0x29, 0x29, 0x2F, 0x28, // A6
220  0x26, 0x29, 0x29, 0x29, 0x26, // A7
221  0x30, 0x48, 0x4D, 0x40, 0x20, // A8
222  0x38, 0x08, 0x08, 0x08, 0x08, // A9
223  0x08, 0x08, 0x08, 0x08, 0x38, // AA
224  0x2F, 0x10, 0xC8, 0xAC, 0xBA, // AB
225  0x2F, 0x10, 0x28, 0x34, 0xFA, // AC
226  0x00, 0x00, 0x7B, 0x00, 0x00, // AD
227  0x08, 0x14, 0x2A, 0x14, 0x22, // AE
228  0x22, 0x14, 0x2A, 0x14, 0x08, // AF
229  // Bx Group
230  0x55, 0x00, 0x55, 0x00, 0x55, // B0
231  0xAA, 0x55, 0xAA, 0x55, 0xAA, // B1
232  0xFF, 0x55, 0xFF, 0x55, 0xFF, // B2
233  0x00, 0x00, 0x00, 0xFF, 0x00, // B3
234  0x10, 0x10, 0x10, 0xFF, 0x00, // B4
235  0x14, 0x14, 0x14, 0xFF, 0x00, // B5
236  0x10, 0x10, 0xFF, 0x00, 0xFF, // B6
237  0x10, 0x10, 0xF0, 0x10, 0xF0, // B7
238  0x14, 0x14, 0x14, 0xFC, 0x00, // B8
239  0x14, 0x14, 0xF7, 0x00, 0xFF, // B9
240  0x00, 0x00, 0xFF, 0x00, 0xFF, // BA
241  0x14, 0x14, 0xF4, 0x04, 0xFC, // BB
242  0x14, 0x14, 0x17, 0x10, 0x1F, // BC
243  0x10, 0x10, 0x1F, 0x10, 0x1F, // BD
244  0x14, 0x14, 0x14, 0x1F, 0x00, // BE
245  0x10, 0x10, 0x10, 0xF0, 0x00, // BF
246  // Cx Group
247  0x00, 0x00, 0x00, 0x1F, 0x10, // C0
248  0x10, 0x10, 0x10, 0x1F, 0x10, // C1
249  0x10, 0x10, 0x10, 0xF0, 0x10, // C2
250  0x00, 0x00, 0x00, 0xFF, 0x10, // C3
251  0x10, 0x10, 0x10, 0x10, 0x10, // C4
252  0x10, 0x10, 0x10, 0xFF, 0x10, // C5
253  0x00, 0x00, 0x00, 0xFF, 0x14, // C6
254  0x00, 0x00, 0xFF, 0x00, 0xFF, // C7
255  0x00, 0x00, 0x1F, 0x10, 0x17, // C8
256  0x00, 0x00, 0xFC, 0x04, 0xF4, // C9
257  0x14, 0x14, 0x17, 0x10, 0x17, // CA
258  0x14, 0x14, 0xF4, 0x04, 0xF4, // CB
259  0x00, 0x00, 0xFF, 0x00, 0xF7, // CC
260  0x14, 0x14, 0x14, 0x14, 0x14, // CD
261  0x14, 0x14, 0xF7, 0x00, 0xF7, // CE
262  0x14, 0x14, 0x14, 0x17, 0x14, // CF
263  // Dx Group
264  0x10, 0x10, 0x1F, 0x10, 0x1F, // D0
265  0x14, 0x14, 0x14, 0xF4, 0x14, // D1
266  0x10, 0x10, 0xF0, 0x10, 0xF0, // D2
267  0x00, 0x00, 0x1F, 0x10, 0x1F, // D3
268  0x00, 0x00, 0x00, 0x1F, 0x14, // D4
269  0x00, 0x00, 0x00, 0xFC, 0x14, // D5
270  0x00, 0x00, 0xF0, 0x10, 0xF0, // D6
271  0x10, 0x10, 0xFF, 0x10, 0xFF, // D7
272  0x14, 0x14, 0x14, 0xFF, 0x14, // D8
273  0x10, 0x10, 0x10, 0x1F, 0x00, // D9
274  0x00, 0x00, 0x00, 0xF0, 0x10, // DA
275  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // DB
276  0xF0, 0xF0, 0xF0, 0xF0, 0xF0, // DC
277  0xFF, 0xFF, 0xFF, 0x00, 0x00, // DD
278  0x00, 0x00, 0x00, 0xFF, 0xFF, // DE
279  0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // DF
280  // Ex Group
281  0x38, 0x44, 0x44, 0x38, 0x44, // E0
282  0xFC, 0x4A, 0x4A, 0x4A, 0x34, // E1
283  0x7E, 0x02, 0x02, 0x06, 0x06, // E2
284  0x02, 0x7E, 0x02, 0x7E, 0x02, // E3
285  0x63, 0x55, 0x49, 0x41, 0x63, // E4
286  0x38, 0x44, 0x44, 0x3C, 0x04, // E5
287  0x40, 0x7E, 0x20, 0x1E, 0x20, // E6
288  0x06, 0x02, 0x7E, 0x02, 0x02, // E7
289  0x99, 0xA5, 0xE7, 0xA5, 0x99, // E8
290  0x1C, 0x2A, 0x49, 0x2A, 0x1C, // E9
291  0x4C, 0x72, 0x01, 0x72, 0x4C, // EA
292  0x30, 0x4A, 0x4D, 0x4D, 0x30, // EB
293  0x30, 0x48, 0x78, 0x48, 0x30, // EC
294  0xBC, 0x62, 0x5A, 0x46, 0x3D, // ED
295  0x3E, 0x49, 0x49, 0x49, 0x00, // EE
296  0x7E, 0x01, 0x01, 0x01, 0x7E, // EF
297  // Fx Group
298  0x2A, 0x2A, 0x2A, 0x2A, 0x2A, // F0
299  0x44, 0x44, 0x5F, 0x44, 0x44, // F1
300  0x40, 0x51, 0x4A, 0x44, 0x40, // F2
301  0x40, 0x44, 0x4A, 0x51, 0x40, // F3
302  0x00, 0x00, 0xFF, 0x01, 0x03, // F4
303  0xE0, 0x80, 0xFF, 0x00, 0x00, // F5
304  0x08, 0x08, 0x6B, 0x6B, 0x08, // F6
305  0x36, 0x12, 0x36, 0x24, 0x36, // F7
306  0x06, 0x0F, 0x09, 0x0F, 0x06, // F8
307  0x00, 0x00, 0x18, 0x18, 0x00, // F9
308  0x00, 0x00, 0x10, 0x10, 0x00, // FA
309  0x30, 0x40, 0xFF, 0x01, 0x01, // FB
310  0x00, 0x1F, 0x01, 0x01, 0x1E, // FC
311  0x00, 0x19, 0x1D, 0x17, 0x12, // FD
312  0x00, 0x3C, 0x3C, 0x3C, 0x3C, // FE
313  0x00, 0x00, 0x00, 0x00, 0x00 // FF
314 #endif
315 };
316 
317 // probe first 3 busses:
318 static const uint8_t I2C_BUS_PROBE_MASK = 0x7;
319 
320 bool Display::init(void)
321 {
322  // exit immediately if already initialised
323  if (_driver != nullptr) {
324  return true;
325  }
326 
327  // initialise driver
328  for(uint8_t i=0; i<8 && _driver == nullptr; i++) {
329  if (! (I2C_BUS_PROBE_MASK & (1<<i))) {
330  continue;
331  }
332  switch (pNotify->_display_type) {
333  case DISPLAY_SSD1306: {
335  break;
336  }
337  case DISPLAY_SH1106: {
339  break;
340  }
341  case DISPLAY_OFF:
342  default:
343  break;
344  }
345  }
346 
347  if (_driver == nullptr) {
348  _healthy = false;
349  return false;
350  }
351  _healthy = true;
352 
353  // update all on display
354  update_all();
355  _driver->hw_update();
356 
357  return true;
358 }
359 
361 {
362  // return immediately if not enabled
363  if (!_healthy) {
364  return;
365  }
366 
367  // max update frequency 2Hz
368  static uint8_t timer = 0;
369  if (timer++ < 25) {
370  return;
371  }
372  timer = 0;
373 
374  if (AP_Notify::flags.armed) {
375  if (_screenpage != 1) {
377  update_arm(3);
378  _screenpage = 1;
379  _driver->hw_update(); //update hw once , do not transmition to display in fly
380  }
381  return;
382  }
383 
384  if (_screenpage != 2) {
385  _driver->clear_screen(); //once clear screen when page changed
386  _screenpage = 2;
387  }
388 
389  update_all();
390  _driver->hw_update(); //update at 2 Hz in disarmed mode
391 
392 }
393 
395 {
396  update_text(0);
397  update_mode(1);
398  update_battery(2);
399  update_gps(3);
400  //update_gps_sats(4);
401  update_prearm(4);
402  update_ekf(5);
403 }
404 
405 void Display::draw_text(uint16_t x, uint16_t y, const char* c)
406 {
407  if (nullptr == c) {
408  return;
409  }
410  while (*c != 0) {
411 #ifndef AP_NOTIFY_DISPLAY_USE_EMOJI
412  if (*c >= ' ' && *c <= '~') {
413  draw_char(x, y, *c - ' ');
414  } else {
415  // convert oob characters to spaces
416  draw_char(x, y, 0);
417  }
418 #else
419  draw_char(x, y, *c);
420 #endif
421  x += 7;
422  c++;
423  }
424 }
425 
426 void Display::draw_char(uint16_t x, uint16_t y, const char c)
427 {
428  uint8_t line;
429 
430  // draw char to pixel
431  for (uint8_t i = 0; i < 6; i++) {
432  if (i == 5) {
433  line = 0;
434  } else {
435  line = _font[(c * 5) + i];
436  }
437 
438  for (uint8_t j = 0; j < 8; j++) {
439  if (line & 1) {
440  _driver->set_pixel(x + i, y + j);
441  } else {
442  _driver->clear_pixel(x + i, y + j);
443  }
444  line >>= 1;
445  }
446  }
447 }
448 
449 void Display::update_arm(uint8_t r)
450 {
451  if (AP_Notify::flags.armed) {
452  draw_text(COLUMN(0), ROW(r), ">>>>> ARMED! <<<<<");
453  } else {
454  draw_text(COLUMN(0), ROW(r), " disarmed ");
455  }
456 }
457 
458 void Display::update_prearm(uint8_t r)
459 {
460  if (AP_Notify::flags.pre_arm_check) {
461  draw_text(COLUMN(0), ROW(r), "Prearm: passed ");
462  } else {
463  draw_text(COLUMN(0), ROW(r), "Prearm: failed ");
464  }
465 }
466 
467 void Display::update_gps(uint8_t r)
468 {
469  static const char * gpsfixname[] = {"Other", "NoGPS","NoFix","2D","3D","DGPS", "RTK f", "RTK F"};
470  char msg [DISPLAY_MESSAGE_SIZE];
471  const char * fixname;
472  switch (AP_Notify::flags.gps_status) {
473  case AP_GPS::NO_GPS:
474  fixname = gpsfixname[1];
475  break;
476  case AP_GPS::NO_FIX:
477  fixname = gpsfixname[2];
478  break;
480  fixname = gpsfixname[3];
481  break;
483  fixname = gpsfixname[4];
484  break;
486  fixname = gpsfixname[5];
487  break;
489  fixname = gpsfixname[6];
490  break;
492  fixname = gpsfixname[7];
493  break;
494  default:
495  fixname = gpsfixname[0];
496  break;
497  }
498  snprintf(msg, DISPLAY_MESSAGE_SIZE, "GPS:%-5s Sats:%2u", fixname, (unsigned)AP_Notify::flags.gps_num_sats) ;
499  draw_text(COLUMN(0), ROW(r), msg);
500 }
501 
503 {
504  draw_text(COLUMN(0), ROW(r), "Sats:");
505  draw_char(COLUMN(8), ROW(r), (AP_Notify::flags.gps_num_sats / 10) + '0');
506  draw_char(COLUMN(9), ROW(r), (AP_Notify::flags.gps_num_sats % 10) + '0');
507 }
508 
509 void Display::update_ekf(uint8_t r)
510 {
511  if (AP_Notify::flags.ekf_bad) {
512  draw_text(COLUMN(0), ROW(r), "EKF: fail");
513  } else {
514  draw_text(COLUMN(0), ROW(r), "EKF: ok ");
515  }
516 }
517 
518 void Display::update_battery(uint8_t r)
519 {
520  char msg [DISPLAY_MESSAGE_SIZE];
521  snprintf(msg, DISPLAY_MESSAGE_SIZE, "BAT1: %4.2fV", (double)AP_Notify::flags.battery_voltage) ;
522  draw_text(COLUMN(0), ROW(r), msg);
523  }
524 
525 void Display::update_mode(uint8_t r)
526 {
527  char msg [DISPLAY_MESSAGE_SIZE];
528  if (pNotify->get_flight_mode_str()) {
530  draw_text(COLUMN(0), ROW(r), msg);
531  }
532 }
533 
535 {
536  char msg [DISPLAY_MESSAGE_SIZE] = {};
537  memset(msg, ' ', sizeof(msg)-1);
538  _movedelay = 0;
539  _mstartpos = 0;
540  draw_text(COLUMN(0), ROW(r), msg);
541 }
542 
543 void Display::update_text(uint8_t r)
544 {
545  char msg [DISPLAY_MESSAGE_SIZE] = {};
546  char txt [NOTIFY_TEXT_BUFFER_SIZE] = {};
547 
549  if (!text_is_valid) {
551  return;
552  }
553 
554  if (_movedelay > 0) {
555  _movedelay--;
556  return;
557  }
558 
559  snprintf(txt, sizeof(txt), "%s", pNotify->get_text());
560 
561  memset(msg, ' ', sizeof(msg)-1); // leave null termination
562  const uint8_t len = strlen(&txt[_mstartpos]);
563  const uint8_t to_copy = (len < sizeof(msg)-1) ? len : (sizeof(msg)-1);
564  memcpy(msg, &txt[_mstartpos], to_copy);
565 
566  if (len <= sizeof(msg)-1) {
567  // end-of-message reached; pause scrolling a while
568  _movedelay = 4;
569  // reset startpos so we start scrolling from the start again:
570  _mstartpos = 0;
571  } else {
572  _mstartpos++;
573  }
574 
575  draw_text(COLUMN(0), ROW(0), msg);
576  }
void update_prearm(uint8_t r)
Definition: Display.cpp:458
void update_text_empty(uint8_t r)
Definition: Display.cpp:534
void update_battery(uint8_t r)
Definition: Display.cpp:518
static Display_SSD1306_I2C * probe(AP_HAL::OwnPtr< AP_HAL::Device > dev)
bool _healthy
Definition: Display.h:35
virtual void set_pixel(uint16_t x, uint16_t y)=0
uint8_t _mstartpos
Definition: Display.h:37
#define DISPLAY_SSD1306
Definition: AP_Notify.h:35
uint8_t _movedelay
Definition: Display.h:38
uint32_t timer
void update_gps_sats(uint8_t r)
Definition: Display.cpp:502
AP_Int8 _display_type
Definition: AP_Notify.h:156
virtual void hw_update()=0
const char * get_flight_mode_str() const
Definition: AP_Notify.h:139
#define COLUMN(X)
Definition: Display.h:6
void update_text(uint8_t r)
Definition: Display.cpp:543
#define DISPLAY_OFF
Definition: AP_Notify.h:34
void update_mode(uint8_t r)
Definition: Display.cpp:525
Receiving valid messages and 3D RTK Fixed.
Definition: AP_GPS.h:103
void draw_char(uint16_t x, uint16_t y, const char c)
Definition: Display.cpp:426
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition: AC_PID_test.cpp:14
#define ROW(Y)
Definition: Display.h:5
#define x(i)
void update_ekf(uint8_t r)
Definition: Display.cpp:509
virtual void clear_screen()=0
#define NOTIFY_TEXT_BUFFER_SIZE
Definition: AP_Notify.h:31
#define DISPLAY_MESSAGE_SIZE
Definition: Display.h:8
Receiving valid messages and 3D lock with differential improvements.
Definition: AP_GPS.h:101
Receiving valid messages and 3D RTK Float.
Definition: AP_GPS.h:102
const char * get_text() const
Definition: AP_Notify.h:143
uint32_t millis()
Definition: system.cpp:157
uint32_t _send_text_updated_millis
Definition: AP_Notify.h:161
uint8_t _screenpage
Definition: Display.h:39
Receiving valid messages and 2D lock.
Definition: AP_GPS.h:99
const uint16_t _send_text_valid_millis
Definition: Display.h:42
void update()
Definition: Display.cpp:360
bool init(void)
Definition: Display.cpp:320
const AP_Notify * pNotify
Definition: NotifyDevice.h:24
AP_HAL::I2CDeviceManager * i2c_mgr
Definition: HAL.h:106
Display_Backend * _driver
Definition: Display.h:33
static const uint8_t _font[]
Definition: Display.cpp:38
void update_all()
Definition: Display.cpp:394
Receiving valid GPS messages but no lock.
Definition: AP_GPS.h:98
static struct notify_flags_and_values_type flags
Definition: AP_Notify.h:117
static const uint8_t I2C_BUS_PROBE_MASK
Definition: Display.cpp:318
No GPS connected/detected.
Definition: AP_GPS.h:97
#define DISPLAY_SH1106
Definition: AP_Notify.h:36
void update_gps(uint8_t r)
Definition: Display.cpp:467
int snprintf(char *str, size_t size, const char *fmt,...)
Definition: stdio.c:64
static Display_SH1106_I2C * probe(AP_HAL::OwnPtr< AP_HAL::Device > dev)
Receiving valid messages and 3D lock.
Definition: AP_GPS.h:100
virtual OwnPtr< AP_HAL::I2CDevice > get_device(uint8_t bus, uint8_t address, uint32_t bus_clock=400000, bool use_smbus=false, uint32_t timeout_ms=4)=0
void update_arm(uint8_t r)
Definition: Display.cpp:449
#define NOTIFY_DISPLAY_I2C_ADDR
void draw_text(uint16_t x, uint16_t y, const char *c)
Definition: Display.cpp:405
virtual void clear_pixel(uint16_t x, uint16_t y)=0