6fb3075026c7e8ebdc0a5d0f3f84fb60e499f879
[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, status = 0;
30
31         if (flashlight_init(&pContext) < 0) {
32                 printf ("flashlight-test: error initializing flashlight library\n");
33                 return -1;
34         }
35
36         if (flashlight_open (pContext, "/dev/video0") < 0) {
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) < 0) {
43                 printf ("flashlight-test: error setting flashlight intensity to 11\n");
44                 return -1;
45         }
46
47         if (flashlight_get_intensity(pContext, &intensity) < 0) {
48                 printf ("flashlight-test: error getting flashlight intensity\n");
49                 return -1;
50         }
51         printf ("Current flashlight intensity is %d\n", intensity);
52
53         if (flashlight_get_status(pContext, &status) < 0) {
54                 printf ("flashlight-test: error getting flashlight status\n");
55                 return -1;
56         }
57         printf ("Current flashlight status is 0x%04x\n", status);
58
59         sleep(3);
60
61         printf ("Disabling flash LEDs in flashlight mode\n");
62         if (flashlight_set_intensity(pContext, 0) < 0) {
63                 printf ("flashlight-test: error setting flashlight intensity to 0\n");
64                 return -1;
65         }
66
67         if (flashlight_close (pContext) < 0) {
68                 printf ("flashlight-test: error closing device\n");
69                 return -1;
70         }
71
72         if (flashlight_deinit(pContext) < 0) {
73                 printf ("flashlight-test: error deinitializing flashlight library\n");
74                 return -1;
75         }
76
77         return 0;
78 }