Show Posts
Pages: 1 [2] 3 4 ... 30
16  Products / Arduino Due / Re: Arduino Due libraries (official and 3rd party) on: May 28, 2013, 11:55:40 pm
DueGUI library is now at version 0.13 and with the start of some quite thorough documentation.  All the most important GUI objects are already implemented with more to come.  Why not give it a try:


http://forum.arduino.cc/index.php?topic=164788.0
17  Products / Arduino Due / Re: Due GUI (Graphical user interface) - [now version 0.13] on: May 27, 2013, 07:12:47 pm
Version 0.13 now uploaded with much better manual (still needs lots of work but the objects are all listed).

Addition of new objects:

The cycle button is supplemented with a cycleTEXTbutton which allows you to use an array of Strings as the list of options to select! You can also change the array once the object is drawn!

New ImageButton which allows lots of options of how it works:
1) Just as an image that can do something when clicked
2) As an image that changes momentarily when you click it and you can do something when clicked
3) As an image that changes momentarily then switches to an alternative image and vice versa allowing a boolean on/off which works automatically
4) As above without the momentary alternative image.


Now I've got the hang of recording the array's pointer so as to use the user's own array of strings I will be using this technique to produce a "menu" object, "list box" object and maybe a few more.
18  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 03:15:37 pm
Well I've just finished implementing it and it is fully working.....

It would have been working an hour ago but I managed to use two single equals signs in the range check section which stopped it working!  I have wasted hours because of using single equals instead of double ones smiley-grin

Very much glad we got there in the end.  Thanks all.
19  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 11:07:50 am
I hope you are creating classes for all these menu object types smiley-wink

I have merged the large LCD and touch screen libraries into one library then updated that in turn into a graphical user interface called DueGUI.  This allows a full on graphical user interface to be implemented on the Due with an absolutely tiny sketch!  The whole library is a class DueGUI.  The objects are added one at a time with attributes that the user can specify then the library sets up an interrupt which detects button presses, displays pop up keyboards, updates graphical clocks etc etc.  It is working very well as far as I can see.  The reason for this thread was that I had a few ideas for more objects but they needed lists of strings in order to implement them nicely rather than it looking a bit of a kludge!

So to add a button that cycles through a number of strings the call would be to the function:

int addCycleStringButton(word x,word y,word xs,word ys,long colour,long borcolour,long textcolour,long presscolour,long presstextcolour,byte borwidth,String top,word xo,word yo,int font,int initialstate,String* elements,int cyclexo,int options,bool visible,int URN);

with something like:

addCycleStringButton(300,200,150,50,clrGreen,clrWhite,clrBlack,clrRed,clrWhite,2,"Select:",posLeft,posCentre,BVS_34,2,buttonSelect1,60,0,optVisible,12345);
 
This creates a button 150x50 pixels at location 300x200.
The button is normally green with a white border and black writing but when pressed momentarily goes red with white writing.
The button's text title is "Select:" with this text centred on the Y axis of the button but to the left using font "BVS_34".
The initial state of the button is the 3rd (2) element of the array with the array being "buttonSelect1[]" and the selectable text is located 60 pixels from the right side.
The button is initially visible and has a unique reference number of 12345.

The URN is returned to the sketch in order that the user can, if they wish, do something when the button is pressed although they don't have to because the library and interrupt routine do all the button handling anyway.
20  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 10:51:45 am
Quote
I'm not sure I completely understand it though
The part that you don't seem to get is that an array of arrays is a two dimensional array. Like a checkerboard is an array of 8 rows that are arrays that contain 8 column values.

Once you make that connection, getting data from the array of arrays of pointers is trivial.

No I completely understand multi-dimensional arrays, I've been programming in several languages for 30 years but just didn't understand how you would get to what you got to......  I normally use string arrays in C but I'm much more proficient in Pascal, assembly language and several forms of BASIC (which to be more honest is more like Pascal nowadays!).  I'm still trying to catch up with C and often I know exactly what I want to do and how I would do it in another language but just need to know how to do it in C.  I'm sort of getting there with the normal stuff but often need a little help with C.  
21  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 10:43:23 am
So here is the final test program:

