Subversion Repositories Projects

Rev

Rev 762 | Rev 800 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 762 Rev 783
Line 41... Line 41...
41
const char VM_PAL[] PROGMEM = "PAL ";
41
const char VM_PAL[] PROGMEM = "PAL ";
42
const char VM_NTSC[] PROGMEM = "NTSC";
42
const char VM_NTSC[] PROGMEM = "NTSC";
Line 43... Line 43...
43
 
43
 
Line 44... Line 44...
44
const displaymode_t * mode;
44
const displaymode_t * mode;
45
 
45
 
46
const char ee_message0[] PROGMEM = "Loading Data from EEPROM";
46
const char ee_message0[] PROGMEM = "Loading from EEPROM";
Line 47... Line 47...
47
const char ee_message1[] PROGMEM = "No saved Data in EEPROM";
47
const char ee_message1[] PROGMEM = "No Data in EEPROM";
48
const char* ee_msg[] PROGMEM = {ee_message0, ee_message1};
48
const char* ee_msg[] PROGMEM = {ee_message0, ee_message1};
49
 
49
 
50
/**
50
/**
51
 * read data saved in eeprom, print out message if <verbose> is set
51
 * read data saved in eeprom, print out message if <verbose> is set
52
 */
52
 */
53
void get_eeprom(uint8_t verbose) {
53
void get_eeprom(uint8_t verbose) {
54
    if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) {
54
    if (eeprom_read_byte(&ee_checkbyte1) == CHECKBYTE1 && eeprom_read_byte(&ee_checkbyte2) == CHECKBYTE2) {
55
        if (verbose) write_ascii_string_pgm(2, 9, ee_msg[0]); // Loading data
55
        if (verbose) write_ascii_string_pgm(2, 2, ee_msg[0]); // Loading data
56
        COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES);
56
        COSD_FLAGS_MODES = eeprom_read_byte(&ee_COSD_FLAGS_MODES);
57
        COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG);
57
        COSD_FLAGS_CONFIG = eeprom_read_byte(&ee_COSD_FLAGS_CONFIG);
58
        COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE);
58
        COSD_DISPLAYMODE = eeprom_read_byte(&ee_COSD_DISPLAYMODE);
59
        //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0);
59
        //if (verbose) write_ndigit_number_u(23, 11, COSD_DISPLAYMODE, 2, 0);
