Difference between revisions of "PND Cookbook"

From Pandora Wiki
Jump to: navigation, search
(Initial version)
 
(content moved to Introduction to PNDs)
 
(15 intermediate revisions by 8 users not shown)
Line 1: Line 1:
=== Using a start-up script ===
+
#REDIRECT [[Introduction to PNDs]]
In an ideal world, your application will be completely self-contained and can be run directly without any kind of set-up. It is however often necessary to tweak settings or request input from the user before starting your application. This is easily achieved by having the PND specify a shell script as its executable, which then in turn runs the application. The general structure of such a script is:
 
<pre>
 
#!/bin/sh
 
 
 
# Do stuff here...
 
 
 
./my_app
 
 
 
# Clean-up
 
</pre>
 
The first line identifies the file as a shell script, run using "/bin/sh" as the shell. The other lines beginning with a "#" are comments. Before the application is started, parameters can be gathered and/or set. The application itself then gets run by the "./my_app" line, which means "execute the file ''my_app'' in the current directory". When the application exits, it may be necessary to restore previous settings, delete temporary files, or perform some other kinds of cleaning up.
 
 
 
=== Setting $HOME ===
 
Many applications write configuration data to the user's home directory by default. This is not desirable on the Pandora as this directory resides on the NAND filesystem. It is however often possible to fool an application into writing to a different directory by setting the $HOME environment variable.
 
<pre>
 
export HOME=`pwd`
 
export HOME=$(pwd)
 
</pre>
 
 
 
=== Loading shared libraries ===
 
If your application requires shared libraries which aren't part of the standard firmware, they can be included in the PND along with the executable. In order for the system to be able to find the libraries, it must be told which directories to search. This can be done by setting the LD_LIBRARY_PATH environment variable. For example:
 
<pre>
 
export LD_LIBRARY_PATH=`pwd`      # Load libraries in the root directory of the PND.
 
export LD_LIBRARY_PATH=`pwd`/libs  # Load libraries in the "libs" subdirectory of the PND.
 
</pre>
 
 
 
=== Getting a file/directory ===
 
Its often necessary to ask the user for the location of a file or directory. This may be because your application requires files which aren't included in the PND itself, or simply because you application doesn't have a built in file picker. The commands below will prompt the user for a file, then run "my_app" with that file as an argument. Note the use of different sorts of quotes which is important for proper operation and handling spaces in file names.
 
<pre>
 
FILE="`zenity --file-selection --title='Select a File'`"
 
./my_app $FILE
 
</pre>
 

Latest revision as of 00:21, 29 October 2013