Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 735 → Rev 736

/C-OSD/trunk/CHANGE.LOG
18,6 → 18,11
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
****************************************************************************/
 
20100216-1430
*some menu stuff
*stats in nc_default do not disturb the bigvario anymore
*reduced code size from 16088 bytes (98.2% Full) 15436 bytes (94.2% Full)
 
20100214-1700
+mah wasted per flight (still counts up after landing, but space gets tight)
*init phase from 2000ms to 3000ms
/C-OSD/trunk/config.c
37,30 → 37,10
 
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
 
// store more fixed strings in progmen
char ON[] PROGMEM = "ON ";
char OFF[] PROGMEM = "OFF";
 
// video modes
const char VM_PAL[] PROGMEM = "PAL ";
const char VM_NTSC[] PROGMEM = "NTSC";
 
// menu strings to progmem
const char menu_item0[] PROGMEM = "Video Mode";
const char menu_item1[] PROGMEM = "Full HUD";
const char menu_item2[] PROGMEM = "Art.Horizon in HUD";
const char menu_item3[] PROGMEM = "Big Vario bar";
const char menu_item4[] PROGMEM = "Statistics";
//const char menu_item5[] PROGMEM = "Warnings"; // TODO: do it!
const char menu_item5[] PROGMEM = "Current by FC";
const char menu_item6[] PROGMEM = "Voltage by C-Strom";
const char menu_item7[] PROGMEM = "Reset uptime";
const char menu_item8[] PROGMEM = "Display Mode";
const char menu_item9[] PROGMEM = "Height by";
const char menu_item10[] PROGMEM = "Save config";
const char menu_item11[] PROGMEM = "EXIT";
const char* menu[] = {menu_item0, menu_item1, menu_item2, menu_item3, menu_item4,
menu_item5, menu_item6, menu_item7, menu_item8, menu_item9, menu_item10, menu_item11};
 
const displaymode_t * mode;
 
192,72 → 172,80
* ##########################################################################*/
 
/**
* helper function for flag display
*/
void onoff(uint8_t line, uint8_t onoff) {
if (onoff) {
write_ascii_string_pgm(23, line, PSTR("ON "));
} else {
write_ascii_string_pgm(23, line, PSTR("OFF"));
}
}
 
/**
* helper function for menu updating
*/
void config_menu_drawings(uint8_t chosen) {
uint8_t line = 2;
 
// clear prevoius _cursor_
write_ascii_string(3, (chosen + 2) % 10, " ");
//write_char_xy(3, line + ((chosen + 11) % 12), 0x00);
for (uint8_t x = 2; x < 28; x++) {
write_char_att_xy(x, line + ((chosen + 11) % 12), 0);
write_char_att_xy(x, line + chosen, BLACKBG);
};
// draw current _cursor_
write_ascii_string(3, chosen + 2, ">");
//write_char_xy(3, line + chosen, 0xD9);
 
 
write_ascii_string_pgm(4, line, PSTR("Video Mode"));
if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
write_ascii_string_pgm(23, 2, VM_NTSC);
write_ascii_string_pgm(23, line, VM_NTSC);
} else {
write_ascii_string_pgm(23, 2, VM_PAL);
write_ascii_string_pgm(23, line, VM_PAL);
}
if (COSD_FLAGS_MODES & COSD_FLAG_HUD) {
write_ascii_string_pgm(23, 3, ON);
} else {
write_ascii_string_pgm(23, 3, OFF);
}
if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) {
write_ascii_string_pgm(23, 4, ON);
} else {
write_ascii_string_pgm(23, 4, OFF);
}
if (COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO) {
write_ascii_string_pgm(23, 5, ON);
} else {
write_ascii_string_pgm(23, 5, OFF);
}
if (COSD_FLAGS_MODES & COSD_FLAG_STATS) {
write_ascii_string_pgm(23, 6, ON);
} else {
write_ascii_string_pgm(23, 6, OFF);
}
/*if (COSD_FLAGS_MODES & COSD_FLAG_WARNINGS) {
write_ascii_string_pgm(23, 7, ON);
} else {
write_ascii_string_pgm(23, 7, OFF);
}*/
if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
write_ascii_string_pgm(23, 7, ON);
} else {
write_ascii_string_pgm(23, 7, OFF);
}
if (COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT) {
write_ascii_string_pgm(23, 8, ON);
} else {
write_ascii_string_pgm(23, 8, OFF);
}
//write_ndigit_number_u(23, 10, COSD_DISPLAYMODE, 2, 0);
write_ascii_string_pgm(18, 10, (const char *) (pgm_read_word(&(mode->desc))));
write_ascii_string_pgm(4, ++line, PSTR("Full HUD"));
onoff(line, COSD_FLAGS_MODES & COSD_FLAG_HUD);
write_ascii_string_pgm(4, ++line, PSTR("Art Horizon in HUD"));
onoff(line, COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON);
write_ascii_string_pgm(4, ++line, PSTR("Big Vario bar"));
onoff(line, COSD_FLAGS_MODES & COSD_FLAG_BIGVARIO);
 
