upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
scam.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 SCAM_DEFAULT_UART 0
46 
47 #define SCAM_DEFAULT_CAMERA_ADDR 0
48 
49 namespace upm {
79  class SCAM {
80  public:
81 
82  static const unsigned int MAX_PKT_LEN = 128;
83 
84  typedef enum {
85  FORMAT_VGA = 7, // 640x480
86  FORMAT_CIF = 5, // 352*288
87  FORMAT_OCIF = 3 // ??? (maybe they meant QCIF?)
88  } PIC_FORMATS_T;
89 
96  SCAM(int uart, uint8_t camAddr=SCAM_DEFAULT_CAMERA_ADDR);
97 
101  ~SCAM();
102 
109  bool dataAvailable(unsigned int millis);
110 
121  int readData(uint8_t *buffer, int len);
122 
130  int writeData(uint8_t *buffer, int len);
131 
139  bool setupTty(speed_t baud=B115200);
140 
145  void drainInput();
146 
151  bool init();
152 
158  bool preCapture(PIC_FORMATS_T fmt=FORMAT_VGA);
159 
165  bool doCapture();
166 
173  bool storeImage(const char *fname);
174 
181  int getImageSize() { return m_picTotalLen; };
182 
183  protected:
184  int ttyFd() { return m_ttyFd; };
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 
SCAM(int uart, uint8_t camAddr=SCAM_DEFAULT_CAMERA_ADDR)
Definition: scam.cxx:39
int readData(uint8_t *buffer, int len)
Definition: scam.cxx:113
bool storeImage(const char *fname)
Definition: scam.cxx:394
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
bool setupTty(speed_t baud=B115200)
Definition: scam.cxx:155
int getImageSize()
Definition: scam.hpp:181
API for the Serial Camera.
Definition: scam.hpp:79
~SCAM()
Definition: scam.cxx:76
bool dataAvailable(unsigned int millis)
Definition: scam.cxx:82
bool doCapture()
Definition: scam.cxx:283
bool init()
Definition: scam.cxx:193
bool preCapture(PIC_FORMATS_T fmt=FORMAT_VGA)
Definition: scam.cxx:246
void drainInput()
Definition: scam.cxx:185
int writeData(uint8_t *buffer, int len)
Definition: scam.cxx:131