upm  0.3.1
Sensor/Actuator repository for libmraa (v0.7.2)
grovescam.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Thanks to Seeed Studio for a working arduino sketch
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <string>
29 #include <iostream>
30 
31 #include <stdint.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35 #include <fcntl.h>
36 #include <errno.h>
37 #include <termios.h>
38 #include <sys/time.h>
39 #include <sys/select.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 
43 #include <mraa/uart.h>
44 
45 #define GROVESCAM_DEFAULT_UART 0
46 
47 #define GROVESCAM_DEFAULT_CAMERA_ADDR 0
48 
49 namespace upm {
78  class GROVESCAM {
79  public:
80 
81  static const unsigned int MAX_PKT_LEN = 128;
82 
83  typedef enum {
84  FORMAT_VGA = 7, // 640x480
85  FORMAT_CIF = 5, // 352×288
86  FORMAT_OCIF = 3 // ??? (maybe they meant QCIF?)
87  } PIC_FORMATS_T;
88 
95  GROVESCAM(int uart, uint8_t camAddr=GROVESCAM_DEFAULT_CAMERA_ADDR);
96 
100  ~GROVESCAM();
101 
108  bool dataAvailable(unsigned int millis);
109 
120  int readData(uint8_t *buffer, size_t len);
121 
129  int writeData(uint8_t *buffer, size_t len);
130 
138  bool setupTty(speed_t baud=B115200);
139 
144  void drainInput();
145 
150  bool init();
151 
157  bool preCapture(PIC_FORMATS_T fmt=FORMAT_VGA);
158 
164  bool doCapture();
165 
172  bool storeImage(char *fname);
173 
180  int getImageSize() { return m_picTotalLen; };
181 
182  protected:
183  int ttyFd() { return m_ttyFd; };
184  int setTtyFd(int fd) { m_ttyFd = fd; };
185 
186  private:
187  mraa_uart_context m_uart;
188  int m_ttyFd;
189 
190  uint8_t m_camAddr;
191  int m_picTotalLen;
192  };
193 }
194 
195 
bool doCapture()
Definition: grovescam.cxx:265
Definition: grovescam.h:78
Definition: a110x.h:29
bool init()
Definition: grovescam.cxx:179
bool preCapture(PIC_FORMATS_T fmt=FORMAT_VGA)
Definition: grovescam.cxx:230
GROVESCAM(int uart, uint8_t camAddr=GROVESCAM_DEFAULT_CAMERA_ADDR)
Definition: grovescam.cxx:37
int writeData(uint8_t *buffer, size_t len)
Definition: grovescam.cxx:121
int readData(uint8_t *buffer, size_t len)
Definition: grovescam.cxx:108
bool storeImage(char *fname)
Definition: grovescam.cxx:372
void drainInput()
Definition: grovescam.cxx:171
bool setupTty(speed_t baud=B115200)
Definition: grovescam.cxx:143
bool dataAvailable(unsigned int millis)
Definition: grovescam.cxx:76
~GROVESCAM()
Definition: grovescam.cxx:70
int getImageSize()
Definition: grovescam.h:180