60
    } else {
60
    } else {
Line 61... Line 61...
61
        if (verbose) write_ascii_string_pgm(2, 9, ee_msg[1]); // Loading data
61
        if (verbose) write_ascii_string_pgm(2, 2, ee_msg[1]); // Loading data
Line 77... Line 77...
77
/**
77
/**
78
 * auto config some stuff on startup, currently only battery cells
78
 * auto config some stuff on startup, currently only battery cells
79
 */
79
 */
80
void init_cosd(uint8_t UBat) {
80
void init_cosd(uint8_t UBat) {
81
    clear();
81
    clear();
82
    write_ascii_string_pgm(2, 1, PSTR("C-OSD Initialisation")); // C-OSD Initialisation
82
    write_ascii_string_pgm(2, 1, PSTR("C-OSD Init"));
-
 
83
    write_ascii_string_pgm(2, 4, PSTR(BUILDDATE));
-
 
84
 
83
#if FCONLY
85
#if FCONLY
84
    write_ascii_string_pgm(2, 2, PSTR("FC only Mode")); // FC only mode
86
    write_ascii_string_pgm(2, 3, PSTR("FC only Mode"));
85
#else
87
#else
86
    write_ascii_string_pgm(2, 2, PSTR("NaviCtrl Mode")); // NaviCtrl Mode
88
    write_ascii_string_pgm(2, 3, PSTR("NaviCtrl Mode"));
-
 
89
 
-
 
90
        usart1_EnableTXD();
-
 
91
        usart1_puts_pgm(PSTR(REQUEST_UART_TO_FC));     
-
 
92
        usart1_DisableTXD();
87
#endif
93
#endif
-
 
94
 
-
 
95
 
-
 
96
        usart1_request_blocking('Q', PSTR(REQUEST_CURRENT_SETTING));
-
 
97
 
-
 
98
        //write_ascii_char(4 + 12 * 30, rxd_buffer[2]);
-
 
99
 
-
 
100
    paramset_serial setting;
-
 
101
    setting = *((paramset_serial*)pRxData);
-
 
102
 
88
    write_ascii_string_pgm(2, 3, PSTR(BUILDDATE));
103
        write_ascii_string_pgm(2, 6, PSTR("Setting: "));
-
 
104
        write_ndigit_number_u(11, 6, setting.SettingsIndex, 1, 1);
-
 
105
        write_ascii_string_len(13, 6, setting.param.Name, 12); 
-
 
106
 
89
    uint8_t cellnum = 0;
107
        uint8_t cells = 0;
-
 
108
        write_ascii_string_pgm(2, 8, PSTR("Battery:")); // Guessing Number of Cells
90
    if (CELL_NUM == -1) {
109
        if (CELL_NUM == -1) {        
91
        write_ascii_string_pgm(2, 4, PSTR("Guessing Number of Cells")); // Guessing Number of Cells
110
                #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO
-
 
111
               
-
 
112
                if (setting.param.UnterspannungsWarnung < 50) {
-
 
113
                        // up to 6s LiPo, less than 2s is technical impossible
-
 
114
                        for(cells = 2; cells < 7; cells++) {
-
 
115
                                if(UBat < cells * MAX_CELL_VOLTAGE) break;
-
 
116
                        }
-
 
117
 
-
 
118
                        min_voltage = cells * setting.param.UnterspannungsWarnung;             
92
        do {
119
                } else {
93
            cellnum++;
120
                        min_voltage = setting.param.UnterspannungsWarnung;
94
        } while (UBat > ((cellnum * CELL_VOLT_MAX) + 23));
121
                        cells = min_voltage / CELL_VOLT_MIN;
-
 
122
                }
-
 
123
                //write_ndigit_number_u(10, 13, setting.param.UnterspannungsWarnung, 3, 1);     
95
    } else {
124
    } else {
96
        cellnum = CELL_NUM;
125
        cells = CELL_NUM;
-
 
126
                min_voltage = cells * CELL_VOLT_MIN;
97
    }
127
    }
-
 
128
       
98
    min_voltage = cellnum * CELL_VOLT_MIN;
129
        max_voltage = cells * CELL_VOLT_MAX;
-
 
130
 
99
    max_voltage = cellnum * CELL_VOLT_MAX;
131
    write_ndigit_number_u(11, 8, cells, 1, 0);
100
    write_ascii_string_pgm(2, 5, PSTR("Number of Cells:")); // Number of Cells
132
        write_ascii_string_pgm(13, 8, PSTR("Cells")); // Number of Cells    
101
    write_ndigit_number_u(21, 5, cellnum, 1, 0);
-
 
102
    write_ascii_string_pgm(2, 6, PSTR("Warn Voltage   :")); // Warn Voltage
133
    write_ascii_string_pgm(2, 9, PSTR("Warn:")); // Warn Voltage
103
    write_ndigit_number_s_10th(20, 6, min_voltage, 3, 0);
134
    write_ndigit_number_s_10th(8, 9, min_voltage, 3, 0);
104
    write_ascii_string_pgm(2, 7, PSTR("Max Voltage    :")); // Max Voltage
135
    write_ascii_string_pgm(14, 9, PSTR("Max:")); // Max Voltage
105
    write_ndigit_number_s_10th(20, 7, max_voltage, 3, 0);
136
    write_ndigit_number_s_10th(20, 9, max_voltage, 3, 0);
Line 106... Line 137...
106
 
137
 
Line 107... Line 138...
107
    get_eeprom(1);
138
    get_eeprom(1);
108
 
139
 
109
    //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]);
140
    //write_ascii_string_pgm(23, 2, vm[COSD_FLAGS & COSD_FLAG_NTSC]);
110
    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
141
    if (COSD_FLAGS_CONFIG & COSD_FLAG_NTSC) {
111
        write_ascii_string_pgm(23, 2, VM_NTSC);
142
        write_ascii_string_pgm(23, 1, VM_NTSC);
112
    } else {
143
    } else {
Line 113... Line 144...
113
        write_ascii_string_pgm(23, 2, VM_PAL);
144
        write_ascii_string_pgm(23, 1, VM_PAL);
114
    }
-
 
115
 
-
 
116
    // request version from board
145
    }
117
    rxd_buffer_locked = 0;
146
 
118
    usart1_EnableTXD();
147
    // request version from board
119
#if FCONLY
148
#if FCONLY
120
    //usart1_request_mk_data(0, 'v', 0);
149
    //usart1_request_mk_data(0, 'v', 0);
-
 
150
    write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........"));
121
    write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........"));
151
        usart1_request_blocking('V', PSTR(REQUEST_FC_VERSION));
122
    usart1_puts_pgm(PSTR(REQUEST_FC_VERSION));
-
 
123
#else
152
#else
-
 
153
        usart1_request_nc_uart();
124
    //usart1_request_mk_data(1, 'v', 0);
154
    //usart1_request_mk_data(1, 'v', 0);
125
    usart1_puts_pgm(PSTR(REQUEST_NC_VERSION));
-
 
126
    write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........"));
-
 
127
#endif
-
 
128
    usart1_DisableTXD();
-
 
129
    // wait for response
-
 
130
    while (rxd_buffer_locked == 0) {
-
 
131
        asm("nop");
155
    write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........"));
132
    }
156
    usart1_request_blocking('V', PSTR(REQUEST_NC_VERSION));    
Line 133... Line 157...
133
    Decode64();
157
#endif
134
    str_VersionInfo VersionInfo;
158
    str_VersionInfo VersionInfo;
135
    VersionInfo = *((str_VersionInfo*)pRxData);
159
    VersionInfo = *((str_VersionInfo*)pRxData);
136
 
160
 
Line -... Line 161...
-
 
161
    write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1);
-
 
162
    write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1);
137
    write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1);
163
    write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch);
138
    write_ndigit_number_u(18, 11, VersionInfo.SWMinor, 3, 1);
164
    // end version request
139
    write_ascii_char(22 + 11 * 30, 'a' + VersionInfo.SWPatch);
165
 
140
    // end version request
166
 
141
 
167
 
Line 154... Line 180...
154
    osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
180
    osd_ncmode = (int(*)(void)) pgm_read_word(&mode->dfun);
155
    // re-request OSD Data from NC every 100ms
181
    // re-request OSD Data from NC every 100ms
156
    //usart1_request_mk_data(1, 'o', 100);
182
    //usart1_request_mk_data(1, 'o', 100);
157
#endif
183
#endif
Line 158... Line 184...
158
 
184
 
159
    _delay_ms(3000);
185
    _delay_ms(5000);
160
    clear();
186
    clear();
161
    // update flags to paint display again because of clear
187
    // update flags to paint display again because of clear
162
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;
188
    COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN;