LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-01-2013, 01:32 AM   #1
vomv1988
LQ Newbie
 
Registered: Apr 2013
Posts: 3

Rep: Reputation: Disabled
trying to use /dev/uinput to turn on integrated webcam


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)
 
Old 04-07-2013, 10:33 PM   #2
vomv1988
LQ Newbie
 
Registered: Apr 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Bump.
Maybe I should have put this question in the linux kernel board. Is there any way to do that? Can I ask the moderator to do this?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Webcam integrated microphone in dv6-3013nr photoelectricgeek Linux - Hardware 23 08-08-2012 10:02 PM
Webcam integrada não funciona (Integrated webcam does not work) wiltontsi Debian 5 04-15-2011 06:16 AM
Dell Studio XPS 16 integrated webcam - what is it? turboscrew Linux - Laptop and Netbook 2 03-20-2011 02:35 PM
usb webcam with integrated microphone wastingtime Linux - Hardware 0 10-19-2008 01:35 PM
Philips Usb Webcam - Microphone Integrated pingouinux Linux - Hardware 4 08-02-2004 04:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration