Subversion Repositories Projects

Rev

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

Rev 406 Rev 411
Line 55... Line 55...
55
// +  POSSIBILITY OF SUCH DAMAGE.
55
// +  POSSIBILITY OF SUCH DAMAGE.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include <stdio.h>
57
#include <stdio.h>
58
#include <stdlib.h>
58
#include <stdlib.h>
59
#include <string.h>
59
#include <string.h>
-
 
60
#include "printf_P.h"
60
#include "fat16.h"
61
#include "fat16.h"
61
#include "settings.h"
62
#include "settings.h"
62
#include "uart0.h"
63
#include "uart0.h"
63
#include "uart1.h"
-
 
64
#include "main.h"
-
 
Line 65... Line 64...
65
 
64
 
66
typedef struct
65
typedef struct
67
{
66
{
68
        ParamId_t ParamId;
67
        ParamId_t ParamId;
Line 115... Line 114...
115
                {
114
                {
116
                        CFG_Parameter[i].Value = (uint16_t)atoi(value); // convert string to number and set value
115
                        CFG_Parameter[i].Value = (uint16_t)atoi(value); // convert string to number and set value
117
                        // out of range ?
116
                        // out of range ?
118
                        if((CFG_Parameter[i].Value < CFG_Parameter[i].Min) || (CFG_Parameter[i].Value > CFG_Parameter[i].Max))
117
                        if((CFG_Parameter[i].Value < CFG_Parameter[i].Min) || (CFG_Parameter[i].Value > CFG_Parameter[i].Max))
119
                        {       // print a warning
118
                        {       // print a warning
120
                                sprintf(text,"\r\n%s <-- %d is out of range [%d...%d]", string, CFG_Parameter[i].Value, CFG_Parameter[i].Min, CFG_Parameter[i].Max);
119
                                printf("\r\n%s <-- %d is out of range [%d...%d]", string, CFG_Parameter[i].Value, CFG_Parameter[i].Min, CFG_Parameter[i].Max);
121
                                printf(text);
-
 
122
                                CFG_Parameter[i].Value = CFG_Parameter[i].Default;  // fallback to default
120
                                CFG_Parameter[i].Value = CFG_Parameter[i].Default;  // fallback to default
123
                        }
121
                        }
124
                        retval = 1; // value in range
122
                        retval = 1; // value in range
125
                        break; // end loop
123
                        break; // end loop
126
                }
124
                }
127
        }
125
        }
128
        if(!retval)
126
        if(!retval)
129
        {      
127
        {
130
                sprintf(text,"\r\n%s <-- unknown parameter\r\n", string);
128
                printf("\r\n%s <-- unknown parameter\r\n", string);
131
                printf(text);
-
 
132
        }
129
        }
133
        return(retval);
130
        return(retval);
134
}
131
}
Line 135... Line 132...
135
 
132
 
Line 142... Line 139...
142
        int8_t settingsline[LINE_MAX];
139
        int8_t settingsline[LINE_MAX];
143
        char *name, *value;
140
        char *name, *value;
144
        uint8_t i;
141
        uint8_t i;
145
        char *tmp;
142
        char *tmp;
Line 146... Line 143...
146
 
143
 
147
        printf("\n\rSettings init...");
144
        printf("\r\nSettings init...");
148
        Settings_SetDefaultValues();
145
        Settings_SetDefaultValues();
149
       
146
 
150
        if(Fat16_IsValid())
147
        if(Fat16_IsValid())
151
        {       // check if settings file is existing
148
        {       // check if settings file is existing
152
                if(fexist_("settings.ini"))
149
                if(fexist_("settings.ini"))
153
                {      
150
                {
154
                        fp = fopen_("settings.ini", 'r');               // try to open the file
151
                        fp = fopen_("settings.ini", 'r');               // try to open the file
155
                        if (fp == NULL)                                                 // could not open the file
152
                        if (fp == NULL)                                                 // could not open the file
156
                        {
153
                        {
157
                                printf("ERROR: Opening settings file!");
154
                                printf("ERROR: Opening settings file!");
Line 184... Line 181...
184
                {       // create default settings file
181
                {       // create default settings file
185
                        fp = fopen_("settings.ini", 'w');               // try to open the file
182
                        fp = fopen_("settings.ini", 'w');               // try to open the file
186
                        if(fp == NULL)
183
                        if(fp == NULL)
187
                        {
184
                        {
188
                                printf("ERROR: Creating default settings file!");
185
                                printf("ERROR: Creating default settings file!");
189
                                return;
186
                                return;
190
                        }
187
                        }
191
                        // run thrue all parameters and set value to default
188
                        // run thrue all parameters and set value to default
192
                        for (i = 0; i < sizeof(CFG_Parameter) / sizeof(Parameter_t); i++)
189
                        for (i = 0; i < sizeof(CFG_Parameter) / sizeof(Parameter_t); i++)
193
                        {
190
                        {
194
                                sprintf(settingsline, "%s = %d\r\n", CFG_Parameter[i].Name, CFG_Parameter[i].Default);
191
                                sprintf(settingsline, "%s = %d\r\n", CFG_Parameter[i].Name, CFG_Parameter[i].Default);