Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 761 → Rev 760

/C-OSD/trunk/main.c
108,45 → 108,44
stats_item_3, stats_item_4, stats_item_5, stats_item_6, stats_item_7};
 
//char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "};
//char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219};
//char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219};
const char str_NE[] PROGMEM = "NE";
const char str_E[] PROGMEM = "E ";
const char str_E[] PROGMEM = "E ";
const char str_SE[] PROGMEM = "SE";
const char str_S[] PROGMEM = "S ";
const char str_S[] PROGMEM = "S ";
const char str_SW[] PROGMEM = "SW";
const char str_W[] PROGMEM = "W ";
const char str_W[] PROGMEM = "W ";
const char str_NW[] PROGMEM = "NW";
const char str_N[] PROGMEM = "N ";
const char str_N[] PROGMEM = "N ";
const char *directions[8] PROGMEM = {
str_NE,
str_E,
str_SE,
str_S,
str_SW,
str_W,
str_NW,
str_N
};
str_NE,
str_E,
str_SE,
str_S,
str_SW,
str_W,
str_NW,
str_N};
 
/* ##########################################################################
* Different display mode function pointers
* ##########################################################################*/
const char str_1[] PROGMEM = "default";
const char str_2[] PROGMEM = "minimal";
const char str_3[] PROGMEM = " jopl";
const char str_1[] PROGMEM = "default";
const char str_2[] PROGMEM = "minimal";
const char str_3[] PROGMEM = " jopl";
 
const displaymode_t ncdisplaymodes[] PROGMEM = {
{ osd_ncmode_default, (char *)str_1},
{ osd_ncmode_minimal, (char *)str_2}
{ osd_ncmode_default, (char *)str_1 },
{ osd_ncmode_minimal, (char *)str_2 }
};
 
const displaymode_t fcdisplaymodes[] PROGMEM = {
{ osd_fcmode_default, (char *)str_1},
{ osd_fcmode_jopl, (char *)str_3}
{ osd_fcmode_default, (char *)str_1 },
{ osd_fcmode_jopl, (char *)str_3 }
};
 
int (*osd_ncmode)(void) = (int(*)(void)) & osd_ncmode_default;
int (*osd_fcmode)(void) = (int(*)(void)) & osd_fcmode_default;
int (*osd_ncmode)(void) = (int(*)(void)) &osd_ncmode_default;
int (*osd_fcmode)(void) = (int(*)(void)) &osd_fcmode_default;
#endif
 
