Aphasia Development Tutorial

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(OpenWrt)
(Runtime Environment)
Line 82: Line 82:
  
 
==Runtime Environment==
 
==Runtime Environment==
I am developing a vertical market product based on Openmoko, so I want my erlang platform alone to run (no window manager nor Zhone) when the phone is switched on.
+
If you want to include erlang VM in the boot process, simply add a line to /etc/init.d/x11 right after sleep 1:
 
+
<pre
===Quick and dirty===
+
  start() {
Remove packages Enlightenment and Illume.
+
  export DISPLAY=":0"
<font color="green">
+
  config_load x11
<pre>
+
  Xorg $ARGS &
opkg -recursive remove e-wm
+
  sleep 1 # give the xserver some time get initialized
 +
  erl -setcookie SFEWRG34AFDSGAFG35235 -name neo@192.168.0.202 -noshell -pa /root/trunk -s main start > debug.txt
 +
}
 
</pre>
 
</pre>
</font>
 
 
This is my  /etc/X11/Xsession.d/90xXWindowManager. I keep my erlang beam files at /home/root/trunk.
 
<font color="green">
 
<pre>
 
#!/bin/sh -e
 
/home/root/cean/start.sh -setcookie SFEWRG34AFDSGAFG35235 -name neo@192.168.0.202 -noshell -pa /home/root/trunk -s main start > debug.txt
 
</pre>
 
</font>
 
 
 
For Debian users it's /usr/bin/zhone-session. I keep my erlang beam files at /root/erlang/trunk
 
<font color="green">
 
<pre>
 
#zhone &
 
#matchbox-keyboard-toggle &
 
erl -setcookie SFEWRG34AFDSGAFG35235 -name neo@192.168.0.202 -noshell -pa /root/erlang/trunk -s main start > debug.txt
 
#exec matchbox-window-manager -use_titlebar no
 
</pre>
 
</font>
 
 
Replace "-s main start" with "-s your_module_name your_function_name"
 
 
 
All I have to do now is to re-start X whenever I want to run an uploaded app. This is what the last two menu buttons do in SciTe - stop X on the phone, and start X on the phone. As an alternative for stopping and starting X you can use Erlang's built-in [[hot code loading]].
 
 
 
[[Image:Scite.jpg]]
 
 
 
The svn xxx menu items is for version control if you are [[Using Subversion]].
 
 
Type
 
<pre>
 
ssh phone
 
</pre>
 
to get a terminal window and type
 
<font color="green">
 
<pre>
 
tail -f /debug.txt
 
</pre>
 
</font>
 
to read shell printout from the erlang process.
 
 
===The right way===
 
The better installation would be to install a minimal system and then add Erlang.
 
 
This is my runtime environment file system when erlang is installed "Quick-and-dirty" in FSO:
 
<font color="green">
 
<pre>
 
root@om-gta02:~# df -h
 
Filesystem          1K-blocks      Used Available Use% Mounted on
 
/dev/root              252544    93980    158564  37% /
 
/dev/root              252544    93980    158564  37% /dev/.static/dev
 
udev                      2048        44      2004  2% /dev
 
/dev/mmcblk0p1          497920        0    497920  0% /media/card
 
tmpfs                    60400        52    60348  0% /var/volatile
 
tmpfs                    60400        0    60400  0% /dev/shm
 
</pre>
 
</font>
 
 
Compare to this filesystem on OpenWRT minimal with Erlang installed:
 
<font color="green">
 
<pre>
 
root@OpenWrt:/# df -h
 
Filesystem                Size      Used Available Use% Mounted on
 
/dev/root              246.6M    39.6M    207.0M  16% /
 
tmpfs                    61.8M    44.0K    61.7M  0% /tmp
 
tmpfs                  512.0K        0    512.0K  0% /dev
 
</pre>
 
</font>
 
  
 
== Graphics ==
 
== Graphics ==

Revision as of 10:09, 17 July 2009

Contents

Installation

OpenWrt

Aphasia sits on the OpenWrt platform. It's very configurable, and light on system resources. There's a great forum at [1]

Go to OpenWrt, section Build custom image and follow the instructions. When you are at the point Configure target and packages you have to do some choises. Here is the minimum installation for Aphasia:

make menuconf

OpenWrt Kamikaze (r16871) Configuration

Target System (Samsung S3C24xx [2.6])  --->    Samsung S3C24xx [2.6]
Target Profile (Openmoko GTA-02 (minimal))  --->   Openmoko GTA-02 (minimal)

[*] Image configuration  ---> (192.168.0.202) LAN IP Address 

Xorg  --->    app  ---> <*> xauth
Xorg  ---> driver  ---> <*> xf86-input-tslib
Xorg  ---> driver  ---> <*> xf86-video-glamo
Xorg  --->   font  ---> <*> dejavu-fonts-ttf

Network  ---> <*> gpsd
Network  ---> <*> ser2net

Phone  ---> <*> freerunner-alsa-scenarios

Utilities  ---> <*> alsa-utils
Utilities  ---> <*> bash

Extra packages  --->  <*> zoneinfo-europe

Sound  --->   <*> lame
Sound  --->   <*> madplay

Languages  ---> <*> erlang


Install the GUI package ex11

Take a look at this example of what you can do with ex11 [2] Download from http://projects.openmoko.org/frs/?group_id=59 It is sufficient if you take the file at http://projects.openmoko.org/frs/download.php/753/ex11_lib.tgz and unzip it in your source directory.

In file /root/.profile

export DISPLAY=:0

In file /etc/hosts remove . (dot) at the end of line localhost.

127.0.0.1 localhost

In file /root/.erlang

io:format("Running Erlang from root~n").
code:add_patha("/root/trunk").

I keep my erlang source in /root/trunk

Copy Xauthority from host

scp .Xauthority phone:/root

Add localhost to it with xauth

xauth
add OpenWrt/unix:0 MIT-MAGIC-COOKIE-1  cfcc5ef98f9718f90154f355c0ae9f62
exit
cp .Xauthority /

Runtime Environment

If you want to include erlang VM in the boot process, simply add a line to /etc/init.d/x11 right after sleep 1:

 debug.txt
}

Graphics

I'm using vector graphics to produce new widgets. Vector graphics is lightweight and programmable, easy to scale and rotate, and the Byte-Size is small. Use any vector-capable drawing application. I happen to use AutoCAD LT on Wine, but please suggest an open source alternative and I will be happy to create another small conversion program to translate the new drawing file to erlang source. If you have access to AutoCAD, take dxf2erl.erl from here

Drawing a widget in AutoCAD LT

Screencast here

Convert drawing to erlang source

Screencast here

Personal tools

Installation

OpenWrt

Aphasia sits on the OpenWrt platform. It's very configurable, and light on system resources. There's a great forum at [1]

Go to OpenWrt, section Build custom image and follow the instructions. When you are at the point Configure target and packages you have to do some choises. Here is the minimum installation for Aphasia:

make menuconf

OpenWrt Kamikaze (r16871) Configuration

Target System (Samsung S3C24xx [2.6])  --->    Samsung S3C24xx [2.6]
Target Profile (Openmoko GTA-02 (minimal))  --->   Openmoko GTA-02 (minimal)

[*] Image configuration  ---> (192.168.0.202) LAN IP Address 

Xorg  --->    app  ---> <*> xauth
Xorg  ---> driver  ---> <*> xf86-input-tslib
Xorg  ---> driver  ---> <*> xf86-video-glamo
Xorg  --->   font  ---> <*> dejavu-fonts-ttf

Network  ---> <*> gpsd
Network  ---> <*> ser2net

Phone  ---> <*> freerunner-alsa-scenarios

Utilities  ---> <*> alsa-utils
Utilities  ---> <*> bash

Extra packages  --->  <*> zoneinfo-europe

Sound  --->   <*> lame
Sound  --->   <*> madplay

Languages  ---> <*> erlang


Install the GUI package ex11

Take a look at this example of what you can do with ex11 [2] Download from http://projects.openmoko.org/frs/?group_id=59 It is sufficient if you take the file at http://projects.openmoko.org/frs/download.php/753/ex11_lib.tgz and unzip it in your source directory.

In file /root/.profile

export DISPLAY=:0

In file /etc/hosts remove . (dot) at the end of line localhost.

127.0.0.1 localhost

In file /root/.erlang

io:format("Running Erlang from root~n").
code:add_patha("/root/trunk").

I keep my erlang source in /root/trunk

Copy Xauthority from host

scp .Xauthority phone:/root

Add localhost to it with xauth

xauth
add OpenWrt/unix:0 MIT-MAGIC-COOKIE-1  cfcc5ef98f9718f90154f355c0ae9f62
exit
cp .Xauthority /

Runtime Environment

I am developing a vertical market product based on Openmoko, so I want my erlang platform alone to run (no window manager nor Zhone) when the phone is switched on.

Quick and dirty

Remove packages Enlightenment and Illume.

opkg -recursive remove e-wm

This is my /etc/X11/Xsession.d/90xXWindowManager. I keep my erlang beam files at /home/root/trunk.

#!/bin/sh -e
/home/root/cean/start.sh -setcookie SFEWRG34AFDSGAFG35235 -name neo@192.168.0.202 -noshell -pa /home/root/trunk -s main start > debug.txt


For Debian users it's /usr/bin/zhone-session. I keep my erlang beam files at /root/erlang/trunk

#zhone &
#matchbox-keyboard-toggle &
erl -setcookie SFEWRG34AFDSGAFG35235 -name neo@192.168.0.202 -noshell -pa /root/erlang/trunk -s main start > debug.txt
#exec matchbox-window-manager -use_titlebar no

Replace "-s main start" with "-s your_module_name your_function_name"


All I have to do now is to re-start X whenever I want to run an uploaded app. This is what the last two menu buttons do in SciTe - stop X on the phone, and start X on the phone. As an alternative for stopping and starting X you can use Erlang's built-in hot code loading.


Scite.jpg


The svn xxx menu items is for version control if you are Using Subversion.

Type

ssh phone

to get a terminal window and type

tail -f /debug.txt

to read shell printout from the erlang process.

The right way

The better installation would be to install a minimal system and then add Erlang.

This is my runtime environment file system when erlang is installed "Quick-and-dirty" in FSO:

root@om-gta02:~# df -h
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root               252544     93980    158564  37% /
/dev/root               252544     93980    158564  37% /dev/.static/dev
udev                      2048        44      2004   2% /dev
/dev/mmcblk0p1          497920         0    497920   0% /media/card
tmpfs                    60400        52     60348   0% /var/volatile
tmpfs                    60400         0     60400   0% /dev/shm

Compare to this filesystem on OpenWRT minimal with Erlang installed:

root@OpenWrt:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               246.6M     39.6M    207.0M  16% /
tmpfs                    61.8M     44.0K     61.7M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev

Graphics

I'm using vector graphics to produce new widgets. Vector graphics is lightweight and programmable, easy to scale and rotate, and the Byte-Size is small. Use any vector-capable drawing application. I happen to use AutoCAD LT on Wine, but please suggest an open source alternative and I will be happy to create another small conversion program to translate the new drawing file to erlang source. If you have access to AutoCAD, take dxf2erl.erl from here

Drawing a widget in AutoCAD LT

Screencast here

Convert drawing to erlang source

Screencast here