jQuery content slider for Typo3 with typoscript

I wanted to use a dynamic jQuery content slider with menu for Typo3. Something like you see on many modern pages: you have some sort of a menu and the content changes based on click events bound to them with some slide/fade etc. effect

I decided to create a hidden page and then use it’s sub pages as the menu elements for the slider. This way you can have multiple content elements grouped by pages. (to edit the content of a slide you edit a page in the tree. To add/remove more items to the menu you create a page within that tree)

In the image the “About credit cards” page has UID=99 and has the “Hide in menu” property checked. We will use this later in the typoscript.

I am usingTemplavoila so I’ve created and mapped the following lib paths: field_about_menu and field_about_ccontent

1. The Typoscript for the menu

lib.field_about_menu = HMENU
lib.field_about_menu.entryLevel = 0
lib.field_about_menu.special = directory
lib.field_about_menu.special.value = 99
lib.field_about_menu.wrap = <ul class="guide-menu"><li class="guide-menu-title">About Credit Cards</li>|</ul>
lib.field_about_menu.1 = TMENU
lib.field_about_menu.1.NO.subst_elementUid = 1
lib.field_about_menu.1.NO.doNotLinkIt = 1
lib.field_about_menu.1.NO.allWrap = <li><a href="javascript:" rel="#guide-content{elementUid}">|</a></li>

You can see here that I am wrapping an UL around the menu and LI around each menu item. I am also building the links by manually using the doNotLink property. In my javascript code I am using the “rel” attribute to identify the link between a menuitem and the content element i want to slide/fade to.

I am using subst_elementUid property to generate the rel attribute for each A tag.

2. The Typoscript for the content of the slider

Now comes the tricky part: building the contents of each slide.

I will query all the children of my hidden page. (“About credit cards” – has UID of 99)
Next I will query all the content elements that belong to each of the pages in the result set.
Finally I will wrap them in some tag. (in my case UL and LI, but it can be DIV-s or anything you like)


lib.field_about_ccontent = COA
lib.field_about_ccontent.wrap = <ul id="second-carousel">|</ul>
lib.field_about_ccontent.1 = CONTENT
lib.field_about_ccontent.1.table = pages
lib.field_about_ccontent.1.select.pidInList = 99

lib.field_about_ccontent.1.renderObj = COA
lib.field_about_ccontent.1.renderObj.9 = TEXT
lib.field_about_ccontent.1.renderObj.9.field = uid
lib.field_about_ccontent.1.renderObj.9.wrap = <li id=”guide-content|”>
lib.field_about_ccontent.1.renderObj.10 = CONTENT
lib.field_about_ccontent.1.renderObj.10.table = tt_content
lib.field_about_ccontent.1.renderObj.10.select.pidInList.field = uid
lib.field_about_ccontent.1.renderObj.11 = TEXT
lib.field_about_ccontent.1.renderObj.11.value = </li>

Look carefully at the code. You will see that the trick is to tap into the renderObject of the first query.
And then use the UID field to query the content elements of each page.

The code groups the content elements of each page by wrapping them in a LI tag and it will use the page’s UID to generate an ID attribute for this wrapper. (this ID will match the ones used in the REL attributes used in the menu links)

You may now use jQuery to bind click events to your menu and handle the content sliding with your favorite plugin.

On my web page I used something like this:

$(".guide-menu li").has("a").each(function() {
if (!($(this).children("a").hasClass("active"))) {
var nonactives = $(this).children("a").attr("rel");
$(nonactives).hide();
}
});

$(“.guide-menu li a”).click(function() {
if (!($(this).hasClass(“active”))) {
var tohide = $(“.guide-menu li a.active”).attr(“rel”);
$(tohide).hide();
$(“.guide-menu li a.active”).removeClass(“active”);
$(this).addClass(“active”);
var toshow = $(this).attr(“rel”);
$(toshow).fadeIn(1000);
}
});

$(“.guide-menu li a”).first().click();

Here is the output of the above code. (and feel free to comment/ask questions)

Setting up a Sanguino w/644P with an Arduino ISP

I’ve recently killed the Atmega328p chip on my Arduino Duemilanove board. (I accidentally touched a 2000mA power source to one of the output pins….)

Instead of buying a replacement chip I’ve decided to get the Atmega 644P and reuse my old Duemilanove board for USB and Power. 644P has more IO pins, more program memory and more SRAM.

Here are the full specs: DataSheet ATmega644P

I made a Sanguino variant with an ATmega644P on a perf-board as shown here: Sanguino Schematics. I only want to power the 644P chip and have an external oscillator.

This is a minimalist version without the voltage regulator circuitry and only the ICSP header. Everything will be powered and programmed by the old board. I’ve inserted an Atmega8 into the Arduino Duemilanove and flashed a Boot Loader using the BitBang method described below and uploaded the ArduinoISP sketch.

Tasks to be done:

1. Burn Boot Loader to the 644P chip
1.1 Burning via FT232RL BitBang Mode
1.2 Burning via Arduino as ISP

2. Upload the Blink sketch
2.a. Manually
2.b. via Arduino IDE


1. Burn Boot Loader to the 644P chip

1.1 Burning via FT232RL BitBang Mode

An extensive tutorial on the subject: http://www.geocities.jp/arduino_diecimila/bootloader/index_en.html

After installing “avrdude-serjtag” according to the tutorial, open up a terminal and try to read the signature of the 644p chip.

avrdude -c diecimila -p m644p -P ft0

If you can’t get a connection try -B 4800 (worked for me)


You can now copy the file ATMEGABOOT_644p.hex into the bin directoryof avrdude and flash it to the chip.

avrdude -c diecimila -p m644p -P ft0 -B 57600 -U flash:w:atmegaBOOT_644p.hex


Reset your board after detaching the ICSP. The debug LED should blink. (probably 3 times in about 6-8 seconds)

1.2 Burning via Arduino as ISP

You can check a tutorial on it here: ArduinoISP

!!! Upload the ArduinoISP sketch: Remember to upload the Examples/ArduinoISP sketch to your controller board. (You will use this to communicate with the Sanguino) This will turn your Arduino board into an avrisp programmer.

!!! You need to disable AutoResetOnSerialConnection Here is more info: DisablingAutoResetOnSerialConnection

For me I just put a 10uF cap to the 3.3v and the Reset pin but the 120 resistor works too. (make sure you get the polarity right)

Now try to get the signature of the device:

avrdude -p m644p -c avrisp -P com5 -b 19200 -V

You should get something like this. This guarantees a correct read.


You should get the Sanguino folder and copy it into Arduino IDE/hardware/

http://code.google.com/p/sanguino/downloads/list

You might need the 644p profile for avrdude.conf and the ATmegaBOOT_644P.hex

You can now flash the chip manually with avrdude or via Arduino IDE.

a.) Manually

avrdude -p m644p -c avrisp -P com5 -b 19200 -V -U flash:w:atmegaBOOT_644p.hex

You should get a confirmation at the end that all went well.

b.) via Arduino IDE.

To burn the bootloader you need to edit boards.txt files in the Hardware/Sanguino folder and change the content to this:

[code]
sanguino.name=Sanguino (w ArduinoISP)
sanguino.upload.maximum_size=63488
sanguino.upload.speed=19200
sanguino.upload.using=arduino:arduinoisp
sanguino.bootloader.low_fuses=0xFF
sanguino.bootloader.high_fuses=0xDC
sanguino.bootloader.extended_fuses=0xFD
sanguino.bootloader.path=atmega644p
sanguino.bootloader.file=ATmegaBOOT_644P.hex
sanguino.bootloader.unlock_bits=0x3F
sanguino.bootloader.lock_bits=0x0F
sanguino.build.mcu=atmega644p
sanguino.build.f_cpu=16000000L
sanguino.build.core=arduino
[/code]

In Arduino IDE go to Boards and select Sanguino (w ArduinoISP). Now go to Tools/Burn Bootloader/w Arduino ISP. All should go well.

2. Upload the blink sketch

Here is a small modified version of the sketch to loop through all the output pins and blink them.

[code]
void setup() {
for(int i=0;i<32;i++) {
pinMode(i, OUTPUT);
}
}

void loop() {
for(int i=0;i<32;i++) {
digitalWrite(i, HIGH); // set the LED on
delay(5);
digitalWrite(i, LOW); // set the LED off
delay(5);
}
}
[/code]

Make sure you have AutoResetOnSerialConnection disabled and that you get a correct signature read.

If you don’t you will get an error like this:

[code]
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9307
avrdude: Expected signature for ATMEGA644P is 1E 96 0A
Double check chip, or use -F to override this check.

avrdude done. Thank you.
[/code]

Or worse yet you might attempt to use the -F option and overwrite something on your main chip. Remember that if you mess up anything you can always use the ftdi bitbang method to re-flash the bootloaders to your chips.

All you need to do now is to choose Sanguino(w ArduinoISP) from your boards menu and click upload. All should be OK.


How to fix YouTube video playback on an Apple Powerbook G4 running MacOsX 10.4

I almost gave up on this, but luckily I found a good solution that works for me. I own a Powerbook G4 1Ghz 1.25Gb RAM. I noticed that altough movie playback is great in VLC when it comes down to the flash player it has horrible performance. In fullscreen mode even in 360p playback youtube stutters and hangs and does a performance of around 8-12 fps on my system.

Here is a step by step description of what I did. This is for Firefox so make sure you install it!

What we are trying to do is to change the flash video player for Youtube only. Forcing an alternative player that is better supported by the OS. This can be either VLC or Quicktime since both players support FLV and MP4 playback.

Step 1: Get Greasemonkey

In firefox you go to Tools->Add-ons->Get add-ons

Search for the word “greasemonkey” and click “Add to firefox”. After installing this will restart your firefox.

Step 2: Go to userscript.org and get “Youtube without flash auto” script

http://userscripts.org/scripts/show/50771

Click “install”. A window will popup allowing you to install the script.

Step 3: Go to youtube.com and open a video. The flash player will initialize and will stop. A new menu will appear under every video. Click the “YWOF Prefs” button. A config screen will appear.

Step 4: for default quality choose MP4 and the quiality you would like your vids to default to. I use the quicktime plugin so I chose MP4. For “player” leave “Generic”.

Step 4 (Optional): If you would like to use VLC make sure you download and install VLC and the VLC Internet Plugin. You can find both for MacOS 10.4 here: http://www.videolan.org/vlc/download-macosx.html Again: only do this if you are sure you want to use VLC. I am using QuickTime. No need to do VLC unsless QT doesn’t work for you.

Step 5: Next time you open any youtube video the QuickTime plugin will play it. Double click the screen to go to fullscreen mode and enjoy stutter-free youtube on your Powerbook G4 with MacOS 10.4.* (to exit fullscreen: double-click the video, as keyboard did not work for me)

Hope this helps. Figuring this out surely made my day since the biggest issue with my Powerbook G4 for me was the inability to use youtube.

EDIT: Upon further tweaking I noticed that the VLC plugin work much better for me then QT.

.

C64 keyboard in Arduino using multiplexers

I just bought a bunch of low cost 4051 analog multiplexers for use with my Arduino. I am working on a MIDI controller so I will need a lot of input both digital and analogical ones, so the multiplexers will come in handy to do analog reading using as few of the analog pins as possible.

As a first test I tried an adapter for a C64 keyboard, which has all keys placed in a 8×8 matrix of buttons.

The idea came from arduino playground where they explain the usage of multiplexers. The following image fits the c64 keyboard like a glove, so just go ahead and build the one on the right.

Link to more details: http://www.arduino.cc/playground/Learning/4051

Here is my solution. It’s the same circuit only on a perforated board. If you have the skills to make PCB-s, I really suggest to doing so.

And now for the code:

int v=0;

void setup() {
Serial.begin(9600);
Serial.print(“Hello”);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(13,INPUT);

}

byte bin[] = {
0,1,10,11,100,101,110,111};

int readKeyboard() {
int i,j,row,col,v, code;
byte r0,r1,r2;

code=0;
for(i=0;i<8;i++) {
for(j=0;j<8;j++) {
code++;
// address X
row = bin[j];
r0 = row & 0x01;
r1 = (row>>1) & 0x01;
r2 = (row>>2) & 0x01;
digitalWrite(2, r0);
digitalWrite(3, r1);
digitalWrite(4, r2);
// address Y
col = bin[i];
r0 = col & 0x01;
r1 = (col>>1) & 0x01;
r2 = (col>>2) & 0x01;
digitalWrite(5, r0);
digitalWrite(6, r1);
digitalWrite(7, r2);

// Read the actual Value
v = digitalRead(13);

/*
Serial.print(“(“);
Serial.print(j);
Serial.print(“:”);
Serial.print(i);
Serial.print(“)-“);
Serial.println(v);
*/

if(v==LOW) {
// instead of returning, you may use a buffer or whatever to keep track of all pressed keys
return code;
}
}
}
}

void loop() {
v = readKeyboard();
if(v>0) {
Serial.println(v);
}

delay(100);
}

Notes: make sure you click the SerialMonitor so you see some output. The above code will output the number of the key pressed.
For more information concerning the keyboard layout of the c64 here is a schematic of the key matrix.

(click the image to enlarge)

