Rev 738 | Rev 762 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 738 | Rev 761 | ||
---|---|---|---|
Line 106... | Line 106... | ||
106 | const char stats_item_7[] PROGMEM = "max current :"; |
106 | const char stats_item_7[] PROGMEM = "max current :"; |
107 | const char *stats_item_pointers[8] PROGMEM = {stats_item_0, stats_item_1, stats_item_2, |
107 | const char *stats_item_pointers[8] PROGMEM = {stats_item_0, stats_item_1, stats_item_2, |
108 | stats_item_3, stats_item_4, stats_item_5, stats_item_6, stats_item_7}; |
108 | stats_item_3, stats_item_4, stats_item_5, stats_item_6, stats_item_7}; |
Line 109... | Line 109... | ||
109 | 109 | ||
110 | //char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
110 | //char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
111 | //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
111 | //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
112 | const char str_NE[] PROGMEM = "NE"; |
112 | const char str_NE[] PROGMEM = "NE"; |
113 | const char str_E[] PROGMEM = "E "; |
113 | const char str_E[] PROGMEM = "E "; |
114 | const char str_SE[] PROGMEM = "SE"; |
114 | const char str_SE[] PROGMEM = "SE"; |
115 | const char str_S[] PROGMEM = "S "; |
115 | const char str_S[] PROGMEM = "S "; |
116 | const char str_SW[] PROGMEM = "SW"; |
116 | const char str_SW[] PROGMEM = "SW"; |
117 | const char str_W[] PROGMEM = "W "; |
117 | const char str_W[] PROGMEM = "W "; |
118 | const char str_NW[] PROGMEM = "NW"; |
118 | const char str_NW[] PROGMEM = "NW"; |
119 | const char str_N[] PROGMEM = "N "; |
119 | const char str_N[] PROGMEM = "N "; |
120 | const char *directions[8] PROGMEM = { |
120 | const char *directions[8] PROGMEM = { |
121 | str_NE, |
121 | str_NE, |
122 | str_E, |
122 | str_E, |
123 | str_SE, |
123 | str_SE, |
124 | str_S, |
124 | str_S, |
125 | str_SW, |
125 | str_SW, |
126 | str_W, |
126 | str_W, |
127 | str_NW, |
127 | str_NW, |
- | 128 | str_N |
|
Line 128... | Line 129... | ||
128 | str_N}; |
129 | }; |
129 | 130 | ||
130 | /* ########################################################################## |
131 | /* ########################################################################## |
131 | * Different display mode function pointers |
132 | * Different display mode function pointers |
132 | * ##########################################################################*/ |
133 | * ##########################################################################*/ |
133 | const char str_1[] PROGMEM = "default"; |
134 | const char str_1[] PROGMEM = "default"; |
Line 134... | Line 135... | ||
134 | const char str_2[] PROGMEM = "minimal"; |
135 | const char str_2[] PROGMEM = "minimal"; |
135 | const char str_3[] PROGMEM = " jopl"; |
136 | const char str_3[] PROGMEM = " jopl"; |
136 | 137 | ||
137 | const displaymode_t ncdisplaymodes[] PROGMEM = { |
138 | const displaymode_t ncdisplaymodes[] PROGMEM = { |
Line 138... | Line 139... | ||
138 | { osd_ncmode_default, (char *)str_1 }, |
139 | { osd_ncmode_default, (char *)str_1}, |
139 | { osd_ncmode_minimal, (char *)str_2 } |
140 | { osd_ncmode_minimal, (char *)str_2} |
140 | }; |
141 | }; |
141 | 142 | ||
Line 142... | Line 143... | ||
142 | const displaymode_t fcdisplaymodes[] PROGMEM = { |
143 | const displaymode_t fcdisplaymodes[] PROGMEM = { |
143 | { osd_fcmode_default, (char *)str_1 }, |
144 | { osd_fcmode_default, (char *)str_1}, |
144 | { osd_fcmode_jopl, (char *)str_3 } |
145 | { osd_fcmode_jopl, (char *)str_3} |
Line 145... | Line 146... | ||
145 | }; |
146 | }; |
146 | 147 | ||
147 | int (*osd_ncmode)(void) = (int(*)(void)) &osd_ncmode_default; |
148 | int (*osd_ncmode)(void) = (int(*)(void)) & osd_ncmode_default; |
Line 172... | Line 173... | ||
172 | */ |
173 | */ |
173 | ISR(TIMER0_COMP_vect) { |
174 | ISR(TIMER0_COMP_vect) { |
174 | if (!timer--) { |
175 | if (!timer--) { |
175 | uptime++; |
176 | uptime++; |
Line 176... | Line 177... | ||
176 | 177 | ||
177 | #if FCONLY |
178 | #if FCONLY |
178 | if (debugData.Analog[12]>10) { |
179 | if (debugData.Analog[12] > 10) { |
179 | flytime_fc++; |
180 | flytime_fc++; |
180 | } |
181 | } |
Line 181... | Line 182... | ||
181 | #endif |
182 | #endif |
182 | 183 | ||
183 | timer = 999; |
184 | timer = 999; |
184 | seconds_since_last_data++; |
185 | seconds_since_last_data++; |
185 | } |
186 | } |
186 | // in case there is still some spi data to send do it now |
187 | // in case there is still some spi data to send do it now |
187 | // delay to give the slave some time to compute values |
188 | // delay to give the slave some time to compute values |
188 | if (spi_ready && icnt) { |
189 | if (spi_ready && icnt) { |
189 | if (!delay_spi--) { |
190 | if (!delay_spi--) { |
190 | delay_spi = 8; |
191 | delay_spi = 8; |
191 | spi_send_next(); |
192 | spi_send_next(); |
192 | } |
193 | } |
193 | } |
194 | } |
Line 194... | Line 195... | ||
194 | } |
195 | } |
195 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
196 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
196 | 197 | ||
197 | /* ########################################################################## |
198 | /* ########################################################################## |
198 | * MAIN |
199 | * MAIN |
199 | * ##########################################################################*/ |
200 | * ##########################################################################*/ |
200 | int main(void) { |
201 | int main(void) { |
201 | // set up FLAGS |
202 | // set up FLAGS |
202 | COSD_FLAGS_MODES = 0, COSD_FLAGS_CONFIG = 0, COSD_FLAGS_RUNTIME = 0; |
203 | COSD_FLAGS_MODES = 0, COSD_FLAGS_CONFIG = 0, COSD_FLAGS_RUNTIME = 0; |
203 | #if NTSC |
204 | #if NTSC |
204 | COSD_FLAGS_CONFIG |= COSD_FLAG_NTSC; |
205 | COSD_FLAGS_CONFIG |= COSD_FLAG_NTSC; |
205 | #endif |
206 | #endif |
206 | #if HUD |
207 | #if HUD |
207 | COSD_FLAGS_MODES |= COSD_FLAG_HUD; |
208 | COSD_FLAGS_MODES |= COSD_FLAG_HUD; |
208 | #endif |
209 | #endif |
209 | #if ARTHORIZON |
210 | #if ARTHORIZON |
210 | COSD_FLAGS_MODES |= COSD_FLAG_ARTHORIZON; |
211 | COSD_FLAGS_MODES |= COSD_FLAG_ARTHORIZON; |
211 | #endif |
212 | #endif |
212 | #if BIGVARIO |
213 | #if BIGVARIO |
213 | COSD_FLAGS_MODES |= COSD_FLAG_BIGARIO; |
214 | COSD_FLAGS_MODES |= COSD_FLAG_BIGARIO; |
214 | #endif |
215 | #endif |
215 | #if STATS |
216 | #if STATS |
216 | COSD_FLAGS_MODES |= COSD_FLAG_STATS; |
217 | COSD_FLAGS_MODES |= COSD_FLAG_STATS; |
217 | #endif |
218 | #endif |
218 | #if WARNINGS |
219 | #if WARNINGS |
219 | COSD_FLAGS_MODES |= COSD_FLAG_WARNINGS; |
220 | COSD_FLAGS_MODES |= COSD_FLAG_WARNINGS; |
220 | #endif |
221 | #endif |
Line 221... | Line 222... | ||
221 | #if FCONLY |
222 | #if FCONLY |
222 | COSD_FLAGS_CONFIG |= COSD_FLAG_FCMODE; |
223 | COSD_FLAGS_CONFIG |= COSD_FLAG_FCMODE; |
223 | #endif |
224 | #endif |
Line 256... | Line 257... | ||
256 | _delay_ms(1000); |
257 | _delay_ms(1000); |
257 | LED4_OFF |
258 | LED4_OFF |
Line 258... | Line 259... | ||
258 | 259 | ||
259 | //Pushing NEW chars to the MAX7456 |
260 | //Pushing NEW chars to the MAX7456 |
260 | #if (WRITECHARS != -1) |
261 | #if (WRITECHARS != -1) |
261 | // DISABLE display (VM0) |
262 | // DISABLE display (VM0) |
262 | spi_send_byte(0x00, 0b00000000); |
263 | spi_send_byte(0x00, 0b00000000); |
263 | learn_all_chars_pgm(); |
264 | learn_all_chars_pgm(); |
264 | #else |
265 | #else |
265 | // read out config for NTSC/PAL distinguishing |
266 | // read out config for NTSC/PAL distinguishing |
266 | get_eeprom(0); |
267 | get_eeprom(0); |
Line 267... | Line 268... | ||
267 | #endif |
268 | #endif |
268 | 269 | ||
269 | // Setup Video Mode |
270 | // Setup Video Mode |
270 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
271 | if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
271 | // NTSC + enable display immediately (VM0) |
272 | // NTSC + enable display immediately (VM0) |
272 | spi_send_byte(0x00, 0b00001000); |
273 | spi_send_byte(0x00, 0b00001000); |
273 | 274 | ||
274 | bottom_line = 12; |
275 | bottom_line = 12; |
275 | } else { |
276 | } else { |
Line 276... | Line 277... | ||
276 | // PAL + enable display immediately (VM0) |
277 | // PAL + enable display immediately (VM0) |
277 | spi_send_byte(0x00, 0b01001000); |
278 | spi_send_byte(0x00, 0b01001000); |
Line 278... | Line 279... | ||
278 | 279 | ||
279 | bottom_line = 14; |
280 | bottom_line = 14; |
Line 280... | Line 281... | ||
280 | } |
281 | } |
Line 297... | Line 298... | ||
297 | 298 | ||
298 | // keep serial port clean |
299 | // keep serial port clean |
Line 299... | Line 300... | ||
299 | usart1_DisableTXD(); |
300 | usart1_DisableTXD(); |
300 | 301 | ||
301 | // set up timer |
302 | // set up timer |
Line 302... | Line 303... | ||
302 | // CTC, Prescaler /64 |
303 | // CTC, Prescaler /64 |
303 | TCCR0 = (1 << WGM01) | (0 << WGM00) | (0 << CS02) | (1 << CS01) | (1 << CS00); |
304 | TCCR0 = (1 << WGM01) | (0 << WGM00) | (0 << CS02) | (1 << CS01) | (1 << CS00); |
Line 304... | Line 305... | ||
304 | 305 | ||
305 | TCNT0 = 0; |
306 | TCNT0 = 0; |
306 | OCR0 = 250; |
307 | OCR0 = 250; |
Line 307... | Line 308... | ||
307 | 308 | ||
308 | // enable timer output compare interrupt |
309 | // enable timer output compare interrupt |
309 | TIMSK &= ~(1 << TOIE0); |
310 | TIMSK &= ~(1 << TOIE0); |
Line 310... | Line 311... | ||
310 | TIMSK |= (1 << OCIE0); |
311 | TIMSK |= (1 << OCIE0); |
311 | 312 | ||
Line 312... | Line 313... | ||
312 | // SPI setup |
313 | // SPI setup |
313 | DDRD |= (1 << PD2); // PD2 output (INT0) |
314 | DDRD |= (1 << PD2); // PD2 output (INT0) |
314 | SpiMasterInit(); |
315 | SpiMasterInit(); |
Line 326... | Line 327... | ||
326 | 327 | ||
327 | // we are ready |
328 | // we are ready |
Line 328... | Line 329... | ||
328 | LED3_ON |
329 | LED3_ON |
329 | 330 | ||
330 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
331 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
331 | clear(); |
332 | clear(); |
332 | write_all_chars(); |
333 | write_all_chars(); |
333 | LED1_ON |
334 | LED1_ON |
334 | LED2_ON |
335 | LED2_ON |
335 | LED3_ON |
336 | LED3_ON |
Line 336... | Line 337... | ||
336 | LED4_ON |
337 | LED4_ON |
337 | #else |
338 | #else |
338 | 339 | ||
Line 339... | Line 340... | ||
339 | // clear serial screen |
340 | // clear serial screen |
340 | //usart1_puts("\x1B[2J\x1B[H"); |
341 | //usart1_puts("\x1B[2J\x1B[H"); |
341 | //usart1_puts("hello world!123\r\n"); |
342 | //usart1_puts("hello world!123\r\n"); |
342 | 343 | ||
343 | while (1) { |
344 | while (1) { |
344 | // in case SPI is ready and there is nothing to send right now |
345 | // in case SPI is ready and there is nothing to send right now |
345 | if (!icnt && spi_ready) { |
346 | if (!icnt && spi_ready) { |
346 | // correct transfer ends with d (done) |
347 | // correct transfer ends with d (done) |
347 | if (SPI_buffer.buffer.chk == 'd') { |
348 | if (SPI_buffer.buffer.chk == 'd') { |
348 | ampere = SPI_buffer.data.ampere; |
349 | ampere = SPI_buffer.data.ampere; |
349 | ampere_wasted = SPI_buffer.data.mah; |
350 | ampere_wasted = SPI_buffer.data.mah; |
350 | s_volt = SPI_buffer.data.volt; |
351 | s_volt = SPI_buffer.data.volt; |
351 | 352 | ||
352 | // if this is the first receival we should print the small A |
353 | // if this is the first receival we should print the small A |
353 | if (!(COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC)) { |
354 | if (!(COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC)) { |
354 | clear(); |
355 | clear(); |
355 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
356 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
356 | // update this flag |
357 | // update this flag |
357 | COSD_FLAGS_RUNTIME |= COSD_FLAG_STROMREC; |
358 | COSD_FLAGS_RUNTIME |= COSD_FLAG_STROMREC; |
358 | } |
359 | } |
359 | } else { |
360 | } else { |
360 | // update flags |
361 | // update flags |
361 | COSD_FLAGS_RUNTIME &= ~COSD_FLAG_STROMREC; |
362 | COSD_FLAGS_RUNTIME &= ~COSD_FLAG_STROMREC; |
362 | } |
363 | } |
363 | StartTransfer(9); |
364 | StartTransfer(9); |
364 | } |
365 | } |
365 | if (rxd_buffer_locked) { |
366 | if (rxd_buffer_locked) { |
Line 366... | Line 367... | ||
366 | #if FCONLY |
367 | #if FCONLY |
367 | if (rxd_buffer[2] == 'D') { // FC Data |
368 | if (rxd_buffer[2] == 'D') { // FC Data |
368 | Decode64(); |
369 | Decode64(); |
369 | debugData = *((DebugOut_t*) pRxData); |
370 | debugData = *((DebugOut_t*)pRxData); |
370 | 371 | ||
371 | // init on first data retrival, distinguished by last battery :) |
372 | // init on first data retrival, distinguished by last battery :) |
372 | if (last_UBat == 255) { |
373 | if (last_UBat == 255) { |
373 | if (debugData.Analog[9] > 40) { |
374 | if (debugData.Analog[9] > 40) { |
374 | // fix for min_UBat |
375 | // fix for min_UBat |
375 | min_UBat = debugData.Analog[9]; |
376 | min_UBat = debugData.Analog[9]; |
376 | last_UBat = debugData.Analog[9]; |
377 | last_UBat = debugData.Analog[9]; |
377 | init_cosd(last_UBat); |
378 | init_cosd(last_UBat); |
378 | } |
379 | } |
379 | } else { |
380 | } else { |
380 | osd_fcmode(); |
381 | osd_fcmode(); |
381 | } |
382 | } |
382 | seconds_since_last_data = 0; |
383 | seconds_since_last_data = 0; |
Line 383... | Line 384... | ||
383 | } |
384 | } |
384 | #else |
385 | #else |
385 | if (rxd_buffer[2] == 'O') { // NC OSD Data |
386 | if (rxd_buffer[2] == 'O') { // NC OSD Data |
386 | Decode64(); |
387 | Decode64(); |
387 | naviData = *((NaviData_t*) pRxData); |
388 | naviData = *((NaviData_t*)pRxData); |
388 | 389 | ||
389 | // init on first data retrival, distinguished by last battery :) |
390 | // init on first data retrival, distinguished by last battery :) |
390 | if (last_UBat == 255) { |
391 | if (last_UBat == 255) { |
391 | if (naviData.UBat > 40) { |
392 | if (naviData.UBat > 40) { |
392 | // fix for min_UBat |
393 | // fix for min_UBat |
393 | min_UBat = naviData.UBat; |
394 | min_UBat = naviData.UBat; |
394 | last_UBat = naviData.UBat; |
395 | last_UBat = naviData.UBat; |
395 | init_cosd(last_UBat); |
396 | init_cosd(last_UBat); |
396 | } |
397 | } |
397 | } else { |
398 | } else { |
398 | osd_ncmode(); |
399 | osd_ncmode(); |
399 | } |
400 | } |
400 | //seconds_since_last_data = 0; |
401 | //seconds_since_last_data = 0; |
401 | } |
402 | } |
402 | #endif |
403 | #endif |
403 | rxd_buffer_locked = 0; |
404 | rxd_buffer_locked = 0; |
404 | } |
405 | } |
405 | // handle keypress |
406 | // handle keypress |
406 | if (s1_pressed()) { |
407 | if (s1_pressed()) { |
407 | config_menu(); |
408 | config_menu(); |
408 | } |
409 | } |
409 | if (seconds_since_last_data > 0) { |
410 | if (seconds_since_last_data > 0) { |
410 | usart1_EnableTXD(); |
411 | usart1_EnableTXD(); |
411 | //usart1_puts_pgm(PSTR("zu alt\r\n")); |
412 | //usart1_puts_pgm(PSTR("zu alt\r\n")); |
412 | #if FCONLY |
413 | #if FCONLY |
413 | // request data ever 100ms from FC; |
414 | // request data ever 100ms from FC; |
Line 414... | Line 415... | ||
414 | //usart1_request_mk_data(0, 'd', 100); |
415 | //usart1_request_mk_data(0, 'd', 100); |
415 | usart1_puts_pgm(PSTR(REQUEST_DBG_DATA)); |
416 | usart1_puts_pgm(PSTR(REQUEST_DBG_DATA)); |
416 | #else |
417 | #else |
417 | // request OSD Data from NC every 100ms |
418 | // request OSD Data from NC every 100ms |
418 | //usart1_request_mk_data(1, 'o', 100); |
419 | //usart1_request_mk_data(1, 'o', 100); |
419 | usart1_puts_pgm(PSTR(REQUEST_OSD_DATA)); |
420 | usart1_puts_pgm(PSTR(REQUEST_OSD_DATA)); |
420 | 421 | ||
421 | // and disable debug... |
422 | // and disable debug... |
422 | //usart1_request_mk_data(0, 'd', 0); |
423 | //usart1_request_mk_data(0, 'd', 0); |
423 | #endif |
424 | #endif |
424 | // reset last time counter |
425 | // reset last time counter |