Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > More E-Book Readers > iRex > iRex Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 11-13-2008, 01:49 PM   #1
hansel
JSR FFD2
hansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheese
 
hansel's Avatar
 
Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
Angry Button check

Hi,
I wrote a small program to check if a button is pressed:
Code:
* ----- Small test program to check which button is pressed ---------
 * Prints a string (2 characters) to stdout:
 * FF:  No key pressed
 * 00:  Connect (IDS)
 * 01:  Button avove page bar
 * 02:  Top left button
 * 03:  NEWS
 * 04:  BOOKS
 * 05:  DOCS
 * 06:  NOTES
 * 07:  page bar left
 * 08:  page bar right
 * 09:  UP arrow
 * 0A:  DOT (enter)
 * 0B:  DOWN arrow
 * 0E:  Power on button
 * E0:  Error, cannot open device
 * E1:  Error, cannot get button state
 */

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define BUTTON_IOCTL_BASE               'b'
#define BUTTON_IOCTL_GET_STATUS         _IOR( BUTTON_IOCTL_BASE,7,unsigned int)

int main(int argc, char *argv[]) {
    int i;
    int status;
    int dev;

    if ((dev = open("/dev/buttons", O_RDWR)) < 0) {
        fprintf(stderr,"ERROR opening failed\n");
        status = 0xe0;
    }
    else if (ioctl(dev, BUTTON_IOCTL_GET_STATUS, &status)) {
        fprintf(stderr, "ERROR: BUTTON_IOCTL_GET_STATUS failed\n");
        status = 0xe2;
    }
    printf("%02X", status & 0xff);
    return 0;
}
It can be compiled as follows (with de development kit installed and running setup_build_env.sh)
Code:
arm-linux-gcc checkbutton.c -o checkbutton
It works like a charm (when I run it on the iliad via ssh), except when I run it from the startup scripts (like /home/root/start.sh). And THAT's why I wrote it in the first place: to activate special things by holding a button while booting...

ANY idea what might be happening? The program always returns 'FF', no key pressed...

EDIT: when I do a lsmod just before calling buttoncheck, I see tha the button module is loaded...

Last edited by hansel; 11-13-2008 at 02:06 PM. Reason: more info
hansel is offline   Reply With Quote
Old 11-14-2008, 09:23 AM   #2
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 976
Karma: 687
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
Does contentlister trap all button input before this program?
This topic is too far from my current knowledge.
ericshliao is offline   Reply With Quote
Advert
Old 11-14-2008, 11:09 AM   #3
jharker
Developer
jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.
 
Posts: 345
Karma: 3473
Join Date: Apr 2007
Location: Brooklyn, NY, USA
Device: iRex iLiad v1, Blackberry Tour, Kindle DX, iPad.
Why are you only reading the button status once?

Okay, for the record, here is the thread about all things button-related. Someone should really sticky that thread, I keep referring people to it.

The short answer is, every time the button status is checked, the buffer is then reset to "ff". The ContentLister checks button status 10 times per second. So if your program runs its one single button check just after the ContentLister, it's possible that it won't see it.

It also depends on how you're pressing the button. Are you holding it down? For how long? At what point during boot do you start pressing it? When does your program run (i.e. what does your start.sh script look like)?
jharker is offline   Reply With Quote
Old 11-14-2008, 02:09 PM   #4
hansel
JSR FFD2
hansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheese
 
hansel's Avatar
 
Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
Quote:
Originally Posted by jharker View Post
Why are you only reading the button status once?

Okay, for the record, here is the thread about all things button-related. Someone should really sticky that thread, I keep referring people to it.

The short answer is, every time the button status is checked, the buffer is then reset to "ff". The ContentLister checks button status 10 times per second. So if your program runs its one single button check just after the ContentLister, it's possible that it won't see it.

It also depends on how you're pressing the button. Are you holding it down? For how long? At what point during boot do you start pressing it? When does your program run (i.e. what does your start.sh script look like)?
Thanks for the link. My program certainly looks like yours... I looked up the defines in the freshly released code. The program works fine when called in ssh...


I poll before contenLister is even started (at the start of /home/root/start.sh) I want to use it do decide between the normal start-up (powrMgr, contenLister, etc), and my experimental stuff. When I make a mistake, I can always boot the normal way (just don't press the magic button). I could also start sshd by pressing 'BOOKS' while booting

I've tried polling 10 times with a small interval, but I get FF ten times...
I hold the button at power-on, and only let it go when contentLister is showing...

Aparently I miss something, or something is still disabled when I poll...
Did you try to call your poll program in start.sh?
hansel is offline   Reply With Quote
Old 11-14-2008, 02:32 PM   #5
jharker
Developer
jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.
 
Posts: 345
Karma: 3473
Join Date: Apr 2007
Location: Brooklyn, NY, USA
Device: iRex iLiad v1, Blackberry Tour, Kindle DX, iPad.
I'm pretty sure I've had my program in start.sh in the past, and it worked fine. Can't really remember, though.

The problem might be that you're holding down the button before the module is loaded?

You could also try installing my program and see if that works?
jharker is offline   Reply With Quote
Advert
Old 11-14-2008, 03:32 PM   #6
hansel
JSR FFD2
hansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheese
 
hansel's Avatar
 
Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
Cool

jharker (and All)

I get the same results with your sample program (as expected). May be I'm pressing the key to early... But since I want to detect it very early in the boor process I don't have much choice...

I discovered one VERY USEFUL thing. (As I already new) the button info is in the lower two nibbles of the return data, BUT the next nibble tells if a CF card or a SD card is inserted (even the dummy plastic one).

My CF is always inserted (that's where my sshd runs)
  • When the (fake) SD is inserted I get status=0xCFF
  • When the (fake) SD is absent I get status=0x4FF
  • With only a SD card you would probably get status=0X8FF (yout situation?)
  • With both card removed I would probably get 0x0FF, but when I do that, sshd dies ;-)

The interesting part is that this holds at boot time. I can activate my experimental stuff by inserting the dummy plastic SD card

PS: If somebody has any ideas why the key detection at boot time doesn't work, I'd be very interested to hear them.
hansel is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you check your formatting? deferredreward Writers' Corner 2 08-31-2010 03:41 PM
Anybody get their rebate check? DrBen Astak EZReader 9 09-16-2009 03:59 PM
Check it out Dragoro Lounge 0 04-07-2009 01:17 AM
Check out my books HistoryWes Amazon Kindle 5 02-20-2009 06:57 PM
Reality check rlauzon Bookeen 46 03-06-2008 02:40 PM


All times are GMT -4. The time now is 12:13 AM.


MobileRead.com is a privately owned, operated and funded community.