upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
ds2413.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <iostream>
28 #include <map>
29 
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 
34 #include <mraa/common.hpp>
35 #include <mraa/uart_ow.hpp>
36 
37 #define DS2413_DEFAULT_UART 0
38 
39 namespace upm {
77  class DS2413 {
78  public:
79 
80  // The family code for these devices. We handle all of them that
81  // are found on the bus.
82  static const uint8_t DS2413_FAMILY_CODE = 0x3a;
83 
84  // commands
85  typedef enum {
86  ACCESS_READ = 0xf5,
87  ACCESS_WRITE = 0x5a
88  } DS2413_CMD_T;
89 
90  // possible ack responses for gpio writes
91  typedef enum {
92  ACK_SUCCESS = 0xaa,
93  ACK_FAILURE = 0xff
94  } DS2413_ACK_T;
95 
101  DS2413(int uart=DS2413_DEFAULT_UART);
102 
106  ~DS2413();
107 
115  void init();
116 
124  {
125  return m_devicesFound;
126  }
127 
138  int readGpios(int index=0);
139 
149  void writeGpios(int index, int value);
150 
160  std::string getId(int index)
161  {
162  return m_deviceMap[index];
163  }
164 
165  protected:
166  mraa::UartOW m_uart;
167 
168  // the total number of devices found
169  int m_devicesFound;
170 
171  std::map<int, std::string> m_deviceMap;
172 
173  private:
174  };
175 }
int devicesFound()
Definition: ds2413.hpp:123
~DS2413()
Definition: ds2413.cxx:51
DS2413(int uart=DS2413_DEFAULT_UART)
Definition: ds2413.cxx:35
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void writeGpios(int index, int value)
Definition: ds2413.cxx:130
std::string getId(int index)
Definition: ds2413.hpp:160
int readGpios(int index=0)
Definition: ds2413.cxx:100
void init()
Definition: ds2413.cxx:55
API for the DS2413 1-Wire Dual Channel Addressable Switch.
Definition: ds2413.hpp:77