EihiS

June 26, 2014

Linux : Reading the Mouse events datas from /dev/input/mouse0

Filed under: Raspberry 3.14, linux — Tags: , , , — admin @ 8:53 am

A simple program to check the /dev/input/mouse0 datas

Tested on the raspberry PI with GPM installed

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h>

#define MOUSEFILE "/dev/input/mouse0"
//
int main()
{
    int fd;
    struct input_event ie;
    //
    unsigned char button,bLeft,bMiddle,bRight;
    char x,y;
    int absolute_x,absolute_y;

    if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {
        printf("Device open ERROR\n");
        exit(EXIT_FAILURE);
    }
    else
    {
        printf("Device open OK\n");
    }
    //
    printf("right-click to set absolute x,y coordinates origin (0,0)\n");
    while(read(fd, &ie, sizeof(struct input_event)))
    {
        unsigned char *ptr = (unsigned char*)&ie;
        int i;       
        //
        button=ptr[0];
        bLeft = button & 0x1;
        bMiddle = ( button & 0x4 ) > 0;
        bRight = ( button & 0x2 ) > 0;
        x=(char) ptr[1];y=(char) ptr[2];
        printf("bLEFT:%d, bMIDDLE: %d, bRIGHT: %d, rx: %d  ry=%d\n",bLeft,bMiddle,bRight, x,y);
        //
        absolute_x+=x;
        absolute_y-=y;
        if (bRight==1)
        {
            absolute_x=0;
            absolute_y=0;
            printf("Absolute x,y coords origin recorded\n");
        }
        //
        printf("Absolute coords from TOP_LEFT= %i %i\n",absolute_x,absolute_y);
        //
        // comment to disable the display of raw event structure datas
        //
        for(i=0; i<sizeof(ie); i++)
        {
            printf("%02X ", *ptr++);
        }
        printf("\n");
    }

return 0;
}

The read() command is blocking for now.
The following C code does almost the same thing, with non-blocking option enabled this time:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h>

#define MOUSEFILE "/dev/input/mouse0\0"
//
int main()
{
    int fd;
    struct input_event ie;
    unsigned char *ptr = (unsigned char*)&ie;
    //
    unsigned char button,bLeft,bMiddle,bRight;
    char x,y;                                                            // the relX , relY datas
    int absolute_x,absolute_y;

    if((fd = open(MOUSEFILE, O_RDONLY | O_NONBLOCK )) == -1)
    {
        printf("NonBlocking %s open ERROR\n",MOUSEFILE);
        exit(EXIT_FAILURE);
    }
    else
    {
        printf("NonBlocking %s open OK\n",MOUSEFILE);
    }
    //
    printf("--------------------------------------------------------\n");
    printf("right-click to set absolute x,y coordinates origin (0,0)\n");
    printf("left+right click to EXIT\n");
    printf("--------------------------------------------------------\n");
    //
    while(1)
    {       
        if(read(fd, &ie, sizeof(struct input_event))!=-1)
        {
            //
            button=ptr[0];
            bLeft = button & 0x1;
            bMiddle = ( button & 0x4 ) > 0;
            bRight = ( button & 0x2 ) > 0;
            x=(char) ptr[1];y=(char) ptr[2];
            if(bLeft&bRight) { printf("\nright+left ,EXIT\n");break;}
            // computes absolute x,y coordinates
            absolute_x+=x;
            absolute_y-=y;
            // set absolute reference ?
            if (bRight==1)
            {
                absolute_x=0;
                absolute_y=0;
                printf("Absolute x,y coords origin recorded\n");
            }
            // show it!
            printf("X%i Y%i\n",absolute_x,absolute_y);
            fflush(stdout);
        }
    }
    //
    close(fd);
return 0;
}
314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

April 23, 2014

DSL on a toshiba 4600 satellite laptop…