write_ascii_string_pgm(4, ++line, PSTR("Statistics"));
onoff(line, COSD_FLAGS_MODES & COSD_FLAG_STATS);
 
write_ascii_string_pgm(4, ++line, PSTR("Current by FC"));
onoff(line, COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT);
 
write_ascii_string_pgm(4, ++line, PSTR("Voltage by C-Strom"));
onoff(line, COSD_FLAGS_MODES & COSD_FLAG_STROMVOLT);
 
write_ascii_string_pgm(4, ++line, PSTR("Reset uptime"));
write_ascii_string_pgm(4, ++line, PSTR("Display Mode"));
write_ascii_string_pgm(18, line, (const char *) (pgm_read_word(&(mode->desc))));
write_ascii_string_pgm(4, ++line, PSTR("Height by"));
if (COSD_FLAGS_CONFIG & COSD_FLAG_GPSHEIGHT) {
write_ascii_string_pgm(20, 11, PSTR(" GPS"));
write_ascii_string_pgm(20, line, PSTR(" GPS"));
} else {
write_ascii_string_pgm(20, 11, PSTR("BARO"));
write_ascii_string_pgm(20, line, PSTR("BARO"));
}
 
write_ascii_string_pgm(4, ++line, PSTR("Save config"));
write_ascii_string_pgm(4, ++line, PSTR("EXIT"));
}
 
