Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 89 → Rev 90

/trunk/fat16.c
482,6 → 482,19
 
 
/****************************************************************************************************************************************/
/* Function: Fat16_IsValid(void); */
/* */
/* Description: This function return the Fat 15 filesystem state */
/* */
/* Returnvalue: The function returns "1" on success */
/****************************************************************************************************************************************/
u8 Fat16_IsValid(void)
{
return(Partition.IsValid);
}
 
 
/****************************************************************************************************************************************/
/* Function: Fat16_Deinit(void); */
/* */
/* Description: This function uninitializes the fat 16 api */
/trunk/fat16.h
46,6 → 46,7
 
u8 Fat16_Init(void);
u8 Fat16_Deinit(void);
u8 Fat16_IsValid(void);
File_t *fopen_(s8 * const filename, const s8 mode);
s16 fclose_(File_t *file);
56,7 → 57,7
s16 fputc_(s8 c, File_t * const file);
u32 fread_(void *buffer, u32 size, u32 count, File_t * const file);
u32 fwrite_(void *buffer, u32 size, u32 count, File_t * const file);
s16 fputs_(s8 * const string, File_t *file);
s16 fputs_(s8 * const string, File_t * const file);
s8 * fgets_(s8 * const string, s16 length, File_t * const file);
u8 feof_(File_t * const file);
 
/trunk/settings.c
65,7 → 65,7
typedef struct
{
ParamId_t ParamId;
s8 Name[16];
s8 Name[17]; // 0 terminator is the last byte
u8 Group; // 0 = reserved 1,2,3,4
u16 Value;
u16 Default;
95,12 → 95,14
 
//----------------------------------------------------------------------------------
// set parameter from string based name and value
void Settings_SetParameterFromString(s8 *name, s8 *value)
u8 Settings_SetParameterFromString(s8 *name, s8 *value)
{
u8 i;
u8 i, retval = 0;
s8 string[] = " \0"; // null terminated string of 16 characters
s8 text[32];
s8 text[64];
 
if((name == NULL) || (value == NULL)) return(retval);
 
i = strlen(name); // lenght of the parameter name
if (i > 16) i = 16; // cut off at 16
 
110,18 → 112,26
// search name in parameter list
for (i = 0; i < sizeof(CFG_Parameter) / sizeof(Parameter_t); i++)
{
//sprintf(text,"#%s#\n\r", CFG_Parameter[i].Name); SerialPutString(text);
if(strncmp(string, CFG_Parameter[i].Name, 16) == 0) // names are matching
{
CFG_Parameter[i].Value = (u16)atoi(value); // convert string to number and set value
// range within min/max
if(CFG_Parameter[i].Value < CFG_Parameter[i].Min) CFG_Parameter[i].Value = CFG_Parameter[i].Min;
 
sprintf(text,"\r\n%s = %d", string, CFG_Parameter[i].Value);
SerialPutString(text);
// out of range ?
if((CFG_Parameter[i].Value < CFG_Parameter[i].Min) || (CFG_Parameter[i].Value > CFG_Parameter[i].Max))
{ // print a warning
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);
SerialPutString(text);
CFG_Parameter[i].Value = CFG_Parameter[i].Default; // fallback to default
}
retval = 1; // value in range
break; // end loop
}
}
if(!retval)
{
sprintf(text,"\r\n%s <-- unknown parameter\r\n", string);
SerialPutString(text);
}
return(retval);
}
 
//----------------------------------------------------------------------------------
132,38 → 142,69
File_t *fp;
s8 text[LINE_MAX];
s8 *name, *value;
u8 i;
 
SerialPutString("\n\rSettings init...");
Settings_SetDefaultValues();
SerialPutString("\n\rReading settings from file...");
fp = fopen_("settings.ini", 'r');
 
if (fp == NULL) // could not open the file
{
SerialPutString("ERROR: File not found !");
return;
}
// read all lines from file
while(fgets_(text, LINE_MAX, fp) != 0)
{
if ( // ignorelines starting with \r,\n,' ',';','#'
(text[0] != '\n') &&
(text[0] != '\r') &&
(text[0] != ' ' ) &&
(text[0] != ';' ) &&
(text[0] != '#' )
)
{
name = strtok(text, "="); // get name
value = strtok(NULL, "="); // get value
if ((name != NULL) && (value != NULL)) // if '=' has been found
if(Fat16_IsValid())
{ // check if settings file is existing
if(fexist_("settings.ini"))
{
fp = fopen_("settings.ini", 'r'); // try to open the file
if (fp == NULL) // could not open the file
{
Settings_SetParameterFromString(name, value);
SerialPutString("ERROR: Opening settings file!");
return;
}
// read all lines from file
while(fgets_(text, LINE_MAX, fp) != 0)
{
if ( // ignorelines starting with \r,\n,' ',';','#'
(text[0] != '\n') &&
(text[0] != '\r') &&
(text[0] != ' ' ) &&
(text[0] != ';' ) &&
(text[0] != '#' )
)
{
name = strtok(text, "="); // get name
value = strtok(NULL, "="); // get value
if ((name != NULL) && (value != NULL))
{
Settings_SetParameterFromString(name, value);
}
}
}
fclose_(fp);
SerialPutString("ok");
return;
}
else // settings file does not exist
{ // create default settings file
fp = fopen_("settings.ini", 'w'); // try to open the file
if(fp == NULL)
{
SerialPutString("ERROR: Creating default settings file!");
return;
}
// run thrue all parameters and set value to default
for (i = 0; i < sizeof(CFG_Parameter) / sizeof(Parameter_t); i++)
{
sprintf(text, "%s = %d\r\n", CFG_Parameter[i].Name, CFG_Parameter[i].Default);
fputs_(text, fp); // write to file
}
fputs_("\r\n", fp); // newline at the end of file
fclose_(fp);
SerialPutString("Default settings file created!");
return;
}
}
 
fclose_(fp);
SerialPutString("ok");
else // no acces to fat 16 filesystem
{
SerialPutString("Using default values!");
return;
}
}
 
 
/trunk/uart1.c
131,7 → 131,7
 
const u8 ANALOG_LABEL[32][16] =
{
//1234567890123456
//1234567890123456
"AngleNick ", //0
"AngleRoll ",
"AccNick ",