getchar
getchar
I have been working with a program called Graphcan originally written for a Zaurus running Linux by Atilla Vass and ported to use with the Eee PC by Peter Astrand. I made some modification to the program, mainly cosmetic. However, one feature that I could not get to work correctly is keyboard input. If i launch the program directly text input does not work. If I run it from a terminal and I keep the terminal in focus, the text input does work. I'm thinking that Puppy does not think Graphcan is the focus, even in full screen mode. How can I verify what is happening?
Here is the relevant Graphcan code:
if (select(FD_SETSIZE, &fdset, 0, 0, &to) != -1) {
if (FD_ISSET(0, &fdset))
{
c = getchar();
switch (c) {
case 0xa: // ReStart
if (Sleeping) {
ProcessGo = 0;
ContSignal = 1;
Sleeping = 0;
PriusIsPowered = 1;
}
else {
alarm(0);
SaveStat();
Sleeping = 1;
if (Port >= 0) {
sprintf(Message, "C\015"); // Close the CAN channel
if (WriteToPort(Message)) {
fprintf(stderr, "Error writing to port : Close CAN Channel\n");
}
close(Port);
Port = -1;
}
}
break;
case 'q':
ProcessGo = 0;
RealQuit = 1;
break;
case 's':
if (++SI_Measurements > 1)
SI_Measurements = 0;
break;
case 'p':
PriusIsPowered = 0;
Sleeping = 0;
CurrentSpeed = 0;
break;
case 0x7F: // BS
if (++VoiceMode > 1)
VoiceMode = 0;
break;
case ' ':
NeedSynced = 1;
FSRCntr = 1;
break;
}
}
}
#endif
return;
Thanks for your comments in advance.
Howard
Here is the relevant Graphcan code:
if (select(FD_SETSIZE, &fdset, 0, 0, &to) != -1) {
if (FD_ISSET(0, &fdset))
{
c = getchar();
switch (c) {
case 0xa: // ReStart
if (Sleeping) {
ProcessGo = 0;
ContSignal = 1;
Sleeping = 0;
PriusIsPowered = 1;
}
else {
alarm(0);
SaveStat();
Sleeping = 1;
if (Port >= 0) {
sprintf(Message, "C\015"); // Close the CAN channel
if (WriteToPort(Message)) {
fprintf(stderr, "Error writing to port : Close CAN Channel\n");
}
close(Port);
Port = -1;
}
}
break;
case 'q':
ProcessGo = 0;
RealQuit = 1;
break;
case 's':
if (++SI_Measurements > 1)
SI_Measurements = 0;
break;
case 'p':
PriusIsPowered = 0;
Sleeping = 0;
CurrentSpeed = 0;
break;
case 0x7F: // BS
if (++VoiceMode > 1)
VoiceMode = 0;
break;
case ' ':
NeedSynced = 1;
FSRCntr = 1;
break;
}
}
}
#endif
return;
Thanks for your comments in advance.
Howard
- Moose On The Loose
- Posts: 965
- Joined: Thu 24 Feb 2011, 14:54
Re: getchar
fprintf(LogFile,"Got a %x\n",c);vertex wrote:I have been working with a program called Graphcan originally written for a Zaurus running Linux by Atilla Vass and ported to use with the Eee PC by Peter Astrand.
.......
c = getchar();
Just to see if you got a character at all. I don't think your keyboard is your standard in at all but this will show if you got anything.
-
- Posts: 229
- Joined: Wed 25 Aug 2010, 15:38
- Location: ISM Dhanbad, Jharkhand, India
getchar actually reads a character from stdin and not from keyboard.
In terminal, stdin is usually keyboard input.
And what's worse, stdin is line buffered, i.e. program won't get anything till you press enter key.
So you have to think of accessing keyboard directly.
I will search and come back after I have found something, useful.
In terminal, stdin is usually keyboard input.
And what's worse, stdin is line buffered, i.e. program won't get anything till you press enter key.
So you have to think of accessing keyboard directly.
I will search and come back after I have found something, useful.
- Moose On The Loose
- Posts: 965
- Joined: Thu 24 Feb 2011, 14:54
stdin can be line edited or just character by character. The C functions for reading from stdin are just the same as the ones that read from files but stdin is implied. This is not the same as the keyboard.vertex wrote:Of course c is declared, otherwise it wouldn't even compile.
The program works when run in termnal, without a carriage return.
Doesn't that mean that the keyboard is working throhgg stdin, or is it somehow redirected?
- Dougal
- Posts: 2502
- Joined: Wed 19 Oct 2005, 13:06
- Location: Hell more grotesque than any medieval woodcut
That's what I said... everything run from the WM ends up under tty1.vertex wrote:Acutally, it is the opposite, when run from the command box, it is pts/0, which works. from the icon it is tty1. What can I do to fix that?
As far as I understand, /dev/pts is the old (deprecated) way of doing things, so theoretically you'll need to change th program to use /dev/tty. There might be some way to force it to use /dev/pts when run from the WM (via a special program), but I don't know it...
However, something you can do is write a simple shell-wrapper that will run the program from a terminal:
Code: Select all
#!/bin/sh
exec rxvt -e "graphcan"
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind
Some say your nose
Some say your toes
But I think it's your mind