My hack of the day: an Infrared remote for XBMC / Debian

I now have xbmc installed on my server, which is plugged into my monitor via a looong extension cable. Having a wireless mouse for controlling used to be OK, but it got kind of annoying to find a flat surface every time you wanted to pause the movie or browse through directories.

So I thought it would be nice to attach an IR pickup and preferably use the unused buttons of my Samsung T240HD TV’s remote. When in PC monitor mode, the TV does not use it’s directional keys, OK, Escape and none of the Colored buttons, so mapping these would be perfect.

To use IR you need two things: 1. an InfraRed receiver and 2. some software to go with it. In my case I did not have a nice usb IrDA, so I had to make my own. Luckily it’s quite simple. All you need is and infrared pickup diode(old tv or whatever) and +5V to power it. The computer will pick up the signals via your computer’s audio line-in port. You simply build this contraption and hook it up to you line-inport: http://lirc.org/ir-audio.html

You can get +5V from any of your power connectors, if you have a multimeter make sure you have the correct tension before connecting everything to your sound card.

When everything is done, you can test it by enabling the Line-In playback on your PC and pressing some buttons. If everything is set up correctly you will hear strange noises when the IR receiver picks up any signals.

Now for the fun part: using LIRC to map unknown IR signals to keyboard events.

1. Install LIRC using aptitude or whatever, and make sure the programs irrecord and irxevent are installed.

2. You need to start up irrecord so you can test your connection and records some IR events.(i have mi input on the right channel of the sound input, depending on how you’ve set up your rig yours mith use the l parameter)

irrecord –driver audio_alsa –device hw@44100,r myConfigFileToBe

This will fire up irrecord and you can name your buttons after each successful read. You will also get a new config file which contains the codes of your remote.

Once this is done, it is time to test it:

1. Run the lirc daemon

lircd –driver audio_alsa –device hw@44100,r pathToYourConfigFileThatWasJustCreated

2. run irw

irw

When you push buttons on your remote, irx will look them up in your config file and display the appropriate events.

All we need now is to map this input to keyboard events. You do this by using a program called irxevent. Once the lirc daemon is running, you can start irxevent by supplying a config file which contains the mappings: you need to create this file manually!

Create a blank text file, and enter any number of mappings in the following form:

begin
prog = irxevent
button = YOURBUTTONNAMEFROMLIRCCONFIG
config = Key Page_Up CurrentWindow
end

begin
prog = irxevent
button = InfraOkButton
config = Key Enter CurrentWindow
end

and so forth…

When you are done, lunch irxevent like this

irxevent yourEventConfigFileName

Now test it: press some IR buttons and see if the keyboard events are fired.

From here, i just lunch XBMC and everything is working fine. (Note that XBMC does have support for lirc directly, you can use that aswell)

How to build XBMC in Debian (etch)

After many long hours of forum sweeping and googleing I finally managed to build XBMC in Debian. It took me exactly 18 hours to do this starting from scratch. (final build after satisfying all perquisites took about 3 hours)

Yes, it is possible to build and run XBMC in Debian without too much hassle.

Why: I have a linux machine running a server environment for my files, and I thought it would be nice to use it as a media center since it is always on. Since it is al set up i did not want to install an ubuntu on it just for the media center, so I had to build XBMC for Debian (etch)  from the sources. Unfortunately Debian is not yet supported by XBMC community, but you can obtain the source code and build it anyway. Here is what i did. (I am in no way a linux wiz, so this is probably not the best way to build it, but it should work)

My configuration: AMD K7 1300 Mhz, 768Mb RAM, GeForce MX440 SE using Debiean (etch) with Kernel Image 2.6.18-6-k7

Step 1 – Get the source code

(assuming you are root and are in your home folder)

(if you don’t have subversion installed: apt-get install subversion )

Step 2 – Install the required packages

Add the backports to your /etc/apt/sources.list

Edit the /etc/apt/sources.list and add contrib and non-free
Install graphics driver so when you run glxinfo you should see Direct rendering enabled.

Now install these packages.

I did my build by excluding faac and pulse audio.

This command will most likely FAIL at the first time you try it, so just get rid of the packages which are not found, and use a tool like aptitude to search for different naming. (lib in front of the name, and/or -dev at the end) My environment is very messy, so I am not sure which ones I had from different sources. Try running ./configure –disable-faac from your XBMC sources directory, and it will complain about what you are missing from the environment.

Step 3 – Configure script