/* ##########################################################################
175,22 → 174,22
if (!timer--) {
uptime++;
 
#if FCONLY
if (debugData.Analog[12] > 10) {
flytime_fc++;
}
#endif
#if FCONLY
if (debugData.Analog[12]>10) {
flytime_fc++;
}
#endif
 
timer = 999;
seconds_since_last_data++;
}
// in case there is still some spi data to send do it now
// delay to give the slave some time to compute values
// delay to give the slave some time to compute values
if (spi_ready && icnt) {
if (!delay_spi--) {
delay_spi = 8;
spi_send_next();
}
if (!delay_spi--) {
delay_spi = 8;
spi_send_next();
}
}
}
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
199,29 → 198,29
* MAIN
* ##########################################################################*/
int main(void) {
// set up FLAGS
COSD_FLAGS_MODES = 0, COSD_FLAGS_CONFIG = 0, COSD_FLAGS_RUNTIME = 0;
#if NTSC
COSD_FLAGS_CONFIG |= COSD_FLAG_NTSC;
#endif
#if HUD
COSD_FLAGS_MODES |= COSD_FLAG_HUD;
#endif
#if ARTHORIZON
COSD_FLAGS_MODES |= COSD_FLAG_ARTHORIZON;
#endif
#if BIGVARIO
COSD_FLAGS_MODES |= COSD_FLAG_BIGARIO;
#endif
#if STATS
COSD_FLAGS_MODES |= COSD_FLAG_STATS;
#endif
#if WARNINGS
COSD_FLAGS_MODES |= COSD_FLAG_WARNINGS;
#endif
#if FCONLY
COSD_FLAGS_CONFIG |= COSD_FLAG_FCMODE;
#endif
// set up FLAGS
COSD_FLAGS_MODES = 0, COSD_FLAGS_CONFIG = 0, COSD_FLAGS_RUNTIME = 0;
#if NTSC
COSD_FLAGS_CONFIG |= COSD_FLAG_NTSC;
#endif
#if HUD
COSD_FLAGS_MODES |= COSD_FLAG_HUD;
#endif
#if ARTHORIZON
COSD_FLAGS_MODES |= COSD_FLAG_ARTHORIZON;
#endif
#if BIGVARIO
COSD_FLAGS_MODES |= COSD_FLAG_BIGARIO;
#endif
#if STATS
COSD_FLAGS_MODES |= COSD_FLAG_STATS;
#endif
#if WARNINGS
COSD_FLAGS_MODES |= COSD_FLAG_WARNINGS;
#endif
#if FCONLY
COSD_FLAGS_CONFIG |= COSD_FLAG_FCMODE;
#endif
 
 
// set up Atmega162 Ports
259,26 → 258,26
 
//Pushing NEW chars to the MAX7456
#if (WRITECHARS != -1)
// DISABLE display (VM0)
spi_send_byte(0x00, 0b00000000);
learn_all_chars_pgm();
// DISABLE display (VM0)
spi_send_byte(0x00, 0b00000000);
learn_all_chars_pgm();
#else
// read out config for NTSC/PAL distinguishing
get_eeprom(0);
// read out config for NTSC/PAL distinguishing
get_eeprom(0);
#endif
 
// Setup Video Mode
if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
// NTSC + enable display immediately (VM0)
spi_send_byte(0x00, 0b00001000);
// Setup Video Mode
if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
// NTSC + enable display immediately (VM0)
spi_send_byte(0x00, 0b00001000);
 
bottom_line = 12;
} else {
// PAL + enable display immediately (VM0)
spi_send_byte(0x00, 0b01001000);
bottom_line = 12;
} else {
// PAL + enable display immediately (VM0)
spi_send_byte(0x00, 0b01001000);
 
bottom_line = 14;
}
bottom_line = 14;
}
 
