Hello.
I've been trying to activate the integrated webcam in my lemote
yeeloong 8089B notebook, by using /dev/uinput, under debian squeeze, with kernel 2.6.32-loongson-2f #1 PREEMPT from
bjlx. I have already achieved activating the WLAN by using uinput, but I can't get the camera to turn on with uinput. Normally, I would press Fn+ESC to turn the camera on, but with uinpuit it just doesn't seem to work. The camera works, and can be tested by:
Code:
mplayer tv:// -really-quiet -tv driver=v4l2:device=/dev/video0 </dev/null
I am using the following program to do try to activate my webcam using uinput:
cam_wlan.c:
Code:
#include <errno.h>
#include <fcntl.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define end(arg) do { \
perror(arg); \
exit(EXIT_FAILURE); \
} while (0)
static int fd = -1;
struct uinput_user_dev uidev;
struct input_event ev;
int setup_uinput_dev();
void cam();
void wifi();
int destroy_close();
int main(void) {
setup_uinput_dev();
cam();
wifi();
destroy_close();
return 0;
}
int setup_uinput_dev() {
fd = open("/dev/uinput", O_WRONLY | O_NDELAY);
if(fd < 0)
end("Unable to open /dev/uinput\n");
memset(&uidev,0,sizeof(uidev));
strncpy(uidev.name, "uinput-sample", UINPUT_MAX_NAME_SIZE);
uidev.id.version = 1;
uidev.id.bustype = BUS_USB;
if(ioctl(fd, UI_SET_EVBIT, EV_KEY) < 0)
end("Unable to setup UINPUT device.\n");
if(ioctl(fd, UI_SET_KEYBIT, KEY_CAMERA) < 0)
end("Unable to setup UINPUT device.\n");
if(ioctl(fd, UI_SET_KEYBIT, KEY_WLAN) < 0)
end("Unable to setup UINPUT device.\n");
if(write(fd, &uidev, sizeof(uidev)) < 0)
end("Unable to write to UINPUT device.\n");
if(ioctl(fd, UI_DEV_CREATE) < 0)
end("Unable to create UINPUT device.\n");
return 0;
}
void cam() {
memset(&ev, 0, sizeof(ev));
ev.type = EV_KEY;
ev.code = KEY_CAMERA;
ev.value = 1;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
end("Unable to write to UINPUT device.\n");
ev.type = EV_SYN;
ev.code = SYN_REPORT;
ev.value = 0;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
end("Unable to write to UINPUT device.\n");
memset(&ev, 0, sizeof(ev));
ev.type = EV_KEY;
ev.code = KEY_CAMERA;
ev.value = 0;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
end("Unable to write to UINPUT device.\n");
ev.type = EV_SYN;
ev.code = SYN_REPORT;
ev.value = 0;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
end("Unable to write to UINPUT device.\n");
}
void wifi() {
memset(&ev, 0, sizeof(ev));
ev.type = EV_KEY;
ev.code = KEY_WLAN;
ev.value = 1;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
end("Unable to write to UINPUT device.\n");
ev.type = EV_SYN;
ev.code = SYN_REPORT;
ev.value = 0;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
end("Unable to write to UINPUT device.\n");
memset(&ev, 0, sizeof(ev));
ev.type = EV_KEY;
ev.code = KEY_WLAN;
ev.value = 0;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
end("Unable to write to UINPUT device.\n");
ev.type = EV_SYN;
ev.code = SYN_REPORT;
ev.value = 0;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
end("Unable to write to UINPUT device.\n");
}
int destroy_close() {
if(ioctl(fd, UI_DEV_DESTROY) < 0)
end("Unable to destroy UINPUT device.\n");
close(fd);
return 0;
}
I compile with
Code:
gcc -o cam_wlan cam_wlan.c
Before running it, one must, as root:
Code:
modprobe uinput
lsmod | grep uinput
ls /dev/uinput
to confirm that the uinput device has been activated.
The problem I'm having is that, when I run cam_wlan, the WLAN LED toggles, but the webcam doesn't. Normally, when I press Fn+ESC to toggle the built-in webcam, dmesg would show:
Code:
[45254.379000] usb 1-1: new high speed USB device using ehci_hcd and address 15
[45254.536000] usb 1-1: New USB device found, idVendor=064e, idProduct=a114
[45254.536000] usb 1-1: New USB device strings: Mfr=2, Product=1, SerialNumber=3
[45254.536000] usb 1-1: Product: USB 2.0 Camera
[45254.539000] usb 1-1: Manufacturer: SuYin
[45254.539000] usb 1-1: SerialNumber: CN0317-S30C-MC03-VS-B20081113
[45254.546000] usb 1-1: configuration #1 chosen from 1 choice
[45254.550000] uvcvideo: Found UVC 1.00 device USB 2.0 Camera (064e:a114)
[45254.567000] input: USB 2.0 Camera as /devices/pci0000:00/0000:00:09.1/usb1/1-1/1-1:1.0/input/input896
lsusb would show:
Code:
Bus 001 Device 015: ID 064e:a114 Suyin Corp.
and applying evtest to /dev/input/event2 would show:
Code:
Input driver version is 1.0.0
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "HotKeys"
Supported events:
Event type 0 (Sync)
Event type 1 (Key)
Event code 113 (Mute)
Event code 114 (VolumeDown)
Event code 115 (VolumeUp)
Event code 142 (Sleep)
Event code 212 (Camera)
Event code 224 (Brightness down)
Event code 225 (Brightness up)
Event code 227 (?)
Event code 238 (?)
Event type 5 (?)
Event code 0 (?)
Testing ... (interrupt to exit)
Event: time 1364796475.137014, type 1 (Key), code 212 (Camera), value 1
Event: time 1364796475.138119, -------------- Report Sync ------------
Event: time 1364796475.138145, type 1 (Key), code 212 (Camera), value 0
Event: time 1364796475.138159, -------------- Report Sync ------------
I've also tried substituting, in the original cam_wlan.c, the lines
Code:
...
if(ioctl(fd, UI_SET_KEYBIT, KEY_WLAN) < 0)
...
ev.code = KEY_WLAN;
...
with
Code:
...
if(ioctl(fd, UI_SET_KEYBIT, KEY_FN_ESC) < 0)
...
ev.code = KEY_FN_ESC;
...
but that didn't work either.
So, I'm open to suggestions. What else could I try in order to activate my integrated webcam from a shell? (i.e., not having to phisically press Fn+ESC on my keyboard to do so)