Subversion Repositories Projects

Rev

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

Rev 783 Rev 800
Line 16... Line 16...
16
 *   along with this program; if not, write to the                          *
16
 *   along with this program; if not, write to the                          *
17
 *   Free Software Foundation, Inc.,                                        *
17
 *   Free Software Foundation, Inc.,                                        *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
19
 ****************************************************************************/
19
 ****************************************************************************/
20
 
20
 
-
 
21
#include "main.h"
21
#include <avr/io.h>
22
#include <avr/io.h>
22
#include <avr/eeprom.h>
23
#include <avr/eeprom.h>
23
#include <avr/pgmspace.h>
24
#include <avr/pgmspace.h>
24
#include <avr/interrupt.h>
25
#include <avr/interrupt.h>
25
#include <util/delay.h>
26
#include <util/delay.h>
26
#include "max7456_software_spi.h"
27
#include "max7456_software_spi.h"
27
#include "config.h"
28
#include "config.h"
28
#include "main.h"
-
 
29
#include "buttons.h"
29
#include "buttons.h"
30
#include "usart1.h"
30
#include "usart1.h"
31
 
31
 
32
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
32
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
33
 
33
 
Line 60... Line 60...
60
    } else {
60
    } else {
61
        if (verbose) write_ascii_string_pgm(2, 2, ee_msg[1]); // Loading data
61
        if (verbose) write_ascii_string_pgm(2, 2, ee_msg[1]); // Loading data
62
    }
62
    }
63
}
63
}
64
 
64
 
65
 
-
 
66
/**
65
/**
67
 * save data to eeprom
66
 * save data to eeprom
68
 */
67
 */
