23,7 → 23,6 |
#include <avr/pgmspace.h> |
#include <avr/interrupt.h> |
#include <util/delay.h> |
//#include <avr/delay.h> |
#include "max7456_software_spi.h" |
#include "config.h" |
#include "main.h" |
55,19 → 54,19 |
* read data saved in eeprom, print out message if <verbose> is set |
*/ |
void get_eeprom(uint8_t verbose) { |
if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) { |
#if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
if (verbose) write_ascii_string_pgm(2, 9, ee_msg[0]); // Loading data |
#endif |
COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES); |
COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG); |
COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE); |
//if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0); |
} else { |
#if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
if (verbose) write_ascii_string_pgm(2, 9, ee_msg[1]); // Loading data |
#endif |
} |
if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) { |
#if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
if (verbose) write_ascii_string_pgm(2, 9, ee_msg[0]); // Loading data |
#endif |
COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES); |
COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG); |
COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE); |
//if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0); |
} else { |
#if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
if (verbose) write_ascii_string_pgm(2, 9, ee_msg[1]); // Loading data |
#endif |
} |
} |
|
#if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
76,29 → 75,28 |
* save data to eeprom |
*/ |
void save_eeprom() { |
eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1); |
eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2); |
eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES); |
eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG); |
eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE); |
eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1); |
eeprom_write_byte(&ee_checkbyte2, CHECKBYTE2); |
eeprom_write_byte(&ee_COSD_FLAGS_MODES, COSD_FLAGS_MODES); |
eeprom_write_byte(&ee_COSD_FLAGS_CONFIG, COSD_FLAGS_CONFIG); |
eeprom_write_byte(&ee_COSD_DISPLAYMODE, COSD_DISPLAYMODE); |
} |
|
|
/** |
* auto config some stuff on startup, currently only battery cells |
*/ |
void init_cosd(uint8_t UBat) { |
clear(); |
write_ascii_string_pgm(2, 1, PSTR("C-OSD Initialisation")); // C-OSD Initialisation |
write_ascii_string_pgm(2, 1, PSTR("C-OSD Initialisation")); // C-OSD Initialisation |
#if FCONLY |
write_ascii_string_pgm(2, 2, PSTR("FC only Mode")); // FC only mode |
write_ascii_string_pgm(2, 2, PSTR("FC only Mode")); // FC only mode |
#else |
write_ascii_string_pgm(2, 2, PSTR("NaviCtrl Mode")); // NaviCtrl Mode |
write_ascii_string_pgm(2, 2, PSTR("NaviCtrl Mode")); // NaviCtrl Mode |
#endif |
write_ascii_string_pgm(2, 3, PSTR(BUILDDATE)); |
uint8_t cellnum = 0; |
if (CELL_NUM == -1) { |
write_ascii_string_pgm(2, 4, PSTR("Guessing Number of Cells")); // Guessing Number of Cells |
write_ascii_string_pgm(2, 4, PSTR("Guessing Number of Cells")); // Guessing Number of Cells |
do { |
cellnum++; |
} while (UBat > ((cellnum * CELL_VOLT_MAX) + 23)); |
107,66 → 105,66 |
} |
min_voltage = cellnum * CELL_VOLT_MIN; |
max_voltage = cellnum * CELL_VOLT_MAX; |
write_ascii_string_pgm(2, 5, PSTR("Number of Cells:")); // Number of Cells |
write_ascii_string_pgm(2, 5, PSTR("Number of Cells:")); // Number of Cells |
write_ndigit_number_u(21, 5, cellnum, 1, 0); |
write_ascii_string_pgm(2, 6, PSTR("Warn Voltage :")); // Warn Voltage |
write_ascii_string_pgm(2, 6, PSTR("Warn Voltage :")); // Warn Voltage |
write_ndigit_number_s_10th(20, 6, min_voltage, 3, 0); |
write_ascii_string_pgm(2, 7, PSTR("Max Voltage :")); // Max Voltage |
write_ascii_string_pgm(2, 7, PSTR("Max Voltage :")); // Max Voltage |
write_ndigit_number_s_10th(20, 7, max_voltage, 3, 0); |
|
get_eeprom(1); |
get_eeprom(1); |
|
//write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]); |
if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
write_ascii_string_pgm(23, 2, VM_NTSC); |
} else { |
write_ascii_string_pgm(23, 2, VM_PAL); |
} |
if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
write_ascii_string_pgm(23, 2, VM_NTSC); |
} else { |
write_ascii_string_pgm(23, 2, VM_PAL); |
} |
|
// request version from board |
rxd_buffer_locked = 0; |
usart1_EnableTXD(); |
#if FCONLY |
//usart1_request_mk_data(0, 'v', 0); |
write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........")); |
usart1_puts_pgm(PSTR(REQUEST_FC_VERSION)); |
#else |
//usart1_request_mk_data(1, 'v', 0); |
usart1_puts_pgm(PSTR(REQUEST_NC_VERSION)); |
write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........")); |
#endif |
usart1_DisableTXD(); |
// wait for response |
while (rxd_buffer_locked == 0) { |
asm("nop"); |
} |
Decode64(); |
str_VersionInfo VersionInfo; |
VersionInfo = *((str_VersionInfo*) pRxData); |
|
write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1); |
write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1); |
write_ascii_char(22 + 11*30, 'a' + VersionInfo.SWPatch); |
// end version request |
// request version from board |
rxd_buffer_locked = 0; |
usart1_EnableTXD(); |
#if FCONLY |
//usart1_request_mk_data(0, 'v', 0); |
write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........")); |
usart1_puts_pgm(PSTR(REQUEST_FC_VERSION)); |
#else |
//usart1_request_mk_data(1, 'v', 0); |
usart1_puts_pgm(PSTR(REQUEST_NC_VERSION)); |
write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........")); |
#endif |
usart1_DisableTXD(); |
// wait for response |
while (rxd_buffer_locked == 0) { |
asm("nop"); |
} |
Decode64(); |
str_VersionInfo VersionInfo; |
VersionInfo = *((str_VersionInfo*)pRxData); |
|
write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1); |
write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1); |
write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch); |
// end version request |
|
#if FCONLY |
COSD_DISPLAYMODE %= (sizeof(fcdisplaymodes) / sizeof(displaymode_t)); |
mode = fcdisplaymodes; |
mode += COSD_DISPLAYMODE; |
osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
// re-request data ever 100ms from FC; |
//usart1_request_mk_data(0, 'd', 100); |
#else |
COSD_DISPLAYMODE %= (sizeof(ncdisplaymodes) / sizeof(displaymode_t)); |
mode = ncdisplaymodes; |
mode += COSD_DISPLAYMODE; |
osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
// re-request OSD Data from NC every 100ms |
//usart1_request_mk_data(1, 'o', 100); |
#endif |
|
_delay_ms(3000); |
#if FCONLY |
COSD_DISPLAYMODE %= (sizeof (fcdisplaymodes) / sizeof (displaymode_t)); |
mode = fcdisplaymodes; |
mode += COSD_DISPLAYMODE; |
osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
// re-request data ever 100ms from FC; |
//usart1_request_mk_data(0, 'd', 100); |
#else |
COSD_DISPLAYMODE %= (sizeof (ncdisplaymodes) / sizeof (displaymode_t)); |
mode = ncdisplaymodes; |
mode += COSD_DISPLAYMODE; |
osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
// re-request OSD Data from NC every 100ms |
//usart1_request_mk_data(1, 'o', 100); |
#endif |
|
_delay_ms(3000); |
clear(); |
// update flags to paint display again because of clear |
COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
179,91 → 177,90 |
/** |
* helper function for flag display |
*/ |
void onoff(uint8_t col, uint8_t line, uint8_t onoff) { |
if (onoff) { |
write_ascii_string_pgm(col, line, PSTR("ON ")); |
} else { |
write_ascii_string_pgm(col, line, PSTR("OFF")); |
} |
void onoff(uint8_t col, uint8_t line, uint8_t onoff) { |
if (onoff) { |
write_ascii_string_pgm(col, line, PSTR("ON ")); |
} else { |
write_ascii_string_pgm(col, line, PSTR("OFF")); |
} |
} |
|
|
/** |
* helper function for menu updating |
*/ |
void config_menu_drawings(uint8_t chosen) { |
static uint8_t old_y = 0; |
uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP; |
static uint8_t old_y = 0; |
uint8_t x = MENU_LEFT, y = MENU_TOP, line = MENU_TOP; |
|
if (chosen > 5 && chosen < 12) { // right |
x = MENU_MIDDLE; |
y = chosen - 6 + MENU_TOP; |
} else if (chosen < 7) { |
y = chosen + MENU_TOP; |
} else { |
y = chosen - 6 + MENU_TOP; |
} |
if (chosen > 5 && chosen < 12) { // right |
x = MENU_MIDDLE; |
y = chosen - 6 + MENU_TOP; |
} else if (chosen < 7) { |
y = chosen + MENU_TOP; |
} else { |
y = chosen - 6 + MENU_TOP; |
} |
|
// clear prevoius _cursor_ and draw current |
for (uint8_t myx = MENU_LEFT; myx < 29; myx++) { |
write_char_att_xy(myx, old_y, 0); |
if (myx > x - 1 && myx < x + 14) { |
write_char_att_xy(myx, y, BLACKBG | INVERT); |
} |
}; |
for (uint8_t myx = MENU_LEFT; myx < 29; myx++) { |
write_char_att_xy(myx, old_y, 0); |
if (myx > x - 1 && myx < x + 14) { |
write_char_att_xy(myx, y, BLACKBG | INVERT); |
} |
}; |
|
write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video")); |
if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC); |
} else { |
write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL); |
} |
|
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD); |
|
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON); |
write_ascii_string_pgm(MENU_LEFT, line, PSTR("Video")); |
if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) { |
write_ascii_string_pgm(MENU_LEFT + 10, line, VM_NTSC); |
} else { |
write_ascii_string_pgm(MENU_LEFT + 10, line, VM_PAL); |
} |
|
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor.")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON); |
|
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats")); |
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Full HUD")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_HUD); |
|
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Horizon")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON); |
|
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Aggr.Hor.")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_AGGRHORIZON); |
|
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("Stats")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STATS); |
|
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT); |
write_ascii_string_pgm(MENU_LEFT, ++line, PSTR("A by FC")); |
onoff(MENU_LEFT + 10, line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT); |
|
// 2nd col |
line = 2; |
// 2nd col |
line = 2; |
|
write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom")); |
onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT); |
|
write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by")); |
if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS")); |
} else { |
write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO")); |
} |
write_ascii_string_pgm(MENU_MIDDLE, line, PSTR("V C-Strom")); |
onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT); |
|
write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph")); |
onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET); |
write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Height by")); |
if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) { |
write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR(" GPS")); |
} else { |
write_ascii_string_pgm(MENU_MIDDLE + 10, line, PSTR("BARO")); |
} |
|
write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario")); |
onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO); |
write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Feet/mph")); |
onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_CONFIG & COSD_FLAG_FEET); |
|
write_ascii_string_pgm(MENU_MIDDLE, ++line, PSTR("Big Vario")); |
onoff(MENU_MIDDLE + 10, line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO); |
|
// bottom |
write_ascii_string_pgm(MENU_LEFT, 9, PSTR("Reset uptime")); |
|
write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Display Mode")); |
write_ascii_string_pgm(18, 10, (const char *) (pgm_read_word(&(mode->desc)))); |
|
write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Save config")); |
write_ascii_string_pgm(MENU_LEFT, 12, PSTR("EXIT")); |
// bottom |
write_ascii_string_pgm(MENU_LEFT, 9, PSTR("Reset uptime")); |
|
old_y = y; |
write_ascii_string_pgm(MENU_LEFT, 10, PSTR("Display Mode")); |
write_ascii_string_pgm(18, 10, (const char *)(pgm_read_word(&(mode->desc)))); |
|
write_ascii_string_pgm(MENU_LEFT, 11, PSTR("Save config")); |
write_ascii_string_pgm(MENU_LEFT, 12, PSTR("EXIT")); |
|
old_y = y; |
} |
|
/** |
286,7 → 283,7 |
clear(); |
|
uint8_t chosen = 0; |
uint8_t inmenu = 1; |
uint8_t inmenu = 1; |
write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu")); |
|
// wait a bit before doing stuff so user has chance to release button |
296,26 → 293,26 |
|
while (inmenu) { |
if (s2_pressed()) { |
chosen = (chosen + 1) % 17; |
if (chosen == 10) chosen = 13; // SKIP unused menu space for now |
config_menu_drawings(chosen); |
_delay_ms(500); |
chosen = (chosen + 1) % 17; |
if (chosen == 10) chosen = 13; // SKIP unused menu space for now |
config_menu_drawings(chosen); |
_delay_ms(500); |
} else if (s1_pressed()) { |
switch (chosen) { |
case 0: // NTSC or PAL |
COSD_FLAGS_CONFIG ^= COSD_FLAG_NTSC; |
// 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; |
} |
break; |
case 1: // full HUD |
COSD_FLAGS_MODES ^= COSD_FLAG_HUD; |
332,7 → 329,7 |
case 5: // current by fc |
COSD_FLAGS_MODES ^= COSD_FLAG_FCCURRENT; |
break; |
case 6: // 2nd voltage by c-strom |
case 6: // 2nd voltage by c-strom |
COSD_FLAGS_MODES ^= COSD_FLAG_STROMVOLT; |
break; |
case 7: // GPS or BARO height |
341,36 → 338,36 |
case 8: // Feet and mph? |
COSD_FLAGS_CONFIG ^= COSD_FLAG_FEET; |
break; |
case 9: // big vario |
case 9: // big vario |
COSD_FLAGS_MODES ^= COSD_FLAG_BIGVARIO; |
break; |
case 13: // reset uptime |
uptime = 0; |
config_menu_doclick(chosen); |
config_menu_doclick(chosen); |
break; |
case 14: // change mode |
#if FCONLY |
COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof(fcdisplaymodes) / sizeof(displaymode_t)); |
mode = fcdisplaymodes; |
mode += COSD_DISPLAYMODE; |
osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
#else |
COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof(ncdisplaymodes) / sizeof(displaymode_t)); |
mode = ncdisplaymodes; |
mode += COSD_DISPLAYMODE; |
osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
#endif |
#if FCONLY |
COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (fcdisplaymodes) / sizeof (displaymode_t)); |
mode = fcdisplaymodes; |
mode += COSD_DISPLAYMODE; |
osd_fcmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
#else |
COSD_DISPLAYMODE = (COSD_DISPLAYMODE + 1) % (sizeof (ncdisplaymodes) / sizeof (displaymode_t)); |
mode = ncdisplaymodes; |
mode += COSD_DISPLAYMODE; |
osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun); |
#endif |
break; |
case 15: // save |
save_eeprom(); |
config_menu_doclick(chosen); |
config_menu_doclick(chosen); |
break; |
case 16: // exit |
inmenu = 0; |
config_menu_doclick(chosen); |
inmenu = 0; |
config_menu_doclick(chosen); |
break; |
} |
config_menu_drawings(chosen); |
config_menu_drawings(chosen); |
_delay_ms(250); |
} |
} |