Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 454 → Rev 455

/C-OSD/trunk/main.c
28,7 → 28,7
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/pgmspace.h>
#include "main.h"
#include "max7456_software_spi.h"
#include "usart1.h"
72,8 → 72,8
char stats_item_4[] PROGMEM = "max time :";
char stats_item_5[] PROGMEM = "longitude :";
char stats_item_6[] PROGMEM = "latitude :";
char* stats_item_pointers[] PROGMEM = {stats_item_0, stats_item_1, stats_item_2,
stats_item_3, stats_item_4, stats_item_5, stats_item_6};
char* stats_item_pointers[] PROGMEM = {stats_item_0, stats_item_1, stats_item_2,
stats_item_3, stats_item_4, stats_item_5, stats_item_6};
 
// store more fixed strings in progmen
char ON[] PROGMEM = "ON ";
96,30 → 96,31
* debounce buttons
* ##########################################################################*/
int s1_pressed() {
if (S1_PRESSED) {
_delay_ms(25);
if (S1_PRESSED) return 1;
}
return 0;
if (S1_PRESSED) {
_delay_ms(25);
if (S1_PRESSED) return 1;
}
return 0;
}
 
int s2_pressed() {
if (S2_PRESSED) {
_delay_ms(25);
if (S2_PRESSED) return 1;
}
return 0;
if (S2_PRESSED) {
_delay_ms(25);
if (S2_PRESSED) return 1;
}
return 0;
}
 
/* ##########################################################################
* Interrupt handler
* ##########################################################################*/
 
/**
* handler for undefined Interrupts
* if not defined AVR will reset in case any unhandled interrupts occur
*/
ISR(__vector_default) {
asm("nop");
asm("nop");
}
 
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
126,6 → 127,7
/* ##########################################################################
* timer stuff
* ##########################################################################*/
 
/**
* timer kicks in every 1000uS ^= 1ms
*/
134,7 → 136,7
if (!timer--) {
uptime++;
timer = 999;
seconds_since_last_data++;
seconds_since_last_data++;
}
}
 