I had a hunch that the array could be changed after it was sent so I included that and it still works smiley-grin

Thank you to everyone that posted.  I know that the test program makes no sense but the technique is what I needed and it will now allow me to create drop down menus, menus and a number of other GUI objects that I wanted.  If you are still interested in what I am actually up to there is a thread in the Due section "DueGUI".......


Code:
String test1[10] = {"1","2","3"};
String test2[10] = {"one","two","three"};
String *stored[100];
int numarrays=0;

void setup() {
  Serial.begin(115200);
  testpassarray(test1);
  testpassarray(test2);
  reprint(0);
  reprint(1);
  test2[3]="four";
  test2[1]="TWOTWOTWO";
  reprint(1);
}

void loop() {
}

void testpassarray(String *elements){
  stored[numarrays]=elements;  
  numarrays+=1;
  Serial.println("");
  Serial.println((unsigned long int)elements,HEX);
  Serial.println(elements[0]);
  Serial.println(elements[1]);
  Serial.println(elements[2]);
}

void reprint(int whicharray){
  
  String elements[10]; ////  This line needs to setup "elements" to point to the String array referenced by stored[whicharray]

  Serial.println("");
  Serial.println("");
  Serial.println((unsigned long int)stored[whicharray],HEX);
  
  int objectNumber=0;
  while (stored[whicharray][objectNumber]!=""){
    Serial.print(objectNumber);
    Serial.print(" = <");
    Serial.print(stored[whicharray][objectNumber]);
    Serial.println(">");
    objectNumber+=1;    
  }
 
}


Which gives the output:

Code:
200706F0
1
2
3

20070790
one
two
three


200706F0
0 = <1>
1 = <2>
2 = <3>


20070790
0 = <one>
1 = <two>
2 = <three>


20070790
0 = <one>
1 = <TWOTWOTWO>
2 = <three>
3 = <four>
22  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 10:35:40 am
Quote
It is the bits in red that are the issue, how do I read the whole String from the global array using just the pointer stored in the global array "stored[]"
They are an issue because they make no sense. elements is not defined anywhere, so you can't print the data in elements.

Where you currently have elements, you want to have stored[whcihArray].
Code:
  int objectNumber=0;
  while (stored[whcihArray][objectNumber]!=""){
    Serial.print(objectNumber);
    Serial.print(" = <");
    Serial.println(stored[whcihArray][objectNumber]);
    Serial.println(">");
    objectNumber+=1;   
  }

Paul,

Thank you!  I know that referring to a non existent array makes no sense but I was just trying to show what I needed to do.

It now works which is brilliant and I should be able to transfer that to the main program but I'd have never worked that out!!

It doesn't seem at all obvious!

I'm not sure I completely understand it though smiley-grin
23  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 10:02:52 am
Quote
  String elements[10]; ////  This line is still included in order to allow the sketch to compile!
Creating a local array of String objects is not the same as using a global array of String pointers. You have a fundamental problem with this code.

Code:
  String elements[10]; ////  This line needs to setup "elements" to point to the String array referenced by stored[whicharray]
But, it doesn't.

That line was only there to allow the sketch to compile so that I could check that the rest of it ran (I put the remark after it to explain that....)

That line can be deleted so giving:

void reprint(int whicharray){
   
  Serial.println("");
  Serial.println("");
  Serial.println((unsigned long int)stored[whicharray],HEX);
 
// This is the important section. How do I actually access the String from the String array at
// position "objectNumber" from the array stored at location "stored[whicharray]" in order to
// test it for being null and to output it to the serial monitor.

  int objectNumber=0;
  while (elements[objectNumber]!=""){
    Serial.print(objectNumber);
    Serial.print(" = <");
    Serial.println(elements[objectNumber]);
    Serial.println(">");
    objectNumber+=1;   
  }
 
  // release any variables etc
 
}


