====== Resources ======
=====XO Laptop=====
====Getting Started====
=== General Tips ===
- An XO can be installed with one of many Sugar(OS) versions. You may or may not need to have the most updated version of Sugar. See the table for what versions have been installed at CCCS: [[xoresources#Version Numbers for XO-1 laptops at CCCS]]
- There is no password for root so it is fairly easy to brick the XO
- CTL-ALT-ERASE is the XO equivelent to CTL-ALT-DEL on a windows computer, you also need to do this anytime you make a change in Terminal before it will take effect
- When the touchpad gets too sensitive it needs to be recalibrated; for instructions on how to do this look at issue 4 in the [[issues#issue 4| Past Issues]] section
- The battery tends to die in about 1.5-2 hrs of constant use
- Be very aware of the [[xoresources#Machine Information|hardware limitations]]
- There is a slot on the lower right hand side of the screen where a SD card can be inserted if you need extra storage space.
- The [[http://en.flossmanuals.net/xo/|floss manual]] is a great place to get more information on the XOs.
===Investigating the XO===
These are general ideas of things you should do and understand before trying to program for the XO
* Turn on your XO, go to the control panel, give it a new name, and choose a new color icon for your XO
* Flip through and understand the different views: Neighborhood, Group, Home, and Activity
* Neighborhood: Press the circle on the left side of the keyboard that has a ring of dots around it
* Group: The circle next to the neighborhood view key that contains three dots
* Home: the circle located next to the group view, and containing a single dot
* Activity:The fourth button in the row of keys, It is a circle with a square in the middle
* Look at the information available in the frame
* The frame is the square in the top right corner of the keyboard
* Investigate the journal and how to open and save files there
* Investigate the wireless networks available and how they appear
* Go to the Terminal Activity and play around, try to figure out the filesystem layout
* Note that there are no folders in the journal
=== Sugar GUI ===
Sugar is the [[http://fedoraproject.org/|Fedora Linux]] based operating system used by [[http://laptop.org/en/|OLPC]] on their XO laptops and now maintained by [[http://www.sugarlabs.org/|SugarLabs]]. For more information on sugar look at the [[http://en.flossmanuals.net/Sugar/|floss manuals]]
==== Preparing for crashes ====
* DO NOT try to open more than three activities at the same time
* Save work early and often
* Create a USB drive for your group with the image of the [[http://wiki.laptop.org/go/Sugar|operating system]] so that if you brick your XO is can be fixed quickly.
* Keep a backup copy of all of your code on a USB or another computer
=== Reflashing ===
Reflashing will restore the XO to its factory settings. This process can be used for upgrading or downgrading the XO. Directions can be found in the [[http://en.flossmanuals.net/xo/ch026_how-to-reflash/|Floss manual]]. While off, insert a USB stick with the image to reflash with, and while holding down the four game buttons, power on the XO.
=====Running Sugar=====
==== Version numbers for XO-1 laptops at CCCS ====
* XO series: (CT4Y machine: XO-1)
* Sugar OS version: (CT4Y machine: 8.2.1 if not upgraded)
* Python version: (CT4Y machine: 2.5.1)
* PyGame version: (CT4Y machine build 802: 1.8.0, CT4Y machine build 852: 1.8.1)
*
import pygame.version
print "PyGame version:", pygame.version.ver
* OLPCGames version: (CT4Y machine: won't be installed. It is only installed on xo machines that are used to develop games and publish xo files. xo files can be transferred to other xo machines without OLPCGames.)
* Security: disabled
====Machine Information====
=== Version Numbers ===
See [[http://wiki.laptop.org/go/How_to_check_the_OS_and_firmware_versions|this page]] which describes how to check your XO version. The information is most likely found under "Control Panel : About my XO".
[[http://wiki.laptop.org/go/Release_notes/|Build, release, and update information.]]
CCCS has XO-1's with build 802.
"OLPC is not the only one making XO-1 operating system builds. You can also obtain builds from others in the wider community" ([[http://wiki.laptop.org/go/F11_for_XO-1|link]]).
* Sugar Labs build: [[http://wiki.sugarlabs.org/go/Dextrose|Dextrose]], Sugar 0.88, Fedora 11.
[[http://wiki.laptop.org/go/OLPC_Firmware_q2e45#Which_Firmware_Do_You_Have.3F|How to differentiate between XO-1 and XO-1.5?]]
Success with getting to the [[http://wiki.laptop.org/go/Ok|OK]] prompt by holding the "X" game button when powering on, and then hitting ESC when prompted to halt the normal startup. So, the laptops at CCCS all appear to be unsecured, and that we will not need a developer key.
===Differences between XO versions===
| ^ Xo-1 ^ XO-1.5 ^XO-1.75 ^
^ Number of dots on hinge | none | three | seven |
^ Wiki Pages |[[http://wiki.laptop.org/go/XO-1|XO-1]]|[[http://wiki.laptop.org/go/Hardware_specification_1.5|XO-1.5]]|[[http://wiki.laptop.org/go/XO_1.75_C2|XO-1.75]]|
^ DRAM | 256 MiB | 1 GiB | n/a |
^Mass Storage | 1024 MiB | 4 GiB | n/a |
^Fedora | varied | 11 | 14 |
^Python Version |n/a | v2.6 | v2.7 |
====Emulation====
=== Emulating the XO ===
* The XO Laptop Wiki no longer recommends using the QEMU emulator for emulating the XO. For new information on emulating the XO look here:
* [[http://wiki.laptop.org/go/Emulating_the_XO | Emulating the XO]]
* [[http://wiki.sugarlabs.org/go/Sugar_on_a_Stick|Sugar on a Stick]]
Install the sugar package that comes with Ubuntu to use their Sugar Emulator. You can actually open up two different emulators and have them act as two different XOs.
Open two different emulators using these two seperate commands:
ubuntu-prompt$ SUGAR_PROFILE=cat sugar-emulator
ubuntu-prompt$ SUGAR_PROFILE=dog sugar-emulator
Note that cat and dog can be anything, as long as they are different.
===Sugar on a Stick===
With [[http://wiki.sugarlabs.org/go/Sugar_on_a_Stick|Sugar on a Stick (SOAS)]], you can boot directly to the Sugar OS on any machine without the need virtualizing or emulating Sugar. Students can use the journal on the stick to save their work.
==Windows==
In order to use sugar on a stick:
- Download the [[https://fedorahosted.org/liveusb-creator/|liveUSB creator]]
- Either download sugar on a stick onto the flash drive or use the liveUSB creator to install a version of sugar
- Follow the instructions for the USB creator to make a live USB
- **Note:** When making a live USB make sure to leave persistent storage space if you want to be able to save anything
- Restart your computer and look for an option to go into settings and change BIOS boot order so that the USB flash drive is first
- Some computers do have the option of booting to a USB drive without changing your settings, but if you intend to use sugar on a stick more than a couple of times, you will most likely want to change your BIOS settings anyway
- You should now boot to your flash drive. It is possible that you will have to press and extra key in order to successfully boot sugar on a stick, so pay attention
- For more information on booting to a flash drive look [[http://pcsupport.about.com/od/tipstricks/ht/bootusbflash.htm|here]]
==Mac==
Go [[http://wiki.sugarlabs.org/go/Downloads#Apple_Mac_OS_X|here]] for information on downloading sugar on a stick. The instructions are still in beta, and may not be effective.
===VirtualBox===
VirtualBox is useful for emulating a variety of operating systems including sugar. To download VirtualBox go [[https://www.virtualbox.org/wiki/Downloads|here]]. Once you have installed VirtualBox, you can press the "New" button and follow the instructions to create a virtual machine. Make sure that you select the correct operating system and version for Fedora. If your virtual machine is running slowly, you may want to allocate more RAM for it.
You will also need a virtual image of the OS you wish to emulate. You can get a .iso file of Fedora [[http://fedoraproject.org/get-fedora|here]]. The first time you run your virtual machine you will be prompted to provide a bootable drive. Use the disk image you just downloaded. If you run into errors attempting to run your virtual machine, your file may have been corrupted during the download. In this instance, you will have to re-download Fedora. Then, in VirtualBox, click on the yellow "Settings" button on the top of the screen. On the left side of that screen click on storage, and in the center panel select the cd image under IDE controller. On the right there should be a section labeled attributes. Under that it will say CD/DVD drive. Click on the little disk icon next to the drop down menu to select a new disk image.
Once you have a running emulation of Fedora, go to applications and then to add/remove software. Then search for sugar and select "The emulator for the Sugar Learning Environment" and any activities you want installed. You should then be able to run a sugar emulator.
===SOAS with VirtualBox===
It is also possible to use VirtualBox to run the Sugar on a Stick file. Go into settings for your Fedora virtual machine and change the disk image to the sugar on stick iso file. You should then be able to boot the Virtual Machine normally, and it will go directly to Sugar.
====Linux====
Familiarity with the Linux family of operating systems can be useful when dealing with the XO. If you haven't done so before, you might consider installing Linux on a machine you have access to. Ubuntu is a distribution that is particularly suited for beginners, and Fedora (the basis for the XO operating system) is good for intermediate users. The Gentoo installation process is considerably more involved, but upon completion you will have a better understanding and appreciation for Linux. For Windows users, the Ubuntu CD provides Wubi, a Windows program that allows Ubuntu to be installed without re-partitioning your computer. Sun Microsystem's VirtualBox provides Windows and Mac OS X users the ability to install any flavor of Linux as a virtual machine inside their existing OS, free of charge.
Some useful links related to Linux:
* [[http://www.virtualbox.org|Sun VirtualBox]]
* [[http://www.ubuntu.com|Get Ubuntu!]]
* [[https://help.ubuntu.com|Ubuntu Documentation]]
* [[http://fedoraproject.org|Fedora Linux]]
* [[http://carroarmato0.wordpress.com/about/bash-commands-list|List of common bash (command prompt) commands]]
* [[http://lug.udel.edu/dokuwiki/doku.php?id=articles:vim|Intro to the Vim text editor (UD Linux Users Group)]]
* [[http://www.gentoo.org/doc/en/handbook|The Gentoo Install Handbook, for dedicated Linux users]]
=====Programming=====
====Setting up a Development Environment====
The XO Laptop Wiki Provides these guides for setting up a development environment (These are //**extremely important!!**//):
* [[http://wiki.laptop.org/go/Developers|XO developer guide]]
* [[http://wiki.laptop.org/go/Developers/Setup|Setting up a development environment]]
==== XO API and Software ====
[[http://wiki.laptop.org/go/API_Reference|Reference Material and Samples for XO API]]
=== Extracting activity source code from .xo actvity files ===
When an application is ready for deployment on the XO, the source code is packaged into a .xo file which can be natively imported by the XO laptop. If you need to obtain the source code for an XO application, there are 2 possible ways to do it:
**If the program has been imported as an XO activity:**
* The source code may be found in the directory called /usr/share/sugar/activities/ACTIVITY_NAME.activity
**If you have access to the .xo file:**\\
A .xo file is really a compressed zip file: it can be extracted/opened to show the source code and other relevant files. Use:
* unzip FILENAME.xo -d DESTINATION_DIRECTORY
or a similar command. The source code for the application can be found in DESTINATION_DIRECTORY/bin/
===Downloading an activity===
* Copy the activity folder onto a flash drive
* Plug the flash drive into the XO and give it about 20 seconds to process
* Open the Terminal and type in the following commands pressing enter at the end of each line:
* cd /media
* ls (this will make the name of your flash drive appear)
* cd NameOfYourFlashDrive
* cd NameOfActivity.activity
* You may have to move down a couple of levels to get to this point using the ls and cd commands
* python setup.py dist_xo
* Go to the journal and find the activity there. If you click on it, it should install
If you have access to the .xo file then you can move into the flash-drive and then use the "sugar-install-bundle" command on the .xo file to install the activity on the XO. This method shows you each step of the installation process and is useful for debugging the bundling issues.
=== Bundling activities for the XO ===
* The XO Laptop wiki provides a lot of information for construction an activity:
* [[http://magazine.redhat.com/2007/03/26/building-the-xo-the-anatomy-of-an-activity/|Anatomy of an Activity]] -- A "Hello World" style activity guide
* [[http://wiki.sugarlabs.org/go/Development_Team/Almanac/Activity_Bundles|Activity bundles]] -- A more in-depth look at the structure of an activity bundle.
* [[http://en.flossmanuals.net/make-your-own-sugar-activities|XO Activities Guide from FLOSS Manuals]]
=== Mesh ===
Mesh Networks are no longer supported in XO 1.5 [[http://wiki.laptop.org/go/Mesh_Network_FAQ|source]]
=====Python=====
==== Install Python on your computer ====
=== For Windows Users: ===
- Python
- The first step in this process is to download a copy of the Python installer, this can easily be accomplished via Python’s website.
* Online guides will frequently point you toward ActivePython, while this program is highly rated it also requires an email subscription to access the download. For this reason I have avoided using it
- Go to Python’s website ( http://www.python.org )
- Click on “Downloads”
- Select the appropriate Windows installer and download it.
* Pygame will will mostly work with python 3 with a few exceptions [[http://www.pygame.org/wiki/FrequentlyAskedQuestions#Does Pygame work with Python 3?| Pygame FAQ]] but version 2 is still necessary for working on the XOs.
- After the file is completely downloaded, open the containing folder and open the executable file you just downloaded
- Follow the installer instructions
* This method of installation will also install the default Python IDE (called IDLE) for editing code, there is additional information needed to install Python for a different IDE such as Emacs, Eclipse, or VI
- Pygame
- Go to the official website for Pygame ( http://www.pygame.org/ )
- Click on the “Download” tab from the main page
- Under the sub-category Windows select the appropriate version of the installer for your machine (this is completely dependent on which version of Python was installed in Step1)
* If one were to install the build for Python 2.5.4 they would then want to download the Pygame installer file titled “pygame.x.x.x.win32-py2.5.msi” (where the x’s represent the version number of Pygame).
- Find and open this update to Python, it will run an automated installer
- Upon completing the setup be sure to test that functions and other aspects of Pygame are working correctly.
=== For Ubuntu (or similar Unix Distributions) ===
==Python==
* Being a developer friendly environment, Ubuntu comes with a pre-installed and fully operational version of Python
* Otherwise, one would the package manager of your specific distribution to download the necessary files…
* Ubuntu/Debian use aptitude:
# apt-get install python
* RHEL/CentOS/Fedora (this includes your XO) use yum:
# yum install python
* Gentoo/Sabayon use portage (consult documentation about USE flags for these distributions):
# emerge -av python
* These package managers are to be executed from the terminal command line, a shell (search “term”). They must be run with root (administrator) privileges, using the "sudo" command.
* To access Python, simply enter ‘python’ in the command shell; this will allow one to interact with the Python interpreter via the shell
* The pre-installed build of Python on Ubuntu does not come with an editor, however, it is fairly easy to configure Emacs or any other editor to be used with the language.
* To install Emacs you can, once again, use a package manager like apt-get
# apt-get install emacs21
* Python's default editor, IDLE, is also friendly for programmers new to python, and can be installed with the package manager.
==Pygame==
* Pygame is not a standard library for the Python programming language, therefore it is not included in your Ubuntu environment and must be installed
* As mentioned in Step 1, the package manager can be made use of to install applications and packages – the same can be done to install the Pygame graphics library using:
# apt-get install python-pygame
===Vista and PyGame Instructions===
If you have Python (2.5 or higher) and PyGame 1.8 installed, you should be good to go. I've tested crashRun on both MacOS X and Windows and I hope it'll run on Linux, too.\\
If you need Python, you can download it from: http://python.org/download/\\
And PyGame is available here: http://pygame.org/download.shtml \\
** Vista users note: when I tried the python installer on a Vista machine, the installer didn't modify the PATH to include Python (it appeared to on XP). You can set this variable by right-clicking My Computer in the Start menu, selecting Properties, Advanced, and then pressing the Environment Variables button. You'll need to append ";C:\Python25\" to the end of the PATH variable.**
==== Some Python Notes ====
**Recursion**
* Python is not optimized for tail recursion
* Recursion uses a lot of memory, not good on an XO laptop
* It is recommended to use loops instead of recursion when possible
==== Python Links ====
For those new to python, the following links can be of great benefit:
* [[http://docs.python.org|Python API documentation]]
* [[http://www.greenteapress.com/thinkpython|"How to Think Like a Computer Scientist - Python Software Design]] \\
Some Slides from previous classes:
* {{:courses:cisc366:share:the_if_statement.ppt|Conditional Statements}}
* {{:courses:cisc366:share:streams.ppt|Streams}}
* {{:courses:cisc366:share:python_gui_s.ppt|GUI programming}}
* {{:courses:cisc366:share:event_handling.ppt|Event Handling (usefull for GUI)}}
* {{:courses:cisc366:share:pythondocs.ppt|Python Comments and Pydoc}}
Python and Game development tutorials:
* [[http://wiki.laptop.org/go/Tutorials|Python Programming tutorials from wiki.laptop.org]]
* [[http://wiki.laptop.org/go/PyGTK/Hello_World_Tutorial|PyGTK Hello World]]
* [[http://wiki.laptop.org/go/Game_development_HOWTO|Game Development HOW-TO]] -- Provides a guide to setting up OLPCGames, a wrapper for pygame build for the XO environment (VERY USEFUL)
* [[http://wiki.laptop.org/go/Pygame_wrapper|OLPCGames in-depth information]] -- More in-depth guide on how to use OLPCGames (highly useful for creating activities).
* More tutorials exist at the Tutorials link above, check them out!
A separate page has been created that contains example python programs and games made by previous classes. \\
[[courses:ct4y/resources/python-examples|Python Example Programs]]
===== Pygame =====
Pygame provides a relatively simple API for programming games in python, and is incredibly useful for animations. It does not however, provide GUI elements such as buttons/text fields/menus/etc. These must be created by hand when using pygame.
**Pygame Tips**
* [[http://pygame.org/docs/ref/index.html|PyGame Basics Slides]]
* [[http://dev.laptop.org/~coderanger/pygame.pdf|PyGame Basics Slides]]
* [[http://code.google.com/p/pgu/|Helpful modules for writing games in PyGame]]
* [[http://www.daniweb.com/forums/thread181323.html#|PyGame + Vista issues]]
* [[http://www.pygame.org/docs/tut/newbieguide.html|PyGame Guide for Newbies]]
* [[http://www.amazon.com/Beginning-Game-Development-Python-Pygame/dp/1590598725/ref=sr_1_1?ie=UTF8&s=books&qid=1253498699&sr=8-1|Beginning Game Development with Python and Pygame]] -- Excellent book for those starting with both Python and Pygame.
=====Spyral=====
[[https://github.com/rdeaton/spyral | Spyral Link]]\\
[[http://www.eecis.udel.edu/~rdeaton/spyral|Spyral Documentation]]
=====Making a Game=====
These are two useful skeletons for building a game. These skeletons are compatible with various versions of sugar. The pygtk example is useful for games that don't require much animation. Otherwise, the pygame example is the better starting point.
{{:courses:ct4y:resources:skeletons.rar|}}
=====Virtual Machine=====
We have a virtual machine set up for our server needs. The information for it is located on [[virtualmachine|this]] page.
The database information is [[virtualmachine#database|here]]
==== Example Communication via POST ====
This file passes data via the POST method to the server. The server will log all data passed by $_POST["data"]. So in this example, "test data from python again" will be passed.
The server script [[http://cisc367.acad.cis.udel.edu/post-server.php|post-server.php]] catches this string and appends it to an output file [[http://cisc367.acad.cis.udel.edu/test-output.txt|test-output.txt]].
Try it out, and run this python script from your local machine!
'''
Richard Burns
November 28, 2010
Test script which passes information to the class apache server via the POST method.
The server script currently captures this information and appends it to a testing
output file, demonstrating one way that we can pass data to the server for it to
record.
Taken from:
http://docs.python.org/library/httplib.html
TODO: test size limitations of the POST
'''
import httplib, urllib
#params = urllib.urlencode({'milk': 1, 'eggs': 2, 'bacon': 0})
params = urllib.urlencode({'data': "test data from python again"});
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = httplib.HTTPConnection("cisc367.acad.cis.udel.edu:80")
#conn.request("POST", "/cgi-bin/query", params, headers)
conn.request("POST", "/post-server.php", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
===== Useful Links =====
* [[http://laptop.org/en/|OLPC homepage]]
* [[http://wiki.laptop.org/go/The_OLPC_Wiki|OLPC official wiki]]
* [[http://www.sugarlabs.org/|SugarLabs]]
* [[http://activities.sugarlabs.org//en-US/sugar/|Activities for Sugar]]
* [[http://www.olpcnews.com/|OLPC News]]
* [[http://en.flossmanuals.net/|Floss Manuals]]
* [[http://wiki.laptop.org/go/School_server|XS: The XO School Server]]
* [[http://www.chestercommunitycharter.org/|Chester Community Charter School (CCCS)]]
* [[http://www.python.org/|Python]]
* [[http://www.pygame.org/|Pygame]]
* [[https://github.com/rdeaton/spyral|Spyral]]
* [[http://www.eecis.udel.edu/~rdeaton/spyral|Spyral Documentation]]
* [[https://sites.google.com/site/computeteams4youth/|Compute Teams 4 Youth - Google Site]]