Filed under: linux — Tags: , , , , — admin @ 10:40 am
  • Download and burn a Damn small linux 4.4.10 ISO (syslinux)
  • Install process : select framebuffer fb1024×768
  • After installing on HDD, first step :
  • Check and fine tune the Ethernet Adapter ( driver : EPRO100 )
    - Panel->Netcardconfig , and Panel->DHCP client toggle button : enable/disable if using a dhcp
    - use mii-tool to configure it properly ( ex : mii-tool -v eth0 ) : 10/100 , HD or FullDuplex..
    - perform several pings to be sure the connection works properly ( no eth0 hang-outs.. ) : errors can be checked fast by looking at the dmesg button of the Panel->System Stats
  • then enable gnu utils  ( busybox is really poor ) ,in DSL->App->tools->upgrade to GNU utils
  • enable aptitude : DSL->App->tools->Enable APT

–> Any error while downloading a file will corrupt the md5sum checksum process. if an error occured while downloading , remove the corrupted file and it’s checksum file before retrying the download process

X11 look

X11 look of DSL on the satellite 4600 laptop

314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

August 26, 2013

How-to activate the Pi SPI interface for 3.6.11+ kernel

Filed under: Raspberry 3.14 — Tags: , , , , , , — admin @ 10:41 am

Raspbian linux 3.6.11+ does not have SPI enabled by default.
the SPI is blacklisted in /etc/modprobe.d/raspi-blacklist.conf

Edit and comment (#) the SPI section in the file. Save and reboot.

Now, the SPI is listed when doing :

$ ls /dev/sp*

as /dev/spidev0.0 and /dev/spidev0.1 , wich are the 2 spi interfaces linked to the GPIO port ‘SS0 , SS1′ slave SPI “select” outputs.

Enjoy !

314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808

August 1, 2013

Raspberry pi : A LCD display hardware and software example

Following the previous article about the linux kernel module’s compilation, this post will expose a concrete example of hardware wiring to the Pi GPIOs , and also cover the software aspect, with the implementation of a kernel module who drives the hardware.

The basic idea, and schematic of the hardware, is here:

The Pi GPIO ports, P0 and P5 ( rev2 , raspi version) are visible.
Some GPIO outputs/inputs pins are connected to a 74hc574 latch , wich, in turn, is connected to the LCD display ( industry standard, HD44780 based display).

It’s not obvious, why there is a 74hc574 between the Pi and the LCD display. but, in fact, this ‘574 Latch is freeing 6 pins of the GPIO when the LCD does not have to be adressed. The only pin permanently occupied is the latch clock pin, wich latches the datas to THIS latch (adressing-like, on a microproc. bus). a little bit thinking will let you imagine that the latch enables a BUS-like architecture (more on this later).

The uggly hardware proto board, as usual

The 4x20 LCD display used for my proto

Well the second thing one can notice, is that the LCD display is used in 4-bit mode. nothing new here. 4 bit mode data bus is ‘GPIO-pin-efficient’ solution.
The third thing is that 2 bits of the latch remains unused ( free for other ouputs, your taste… )

I know there’s plenty of LCD connected to raspberry pi everywhere on the internet.latched LCD’s ? there must be less . latched LCD’s with complete kernel module in C code ? there should be lesser again.

A test display text

a capture showing the console in linux : INSMOD of the module, then dump of the kernel messages queue, then echo the test TEXT to /dev/mynull

that’s why this post is here : dive into that code, and help you understand what i’ve understood by diggin and trying a lot of things.
Like for the past post about kernel module’s build under linux, i’ll go straightforward to the essential.It’s up to you to dig into the links i give, and google for words or concepts you dont understand.
- And dont forget i’m a linux newbie -

coming after my hollidays : The why of a linux module : the char device, ioctl accesses and so on…

314159265358979323846264338327950288
419716939937510582097494459230781640
628620899862803482534211706798214808
« Newer PostsOlder Posts »

cat{ } { post_445 } { } 2009-2015 EIhIS Powered by WordPress