/**
* some sort of clicking response in the menu
*/
void config_menu_doclick(uint8_t chosen, const char* menu[]) {
void config_menu_doclick(uint8_t chosen) {
write_ascii_string_pgm(4, chosen + 2, PSTR("DONE "));
_delay_ms(500);
write_ascii_string_pgm(4, chosen + 2, menu[chosen]);
config_menu_drawings(chosen);
}
 
/**
270,33 → 258,19
// clear screen
clear();
 
uint8_t chosen = 0;
uint8_t inmenu = 1;
uint8_t chosen = 0;
write_ascii_string_pgm(6, 1, PSTR("C-OSD Config Menu"));
 
// wait a bit before doing stuff so user has chance to release button
_delay_ms(250);
 
write_ascii_string_pgm(4, 2, menu[0]);
write_ascii_string_pgm(4, 3, menu[1]);
write_ascii_string_pgm(4, 4, menu[2]);
write_ascii_string_pgm(4, 5, menu[3]);
write_ascii_string_pgm(4, 6, menu[4]);
write_ascii_string_pgm(4, 7, menu[5]);
write_ascii_string_pgm(4, 8, menu[6]);
write_ascii_string_pgm(4, 9, menu[7]);
write_ascii_string_pgm(4, 10, menu[8]);
write_ascii_string_pgm(4, 11, menu[9]);
write_ascii_string_pgm(4, 12, menu[10]);
write_ascii_string_pgm(4, 13, menu[11]);
 
config_menu_drawings(chosen);
 
while (inmenu) {
if (s2_pressed()) {
write_ascii_string(3, chosen + 2, " ");
chosen = (chosen + 1) % 12;
write_ascii_string(3, chosen + 2, ">");
config_menu_drawings(chosen);
_delay_ms(500);
} else if (s1_pressed()) {
switch (chosen) {
346,7 → 320,7
break;
case 7: // reset uptime
uptime = 0;
config_menu_doclick(chosen, menu);
config_menu_doclick(chosen);
break;
case 8: // change mode
#if FCONLY
368,7 → 342,7
break;
case 10: // save
save_eeprom();
config_menu_doclick(chosen, menu);
config_menu_doclick(chosen);
break;
case 11: // exit
inmenu = 0;
/C-OSD/trunk/main.c
254,7 → 254,7
 
// give the FC/NC and the maxim time to come up
LED4_ON
_delay_ms(2000);
_delay_ms(1000);
LED4_OFF
 
//Pushing NEW chars to the MAX7456
315,7 → 315,6
ppm_init();
 
// enable interrupts
 
sei();
#endif
 
/C-OSD/trunk/main.h
56,7 → 56,9
#define RCLVL_WRN 100 // make the RC level blink if below this number
 
// ### read datasheet before changing stuff below this line :)
#define BLINK 0b01001111 // attribute byte for blinking chars
#define BLINK 0b01001111 // attribute byte for blinking characters
#define INVERT 0b00101111 // attribute byte for inverted characters
#define BLACKBG 0b10001111 // attribute byte for _black background_ on characters
 
/* ##########################################################################
* FLAGS usable during runtime that get saved
/C-OSD/trunk/max7456_software_spi.c
27,6 → 27,9
#include "main.h"
#include "max7456_software_spi.h"
 
 
char conv_array[7]; // general array for number -> char conversation
 
/* ##########################################################################
* MAX7456 SPI & Display stuff
* ##########################################################################*/
91,6 → 94,7
}
 
 
#if (ALLCHARSDEBUG|(WRITECHARS != -1))
/**
* for testing write all chars to screen
*/
105,6 → 109,30
}
}
 
/**
* let the MAX7456 learn a new character at <number>
* with <data>.
*/
void learn_char(uint8_t number, unsigned char* data) {
// select character to write (CMAH)
spi_send_byte(0x09, number);
 
for (uint8_t i = 0; i < 54; i++) {
// select 4pixel byte of char (CMAL)
spi_send_byte(0x0A, i);
 
// write 4pixel byte of char (CMDI)
spi_send_byte(0x0B, data[i]);
}
 
// write to the NVM array from the shadow RAM (CMM)
spi_send_byte(0x08, 0b10100000);
 
// according to maxim writing to nvram takes about 12ms, lets wait longer
_delay_ms(120);
}
#endif
 
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
 
/**
135,29 → 163,6
}
 
/**
* let the MAX7456 learn a new character at <number>
* with <data>.
*/
void learn_char(uint8_t number, unsigned char* data) {
// select character to write (CMAH)
spi_send_byte(0x09, number);
 
for (uint8_t i = 0; i < 54; i++) {
// select 4pixel byte of char (CMAL)
spi_send_byte(0x0A, i);
 
// write 4pixel byte of char (CMDI)
spi_send_byte(0x0B, data[i]);
}
 
// write to the NVM array from the shadow RAM (CMM)
spi_send_byte(0x08, 0b10100000);
 
// according to maxim writing to nvram takes about 12ms, lets wait longer
_delay_ms(120);
}
 