69
void save_eeprom() {
68
void save_eeprom() {
70
    eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1);
69
    eeprom_write_byte(&ee_checkbyte1, CHECKBYTE1);
Line 85... Line 84...
85
#if FCONLY
84
#if FCONLY
86
    write_ascii_string_pgm(2, 3, PSTR("FC only Mode"));
85
    write_ascii_string_pgm(2, 3, PSTR("FC only Mode"));
87
#else
86
#else
88
    write_ascii_string_pgm(2, 3, PSTR("NaviCtrl Mode"));
87
    write_ascii_string_pgm(2, 3, PSTR("NaviCtrl Mode"));
89
 
88
 
90
        usart1_EnableTXD();
89
    usart1_EnableTXD();
91
        usart1_puts_pgm(PSTR(REQUEST_UART_TO_FC));     
90
    usart1_puts_pgm(PSTR(REQUEST_UART_TO_FC));
92
        usart1_DisableTXD();
91
    usart1_DisableTXD();
93
#endif
92
#endif
94
 
93
 
95
 
94
 
96
        usart1_request_blocking('Q', PSTR(REQUEST_CURRENT_SETTING));
95
    usart1_request_blocking('Q', PSTR(REQUEST_CURRENT_SETTING));
97
 
96
 
98
        //write_ascii_char(4 + 12 * 30, rxd_buffer[2]);
97
    //write_ascii_char(4 + 12 * 30, rxd_buffer[2]);
99
 
98
 
100
    paramset_serial setting;
99
    paramset_serial setting;
101
    setting = *((paramset_serial*)pRxData);
100
    setting = *((paramset_serial*)pRxData);
102
 
101
 
103
        write_ascii_string_pgm(2, 6, PSTR("Setting: "));
102
    write_ascii_string_pgm(2, 6, PSTR("Setting: "));
104
        write_ndigit_number_u(11, 6, setting.SettingsIndex, 1, 1);
103
    write_ndigit_number_u(11, 6, setting.SettingsIndex, 1, 1);
105
        write_ascii_string_len(13, 6, setting.param.Name, 12); 
104
    write_ascii_string_len(13, 6, setting.param.Name, 12);
106
 
105
 
107
        uint8_t cells = 0;
106
    uint8_t cells = 0;
108
        write_ascii_string_pgm(2, 8, PSTR("Battery:")); // Guessing Number of Cells
107
    write_ascii_string_pgm(2, 8, PSTR("Battery:")); // Guessing Number of Cells
109
        if (CELL_NUM == -1) {        
108
    if (CELL_NUM == -1) {
110
                #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO
109
#define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO
111
               
110
 
112
                if (setting.param.UnterspannungsWarnung < 50) {
111
        if (setting.param.UnterspannungsWarnung < 50) {
113
                        // up to 6s LiPo, less than 2s is technical impossible
112
            // up to 6s LiPo, less than 2s is technical impossible
114
                        for(cells = 2; cells < 7; cells++) {
113
            for (cells = 2; cells < 7; cells++) {
115
                                if(UBat < cells * MAX_CELL_VOLTAGE) break;
114
                if (UBat < cells * MAX_CELL_VOLTAGE) break;
116
                        }
115
            }
117
 
116
 
118
                        min_voltage = cells * setting.param.UnterspannungsWarnung;             
117
            min_voltage = cells * setting.param.UnterspannungsWarnung;
119
                } else {
118
        } else {
120
                        min_voltage = setting.param.UnterspannungsWarnung;
119
            min_voltage = setting.param.UnterspannungsWarnung;
121
                        cells = min_voltage / CELL_VOLT_MIN;
120
            cells = min_voltage / CELL_VOLT_MIN;
122
                }
121
        }
123
                //write_ndigit_number_u(10, 13, setting.param.UnterspannungsWarnung, 3, 1);     
122
        //write_ndigit_number_u(10, 13, setting.param.UnterspannungsWarnung, 3, 1);
124
    } else {
123
    } else {
125
        cells = CELL_NUM;
124
        cells = CELL_NUM;
126
                min_voltage = cells * CELL_VOLT_MIN;
125
        min_voltage = cells * CELL_VOLT_MIN;
127
    }
126
    }
128
       
127
 
129
        max_voltage = cells * CELL_VOLT_MAX;
128
    max_voltage = cells * CELL_VOLT_MAX;
130
 
129
 
131
    write_ndigit_number_u(11, 8, cells, 1, 0);
130
    write_ndigit_number_u(11, 8, cells, 1, 0);
132
        write_ascii_string_pgm(13, 8, PSTR("Cells")); // Number of Cells    
131
    write_ascii_string_pgm(13, 8, PSTR("Cells")); // Number of Cells
133
    write_ascii_string_pgm(2, 9, PSTR("Warn:")); // Warn Voltage
132
    write_ascii_string_pgm(2, 9, PSTR("Warn:")); // Warn Voltage
134
    write_ndigit_number_s_10th(8, 9, min_voltage, 3, 0);
133
    write_ndigit_number_s_10th(8, 9, min_voltage, 3, 0);
135
    write_ascii_string_pgm(14, 9, PSTR("Max:")); // Max Voltage
134
    write_ascii_string_pgm(14, 9, PSTR("Max:")); // Max Voltage
136
    write_ndigit_number_s_10th(20, 9, max_voltage, 3, 0);
135
    write_ndigit_number_s_10th(20, 9, max_voltage, 3, 0);
137
 
136
 
Line 146... Line 145...
146
 
145
 
147
    // request version from board
146
    // request version from board
148
#if FCONLY
147
#if FCONLY
149
    //usart1_request_mk_data(0, 'v', 0);
148
    //usart1_request_mk_data(0, 'v', 0);
150
    write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........"));
149
    write_ascii_string_pgm(2, 11, PSTR("FC VERSION: ........"));
151
        usart1_request_blocking('V', PSTR(REQUEST_FC_VERSION));
150
    usart1_request_blocking('V', PSTR(REQUEST_FC_VERSION));
152
#else
151
#else
153
        usart1_request_nc_uart();
152
    usart1_request_nc_uart();
154
    //usart1_request_mk_data(1, 'v', 0);
153
    //usart1_request_mk_data(1, 'v', 0);
155
    write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........"));
154
    write_ascii_string_pgm(2, 11, PSTR("NC VERSION: ........"));
156
    usart1_request_blocking('V', PSTR(REQUEST_NC_VERSION));    
155
    usart1_request_blocking('V', PSTR(REQUEST_NC_VERSION));
157
#endif
156
#endif
158
    str_VersionInfo VersionInfo;
157
    str_VersionInfo VersionInfo;
159
    VersionInfo = *((str_VersionInfo*)pRxData);
158
    VersionInfo = *((str_VersionInfo*)pRxData);
160
 
159
 
161
    write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1);
160
    write_ndigit_number_u(14, 11, VersionInfo.SWMajor, 3, 1);