upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
nlgpio16.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 
39 #define NLGPIO16_DEFAULT_UART_DEV "/dev/ttyACM0"
40 
41 // ADC analog ref voltage is 3.3v
42 #define ADC_AREF 3.3
43 
44 // 10-bit precision (0-1023)
45 #define ADC_PRECISION 10
46 
47 namespace upm {
88  class NLGPIO16 {
89  public:
90 
96  NLGPIO16(std::string uart=NLGPIO16_DEFAULT_UART_DEV);
97 
101  ~NLGPIO16();
102 
108  std::string getVersion();
109 
116  std::string getID();
117 
125  void setID(std::string id);
126 
134  void gpioSet(int gpio);
135 
143  void gpioClear(int gpio);
144 
153  bool gpioRead(int gpio);
154 
162  unsigned int gpioReadAll();
163 
176  void gpioSetIOMask(int mask);
177 
188  void gpioSetIODir(int mask);
189 
198  void gpioWriteAll(int mask);
199 
210  int analogReadValue(int adc);
211 
223  float analogReadVolts(int adc);
224 
225 
226  protected:
227  mraa::Uart m_uart;
228 
229  // UART helpers
230  bool dataAvailable(unsigned int millis);
231  std::string readStr(int len);
232  int writeStr(std::string data);
233 
234  // does most of the work for sending commands and getting responses
235  std::string sendCommand(std::string cmd);
236 
237  private:
238  };
239 }
std::string getVersion()
Definition: nlgpio16.cxx:286
void setID(std::string id)
Definition: nlgpio16.cxx:296
void gpioWriteAll(int mask)
Definition: nlgpio16.cxx:266
API for the NLGPIO16 16 channel USB GPIO Module.
Definition: nlgpio16.h:88
~NLGPIO16()
Definition: nlgpio16.cxx:72
float analogReadVolts(int adc)
Definition: nlgpio16.cxx:338
std::string getID()
Definition: nlgpio16.cxx:291
void gpioSetIOMask(int mask)
Definition: nlgpio16.cxx:226
int analogReadValue(int adc)
Definition: nlgpio16.cxx:313
void gpioClear(int gpio)
Definition: nlgpio16.cxx:166
unsigned int gpioReadAll()
Definition: nlgpio16.cxx:207
void gpioSet(int gpio)
Definition: nlgpio16.cxx:149
NLGPIO16(std::string uart=NLGPIO16_DEFAULT_UART_DEV)
Definition: nlgpio16.cxx:66
void gpioSetIODir(int mask)
Definition: nlgpio16.cxx:246
bool gpioRead(int gpio)
Definition: nlgpio16.cxx:183