Subversion Repositories NaviCtrl

Rev

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

Rev 88 Rev 89
Line 97... Line 97...
97
// set parameter from string based name and value
97
// set parameter from string based name and value
98
void Settings_SetParameterFromString(s8 *name, s8 *value)
98
void Settings_SetParameterFromString(s8 *name, s8 *value)
99
{
99
{
100
        u8 i;
100
        u8 i;
101
        s8 string[] = "                \0"; // null terminated string of 16 characters
101
        s8 string[] = "                \0"; // null terminated string of 16 characters
-
 
102
        s8 text[32];
Line 102... Line 103...
102
 
103
 
103
        i = strlen(name);                                       // lenght of the parameter name
104
        i = strlen(name);                                       // lenght of the parameter name
Line 104... Line 105...
104
        if (i > 16) i = 16;                                     // cut off at 16
105
        if (i > 16) i = 16;                                     // cut off at 16
Line 114... Line 115...
114
                {
115
                {
115
                        CFG_Parameter[i].Value = (u16)atoi(value); // convert string to number and set value
116
                        CFG_Parameter[i].Value = (u16)atoi(value); // convert string to number and set value
116
                        // range within min/max
117
                        // range within min/max
117
                        if(CFG_Parameter[i].Value < CFG_Parameter[i].Min) CFG_Parameter[i].Value = CFG_Parameter[i].Min;
118
                        if(CFG_Parameter[i].Value < CFG_Parameter[i].Min) CFG_Parameter[i].Value = CFG_Parameter[i].Min;
Line 118... Line 119...
118
 
119
 
119
                        //sprintf(text,"%s = %d\n\r", string, CFG_Parameter[i].Value);
120
                        sprintf(text,"\r\n%s = %d", string, CFG_Parameter[i].Value);
120
                        //SerialPutString(text);
121
                        SerialPutString(text);
121
                        break; // end loop
122
                        break; // end loop
122
                }
123
                }
123
        }
124
        }
Line 127... Line 128...
127
// read settings from file on sd-card
128
// read settings from file on sd-card
128
void Settings_Init(void)
129
void Settings_Init(void)
129
{
130
{
130
        #define LINE_MAX 32
131
        #define LINE_MAX 32
131
        File_t *fp;
132
        File_t *fp;
132
        u8 text[LINE_MAX];
133
        s8 text[LINE_MAX];
133
        u8 *token;
134
        s8 *name, *value;
Line 134... Line 135...
134
 
135
 
135
        Settings_SetDefaultValues();
136
        Settings_SetDefaultValues();
136
        SerialPutString("\n\rReading settings from file...\n\r");
137
        SerialPutString("\n\rReading settings from file...");
Line 137... Line 138...
137
        fp = fopen_("settings.ini", 'r');
138
        fp = fopen_("settings.ini", 'r');
138
 
139
 
139
        if (fp == NULL) // could not open the file
140
        if (fp == NULL) // could not open the file
140
        {
141
        {
141
                SerialPutString("ERROR: File not found !");
142
                SerialPutString("ERROR: File not found !");
142
                return;
-
 
143
        }
143
                return;
144
 
144
        }
145
        // read all lines from file
145
        // read all lines from file
146
        while(fgets_(text, LINE_MAX, fp) != NULL)
146
        while(fgets_(text, LINE_MAX, fp) != 0)
147
        {
147
        {
148
                if ( // ignorelines starting with \r,\n,' ',';','#'
148
                if ( // ignorelines starting with \r,\n,' ',';','#'
149
                        (text[0] != '\n') &&
149
                        (text[0] != '\n') &&
150
                        (text[0] != '\r') &&
150
                        (text[0] != '\r') &&
151
                        (text[0] != ' ' ) &&
151
                        (text[0] != ' ' ) &&
152
                        (text[0] != ';' ) &&
152
                        (text[0] != ';' ) &&
153
                        (text[0] != '#' )
153
                        (text[0] != '#' )
154
                        )
154
                        )
-
 
155
                {
155
                {
156
                        name  = strtok(text, "="); // get name
156
                        token = strtok(text, "="); //find the '='
157
                        value = strtok(NULL, "="); // get value
157
                        if (token != NULL) // if '=' has been found
-
 
158
                        {
158
                        if ((name != NULL) && (value != NULL)) // if '=' has been found
159
                          //SerialPutString(token);SerialPutString(" --> ");
-
 
160
                  Settings_SetParameterFromString(token, strtok(NULL, "="));
159
                        {
161
                          //SerialPutString("\n\r");
160
                                Settings_SetParameterFromString(name, value);
162
                        }
161
                        }
-
 
162
                }
163
                }
163
        }
164
        }
164
 
165
        fclose_(fp);
165
        fclose_(fp);