/*// clear all display-mem (DMM)
spi_send_byte(0x04, 0b00000100);
300,22 → 299,22
usart1_DisableTXD();
 
// set up timer
// CTC, Prescaler /64
TCCR0 = (1 << WGM01) | (0 << WGM00) | (0 << CS02) | (1 << CS01) | (1 << CS00);
// CTC, Prescaler /64
TCCR0 = (1 << WGM01) | (0 << WGM00) | (0 << CS02) | (1 << CS01) | (1 << CS00);
 
TCNT0 = 0;
OCR0 = 250;
TCNT0 = 0;
OCR0 = 250;
 
// enable timer output compare interrupt
TIMSK &= ~(1 << TOIE0);
TIMSK |= (1 << OCIE0);
// enable timer output compare interrupt
TIMSK &= ~(1 << TOIE0);
TIMSK |= (1 << OCIE0);
 
// SPI setup
// SPI setup
DDRD |= (1 << PD2); // PD2 output (INT0)
SpiMasterInit();
 
// PPM detection setup
ppm_init();
// PPM detection setup
ppm_init();
 
// enable interrupts
sei();
329,17 → 328,17
LED3_ON
 
#if ALLCHARSDEBUG | (WRITECHARS != -1)
clear();
write_all_chars();
LED1_ON
LED2_ON
LED3_ON
LED4_ON
clear();
write_all_chars();
LED1_ON
LED2_ON
LED3_ON
LED4_ON
#else
 
// clear serial screen
//usart1_puts("\x1B[2J\x1B[H");
//usart1_puts("hello world!123\r\n");
// clear serial screen
//usart1_puts("\x1B[2J\x1B[H");
//usart1_puts("hello world!123\r\n");
 
while (1) {
// in case SPI is ready and there is nothing to send right now
346,59 → 345,59
if (!icnt && spi_ready) {
// correct transfer ends with d (done)
if (SPI_buffer.buffer.chk == 'd') {
ampere = SPI_buffer.data.ampere;
ampere_wasted = SPI_buffer.data.mah;
s_volt = SPI_buffer.data.volt;
ampere = SPI_buffer.data.ampere;
ampere_wasted = SPI_buffer.data.mah;
s_volt = SPI_buffer.data.volt;
 
// if this is the first receival we should print the small A
if (!(COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC)) {
clear();
COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
// update this flag
COSD_FLAGS_RUNTIME |= COSD_FLAG_STROMREC;
}
// if this is the first receival we should print the small A
if (!(COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC)) {
clear();
COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
// update this flag
COSD_FLAGS_RUNTIME |= COSD_FLAG_STROMREC;
}
} else {
// update flags
COSD_FLAGS_RUNTIME &= ~COSD_FLAG_STROMREC;
}
StartTransfer(9);
StartTransfer(9);
}
if (rxd_buffer_locked) {
#if FCONLY
if (rxd_buffer[2] == 'D') { // FC Data
Decode64();
debugData = *((DebugOut_t*)pRxData);
debugData = *((DebugOut_t*) pRxData);
 
// init on first data retrival, distinguished by last battery :)
if (last_UBat == 255) {
if (debugData.Analog[9] > 40) {
// fix for min_UBat
min_UBat = debugData.Analog[9];
last_UBat = debugData.Analog[9];
init_cosd(last_UBat);
}
if (debugData.Analog[9] > 40) {
// fix for min_UBat
min_UBat = debugData.Analog[9];
last_UBat = debugData.Analog[9];
init_cosd(last_UBat);
}
} else {
osd_fcmode();
}
seconds_since_last_data = 0;
osd_fcmode();
}
seconds_since_last_data = 0;
}
#else
if (rxd_buffer[2] == 'O') { // NC OSD Data
Decode64();
naviData = *((NaviData_t*)pRxData);
naviData = *((NaviData_t*) pRxData);
 
// init on first data retrival, distinguished by last battery :)
if (last_UBat == 255) {
if (naviData.UBat > 40) {
// fix for min_UBat
min_UBat = naviData.UBat;
last_UBat = naviData.UBat;
init_cosd(last_UBat);
}
if (naviData.UBat > 40) {
// fix for min_UBat
min_UBat = naviData.UBat;
last_UBat = naviData.UBat;
init_cosd(last_UBat);
}
} else {
osd_ncmode();
}
//seconds_since_last_data = 0;
osd_ncmode();
}
//seconds_since_last_data = 0;
}
#endif
rxd_buffer_locked = 0;
408,23 → 407,23
config_menu();
}
if (seconds_since_last_data > 0) {
usart1_EnableTXD();
//usart1_puts_pgm(PSTR("zu alt\r\n"));
usart1_EnableTXD();
//usart1_puts_pgm(PSTR("zu alt\r\n"));
#if FCONLY
// request data ever 100ms from FC;
//usart1_request_mk_data(0, 'd', 100);
usart1_puts_pgm(PSTR(REQUEST_DBG_DATA));
usart1_puts_pgm(PSTR(REQUEST_DBG_DATA));
#else
// request OSD Data from NC every 100ms
//usart1_request_mk_data(1, 'o', 100);
usart1_puts_pgm(PSTR(REQUEST_OSD_DATA));
usart1_puts_pgm(PSTR(REQUEST_OSD_DATA));
 
// and disable debug...
//usart1_request_mk_data(0, 'd', 0);
#endif
// reset last time counter
seconds_since_last_data = 0;
usart1_DisableTXD();
// reset last time counter
seconds_since_last_data = 0;
usart1_DisableTXD();
}
}
#endif