onsdag 23 mars 2011

Progress updates

I have been writing and rewriting the network code for Chrex for a while now..
and it is starting to take form, when the network is finished, the "visual" improvements will be more rapid. not much to show now. I will write a little howto on how to make a good network interface for games later.

There have also been some progress with Kinglo, i have to update with a new download mirror some time soon.. I have also compiled it for Win32, but it requires 60Mb of dll:s, and that is something that takes too long for me to upload, so i wont host it if no one requests it. there have been some progress in recognition of written chinese characters, but its not good enough yet. we know how to make it better, we have just not had the time to improve it.

I have no updates for the STM32 platform, but i have bought a battery and a mic for it, will solder it together soon. will make a simple drawing program for it and then try to get pocketSphinx running on it.

måndag 14 mars 2011

Kinglo v0.4

A small update of Kinglo, I have resolved some bugs, and made the interface more smooth.

Kinglo v0.4 Download

söndag 13 mars 2011

Kinglo an application to help learning Chinese

As i have written earlier, I am now in China and are struggling with the language.
To make it more fun to learn words and make it easier I wrote an application in Qt to test the words. It turned out to be an success, and now after 3 days of development i got a friend that joined in. He is trying to get Character recognition to work with the help of OpenCv. This is to test your writing skills while writing Chinese characters. Meanwhile I have cleaned up the code and fixed some bugs.
I will then try to add voice recognition with the help of CMUSphinx. To help training the pronunciation of words. This project have escalated in quite short time.. But what to do when programming is way much more fun then learning a language :) Here are some pictures and a tar.gz for those who wants to test it.
currently only supports 64bits Linux. I will make a port of it to my Nokia N900 when i got the development environment set up.

You can of cause add your own words and maybe even use it for another language.


 Kinglo v0.3  Download

Pen device

I have bought a cheap Chinese writing pad
I payed 35rmb for it, its about 5$ And i was not too surprised to find out that there where no linux drivers for it. 
So what to do?
lsusb gave this:

Bus 006 Device 003: ID 04b4:fef3 Cypress Semiconductor Corp.

I opened a terminal and run dmesg and got this:
[35842.176268] input: PenPower Touchpad PenPower Touchpad as /devices/pci0000:00/0000:00:1d.0/usb6/6-1/6-1:1.0/input/input12
[35842.176547] generic-usb 0003:04B4:FEF3.0005: input,hidraw1: USB HID v1.10 Device [PenPower Touchpad PenPower Touchpad] on usb-0000:00:1d.0-1/input0
This looked promising, but could not find a program to use it.

i checked "xinput list" which gave me:
⎡ Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                  id=4    [slave  pointer  (2)]
⎜   ↳ ETPS/2 Elantech Touchpad                    id=13    [slave  pointer  (2)]
⎜   ↳ Dexin Corp.  Saitek  Game  Mouse            id=10    [slave  pointer  (2)]

So my pad have not been added as an input device.

i checked that i actually got any input by running:
sudo cat /dev/hidraw1

and i got something like this on random input:
� {� ~� �� �� � � � �# �& �& �V 7^ 7h 7u 7� 7


I wondered what kind of interface it used..
so i piped the input from /dev/input/hidraw1 to a text file

 sudo cat /dev/hidraw1 > lol

And then i pressed one button several times. and then aborted and checked it with a hex editor

ghex2 lol

 i got something like this:

00 00 00 00 02 00 00 00 00 02 00 00 00 00 02 00 00
00 00 02 00 00 00 00 02 00 00 00 00 02 00 00 00 00

which can be changed re-formated to:


00 00 00 00 02
00 00 00 00 02
00 00 00 00 02
00 00 00 00 02
00 00 00 00 02
00 00 00 00 02
00 00 00 00

and i did the same procedure for all the three buttons.

button1 got
00 00 00 00 02

button2 got
00 00 00 00 04

button3 got
00 00 00 00 01

pen down got
XX XX XX XX 08

to make this more easy to see i printed it in binary.
b1 = 0000 0000 0000 0010
b2 = 0000 0000 0000 0100
b3 = 0000 0000 0000 0001
P = XXXX XXXX XXXX 1000

After analysing the pen input for a while it became obvious that the input was formated as follows:

the first byte is the X positon and when it overflows it increases the second byte.
1111 0000 -> 0000 0001
The same applies for the third and fourth byte but for the Y axis.
I actually got disappointed that it was so easy to reverse engineer the interface..

No pressure sensitivity here! but i did not expect that.

I created a wrapper to send the input to the Xserver:
first some offsets:
/* gcc -g -Wall -o xtestmotion xtestmotion.c -L /usr/X11R6/lib/ -lX11 -lXtst */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <X11/extensions/XTest.h>

#define messageSize 5

int main( int argc, char *argv[] )
{
float pad_x = 70, pad_y = 180, pad_width=1255, pad_height=1354;
float canvas_x = 0, canvas_y = 0, canvas_width=1366, canvas_height=768;

        int x,y;
        Display *dpy;
        FILE *hiddev;
        int packet[messageSize];

        dpy = XOpenDisplay( NULL );
        assert(dpy);

        hiddev = fopen("/dev/hidraw1", "r");
        assert(hiddev);
      for(;;)
        {
            packet[0] = getc(hiddev);
            packet[1] = getc(hiddev);
            packet[2] = getc(hiddev);
            packet[3] = getc(hiddev);
            packet[4] = getc(hiddev);
           

            if(packet[4] & (1 << 1))
                printf("\nButton 1\n");
            if(packet[4] & (1 << 2))
                printf("\nButton 2\n");
            if(packet[4] & (1 << 0))
                printf("\nButton 3\n");
            if(packet[4] & (1 << 3))
                printf("\nPen Down\n");
                           

            //if the pen is down aka you are drawing/writing something
            if(packet[4] & (1 << 3))
            {
                    x = (packet[0]+255*packet[1] -pad_x)*(canvas_width/pad_width) + canvas_x;
                    y = (packet[2]+255*packet[3] -pad_y)*(canvas_height/pad_height) + canvas_y;

                    XTestFakeMotionEvent(dpy, -1, x, y, CurrentTime);
                    XTestFakeButtonEvent(dpy, 1, 1, CurrentTime);
            }
            else
            {
                    //mouse button is not pressed any more
                    XTestFakeButtonEvent(dpy, 1, 0, CurrentTime);
                    //mouse button released is not registered in all applications if the mouse is not moved
                    XTestFakeMotionEvent(dpy, -1, x+1, y+1, CurrentTime);

            }

            XFlush(dpy);
        }
        return 0;
}

and then compile, and start a painting program. i used myPaint.
well, i am not an artist but here is my first drawing in myPaint using a pad.
Next up, how to write a real driver for this pad. (when i get time and motivation)

Development Boards

I have recently bought a STM32 ARM Cortex M3 development board from a Chinese company. They actually got some documentation in English :)
After some hours of hacking and some chatting with the guy who sold me the board, i succeed to compile, convert and flash the open-source project that this "mp3/4  player" is based on.  So now it got Linux support, i had to pay 430rmb for it, it is about 65$. But then i got a jtag and some other things too.

Next step on this project is to port the project from the current Keil uVision .uv2 project file, to a makefile using arm-gcc.  The system uses runns uC OS II and have its own GUI. I have bought a small LiPo battery and a mic for it.
I will try to make a drawing application and some kind of voice/sound triggering system.

onsdag 2 mars 2011

Network network network.

I have begun on the network code now, but i am sick so its hard to think straight.
Its just a basic multi-client chat server for now. I will continue with it when i feel better, or i will probably have to rewrite the entire thing..