upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
urm37.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Thanks to Adafruit for supplying a google translated version of the
6  * Chinese datasheet and some clues in their code.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <iostream>
31 
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35 
36 #include <mraa/common.hpp>
37 #include <mraa/uart.hpp>
38 #include <mraa/aio.hpp>
39 #include <mraa/gpio.hpp>
40 
41 #define URM37_DEFAULT_UART 0
42 
43 namespace upm {
84  class URM37 {
85  public:
86 
95  URM37(int aPin, int resetPin, int triggerPin, float aref=5.0);
96 
103  URM37(int uart, int resetPin);
104 
108  ~URM37();
109 
115  void reset();
116 
127  float getDistance(int degrees=0);
128 
134  float getTemperature();
135 
143  uint8_t readEEPROM(uint8_t addr);
144 
153  void writeEEPROM(uint8_t addr, uint8_t value);
154 
155  protected:
156  mraa::Uart *m_uart;
157  mraa::Aio *m_aio;
158  mraa::Gpio *m_gpioTrigger;
159  mraa::Gpio m_gpioReset;
160 
161  // initialize reset gpio and call reset
162  void init();
163 
164  // send a serial command and return a 4 byte response (UART mode only)
165  std::string sendCommand(std::string cmd);
166 
167  private:
174  bool dataAvailable(unsigned int millis);
175 
185  std::string readDataStr(int len);
186 
194  int writeDataStr(std::string data);
195 
196  // analog or UART mode
197  bool m_analogMode;
198 
199  // analog reference and resolution
200  float m_aref;
201  int m_aRes;
202  };
203 }
204 
205 
uint8_t readEEPROM(uint8_t addr)
Definition: urm37.cxx:202
void writeEEPROM(uint8_t addr, uint8_t value)
Definition: urm37.cxx:235
~URM37()
Definition: urm37.cxx:75
float getTemperature()
Definition: urm37.cxx:165
API for the DFRobot URM37 Ultrasonic Ranger.
Definition: urm37.h:84
void reset()
Definition: urm37.cxx:93
float getDistance(int degrees=0)
Definition: urm37.cxx:119
URM37(int aPin, int resetPin, int triggerPin, float aref=5.0)
Definition: urm37.cxx:35