/**
* write an ascii <character> to <address> of MAX7456 display memory
*/
void write_ascii_char(uint16_t address, char c) {
169,17 → 174,17
else if (c == '(') c = 63; // remap
else if (c == ')') c = 64; // remap
else if (c == '.') c = 65; // remap
else if (c == '?') c = 66; // remap
else if (c == '-') c = 73; // remap minus
else if (c == ';') c = 67; // remap
else if (c == ':') c = 68; // remap
else if (c == ',') c = 69; // remap
else if (c == '\'') c = 70; // remap
else if (c == '/') c = 71; // remap
else if (c == '"') c = 72; // remap
else if (c == '-') c = 73; // remap minus
else if (c == '<') c = 74; // remap
else if (c == '>') c = 75; // remap
else if (c == '@') c = 76; // remap
// else if (c == '?') c = 66; // remap
// else if (c == '\'') c = 70; // remap
// else if (c == '/') c = 71; // remap
// else if (c == '"') c = 72; // remap
// else if (c == '<') c = 74; // remap
// else if (c == '>') c = 75; // remap
// else if (c == '@') c = 76; // remap
write_char(address, c);
}
 
215,13 → 220,12
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
char s[7];
itoa(number, s, 10 );
for (uint8_t i = 0; i < length - strlen(s); i++) {
itoa(number, conv_array, 10 );
for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
if (pad) write_char((x++)+(y * 30), 10);
else write_ascii_char((x++)+(y * 30), 0);
}
write_ascii_string(x, y, s);
write_ascii_string(x, y, conv_array);
}
 
/**
230,13 → 234,12
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
char s[7];
itoa(number, s, 10 );
for (uint8_t i = 0; i < length - strlen(s); i++) {
itoa(number, conv_array, 10 );
for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
if (pad) write_char((x++)+(y * 30), 10);
else write_ascii_char((x++)+(y * 30), 0);
}
write_ascii_string(x, y, s);
write_ascii_string(x, y, conv_array);
}
 
/**
245,22 → 248,21
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
char s[7];
itoa(number, s, 10 );
uint8_t len = strlen(s);
itoa(number, conv_array, 10 );
uint8_t len = strlen(conv_array);
for (uint8_t i = 0; i < length - len; i++) {
if (pad) write_char((x++)+(y * 30), 10); // zero
else write_char((x++)+(y * 30), 0); // blank
}
char rest = s[len - 1];
s[len - 1] = 0;
char rest = conv_array[len - 1];
conv_array[len - 1] = 0;
if (len == 1) {
write_char((x-1)+(y * 30), 10); // zero
} else if (len == 2 && s[0] == '-') {
} else if (len == 2 && conv_array[0] == '-') {
write_char((x-1)+(y * 30), 0x49); // minus
write_char((x)+(y * 30), 10); // zero
} else {
write_ascii_string(x, y, s);
write_ascii_string(x, y, conv_array);
}
x += len - 1;
write_char((x++)+(y * 30), 65); // decimal point
273,22 → 275,21
* <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7
*/
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
char s[7];
itoa(number, s, 10 );
uint8_t len = strlen(s);
itoa(number, conv_array, 10 );
uint8_t len = strlen(conv_array);
for (uint8_t i = 0; i < length - len; i++) {
if (pad) write_char((x++)+(y * 30), 10); // zero
else write_char((x++)+(y * 30), 0); // blank
}
char rest = s[len - 1];
s[len - 1] = 0;
char rest = conv_array[len - 1];
conv_array[len - 1] = 0;
if (len == 1) {
write_char((x-1)+(y * 30), 10); // zero
} else if (len == 2 && s[0] == '-') {
} else if (len == 2 && conv_array[0] == '-') {
write_char((x-1)+(y * 30), 0x49); // minus
write_char((x)+(y * 30), 10); // zero
} else {
write_ascii_string(x, y, s);
write_ascii_string(x, y, conv_array);
}
x += len - 1;
write_char((x++)+(y * 30), 65); // decimal point
/C-OSD/trunk/max7456_software_spi.h
122,6 → 122,7
*/
void write_time(uint8_t, uint8_t, uint16_t);
 
#if (ALLCHARSDEBUG|(WRITECHARS != -1))
/**
* for testing write all chars to screen
*/
132,6 → 133,7
* with <data>.
*/
void learn_char(uint8_t, unsigned char*);
#endif
 