It is the bits in red that are the issue, how do I read the whole String from the global array using just the pointer stored in the global array "stored[]"
24  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 09:53:49 am
Quote
and crucially once that is done how do I use the address in stored[] to actually pull the data from the original global array?
The array, stored, is a collection of pointers to arrays. That makes it a 2D array, as I mentioned earlier.

stored[ 0 ][ 0 ] is a pointer to the first element of the first array. stored[ 0 ][ 1 ] is a pointer to the second element of the first array. stored[ 1 ][ 0 ] is a pointer to the first element of the second array.

Thanks,  I must have mis-understood something said because how you described it in the previous post is how I had it originally smiley-grin

So current position is that the function "testpassarray(String *elements)" passes the String array to my function which then records the global array's address in the global array stored[] and just for good measure it prints the address & contents to the Serial monitor....

So the next thing is the function "reprint(int whicharray)"

the current code is:

Code:
String test1[10] = {"1","2","3"};
String test2[10] = {"one","two","three"};
String *stored[100];
int numarrays=0;

void setup() {
  Serial.begin(115200);
  testpassarray(test1);
  testpassarray(test2);
  reprint(0);
  reprint(1);
}

void loop() {
}

void testpassarray(String *elements){
  stored[numarrays]=elements;  
  numarrays+=1;
  Serial.println("");
  Serial.println((unsigned long int)elements,HEX);
  Serial.println(elements[0]);
  Serial.println(elements[1]);
  Serial.println(elements[2]);
}

void reprint(int whicharray){
  
  String elements[10]; ////  This line needs to setup "elements" to point to the String array referenced by stored[whicharray]

  Serial.println("");
  Serial.println("");
  Serial.println((unsigned long int)stored[whicharray],HEX);
  
  int objectNumber=0;
  while (elements[objectNumber]!=""){
    Serial.print(objectNumber);
    Serial.print(" = <");
    Serial.println(elements[objectNumber]);
    Serial.println(">");
    objectNumber+=1;    
  }
 
  // release any variables etc
 
}

which gives the output:

Code:
200706F0
1
2
3

20070790
one
two
three


200706F0


20070790

based on knowing the address of the global String array which is stored in the array "stored[location]" how can I print the contents of that array to the serial monitor?

void reprint(int whicharray){
  
  String elements[10]; ////  This line is still included in order to allow the sketch to compile!

  Serial.println("");
  Serial.println("");
  Serial.println((unsigned long int)stored[whicharray],HEX);
  
// This is the important section. How do I actually access the String from the String array at
// position "objectNumber" from the array stored at location "stored[whicharray]" in order to
// test it for being null and to output it to the serial monitor.

  int objectNumber=0;
  while (elements[objectNumber]!=""){
    Serial.print(objectNumber);
    Serial.print(" = <");
    Serial.println(elements[objectNumber]);
    Serial.println(">");
    objectNumber+=1;    
  }
 
  // release any variables etc
 
}
25  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 09:53:19 am
Thanks,  as per the example I'm using a null entry to signify the last entry.

I will read the array in the add function and store the number of entries.

Do you intend to create an internal copy of the array supplied, or only record the address of the array that you were supplied with? Obviously in the latter case you will be screwed if the caller then changes or disposes of the array.

For now I am looking at just recording the actual address.  The add call is the user's opportunity to pass the data once passed they must use the update function to change things because this also updates the screen.
26  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 08:30:00 am
I really do appreciate all your help in this matter.  The test program was created just to find the answers.  I couldn't really use the actual program as it is 7000 lines of code spread across multiple files.

once I understand this using the test program I can transfer that understanding to the actual library....

27  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 08:27:07 am
Quote
1) So how do I pass the address of the string array to the function?
You don't have a string array. You have a String array. The differences are crucial. The address of the array and the address of the first element in the array are, by definition, the same thing. You can use either &test1[ 0 ] or simply test1.