154,7 → 156,7
if (COSD_FLAGS & COSD_FLAG_HUD) {
write_ascii_string_pgm(23, 5, ON);
} else {
write_ascii_string_pgm(23, 5, OFF);
write_ascii_string_pgm(23, 5, OFF);
}
if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) {
write_ascii_string_pgm(23, 6, ON);
161,12 → 163,12
} else {
write_ascii_string_pgm(23, 6, OFF);
}
if (COSD_FLAGS & COSD_FLAG_BIGVARIO) {
if (COSD_FLAGS & COSD_FLAG_BIGVARIO) {
write_ascii_string_pgm(23, 7, ON);
} else {
write_ascii_string_pgm(23, 7, OFF);
write_ascii_string_pgm(23, 7, OFF);
}
if (COSD_FLAGS & COSD_FLAG_STATS) {
if (COSD_FLAGS & COSD_FLAG_STATS) {
write_ascii_string_pgm(23, 8, ON);
} else {
write_ascii_string_pgm(23, 8, OFF);
182,9 → 184,9
* some sort of clicking response in the menu
*/
void config_menu_doclick(uint8_t chosen, char** menu) {
write_ascii_string(4, chosen + 5, "DONE ");
_delay_ms(1000);
write_ascii_string(4, chosen + 5, menu[chosen]);
write_ascii_string(4, chosen + 5, "DONE ");
_delay_ms(1000);
write_ascii_string(4, chosen + 5, menu[chosen]);
}
 
/**
191,111 → 193,149
* a simple config menu tryout
*/
void config_menu(void) {
// disable interrupts (makes the menu more smoothely)
cli();
// disable interrupts (makes the menu more smoothely)
cli();
 
// clear screen
clear();
char* menu[9] = {"Full HUD",
"Art.Horizon in HUD",
"Big Vario bar",
"Statistics",
"Warnings", // TODO: do it!
"Reset uptime",
"Request OSD-data",
"Disable Debug-data",
"EXIT"};
// clear screen
clear();
 
uint8_t inmenu = 1;
uint8_t chosen = 0;
write_ascii_string(6, 2, "C-OSD Config Menu");
char* menu[9] = {"Full HUD",
"Art.Horizon in HUD",
"Big Vario bar",
"Statistics",
"Warnings", // TODO: do it!
"Reset uptime",
"Request OSD-data",
"Disable Debug-data",
"EXIT"};
 
// wait a bit before doing stuff so user has chance to release button
_delay_ms(250);
uint8_t inmenu = 1;
uint8_t chosen = 0;
write_ascii_string(6, 2, "C-OSD Config Menu");
 
write_ascii_string(4, 5, menu[0]);
write_ascii_string(4, 6, menu[1]);
write_ascii_string(4, 7, menu[2]);
write_ascii_string(4, 8, menu[3]);
write_ascii_string(4, 9, menu[4]);
write_ascii_string(4, 10, menu[5]);
write_ascii_string(4, 11, menu[6]);
write_ascii_string(4, 12, menu[7]);
write_ascii_string(4, 13, menu[8]);
// wait a bit before doing stuff so user has chance to release button
_delay_ms(250);
 
config_menu_drawings(chosen);
write_ascii_string(4, 5, menu[0]);
write_ascii_string(4, 6, menu[1]);
write_ascii_string(4, 7, menu[2]);
write_ascii_string(4, 8, menu[3]);
write_ascii_string(4, 9, menu[4]);
write_ascii_string(4, 10, menu[5]);
write_ascii_string(4, 11, menu[6]);
write_ascii_string(4, 12, menu[7]);
write_ascii_string(4, 13, menu[8]);
 
while (inmenu) {
if (s2_pressed()) {
write_ascii_string(3, chosen+5, " ");
chosen = (chosen + 1) % 9;
write_ascii_string(3, chosen+5, ">");
_delay_ms(500);
} else if (s1_pressed()) {
switch (chosen) {
case 0: // full HUD
COSD_FLAGS ^= COSD_FLAG_HUD;
config_menu_drawings(chosen);
break;
case 1: // art horizon
COSD_FLAGS ^= COSD_FLAG_ARTHORIZON;
config_menu_drawings(chosen);
break;
case 2: // big vario
COSD_FLAGS ^= COSD_FLAG_BIGVARIO;
config_menu_drawings(chosen);
break;
case 3: // statistics
COSD_FLAGS ^= COSD_FLAG_STATS;
config_menu_drawings(chosen);
break;
case 4: // warnings
COSD_FLAGS ^= COSD_FLAG_WARNINGS;
config_menu_drawings(chosen);
break;
case 5: // reset uptime
uptime = 0;
config_menu_doclick(chosen, menu);
break;
case 6: // re-request OSD data
config_menu_drawings(chosen);
 
while (inmenu) {
if (s2_pressed()) {
write_ascii_string(3, chosen + 5, " ");
chosen = (chosen + 1) % 9;
write_ascii_string(3, chosen + 5, ">");
_delay_ms(500);
} else if (s1_pressed()) {
switch (chosen) {
case 0: // full HUD
COSD_FLAGS ^= COSD_FLAG_HUD;
config_menu_drawings(chosen);
break;
case 1: // art horizon
COSD_FLAGS ^= COSD_FLAG_ARTHORIZON;
config_menu_drawings(chosen);
break;
case 2: // big vario
COSD_FLAGS ^= COSD_FLAG_BIGVARIO;
config_menu_drawings(chosen);
break;
case 3: // statistics
COSD_FLAGS ^= COSD_FLAG_STATS;
config_menu_drawings(chosen);
break;
case 4: // warnings
COSD_FLAGS ^= COSD_FLAG_WARNINGS;
config_menu_drawings(chosen);
break;
case 5: // reset uptime
uptime = 0;
config_menu_doclick(chosen, menu);
break;
case 6: // re-request OSD data
#if FCONLY
// request data ever 100ms from FC;
usart1_request_mk_data(0, 'd', 100);
// request data ever 100ms from FC;
usart1_request_mk_data(0, 'd', 100);
#else
// request OSD Data from NC every 100ms
usart1_request_mk_data(1, 'o', 100);
// request OSD Data from NC every 100ms
usart1_request_mk_data(1, 'o', 100);
 
// and disable debug...
usart1_request_mk_data(0, 'd', 0);
// and disable debug...
usart1_request_mk_data(0, 'd', 0);
#endif
config_menu_doclick(chosen, menu);
break;
case 7: // disable debug data
// disable sending of debug data
// may result in smoother ddata display
usart1_request_mk_data(0, 'd', 0);
config_menu_doclick(chosen, menu);
break;
case 8: // exit
inmenu = 0;
break;
}
_delay_ms(250);
}
}
config_menu_doclick(chosen, menu);
break;
case 7: // disable debug data
// disable sending of debug data
// may result in smoother ddata display
usart1_request_mk_data(0, 'd', 0);
config_menu_doclick(chosen, menu);
break;
case 8: // exit
inmenu = 0;
break;
}
_delay_ms(250);
}
}
 
// clear screen up again
clear();
// clear screen up again
clear();
 
// update flags to paint display again if needed
COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
// update flags to paint display again if needed
COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
 
// enable interrupts again
sei();
// enable interrupts again
sei();
}
 
/**
* auto config some stuff on startup, currently only battery cells
* TODO: this is testing stuff, strings should go progmem and so on...
*/
void auto_config(uint8_t UBat, uint8_t* min_UBat) {
clear();
// fix for min_bat glitch caused by data only gathered during motors up
*min_UBat = UBat;
write_ascii_string(2, 2, "C-OSD Initialisation");
#if FCONLY
write_ascii_string(2, 3, "FC only Mode");
#else
write_ascii_string(2, 3, "NaviCtrl Mode");
#endif
uint8_t cellnum = 0;
if (CELL_NUM == -1) {
write_ascii_string(2, 5, "Guessing Number of Cells");
do {
cellnum++;
} while (UBat > ((cellnum * CELL_VOLT_MAX) + 10));
} else {
cellnum = CELL_NUM;
}
min_voltage = cellnum * CELL_VOLT_MIN;
max_voltage = cellnum * CELL_VOLT_MAX;
write_ascii_string(2, 7, "Number of Cells:");
write_ndigit_number_u(21, 7, cellnum, 1, 0);
write_ascii_string(2, 8, "Warn Voltage :");
write_ndigit_number_s_10th(20, 8, min_voltage, 100, 0);
write_ascii_string(2, 9, "Max Voltage :");
write_ndigit_number_s_10th(20, 9, max_voltage, 100, 0);
_delay_ms(200);
clear();
// update flags to paint display again because of clear
COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
}
 
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
 
/* ##########################################################################
* MAIN
* ##########################################################################*/
304,8 → 344,8
COSD_FLAGS = (NTSC << 0);
COSD_FLAGS |= (HUD << 1);
COSD_FLAGS |= (ARTHORIZON << 2);
COSD_FLAGS |= (BIGVARIO << 3);
COSD_FLAGS |= (STATS << 4);
COSD_FLAGS |= (BIGVARIO << 3);
COSD_FLAGS |= (STATS << 4);
COSD_FLAGS |= (WARNINGS << 5);
 
// set up Atmega162 Ports
354,10 → 394,9
#if (WRITECHARS != -1)
// DISABLE display (VM0)
spi_send_byte(0x00, 0b00000000);
#include "characters.c"
#include "characters.c"
#endif
 
#endif
 
// Setup Video Mode
if (COSD_FLAGS & COSD_FLAG_NTSC) {
// NTSC + enable display immediately (VM0)
400,22 → 439,21
LED3_ON
 
#if ALLCHARSDEBUG | (WRITECHARS != -1)
clear();
clear();
write_all_chars();
#else
// clear serial screen
//usart1_puts("\x1B[2J\x1B[H");
//usart1_puts("hello world!\r\n");
 
// clear serial screen
//usart1_puts("\x1B[2J\x1B[H");
//usart1_puts("hello world!\r\n");
#if FCONLY
// request data ever 100ms from FC;
usart1_request_mk_data(0, 'd', 100);
// request data ever 100ms from FC;
usart1_request_mk_data(0, 'd', 100);
#else
// request OSD Data from NC every 100ms
usart1_request_mk_data(1, 'o', 100);
// request OSD Data from NC every 100ms
usart1_request_mk_data(1, 'o', 100);
 
// and disable debug...
usart1_request_mk_data(0, 'd', 0);
usart1_request_mk_data(0, 'd', 0);
#endif
 
// stats for after flight
435,20 → 473,20
// write icons at init or after menu/mode-switch
if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && (COSD_FLAGS & COSD_FLAG_HUD)) {
#if FCONLY
// FC Mode ICONS
write_char_xy(10, top_line, 0xCA); // RC-transmitter
write_char_xy(27, top_line, 0xCC); // small meters m height
write_char_xy(7, bottom_line, 0x9E); // small v
// FC Mode ICONS
write_char_xy(10, top_line, 0xCA); // RC-transmitter
write_char_xy(27, top_line, 0xCC); // small meters m height
write_char_xy(7, bottom_line, 0x9E); // small v
#else
// NAVI Mode ICONS
// NAVI Mode ICONS
write_char_xy(5, top_line, 0xCB); // km/h
write_char_xy(10, top_line, 0xCA); // RC-transmitter
write_char_xy(16, top_line, 0xD0); // degree symbol
write_char_xy(27, top_line, 0xCC); // small meters m height
write_char_xy(20, top_line+1, 0xB0); // left circle
write_char_xy(22, top_line+1, 0xB2); // right circle
write_char_xy(27, top_line+1, 0xCC); // small meters m home
write_char_xy(7, bottom_line, 0x9E); // small v
write_char_xy(20, top_line + 1, 0xB0); // left circle
write_char_xy(22, top_line + 1, 0xB2); // right circle
write_char_xy(27, top_line + 1, 0xCC); // small meters m home
write_char_xy(7, bottom_line, 0x9E); // small v
write_char_xy(14, bottom_line, 0xD1); // on clock
write_char_xy(21, bottom_line, 0xD2); // fly clock
write_char_xy(26, bottom_line, 0xC8); // sat1
462,29 → 500,37
if (rxd_buffer[2] == 'D') { // FC Data
Decode64();
debugData = *((DebugOut_t*) pRxData);
write_ascii_string(2, 2, "FCONLY MODE");
 
write_ndigit_number_u(7, top_line, debugData.Analog[10], 100, 0);
if (debugData.Analog[10] <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) {
for (uint8_t x = 0; x < 4; x++)
write_char_att_xy(7 + x, top_line, BLINK);
} else if (debugData.Analog[10] > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) {
for (uint8_t x = 0; x < 4; x++)
write_char_att_xy(7 + x, top_line, 0);
}
last_RC_Quality = debugData.Analog[10];
// init on first data retrival, distinguished by last battery :)
if (last_UBat == 255) {
auto_config(debugData.Analog[9], &min_UBat);
}
 
write_ndigit_number_u(7, top_line, debugData.Analog[10], 100, 0);
if (debugData.Analog[10] <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) {
for (uint8_t x = 0; x < 4; x++)
write_char_att_xy(7 + x, top_line, BLINK);
} else if (debugData.Analog[10] > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) {
for (uint8_t x = 0; x < 4; x++)
write_char_att_xy(7 + x, top_line, 0);
}
last_RC_Quality = debugData.Analog[10];
 
if (debugData.Analog[5] > 300 || debugData.Analog[5] < -300) {
// above 10m only write full meters
write_ndigit_number_s(23, top_line, debugData.Analog[5] / 30, 1000, 0);
} else {
// up to 10m write meters.dm
write_ndigit_number_s_10th(23, top_line, debugData.Analog[5] / 3, 100, 0);
}
 
draw_battery(2, bottom_line, min_voltage, debugData.Analog[9], max_voltage);
write_ndigit_number_u_10th(3, bottom_line, debugData.Analog[9], 100, 0);
if (debugData.Analog[5] > 300 || debugData.Analog[5] < -300) {
// above 10m only write full meters
write_ndigit_number_s(23, top_line, debugData.Analog[5] / 30, 1000, 0);
} else {
// up to 10m write meters.dm
write_ndigit_number_s_10th(23, top_line, debugData.Analog[5] / 3, 100, 0);
}
 
if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) {
draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll);
}
 
draw_battery(2, bottom_line, min_voltage, debugData.Analog[9], max_voltage);
write_ndigit_number_u_10th(3, bottom_line, debugData.Analog[9], 100, 0);
if (debugData.Analog[9] <= min_voltage && last_UBat > min_voltage) {
for (uint8_t x = 2; x < 8; x++)
write_char_att_xy(x, bottom_line, BLINK);
492,56 → 538,31
for (uint8_t x = 2; x < 8; x++)
write_char_att_xy(x, bottom_line, 0);
}
// remember last values
last_UBat = debugData.Analog[9];
// remember last values
last_UBat = debugData.Analog[9];
 
/*
debugData.Analog[0]); // AngleNick
debugData.Analog[0]); // AngleNick
debugData.Analog[1]); // AngleRoll
debugData.Analog[5]); // Height
debugData.Analog[5]); // Height
debugData.Analog[9]); // Voltage
debugData.Analog[10]);// RC Signal
debugData.Analog[11]);// Gyro compass
*/
seconds_since_last_data = 0;
debugData.Analog[11]);// Gyro compass
*/
seconds_since_last_data = 0;
}
#else
if (rxd_buffer[2] == 'O') { // NC OSD Data
if (rxd_buffer[2] == 'O') { // NC OSD Data
Decode64();
naviData = *((NaviData_t*) pRxData);
// init on first data retrival, distinguished by last battery :)
// TODO: this is testing stuff, strings should go progmem and so on...
if (last_UBat == 255) {
clear();
// fix for min_bat glitch caused by data only gathered during motors up
min_UBat = naviData.UBat;
write_ascii_string(2, 2, "C-OSD Initialisation");
uint8_t cellnum = 0;
if (CELL_NUM == -1) {
write_ascii_string(2, 5, "Guessing Number of Cells");
do {
cellnum++;
} while (naviData.UBat > ((cellnum * CELL_VOLT_MAX) + 10));
} else {
cellnum = CELL_NUM;
}
min_voltage = cellnum * CELL_VOLT_MIN;
max_voltage = cellnum * CELL_VOLT_MAX;
write_ascii_string(2, 7, "Number of Cells:");
write_ndigit_number_u(21, 7, cellnum, 1, 0);
write_ascii_string(2, 8, "Warn Voltage :");
write_ndigit_number_s_10th(20, 8, min_voltage, 100, 0);
write_ascii_string(2, 9, "Max Voltage :");
write_ndigit_number_s_10th(20, 9, max_voltage, 100, 0);
_delay_ms(200);
clear();
// update flags to paint display again because of clear
COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
}
 
// init on first data retrival, distinguished by last battery :)
if (last_UBat == 255) {
auto_config(naviData.UBat, &min_UBat);
}
 
// first line
write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t)9) / (uint32_t)250), 100, 0);
write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 100, 0);
 
