I'm working on a project with a Matrix Orbital display. I'm trying to implement a screen change.
Sample Code snippet from manufacturer:
void returnToMenu(){
Serial.println("Return to menu"); //Let user know that the program will be returning to the main menu
byte scriptFileLength = 31;
switch(productSelected){
case 49:{
char* scriptFileName = {"Screen Tracking\\GTT35\\GTT35.bin"};
runScriptFile(scriptFileName,scriptFileLength); //Return to the main menu
}
break;
<remainder of select case deleted>
The screen change is called by passing the DECIMAL command 254 93 followed by the path to the .bin file associated with the desired screen
I'm trying to understand why a pointer is being used when passing the path to the .bin file?
Also, what's going on with the curly braces around the path name? Are they part of the string that's being sent, or a delimiter of some sort? edit - I guess the curly braces are there because the path name is an array?
In my case, I only have one screen change during bootup. I could just hard code the path into the function without passing it in.
That is the usual method of passing an array to a function. In this case, the .bin file name is stored in a null-terminated char array, and scriptFileName is a pointer to that array.
In this instance, the curly brackets are meaningless, and can be removed.
Of more concern, scriptFileName should be a const char*, not a char*, and scriptFileLength is set to a fixed value instead of determining the length of the .bin file name using the strlen() function. It is not even necessary to pass scriptFileLength to the runScriptFile() function, if that function always expects the char* to point to a null-terminated char array.
I thought that you need to declare the variable first, then point to it. Apparently the above line is doing it all in one go.
And also that the whitespace is after the asterisk (char* scriptFileName), not before (char *scriptFileName) Most everything I read about pointers has the asterisk attached to the type, not the variable, but I guess the whitespace is irrelevant?