Quote
2) If I have the String array address how do I access the array itself?
Serial.println(test1[ 0 ]);
Serial.println(test1[ 1 ]);
etc.

When you store the pointer to a one dimensional array in a one dimensional array, you are creating a 2D array.

elements[ 0 ][ 0 ] is the same as test1[ 0 ] if elements[ 0 ] is pointing to test1.

Thanks, "strings" was a typo, you've pulled me up on that one before smiley-grin.  I am only looking at Strings here.....

I have tried calling the function with testpassarray(&test1[]);  and   testpassarray(&test1);

I get an error due to the type in the function....  What type should it be to receive the pointer and how do I implement it?


void testpassarray( <what type> elements){
  stored[numarrays]=elements;   // store the address in the stored[] array as a pointer to the actual array
  numarrays+=1;
  Serial.println("");
  Serial.println((unsigned long int)elements,HEX);   // was used to show the address but can be ignored
//  Serial.println(elements[0]);
//  Serial.println(elements[1]);
//  Serial.println(elements[2]);

}

and crucially once that is done how do I use the address in stored[] to actually pull the data from the original global array?
28  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 08:20:13 am
What I am trying to do is allow the user to pass a function:

addCycleStringButton(word x,word y,word xs,word ys,long colour,long borcolour,long textcolour,long presscolour,long presstextcolour,byte borwidth,String top,word xo,word yo,int font,int initialstate,String* elements,int cyclexo,int options,bool visible,int URN);
 
Where the variable passed in red is an array of elements for a drop down list.

You need to provide your function with a way to know how many items are in the array. From what you have said so far, your code does not know this already so the caller needs to prove the information in some form. The two options I can see are (1) add an argument to receive the number of items in the array, or (2) require that the array have some special value such as a null pointer in the last position that your library code can detect.

You also need to decide whether you are going to create a copy of the array that was passed in, or merely remember the pointer you received. If you only store the pointer then you rely on the caller retaining the array intact for as long as you need it and this introduces the risk of some nastybugs if the caller gets it wrong; if you take copy the array, obviously this needs extra memory.

Implementing any of these approaches is simple enough once you have decided which approach you want to take.

Thanks,  as per the example I'm using a null entry to signify the last entry.

I will read the array in the add function and store the number of entries.
29  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 08:02:23 am
Quote
OK, just realised what you are saying and that the array is created as a local variable and passed rather than the address.....
That's true here:
Code:
void setup() {
 test1[0]="1"; test1[1]="2"; test1[2]="3";
 test2[0]="one"; test2[1]="two"; test2[2]="three";
 Serial.begin(115200);

  testpassarray(test1);

It's not true here:
Code:
String test1[10] = {"1","2","3"};
String test2[10] = {"one","two","three"};
String *stored[100];
int numarrays=0;

void setup() {
  Serial.begin(115200);
  testpassarray(test1);

The first code pass a pointer to the local array to the function.
The second code passes a pointer to the global array to the function.

Quote
So how can I pass the address of the global variable to the store function
Use the second code, there the array variable IS a global variable.

Quote
How do I access the Strings of the global array whilst inside either function when I have the address?
Just like you are doing in the second code.


I don't understand how version 1 and version 2 are not the same.  Both of the arrays are created globally I just stick the contents into the already created array in the original version and stick them in at the creation time in the second one.

1) So how do I pass the address of the string array to the function?
2) If I have the String array address how do I access the array itself?
30  Using Arduino / Programming Questions / Re: Storing an array pointer in an array! on: May 27, 2013, 07:45:45 am
OK, just realised what you are saying and that the array is created as a local variable and passed rather than the address.....

So how can I pass the address of the global variable to the store function

AND

How do I access the Strings of the global array whilst inside either function when I have the address?

I tried:

testpassarray(&test1);

but it doesn't like it.....
Pages: 1 [2] 3 4 ... 30