write_ndigit_number_u(7, top_line, naviData.RC_Quality, 100, 0);
if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) {
551,20 → 572,20
for (uint8_t x = 0; x < 4; x++)
write_char_att_xy(7 + x, top_line, 0);
}
last_RC_Quality = naviData.RC_Quality;
if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) {
write_char_xy(11, top_line, 0); // clear
} else {
write_char_xy(11, top_line, 0xC6); // PC icon
}
last_RC_Quality = naviData.RC_Quality;
 
if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) {
write_char_xy(11, top_line, 0); // clear
} else {
write_char_xy(11, top_line, 0xC6); // PC icon
}
 
write_ndigit_number_u(13, top_line, naviData.CompassHeading, 100, 0);
 
write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]);
draw_variometer(21, top_line, naviData.Variometer);
 
draw_variometer(21, top_line, naviData.Variometer);
 
//note:lephisto:according to several sources it's /30
if (naviData.Altimeter > 300 || naviData.Altimeter < -300) {
// above 10m only write full meters
572,7 → 593,7
} else {
// up to 10m write meters.dm
//write_number_u_10th(21, top_line, naviData.Altimeter / 3);
write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 100, 0);
write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 100, 0);
}
 
// seccond line
581,8 → 602,8
// TODO: verify correctness
uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360;
//write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]);
// finer resolution, 0xa0 is first character and we add the index 0 <= index < 16
write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home));
// finer resolution, 0xa0 is first character and we add the index 0 <= index < 16
write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home));
 
