upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
grovescam.hpp
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 {
80  class GROVESCAM {
81  public:
82 
83  static const unsigned int MAX_PKT_LEN = 128;
84 
85  typedef enum {
86  FORMAT_VGA = 7, // 640x480
87  FORMAT_CIF = 5, // 352*288
88  FORMAT_OCIF = 3 // ??? (maybe they meant QCIF?)
89  } PIC_FORMATS_T;
90 
97  GROVESCAM(int uart, uint8_t camAddr=GROVESCAM_DEFAULT_CAMERA_ADDR);
98 
102  ~GROVESCAM();
103 
110  bool dataAvailable(unsigned int millis);
111 
122  int readData(uint8_t *buffer, int len);
123 
131  int writeData(uint8_t *buffer, int len);
132 
140  bool setupTty(speed_t baud=B115200);
141 
146  void drainInput();
147 
152  bool init();
153 
159  bool preCapture(PIC_FORMATS_T fmt=FORMAT_VGA);
160 
166  bool doCapture();
167 
174  bool storeImage(const char *fname);
175 
182  int getImageSize() { return m_picTotalLen; };
183 
184  protected:
185  int ttyFd() { return m_ttyFd; };
186 
187  private:
188  mraa_uart_context m_uart;
189  int m_ttyFd;
190 
191  uint8_t m_camAddr;
192  int m_picTotalLen;
193  };
194 }
195 
196 
bool doCapture()
Definition: grovescam.cxx:283
int writeData(uint8_t *buffer, int len)
Definition: grovescam.cxx:131
API for the Grove Serial Camera.
Definition: grovescam.hpp:80
int readData(uint8_t *buffer, int len)
Definition: grovescam.cxx:113
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
bool init()
Definition: grovescam.cxx:193
bool preCapture(PIC_FORMATS_T fmt=FORMAT_VGA)
Definition: grovescam.cxx:246
GROVESCAM(int uart, uint8_t camAddr=GROVESCAM_DEFAULT_CAMERA_ADDR)
Definition: grovescam.cxx:39
bool storeImage(const char *fname)
Definition: grovescam.cxx:394
void drainInput()
Definition: grovescam.cxx:185
bool setupTty(speed_t baud=B115200)
Definition: grovescam.cxx:155
bool dataAvailable(unsigned int millis)
Definition: grovescam.cxx:82
~GROVESCAM()
Definition: grovescam.cxx:76
int getImageSize()
Definition: grovescam.hpp:182