You are right. Your thinking is correct.
In my interface I can move a single automatic frequency slider
trough the values sequence I manually enter in the 24 Fl_Value_Inputs so
as the slider automatically goes, for example, from 100 Hz to 200 Hz and
so on in the specified time step.
When I decide to update the values I entered, I have to re-write
every of them.
I would like to have the opportunity to read and write
synchronously the new values, with which to update the old values, from
a stored file.
________________________________
I don't know if this is the sort of thing you want to do (example below)
- perhaps it will be some help?
The example code opena and parses values from a file, also attached. The
format of the file, and the parsing of it, are really too simplistic,
you would want to do something more robust, but hopefully this will show
you how to proceed.
---------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Value_Input.H>
static Fl_Double_Window *main_win=(Fl_Double_Window *)0;
static Fl_Button *exit_bt=(Fl_Button *)0;
static Fl_Button *nxt_bt=(Fl_Button *)0;
static Fl_Input *fname=(Fl_Input *)0;
static Fl_Value_Input *v1=(Fl_Value_Input *)0;
static Fl_Value_Input *v2=(Fl_Value_Input *)0;
static Fl_Value_Input *v3=(Fl_Value_Input *)0;
static Fl_Value_Input *v4=(Fl_Value_Input *)0;
static Fl_Value_Input *v5=(Fl_Value_Input *)0;
static Fl_Value_Input *v6=(Fl_Value_Input *)0;
FILE *fp = NULL;
// Hack file parser - you really want to do somethng better!
static void next_entry(void)
{
char values[1024];
float n1, n2, n3, n4, n5, n6;
// is our file open?
if(!fp)
{
puts("fopen");fflush(stdout);
char name[1024];
strncpy(name, fname->value(), 1024);
if(strlen(name) < 2) return;
// needs more robust checking!
fp = fopen(name, "r"); // open file read only
if (!fp)
{
puts("file open failed!");
puts(name); fflush(stdout);
return;
}
}
next_line:
// get the next line from the file
char *pc = fgets(values, 1024, fp);
if(pc == NULL)
{
// are we at EOF?
if(feof(fp))
{
// rewind the file
fseek(fp, 0, SEEK_SET);
goto next_line;
}
else return; // we are broken in some way
}
// is it a comment?
if(values[0] == '#') goto next_line;
// is it a blank line
if(strlen(values) < 4) goto next_line;
// parse the line
int res = sscanf(values, "%f %f %f %f %f %f", &n1, &n2, &n3,
&n4, &n5, &n6);
if (res != 6)
{
puts("Bad Values line read");
}
else
{
v1->value(n1);
v2->value(n2);
v3->value(n3);
v4->value(n4);
v5->value(n5);
v6->value(n6);
}
}
static void cb_exit_bt(Fl_Button*, void*) {
main_win->hide();
}
static void cb_nxt_bt(Fl_Button*, void*) {
// do nxt button;
next_entry();
}
int main(int argc, char **argv) {
{ main_win = new Fl_Double_Window(577, 197);
{ exit_bt = new Fl_Button(495, 150, 70, 25, "Exit");
exit_bt->callback((Fl_Callback*)cb_exit_bt);
} // Fl_Button* exit_bt
{ nxt_bt = new Fl_Button(485, 35, 64, 25, "Next");
nxt_bt->callback((Fl_Callback*)cb_nxt_bt);
} // Fl_Button* nxt_bt
{ fname = new Fl_Input(75, 36, 385, 23, "File Name");
} // Fl_Input* fname
{ v1 = new Fl_Value_Input(65, 76, 55, 23, "V1");
} // Fl_Value_Input* v1
{ v2 = new Fl_Value_Input(158, 76, 55, 23, "V2");
} // Fl_Value_Input* v2
{ v3 = new Fl_Value_Input(251, 76, 55, 23, "V3");
} // Fl_Value_Input* v3
{ v4 = new Fl_Value_Input(344, 76, 55, 23, "V4");
} // Fl_Value_Input* v4
{ v5 = new Fl_Value_Input(437, 76, 55, 23, "V5");
} // Fl_Value_Input* v5
{ v6 = new Fl_Value_Input(530, 76, 55, 23, "V6");
} // Fl_Value_Input* v6
main_win->end();
} // Fl_Double_Window* main_win
main_win->show(argc, argv);
int res = Fl::run();
if(fp) fclose(fp);
return res;
}
/* end of file */
---------------------
# This is a comment - it is ignored in parsing
# blank lines also ignored
1 2 3 4 5 6
1.1 2.1 3.1 4.1 5.1 6.1
1.2 2.2 3.2 4.2 5.2 6.2
1.3 2.3 3.3 4.3 5.3 6.3
1.4 2.4 3.4 4.4 5.4 6.4
# end of file
---------------------
SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14
3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk