浏览代码

apds9930: Initial implementation

Signed-off-by: Lay, Kuan Loon <kuan.loon.lay@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Lay, Kuan Loon 9 年前
父节点
当前提交
828a9ce7d8

+ 1
- 0
examples/c++/CMakeLists.txt 查看文件

@@ -240,6 +240,7 @@ if (MODBUS_FOUND)
240 240
 endif()
241 241
 add_example (hdxxvxta)
242 242
 add_example (rhusb)
243
+add_example (apds9930)
243 244
 
244 245
 # These are special cases where you specify example binary, source file and module(s)
245 246
 include_directories (${PROJECT_SOURCE_DIR}/src)

+ 63
- 0
examples/c++/apds9930.cxx 查看文件

@@ -0,0 +1,63 @@
1
+/*
2
+ * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
3
+ * Copyright (c) 2015 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
+
25
+#include <unistd.h>
26
+#include <iostream>
27
+#include <signal.h>
28
+#include "apds9930.h"
29
+
30
+using namespace std;
31
+
32
+int shouldRun = true;
33
+
34
+void
35
+sig_handler(int signo)
36
+{
37
+    if (signo == SIGINT)
38
+        shouldRun = false;
39
+}
40
+
41
+int
42
+main()
43
+{
44
+    signal(SIGINT, sig_handler);
45
+    //! [Interesting]
46
+    // Instantiate a Digital Proximity and Ambient Light sensor on iio device 4
47
+    upm::APDS9930* light_proximity = new upm::APDS9930(4);
48
+
49
+    while (shouldRun) {
50
+        float lux = light_proximity->getAmbient();
51
+        cout << "Luminance value is " << lux << endl;
52
+        float proximity = light_proximity->getProximity();
53
+        cout << "Proximity value is " << proximity << endl;
54
+        sleep(1);
55
+    }
56
+    //! [Interesting]
57
+
58
+    cout << "Exiting" << endl;
59
+
60
+    delete light_proximity;
61
+
62
+    return 0;
63
+}

+ 5
- 0
src/apds9930/CMakeLists.txt 查看文件

@@ -0,0 +1,5 @@
1
+set (libname "apds9930")
2
+set (libdescription "upm apds9930 sensor module")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 61
- 0
src/apds9930/apds9930.cxx 查看文件

@@ -0,0 +1,61 @@
1
+/*
2
+ * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
3
+ * Copyright (c) 2015 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
+
25
+#include <iostream>
26
+#include <string>
27
+#include <stdexcept>
28
+
29
+#include "apds9930.h"
30
+
31
+using namespace upm;
32
+
33
+APDS9930::APDS9930(int device)
34
+{
35
+    if (!(m_iio = mraa_iio_init(device))) {
36
+        throw std::invalid_argument(std::string(__FUNCTION__) +
37
+                                    ": mraa_iio_init() failed, invalid device?");
38
+        return;
39
+    }
40
+}
41
+
42
+APDS9930::~APDS9930()
43
+{
44
+    // mraa_iio_stop(m_iio);
45
+}
46
+
47
+int
48
+APDS9930::getAmbient()
49
+{
50
+    int iio_value = 0;
51
+    mraa_iio_read_integer(m_iio, "in_illuminance_input", &iio_value);
52
+    return iio_value;
53
+}
54
+
55
+int
56
+APDS9930::getProximity()
57
+{
58
+    int iio_value = 0;
59
+    mraa_iio_read_integer(m_iio, "in_proximity_raw", &iio_value);
60
+    return iio_value;
61
+}

+ 82
- 0
src/apds9930/apds9930.h 查看文件

@@ -0,0 +1,82 @@
1
+/*
2
+ * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
3
+ * Copyright (c) 2015 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 <mraa/iio.h>
28
+
29
+namespace upm
30
+{
31
+/**
32
+ * @brief APDS9930 Digital Proximity and Ambient Light Sensor library
33
+ * @defgroup apds9930 libupm-apds9930
34
+ * @ingroup Avago Technologies iio i2c proximity and ambient light sensor
35
+ */
36
+
37
+/**
38
+ * @library apds9930
39
+ * @sensor apds9930
40
+ * @comname APDS9930 Digital Proximity and Ambient Light Sensor
41
+ * @type light proximity
42
+ * @man Avago Technologies
43
+ * @con iio i2c
44
+ *
45
+ * @brief APDS9930 Digital Proximity and Ambient Light Sensor
46
+ *
47
+ * This sensor provides digital ambient light sensing (ALS),
48
+ * IR LED and a complete proximity detection system.
49
+ *
50
+ * @snippet apds9930.cxx Interesting
51
+ */
52
+
53
+class APDS9930
54
+{
55
+  public:
56
+    /**
57
+     * APDS-9930 digital proximity and ambient light sensor constructor
58
+     *
59
+     * @param iio device number
60
+     */
61
+    APDS9930(int device);
62
+    /**
63
+     * APDS9930 destructor
64
+     */
65
+    ~APDS9930();
66
+    /**
67
+     * Gets the ambient luminance value from the sensor
68
+     *
69
+     * @return Ambient Luminance value
70
+     */
71
+    int getAmbient();
72
+    /**
73
+     * Gets the proximity value from the sensor
74
+     *
75
+     * @return Proximity value
76
+     */
77
+    int getProximity();
78
+
79
+  private:
80
+    mraa_iio_context m_iio;
81
+};
82
+}

+ 14
- 0
src/apds9930/javaupm_apds9930.i 查看文件

@@ -0,0 +1,14 @@
1
+%module javaupm_apds9930
2
+%include "../upm.i"
3
+%include "stdint.i"
4
+%include "typemaps.i"
5
+
6
+%feature("director") IsrCallback;
7
+
8
+%ignore generic_callback_isr;
9
+%include "../IsrCallback.h"
10
+
11
+%{
12
+    #include "apds9930.h"
13
+%}
14
+%include "apds9930.h"

+ 8
- 0
src/apds9930/jsupm_apds9930.i 查看文件

@@ -0,0 +1,8 @@
1
+%module jsupm_apds9930
2
+%include "../upm.i"
3
+
4
+%{
5
+    #include "apds9930.h"
6
+%}
7
+
8
+%include "apds9930.h"

+ 9
- 0
src/apds9930/pyupm_apds9930.i 查看文件

@@ -0,0 +1,9 @@
1
+%module pyupm_apds9930
2
+%include "../upm.i"
3
+
4
+%feature("autodoc", "3");
5
+
6
+%include "apds9930.h"
7
+%{
8
+    #include "apds9930.h"
9
+%}