Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 339 → Rev 336

/C-OSD/trunk/main.c
47,14 → 47,13
#endif
 
#ifndef NTSC // if NTSC is not thet via makefile
#define NTSC 1 // set to 1 for NTSC mode + lifts the bottom line
#define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line
#endif
 
#define HUD 1 // set to 0 to disable HUD by default
#define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon by default
#define STATS 1 // set to 1 to enable statistics during motor off by default
#define WARNINGS 1 // set to 1 to display battery+rc warning even if HUD is disabled
 
#define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon
#define NOOSD 0 // set to 1 to disable OSD completely
#define NOOSD_BUT_WRN 0 // set to 1 to disable OSD completely but show
// battery and receive signal warnings
#define UBAT_WRN 94 // voltage for blinking warning, like FC settings
#define RCLVL_WRN 100 // make the RC level blink if below this number
 
65,11 → 64,10
* FLAGS usable during runtime
* ##########################################################################*/
#define COSD_FLAG_NTSC 1
#define COSD_FLAG_HUD 2
#define COSD_FLAG_ARTHORIZON 4
#define COSD_FLAG_STATS 8
#define COSD_FLAG_WARNINGS 16
#define COSD_ICONS_WRITTEN 32
#define COSD_FLAG_ARTHORIZON 2
#define COSD_FLAG_NOOSD 4
#define COSD_FLAG_NOOSD_BUT_WRN 8
#define COSD_ICONS_WRITTEN 16
 
/* ##########################################################################
* LED controll
294,40 → 292,6
/* ##########################################################################
* A simple config menu for the flags
* ##########################################################################*/
 
/**
* helper function for menu updating
*/
void config_menu_drawings(uint8_t chosen) {
// clear prevoius _cursor_
write_ascii_string(3, (chosen + 4) % 5, " ");
// draw current _cursor_
write_ascii_string(3, chosen + 6, ">");
if (COSD_FLAGS & COSD_FLAG_HUD) {
write_ascii_string(23, 6, "ON ");
} else {
write_ascii_string(23, 6, "OFF");
}
if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) {
write_ascii_string(23, 7, "ON ");
} else {
write_ascii_string(23, 7, "OFF");
}
if (COSD_FLAGS & COSD_FLAG_STATS) {
write_ascii_string(23, 8, "ON ");
} else {
write_ascii_string(23, 8, "OFF");
}
if (COSD_FLAGS & COSD_FLAG_WARNINGS) {
write_ascii_string(23, 9, "ON ");
} else {
write_ascii_string(23, 9, "OFF");
}
}
 
/**
* a simple config menu tryout
*/
void config_menu(void) {
// disable interrupts (makes the menu more smoothely)
cli();
335,58 → 299,44
// clear screen
clear();
char* menu[5] = {"Full HUD",
"Art.Horizon in HUD",
"Statistics",
"Warnings", // TODO: do it!
"EXIT"};
char* menu[4] = {"Normal OSD ",
"Art.Horizon ",
"NO OSD ",
"NO OSD but WRN "};
 
uint8_t inmenu = 1;
uint8_t chosen = 0;
write_ascii_string(6, 2, "C-OSD Config Menu");
write_ascii_string(10, 4, "Config Menu");
 
// clear all mode flags
COSD_FLAGS &= ~(COSD_FLAG_ARTHORIZON | COSD_FLAG_NOOSD | COSD_FLAG_NOOSD_BUT_WRN);
 
// wait a bit before doing stuff so user has chance to release button
_delay_ms(250);
 
write_ascii_string(4, 6, menu[0]);
write_ascii_string(4, 7, menu[1]);
write_ascii_string(4, 8, menu[2]);
write_ascii_string(4, 9, menu[3]);
write_ascii_string(4, 10, menu[4]);
 
config_menu_drawings(chosen);
 
while (inmenu) {
write_ascii_string(2, 7, menu[chosen]);
if (s2_pressed()) {
write_ascii_string(3, chosen+6, " ");
chosen = (chosen + 1) % 5;
write_ascii_string(3, chosen+6, ">");
chosen = (chosen + 1) % 4;
_delay_ms(500);
} else if (s1_pressed()) {
switch (chosen) {
case 0: // full HUD
COSD_FLAGS ^= COSD_FLAG_HUD;
config_menu_drawings(chosen);
case 1: // artificial horizon
COSD_FLAGS |= COSD_FLAG_ARTHORIZON;
break;
case 1: // art horizon
COSD_FLAGS ^= COSD_FLAG_ARTHORIZON;
config_menu_drawings(chosen);
case 2: // everything off
COSD_FLAGS |= COSD_FLAG_NOOSD;
break;
case 2: // statistics
COSD_FLAGS ^= COSD_FLAG_STATS;
config_menu_drawings(chosen);
case 3: // only warning
COSD_FLAGS |= COSD_FLAG_NOOSD_BUT_WRN;
break;
case 3: // warnings
COSD_FLAGS ^= COSD_FLAG_WARNINGS;
config_menu_drawings(chosen);
break;
case 4: // exit
//default: // normal OSD, so let the flags cleared
}
// leave menu
inmenu = 0;
break;
_delay_ms(500);
}
_delay_ms(250);
}
}
 