Change to your sources directory and run the ./configure script. (for me it is linuxport/XBMC/)
If ./configure finished successfully you should try to run make
If your lucky enough it might run, but I had several issues with it.

For me the first fix was to re-run configure with disabled PulseAudio and faac.

Step 4 – Editing and running the makefile

From this point my serious issues started, I will list a few which i had, if you are lucky and make finishes successfully, you may skip this section 🙂

The sqlite3_prepare_v2() issue
I got a missing function error here, so i changed the line of code in question(in the file the error was coming from).

Changed the function name sqlite3_prepare_v2 to sqlite3_prepare

I guess my sqlite libraries are old, you might try updating yours.

The CPulseAudioDirectSound issue

I got an error in the file “AudioRendererFactory.cpp” in line 64 related to CPulseAudioDirectSound not being found. This was strange because i explicitly disabled Pulseaudio. I just commented out both lines of code in this section. (lines 64 and 65)

The smbclient issue

This was a strange issue, i don’t know why xbmc-s internal smbclient library does not work. In any case, I’ve installed smbclient via: apt-get install smbclient smbclient-dev

And edited the Makefile like this:

Find something like: OBJSXBMC += \
continued by path to libsmbclient-i486-linux.a, should be around line 314 and 315, and enclose it in /* .. */ block. (comment it out)

Next look for the LIBS=… line (around line 85) which contains all libraries and append: -lsmbclient to it’s end.

The xrandr.c issues
All of these can be solved by upgrading your libxrandr packages. I did this by manually fetching the files and requirements from the debian packages list. Etch has xrandr 1.1.0 i think, and xbmc requires at least 1.2.3

http://packages.debian.org/lenny/libxrandr-dev

You can get the deb file here and try to install it by: dpkg -i PACKAGENAME.DEB (it will tell you what it’s missing, and follow the links on the debian page, you will find them there. Get those packages, and install them the same way, then retry installing xrandr package)

Step 5 – Make Install

Once make has completed successfully (will take a few hours on slower machines) you can install xbmc.

Step 6 – Run and enjoy

Once you installed run it by typing “xbmc” in your terminal.

————————————–

I will try to keep this list updated as comments roll in with problems and solutions.

Have fun using XBMC, and thank the guys and babes at xbmc.org for making such a cool software.

How to run Fallout3 in linux with Wine on Ubuntu (nvidia)

To run Fallout3 installer and game in Wine, you need to download the source code, patch and compile Wine.

1. Download the wine sources

I use 1.1.8: http://ibiblio.org/pub/linux/system/emulators/wine/wine-1.1.8.tar.bz2

2. Get the following patches (save them to your computer):

– the mouse patch (mousepatch.diff)

http://bugs.winehq.org/attachment.cgi?id=15638

– the directx patch (driver.diff)

http://bugs.winehq.org/attachment.cgi?id=17130

3. extract the source code files within the archive to any folder, copy the patches into the the same folder, change directory to it and  run the following commands using a terminal:

patch -p1 < mousepatch.diff

patch -p1 < driver.diff

4. to build wine type the following:

./configure

Once ready, you will get some messages, make sure you download all required deppendencies should configure tell you so. (should you get an error sayin no opengl support and you are sure you downloaded libGL, go to /usr/lib and: sudo ln -s libGL.so.1 libGL.so)

Next run:

make depend

make

sudo make install

5. You should have a patched wine ready and installed. It’s time to get winetricks

http://wiki.winehq.org/winetricks

and use it to install vcrun2005, directx

6. type in “regedit” to bring up the registry editor. Open HKEY_CURRENT_USER/Software/Wine/Direct3D

– make a new string value: VideoDescription

– set it to something like: NVIDIA GeForce 8600M GT

– make another string value: VideoDriver

– set it to: nv4_disp.dll

– do a search on “MouseWarpOverride” and set it to: true

if it does not exist create the string value inside HKEY_CURRENT_USER/Software/Wine/DirectInput and add it as a new string value.

7. Install the game. Run the launcher and configure video options, then quit the launcher.

Start game with: wine Fallout3.exe

Everything should be set. If you have problems drop a line in the comments and we’ll try to figure it out.

———————————–

EDIT:

If xlive.dll gives you any trouble try installing this: Try this: http://www.microsoft.com/downloads/details.aspx?familyid=D6A69B9F-2AEF-4125-B162-EDF0AE922CAF&displaylang=en

You will also need XINPUT1_3.dll, which you should google around and download from somewhere.

Both dlls are ment for your .wine/drive_c/windows/system32/ directory.