📜 ⬆️ ⬇️

Indication notification LED webcam [Part 1]

... And I decided to write about this idea post on Habrahabr.

Yesterday, a “thought” came to my mind that ... well, something is not very good: on smartphones in silent mode, you can find out whether there are notifications using the LED indicator, but not on the computer.

Imagine a situation that you forgot to disconnect headphones from a laptop. Then they wrote to you in the background, say, VK, and you cannot find out about it if the notifications in the browser are not included. Need to fix it!
')
Interested? Welcome under the cut!

After about half an hour of thought, I came to a ... dll-file that simplifies life, and at the same time the development of my future program. This DLL is called "escapi" .

Since I am not familiar with C ++, I decided to develop in a very simple way , but quickly and without too much difficulty. (The article was written as it was developed, so here I was deeply wrong ...)

Finally, let's get down to business.


Having downloaded the above library, I immediately got into the “Examples” folder . I found there several compiled examples, as well as their source code. At the simplest and most suitable example for me, my eyes fell immediately. It is logical, because it is called "simplest.exe" . Here is its source:

Source
/* "simplest", example of simply enumerating the available devices with ESCAPI */ #include <stdio.h> #include "escapi.h" void main() { int i, j; /* Initialize ESCAPI */ int devices = setupESCAPI(); if (devices == 0) { printf("ESCAPI initialization failure or no devices found.\n"); return; } /* Set up capture parameters. * ESCAPI will scale the data received from the camera * (with point sampling) to whatever values you want. * Typically the native resolution is 320*240. */ struct SimpleCapParams capture; capture.mWidth = 24; capture.mHeight = 18; capture.mTargetBuf = new int[24 * 18]; /* Initialize capture - only one capture may be active per device, * but several devices may be captured at the same time. * * 0 is the first device. */ if (initCapture(0, &capture) == 0) { printf("Capture failed - device may already be in use.\n"); return; } /* Go through 10 capture loops so that the camera has * had time to adjust to the lighting conditions and * should give us a sane image.. */ for (i = 0; i < 10; i++) { /* request a capture */ doCapture(0); while (isCaptureDone(0) == 0) { /* Wait until capture is done. * Warning: if capture init failed, or if the capture * simply fails (ie, user unplugs the web camera), this * will be an infinite loop. */ } } /* now we have the data.. what shall we do with it? let's * render it in ASCII.. (using 3 top bits of green as the value) */ char light[] = " .,-o+O0@"; for (i = 0; i < 18; i++) { for (j = 0; j < 24; j++) { printf("%c", light[(capture.mTargetBuf[i*24+j] >> 13) & 7]); } printf("\n"); } deinitCapture(0); } 


In short: the program turns on the webcam, takes 10 shots in a row to let the camera focus, set shutter speed, etc., then take the last frame and output some of it to ASCII.

For us, in order to “blink” the camera's LED, it is necessary to take only one shot, without displaying it on the screen and / or doing something else with it. For if the camera's LED turns on only when it (the camera) is active, we just have to remove the extra part of the code, and ... voila! Executual ready.

New code (function only):

My code
 /* WebCamLED Notifier 1.0 by Sdore */ #include <stdio.h> #include "escapi.h" void led() { struct SimpleCapParams capture; capture.mWidth = 24; capture.mHeight = 18; capture.mTargetBuf = new int[24 * 18]; initCapture(0, &capture); doCapture(0); deinitCapture(0); } 


We compile in a pack with escapi library, we start. The camera LED lights up and immediately goes out. Works! Well, it remains only to find a use. Following the idea, it is quite logical to make a notification system. I will outline the program in my favorite development environment "Algorithm 2" .

But this is already in the next part.

PS
I'm not sure that the code is working, because the above has written in advance.

PS This is my first post, but hopefully not the last ...

Thank you for your attention, good luck!


Upd: As noted by one of the commentators,
It would be worth mentioning that the solution described is windows-only.
This is exactly what I forgot to say. Thanks for the addition.

Source: https://habr.com/ru/post/271125/


All Articles