6e8da4fd7edf47f44edc5e5ce22e0fcd0e742b6f
[flashlight-appl] / test / test.c
1 /*
2  *  Flashlight applet (widget) for Maemo.
3  *  Copyright (C) 2009 Roman Moravcik
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23
24 #include "../src/flashlight_lib.h"
25
26 int main (int argc, char **argv)
27 {
28         FlashlightContext_t *pContext = NULL;
29         int intensity = 0;
30
31         if (flashlight_init(&pContext) == -1) {
32                 printf ("flashlight-test: error initializing flashlight library\n");
33                 return -1;
34         }
35
36         if (flashlight_open (pContext, "/dev/video0") == -1) {
37                 printf ("flashlight-test: error openning device\n");
38                 return -1;
39         }
40
41         printf ("Enabling flash LEDs in flashlight mode\n");
42         if (flashlight_set_intensity(pContext, 11) == -1) {
43                 printf ("flashlight-test: error setting flashlight intensity to 11\n");
44                 return -1;
45         }
46
47         if (flashlight_get_intensity(pContext, &intensity) == -1) {
48                 printf ("flashlight-test: error getting flashlight intensity\n");
49                 return -1;
50         }
51         printf ("Current flashlight intensity is %d\n", intensity);
52
53         sleep(3);
54
55         printf ("Disabling flash LEDs in flashlight mode\n");
56         if (flashlight_set_intensity(pContext, 0) == -1) {
57                 printf ("flashlight-test: error setting flashlight intensity to 0\n");
58                 return -1;
59         }
60
61         if (flashlight_close (pContext) == -1) {
62                 printf ("flashlight-test: error closing device\n");
63                 return -1;
64         }
65
66         if (flashlight_deinit(pContext) == -1) {
67                 printf ("flashlight-test: error deinitializing flashlight library\n");
68                 return -1;
69         }
70
71         return 0;
72 }