Showing posts with label mercurial. Show all posts
Showing posts with label mercurial. Show all posts

Saturday, January 19, 2013

RPi.GPIO, l'imposteur

Un module python pour ateliers raspberrypi

L'atelier PyHack qui est présenté par PYPTUG porte sur comment faire interagir le monde virtuel de la programmation avec le monde physique, avec Python, et souvent avec l'ordinateur Raspberry Pi. Mais pas tout le monde a un Raspberry Pi.

Les ateliers, et aussi les tutoriels de ce blog, sont faits pour apprendre l’électronique et le langage de programmation Python. Les techniques Python enseignées ici, peuvent être appliquées a une grande variété de problèmes.

Et donc, ca serait drolement bien si on pouvait rouler le meme code qui est fait pour le raspberry pi, sur un portable? J'ai donc décidé de m'attaquer au probleme.

L'imposteur

J'ai donc ecris un module RPi.GPIO de remplacement pour essayer le code pour Raspberry Pi qui inclus des access aux GPIO sur des plateformes autres que le Raspberry Pi. C'est-a-dire, votre portable.


Image
Votre portable aura une personnalité multiple

Comment?

C'est un module Python (en fait, un package RPi qui inclus un module GPIO) avec une implémentation des fonctions setmode(), setup(), cleanup(), input(), output(), prends en charge les 54 GPIO (états et directions), modes broadcom et board, fonctions vides pour les 4 set_*_event() - peut etre dans le futur j'y ajouterai la logique, et un peu de vitriol. Non, pas ca! Et un peu de logique pour les erreurs (genre, essayer d'acceder a un GPIO avant de l'assigner). Il y a meme un mode de débogage (gpio.debug = True).

Tout cela devrait etre suffisant pour rouler sur un portable du code Python fait pour le Raspberry Pi. Seul hic, pas moyen dans l’immédiat de simuler le changement d’état d'une entrée (simuler un bouton, par exemple).

On se le procure

Chez Mr. Bitbucket (bitbucket.org/fdion)

Pour cela il faut d'abord avoir l'outil Mercurial:

Sous un Linux de type debian
$ sudo apt-get install mercurial

Sous fedora
$ sudo yum install mercurial

Sous solaris / openindiana, c'est disponible par packagemanager.

Pour windows ou mac c'est ici: http://mercurial.selenic.com/

A noter que sous windows on peut aussi se procurer TortoiseHg qui ajoute un menu Mercurial (hg) quand on clique le bouton droit sur un repertoire, dans file manager: tortoisehg.bitbucket.org

Une fois que l'on a installé mercurial:

$ hg clone https://bitbucket.org/fdion/fablocker

On se retrouve avec les ateliers PyHack. RPi.GPIO l'imposteur fait partie du deuxième atelier.

C'est sous le répertoire fablocker/PyHack/workshop02

Il y a un fichier test.py qui importe RPi.GPIO. Comme il y a un répertoire du nom de RPi et a l’intérieur, un fichier python GPIO.py, test.py va importer ce GPIO plutôt que le module système. Pour en faire l'essai, on fait:

python test.py

(RPi.GPIO l'imposteur n'a pas besoin de sudo, ce qui n'est pas le cas du module système). Sur un vrai Raspberry Pi, dans tout autre répertoire l'imposteur ne sera pas trouvé. Mais dans workshop02, si on veux rouler test.py sur les GPIO du Pi, il suffit de renommer le répertoire RPi, et ainsi Python ne le trouvera pas.

Mise a jour


Si vous avez déjà un clone du projet Fablocker, pour faire la mise a jour, il suffit de faire (sous Windows utiliser le hg workshop ou bien la ligne de commande):


pi@raspberrypi ~/bitbucket $cd fablocker
pi@raspberrypi ~/bitbucket/fablocker $ hg pull http://bitbucket.org/fdion/fablocker
real URL is https://bitbucket.org/fdion/fablocker
pulling from http://bitbucket.org/fdion/fablocker
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 5 changes to 5 files
(run 'hg update' to get a working copy)
pi@raspberrypi ~/bitbucket/fablocker $ hg update
5 files updated, 0 files merged, 0 files removed, 0 files unresolved
pi@raspberrypi ~/bitbucket/fablocker $ 

Monday, December 10, 2012

Mercurial, tortoiseHg for Windows

By popular request

I have a lot of readers using Windows, and many who would like to develop on their PC, and then move the code to their Raspberry Pi (if they have a Pi) once they are ready to run. Before we get any further, if you plan on using a PC to develop applications for the Raspberry Pi, I would suggest you click on the menu above named "Sidekick". This is a tutorial to set up SSH and optionally X-Forwarding. Be sure to read through the end of the Sidekic tutorial, there is a link to Sidekick 2 (more advanced options).

Back to Hg

One question that has come up more than a few times (since I keep posting Python code on the blog and keep giving a Mercurial URL on bitbucket.org) is the following: how do I get and use Mercurial?

Mercurial is written in Python with platform independence in mind. It is available for Unix (OpenIndiana, Solaris) and Unix like systems (Linux, Mac OS/X). I've already posted the instructions for Raspbian (and hence all debian derived Linux versions) and Fedora. Today, I'm covering Windows.

Mercurial from the command line

A quick link to download any version of Mercurial:

mercurial.selenic.com/downloads/

32 bit windows with no admin rights required: Mercurial-2.4.1.exe
For the 64 bit windows version: Mercurial-2.4.1-x64.exe

After the download, run the program, and you are guided through an installation wizard. You now need to add the Mercurial path to the system's PATH. Once that is done, you have access to the hg command at the console.

Mercurial integrated in File Manager

Most Windows users will prefer the fully integrated version of Mercurial, through TortoiseHg: You can download TortoiseHg from: tortoisehg.bitbucket.org

The big green button on the right should download the right version for your operating system (Windows 32 or 64 bit, Linux with Gnome or Mac OS/X). After the download, run the program, and you are guided through an installation wizard.

Not only do you get mercurial in file manager, but you also get a command line mercurial: thg, so you don't have to install the console mercurial.



Image

Example

Let's clone my Fablocker repository that is on bitbucket. From the command line that would be hg clone https://bitbucket.org/fdion/fablocker (or thg using the command line TortoiseHg).

But let's try this from File Manager.

From File Manager, create a folder where you will store your repositories. Let's call it bitbucket. Inside that folder, create a new one called fablocker. Right click the folder. You now have a few menu entries for Mercurial. Hg Workbench and TortoiseHg. Select TortoiseHg, then select clone. A dialog appears:

Image


Change the source to read like the image:
source: https://bitbucket.org/fdion/fablocker

Destination should be to your bitbucket\fablocker directory already.

Now click the clone button. You are done!

Image
PyHack Workshop 02 test.py program in Visual Studio
If you use Visual Studio to edit your Python code, you will probably want the Visual Hg plugin for Visual Studio available at:

visualhg.codeplex.com

It is also possible to get Mercurial integration in other IDEs. I'll cover those in a follow up article