// clear screen up again
clear();
399,16 → 349,16
}
 
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
 
/* ##########################################################################
* MAIN
* ##########################################################################*/
int main(void) {
// set up FLAGS, compiler should flatten this one
COSD_FLAGS = (NTSC << 0);
COSD_FLAGS |= (HUD << 1);
COSD_FLAGS |= (ARTHORIZON << 2);
COSD_FLAGS |= (STATS << 3);
COSD_FLAGS |= (WARNINGS << 4);
COSD_FLAGS = (NTSC << (COSD_FLAG_NTSC - 1));
COSD_FLAGS |= (ARTHORIZON << (COSD_FLAG_ARTHORIZON - 1));
COSD_FLAGS |= (NOOSD << (COSD_FLAG_NOOSD - 1));
COSD_FLAGS |= (NOOSD_BUT_WRN << (COSD_FLAG_NOOSD_BUT_WRN - 1));
 
// set up Atmega162 Ports
DDRA |= (1 << PA1); // PA1 output (/CS)
445,6 → 395,12
MAX_RESET_LOW
MAX_RESET_HIGH
 
// check for keypress at startup
if (s2_pressed()) { // togle COSD_FLAG_ARTHORIZON
COSD_FLAGS ^= (1 << (COSD_FLAG_ARTHORIZON - 1));
_delay_ms(100);
}
 
// give the FC/NC and the maxim time to come up
LED4_ON
_delay_ms(2000);
456,8 → 412,8
#if (WRITECHARS != -1)
// DISABLE display (VM0)
spi_send_byte(0x00, 0b00000000);
 
#include "characters.c"
 
#endif
 
// Setup Video Mode
559,7 → 515,7
 
while (1) {
// write icons at init or after menu/mode-switch
if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && (COSD_FLAGS & COSD_FLAG_HUD)) {
if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && !(COSD_FLAGS & COSD_FLAG_NOOSD)) {
write_char_xy(5, top_line, 203); // km/h
write_char_xy(10, top_line, 202); // RC-transmitter
write_char_xy(16, top_line, 208); // degree symbol
572,7 → 528,7
COSD_FLAGS |= COSD_ICONS_WRITTEN;
}
if (rxd_buffer_locked) {
if (COSD_FLAGS & COSD_FLAG_HUD) {
if (!(COSD_FLAGS & COSD_FLAG_NOOSD)) {
if (rxd_buffer[2] == 'D') { // FC Data
/*Decode64();
debugData = *((DebugOut_t*) pRxData);
617,7 → 573,9
write_char_xy(20, top_line, 233); //big arrow down
}
 
// TODO: is this really dm?
//note:lephisto:according to several sources it's /30
//write_number_s(22, top_line, naviData.Altimeter/30);
if (naviData.Altimeter > 300) {
// above 10m only write full meters
write_number_s(22, top_line, naviData.Altimeter / 30);
633,6 → 591,7
uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360;
write_char_xy(27, top_line + 1, arrowdir[heading_conv(heading_home)]);
 
write_number_s(22, top_line + 1, naviData.HomePositionDeviation.Distance / 100);
 
// center
647,7 → 606,6
}
} else {
// stats
if (COSD_FLAGS & COSD_FLAG_STATS) {
write_ascii_string(2, 5, "max Altitude:");
write_number_s(17, 5, max_Altimeter / 30);
write_char_xy(22, 5, 204); // small meters m
658,15 → 616,13
write_number_s(17, 7, max_Distance / 100);
write_char_xy(22, 7, 204); // small meters m
write_ascii_string(2, 8, "min voltage :");
//write_number_s(17, 8, min_UBat/10);
write_number_u_10th(16, 8, min_UBat);
write_ascii_string(22, 8, "V"); // voltage
write_ascii_string(2, 9, "max time :");
write_time(16, 9, max_FlyingTime);
write_char_xy(22, 9, 210); // fly clock
} 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);
}
}
 
// bottom line
write_number_u_10th(0, bottom_line, naviData.UBat);
704,8 → 660,8
if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime;
 
old_MKFlags = naviData.MKFlags;
} // (!(COSD_FLAGS & COSD_FLAG_NOOSD))
}
}
seconds_since_last_data = 0;
rxd_buffer_locked = 0;
}