/**
* wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
/C-OSD/trunk/osd_ncmode_default.c
135,40 → 135,40
// stats
if ((COSD_FLAGS_RUNTIME & COSD_WASFLYING) && (COSD_FLAGS_MODES & COSD_FLAG_STATS)) {
uint8_t line = 3;
write_ascii_string_pgm(2, line, (const char *) (pgm_read_word(&(stats_item_pointers[0])))); // max Altitude
write_ndigit_number_s(18, line, max_Altimeter, 4, 0);
write_char_xy(22, line, 204); // small meters m
write_ascii_string_pgm(2, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[1])))); // max Speed
write_ndigit_number_u(19, line, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0);
write_char_xy(22, line, 203); // km/h
write_ascii_string_pgm(2, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[2])))); // max Distance
write_ndigit_number_u(19, line, max_Distance / 10, 3, 0);
write_char_xy(22, line, 204); // small meters m
write_ascii_string_pgm(2, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[3])))); // min voltage
write_ndigit_number_u_10th(18, line, min_UBat, 3, 0);
write_char_xy(22, line, 0x9E); // small V
write_ascii_string_pgm(1, line, (const char *) (pgm_read_word(&(stats_item_pointers[0])))); // max Altitude
write_ndigit_number_s(16, line, max_Altimeter, 4, 0);
write_char_xy(20, line, 204); // small meters m
write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[1])))); // max Speed
write_ndigit_number_u(17, line, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 3, 0);
write_char_xy(20, line, 203); // km/h
write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[2])))); // max Distance
write_ndigit_number_u(17, line, max_Distance / 10, 3, 0);
write_char_xy(20, line, 204); // small meters m
write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[3])))); // min voltage
write_ndigit_number_u_10th(16, line, min_UBat, 3, 0);
write_char_xy(20, line, 0x9E); // small V
if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
write_ascii_string_pgm(2, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[7])))); // ampere
write_ndigit_number_u_10th(18, line, max_ampere / 10, 3, 0);
write_char_xy(22, line, 0x9F); // small A
write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[7])))); // ampere
write_ndigit_number_u_10th(16, line, max_ampere / 10, 3, 0);
write_char_xy(20, line, 0x9F); // small A
// wasted mampere in this flight (will count up after landing)
if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) && !(COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
write_ndigit_number_u(23, line, (ampere_wasted / 10) - wasted_ampere_offset, 4, 0);
write_ndigit_number_u(21, line, (ampere_wasted / 10) - wasted_ampere_offset, 5, 0);
} else if (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT) {
write_ndigit_number_u(23, line, naviData.UsedCapacity - wasted_ampere_offset, 4, 0);
write_ndigit_number_u(21, line, naviData.UsedCapacity - wasted_ampere_offset, 5, 0);
}
write_char_xy(27, line, 0xB5); // mah
write_char_xy(26, line, 0xB5); // mah
}
write_ascii_string_pgm(2, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[4])))); // max time
write_time(16, line, max_FlyingTime);
write_char_xy(22, line, 210); // fly clock
write_ascii_string_pgm(2, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[5])))); // longitude
write_gps_pos(15, line, naviData.CurrentPosition.Longitude);
write_ascii_string_pgm(2, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[6])))); // latitude
write_gps_pos(15, line, naviData.CurrentPosition.Latitude);
write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[4])))); // max time
write_time(14, line, max_FlyingTime);
write_char_xy(20, line, 210); // fly clock
write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[5])))); // longitude
write_gps_pos(14, line, naviData.CurrentPosition.Longitude);
write_ascii_string_pgm(1, ++line, (const char *) (pgm_read_word(&(stats_item_pointers[6])))); // latitude
write_gps_pos(14, line, naviData.CurrentPosition.Latitude);
} else if (COSD_FLAGS_MODES & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon
if ((COSD_FLAGS_RUNTIME & COSD_FLAG_STROMREC) || (COSD_FLAGS_MODES & COSD_FLAG_FCCURRENT)) {
draw_artificial_horizon(top_line + 2, bottom_line - 2, naviData.AngleNick, naviData.AngleRoll);