1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #include <unistd.h>
26 #include <iostream>
27 #include <signal.h>
28 #include <stdio.h>
29 #include "grovescam.h"
30 
31 using namespace std;
32 using namespace upm;
33 
main(int argc,char ** argv)34 int main (int argc, char **argv)
35 {
36 //! [Interesting]
37 
38   // Instantiate a Grove Serial Camera on UART 0
39   upm::GROVESCAM* camera = new upm::GROVESCAM(0);
40 
41   // make sure port is initialized properly.  115200 baud is the default.
42   if (!camera->setupTty())
43     {
44       cerr << "Failed to setup tty port parameters" << endl;
45       return 1;
46     }
47 
48   if (camera->init())
49     cout << "Initialized..." << endl;
50   else
51     cout << "init() failed" << endl;
52 
53   if (camera->preCapture())
54     cout << "preCapture succeeded..." << endl;
55   else
56     cout << "preCapture failed." << endl;
57 
58   if (camera->doCapture())
59     cout << "doCapture succeeded..." << endl;
60   else
61     cout << "doCapture failed." << endl;
62 
63   cout << "Image size is " << camera->getImageSize() << " bytes" << endl;
64 
65   if (camera->getImageSize() > 0)
66     {
67       cout << "Storing image.jpg..." << endl;
68       if (camera->storeImage("image.jpg"))
69         cout << "storeImage succeeded..." << endl;
70       else
71         cout << "storeImage failed." << endl;
72     }
73 //! [Interesting]
74 
75   delete camera;
76   return 0;
77 }
78