Detect When Laptop Lip Opens

Page 1 of 1

7 Replies - 640 Views - Last Post: 13 July 2011 - 01:02 PM

#1 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

Detect When Laptop Lip Opens

Posted 13 July 2011 - 06:45 AM

Hey everyone,

I'm using Ubuntu 11.04 and trying to write a program that will run in the background and when the laptop lid opens will take a picture through the webcam. I've tried looking on Google but everything I've found is either useless or fro Windows. I'm not asking for the code to do this, just a point in the rights direction on how to detect the lid event, maybe a link to a site that talks about it.

Thanks,
Daniel

Is This A Good Question/Topic? 0
  • +

Replies To: Detect When Laptop Lip Opens

#2 oscode  Icon User is offline

  • D.I.C Regular

Reputation: 109
  • View blog
  • Posts: 257
  • Joined: 24-October 10

Re: Detect When Laptop Lip Opens

Posted 13 July 2011 - 07:02 AM

You could parse the power management settings file to discover what state the laptop goes to/from upon the lid opening. Then when this state change occurs, take a picture. It shouldn't be too hard to find out how to do either of these things.

I wouldn't be surprised if this couldn't be done with a couple of clever BASH scripts.

I came across this: http://ubuntuforums....d.php?t=1076486

This post has been edited by oscode: 13 July 2011 - 07:07 AM

Was This Post Helpful? 1
  • +
  • -

#3 stackoverflow  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 545
  • Joined: 06-July 11

Re: Detect When Laptop Lip Opens

Posted 13 July 2011 - 07:05 AM

I am not sure about it, but I would dig into the screen APIs and see if you can find any functions to identify if the screen is lit up or not. If it is lit it must be open.

I honestly think this is a good job for Bash scripting and/or something like Perl. You could scan the device files and/or the proc files and probably find something that shows if the screen is lit. Then run your C program which takes a snap shot.

edit:

I guess oscode was a couple minutes faster than me. :(

This post has been edited by stackoverflow: 13 July 2011 - 07:06 AM

Was This Post Helpful? 0
  • +
  • -

#4 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1629
  • View blog
  • Posts: 3,092
  • Joined: 30-May 10

Re: Detect When Laptop Lip Opens

Posted 13 July 2011 - 07:09 AM

Found a thread on ubuntu forums
http://ubuntuforums....=1076486&page=5

Or perhaps more generally, google for "dbus events"
Was This Post Helpful? 0
  • +
  • -

#5 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

Re: Detect When Laptop Lip Opens

Posted 13 July 2011 - 07:52 AM

View Postoscode, on 13 July 2011 - 07:02 AM, said:

You could parse the power management settings file to discover what state the laptop goes to/from upon the lid opening. Then when this state change occurs, take a picture. It shouldn't be too hard to find out how to do either of these things.

I wouldn't be surprised if this couldn't be done with a couple of clever BASH scripts.

I came across this: http://ubuntuforums....d.php?t=1076486


This works great! Thanks! I do have one more problem though. I'm trying to use Fswebcam to take the picture for me but I cannot seem to get Ubuntu to recognize my webcam and I simply get errors saying it is not beign detected. lsusb returns this;
$ lsusb
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub



And lspci this;
$ lspci
00:00.0 Host bridge: Intel Corporation Core Processor DRAM Controller (rev 12)
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 12)
00:16.0 Communication controller: Intel Corporation 5 Series/3400 Series Chipset HECI Controller (rev 06)
00:1a.0 USB Controller: Intel Corporation 5 Series/3400 Series Chipset USB2 Enhanced Host Controller (rev 06)
00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 06)
00:1c.0 PCI bridge: Intel Corporation 5 Series/3400 Series Chipset PCI Express Root Port 1 (rev 06)
00:1c.1 PCI bridge: Intel Corporation 5 Series/3400 Series Chipset PCI Express Root Port 2 (rev 06)
00:1c.3 PCI bridge: Intel Corporation 5 Series/3400 Series Chipset PCI Express Root Port 4 (rev 06)
00:1c.5 PCI bridge: Intel Corporation 5 Series/3400 Series Chipset PCI Express Root Port 6 (rev 06)
00:1d.0 USB Controller: Intel Corporation 5 Series/3400 Series Chipset USB2 Enhanced Host Controller (rev 06)
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev a6)
00:1f.0 ISA bridge: Intel Corporation Mobile 5 Series Chipset LPC Interface Controller (rev 06)
00:1f.2 SATA controller: Intel Corporation 5 Series/3400 Series Chipset 4 port SATA AHCI Controller (rev 06)
00:1f.3 SMBus: Intel Corporation 5 Series/3400 Series Chipset SMBus Controller (rev 06)
00:1f.6 Signal processing controller: Intel Corporation 5 Series/3400 Series Chipset Thermal Subsystem (rev 06)
05:00.0 Network controller: Atheros Communications Inc. AR9285 Wireless Network Adapter (PCI-Express) (rev 01)
06:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8101E/RTL8102E PCI Express Fast Ethernet controller (rev 02)
3f:00.0 Host bridge: Intel Corporation Core Processor QuickPath Architecture Generic Non-core Registers (rev 02)
3f:00.1 Host bridge: Intel Corporation Core Processor QuickPath Architecture System Address Decoder (rev 02)
3f:02.0 Host bridge: Intel Corporation Core Processor QPI Link 0 (rev 02)
3f:02.1 Host bridge: Intel Corporation Core Processor QPI Physical 0 (rev 02)
3f:02.2 Host bridge: Intel Corporation Core Processor Reserved (rev 02)
3f:02.3 Host bridge: Intel Corporation Core Processor Reserved (rev 02)



I'm not seeing anything there for the webcam and I cannot figure out why. Any thoughts?

Daniel
Was This Post Helpful? 0
  • +
  • -

#6 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1629
  • View blog
  • Posts: 3,092
  • Joined: 30-May 10

Re: Detect When Laptop Lip Opens

Posted 13 July 2011 - 09:31 AM

You would have to tell us which make/model of laptop you have.

What does this command show -> dmesg | grep -i cam
It should show you if there are any errors when it comes to detecting 'cam'era's
Was This Post Helpful? 0
  • +
  • -

#7 danielair  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 118
  • Joined: 12-July 09

Re: Detect When Laptop Lip Opens

Posted 13 July 2011 - 11:42 AM

View PostSalem_c, on 13 July 2011 - 09:31 AM, said:

You would have to tell us which make/model of laptop you have.

What does this command show -> dmesg | grep -i cam
It should show you if there are any errors when it comes to detecting 'cam'era's


I have a MSI A6200-220US laptop but I couldn't find any drivers from the manufacturer's website or anything. dmesg | grep -i cam has no result, However dmesg | grep -i vid returns;
~$ dmesg | grep -i vid
[    0.000000] BIOS-provided physical RAM map:
[    0.760897] pci 0000:00:02.0: Boot video device
[   15.068872] input: Video Bus as /devices/LNXSYSTM:00/device:00/PNP0A08:00/LNXVIDEO:00/input/input3
[   15.068945] ACPI: Video Device [GFX0] (multi-head: yes  rom: no  post: no)
[  350.476616] Linux video capture interface: v2.00



I looked into a few websites for help but was unable to find anything that worked.

Daniel
Was This Post Helpful? 0
  • +
  • -

#8 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: Detect When Laptop Lip Opens

Posted 13 July 2011 - 01:02 PM

*Moved*

This isn't really C++.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1