write_ndigit_number_u(24, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 100, 0);
 
596,41 → 617,41
if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) {
draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll);
}
// motors are on, assume we were/are flying
COSD_FLAGS |= COSD_WASFLYING;
// motors are on, assume we were/are flying
COSD_FLAGS |= COSD_WASFLYING;
} else {
// stats
if ((COSD_FLAGS & COSD_WASFLYING) && (COSD_FLAGS & COSD_FLAG_STATS)) {
write_ascii_string_pgm(2, 4, stats_item_pointers[0]); // max Altitude
write_ndigit_number_s(18, 4, max_Altimeter / 30, 1000, 0);
write_char_xy(22, 4, 204); // small meters m
write_ascii_string_pgm(2, 5, stats_item_pointers[1]); // max Speed
write_ndigit_number_u(19, 5, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t)9) / (uint32_t)250), 100, 0);
write_char_xy(22, 5, 203); // km/h
write_ascii_string_pgm(2, 6, stats_item_pointers[2]); // max Distance
write_ndigit_number_u(19, 6, max_Distance / 10, 100, 0);
write_char_xy(22, 6, 204); // small meters m
write_ascii_string_pgm(2, 7, stats_item_pointers[3]); // min voltage
write_ndigit_number_u_10th(18, 7, min_UBat, 100, 0);
write_char_xy(22, 7, 0x9E); // small v
write_ascii_string_pgm(2, 8, stats_item_pointers[4]); // max time
write_time(16, 8, max_FlyingTime);
write_char_xy(22, 8, 210); // fly clock
write_ascii_string_pgm(2, 9, stats_item_pointers[5]); // longitude
write_gps_pos(15, 9, naviData.CurrentPosition.Longitude);
write_ascii_string_pgm(2, 10, stats_item_pointers[6]); // latitude
write_gps_pos(15, 10, naviData.CurrentPosition.Latitude);
} else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon
// stats
if ((COSD_FLAGS & COSD_WASFLYING) && (COSD_FLAGS & COSD_FLAG_STATS)) {
write_ascii_string_pgm(2, 4, stats_item_pointers[0]); // max Altitude
write_ndigit_number_s(18, 4, max_Altimeter / 30, 1000, 0);
write_char_xy(22, 4, 204); // small meters m
write_ascii_string_pgm(2, 5, stats_item_pointers[1]); // max Speed
write_ndigit_number_u(19, 5, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 100, 0);
write_char_xy(22, 5, 203); // km/h
write_ascii_string_pgm(2, 6, stats_item_pointers[2]); // max Distance
write_ndigit_number_u(19, 6, max_Distance / 10, 100, 0);
write_char_xy(22, 6, 204); // small meters m
write_ascii_string_pgm(2, 7, stats_item_pointers[3]); // min voltage
write_ndigit_number_u_10th(18, 7, min_UBat, 100, 0);
write_char_xy(22, 7, 0x9E); // small v
write_ascii_string_pgm(2, 8, stats_item_pointers[4]); // max time
write_time(16, 8, max_FlyingTime);
write_char_xy(22, 8, 210); // fly clock
write_ascii_string_pgm(2, 9, stats_item_pointers[5]); // longitude
write_gps_pos(15, 9, naviData.CurrentPosition.Longitude);
write_ascii_string_pgm(2, 10, stats_item_pointers[6]); // latitude
write_gps_pos(15, 10, naviData.CurrentPosition.Latitude);
} else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon
draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll);
}
}
if (COSD_FLAGS & COSD_FLAG_BIGVARIO) {
draw_big_variometer(27, 8, naviData.Variometer);
}
if (COSD_FLAGS & COSD_FLAG_BIGVARIO) {
draw_big_variometer(27, 8, naviData.Variometer);
}
 
// bottom line
draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage);
write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 100, 0);
draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage);
write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 100, 0);
if (naviData.UBat <= min_voltage && last_UBat > min_voltage) {
for (uint8_t x = 2; x < 8; x++)
write_char_att_xy(x, bottom_line, BLINK);
638,8 → 659,8
for (uint8_t x = 2; x < 8; x++)
write_char_att_xy(x, bottom_line, 0);
}
// remember last values
last_UBat = naviData.UBat;
// remember last values
last_UBat = naviData.UBat;
 
write_time(8, bottom_line, uptime);
write_time(15, bottom_line, naviData.FlyingTime);
646,7 → 667,7
 
write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 10, 0);
 
if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) {
if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) {
write_char_xy(23, bottom_line, 0xB3); // rc transmitter
} else {
write_char_xy(23, bottom_line, 0); // clear
664,18 → 685,18
//write_number_s(16, 5, setsReceived++);
 
// remember statistics (only when engines running)
if (naviData.MKFlags & FLAG_MOTOR_RUN) {
if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter;
if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed;
if (naviData.HomePositionDeviation.Distance > max_Distance) {
max_Distance = naviData.HomePositionDeviation.Distance;
}
if (naviData.UBat < min_UBat) min_UBat = naviData.UBat;
if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime;
}
if (naviData.MKFlags & FLAG_MOTOR_RUN) {
if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter;
if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed;
if (naviData.HomePositionDeviation.Distance > max_Distance) {
max_Distance = naviData.HomePositionDeviation.Distance;
}
if (naviData.UBat < min_UBat) min_UBat = naviData.UBat;
if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime;
}
 
old_MKFlags = naviData.MKFlags;
seconds_since_last_data = 0;
seconds_since_last_data = 0;
}
#endif
}
687,14 → 708,14
}
if (seconds_since_last_data > 2) {
#if FCONLY
// request data ever 100ms from FC;
usart1_request_mk_data(0, 'd', 100);
// request data ever 100ms from FC;
usart1_request_mk_data(0, 'd', 100);
#else
// request OSD Data from NC every 100ms
usart1_request_mk_data(1, 'o', 100);
// request OSD Data from NC every 100ms
usart1_request_mk_data(1, 'o', 100);
 
// and disable debug...
usart1_request_mk_data(0, 'd', 0);
// and disable debug...
usart1_request_mk_data(0, 'd', 0);
#endif
}
}