From: Daniel Drake <dsd@laptop.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: mjg@redhat.com, platform-driver-x86@vger.kernel.org, pgf@laptop.org
Subject: Re: [PATCH] OLPC XO-1.5 ebook switch driver
Date: Tue, 11 Jan 2011 14:55:55 +0000 [thread overview]
Message-ID: <1294757755.2529.3.camel@polyethylene> (raw)
In-Reply-To: <20110107013450.GA28842@core.coreip.homeip.net>
[-- Attachment #1: Type: text/plain, Size: 545 bytes --]
On Thu, 2011-01-06 at 17:34 -0800, Dmitry Torokhov wrote:
> No, instead of adding yet another kernel attribute just use ioctl to get
> current switch state. Or write a general purpose utility to query
> switch/key state and contribute it to consoletools project - many people
> have asked fr it ;)
Thanks for the review.
Did you mean consoletools as in http://lct.sourceforge.net/ ?
It looks rather dead.
Perhaps util-linux-ng would be a more appropriate target?
I'm attaching the general purpose utility for your comments.
Thanks,
Daniel
[-- Attachment #2: Type: text/x-csrc, Size: 2836 bytes --]
/*
* evstate: query evdev key/led/sw/snd state
* Returns exit code 1 if the state bit is set (key pressed, LED on, etc.),
* and 0 if the state bit is unset.
*
* Copyright (C) 2011 One Laptop per Child
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/input.h>
#define BITS_PER_LONG (sizeof(long) * 8)
static int test_bit(unsigned int nr, void *addr)
{
return ((1UL << (nr % BITS_PER_LONG)) &
(((unsigned long *) addr)[nr / BITS_PER_LONG])) != 0;
}
static void __attribute__((noreturn)) usage(void)
{
printf("Usage:\n"
" %s <device> <mode> <key>\n"
"Valid modes: key, led, snd, sw\n",
program_invocation_short_name);
exit(2);
}
static const struct mode {
const char *name;
int max;
int rq;
} requests[] = {
{ "key", KEY_MAX, EVIOCGKEY(KEY_MAX) },
{ "led", LED_MAX, EVIOCGLED(LED_MAX) },
{ "snd", SND_MAX, EVIOCGSND(SND_MAX) },
{ "sw", SW_MAX, EVIOCGSW(SW_MAX) },
};
static const struct mode *find_mode(const char *name)
{
int i;
for (i = 0; i < sizeof(requests) / sizeof(*requests); i++) {
const struct mode *mode = &requests[i];
if (strcmp(mode->name, name) == 0)
return mode;
}
return NULL;
}
static int query_state(const char *device, long int keyno,
const struct mode *mode)
{
uint8_t state[(mode->max / 8) + 1];
int fd;
int r;
if (keyno < 0 || keyno > mode->max) {
fprintf(stderr, "Unrecognised key %d\n", keyno);
exit(3);
}
fd = open(device, O_RDONLY);
if (fd == -1) {
perror("open");
exit(3);
}
memset(state, 0, sizeof(state));
r = ioctl(fd, mode->rq, state);
close(fd);
if (r == -1) {
perror("ioctl");
exit(3);
}
return test_bit(keyno, state);
}
int main(int argc, char **argv)
{
const struct mode *mode;
long int keyno;
if (argc != 4)
usage();
mode = find_mode(argv[2]);
if (!mode) {
fprintf(stderr, "Unrecognised mode.\n");
usage();
}
keyno = strtol(argv[3], NULL, 10);
return query_state(argv[1], keyno, mode);
}
prev parent reply other threads:[~2011-01-11 14:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-29 18:58 [PATCH] OLPC XO-1.5 ebook switch driver Daniel Drake
2011-01-07 1:34 ` Dmitry Torokhov
2011-01-11 14:55 ` Daniel Drake [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1294757755.2529.3.camel@polyethylene \
--to=dsd@laptop.org \
--cc=dmitry.torokhov@gmail.com \
--cc=mjg@redhat.com \
--cc=pgf@laptop.org \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.