Browse Source

grove: initial groveLED implementation and move to maa 0.2.2 api

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
Brendan Le Foll 10 years ago
parent
commit
050d6553cd

+ 1
- 1
CMakeLists.txt View File

@@ -7,7 +7,7 @@ if (SWIG_FOUND)
7 7
 endif ()
8 8
 
9 9
 find_package (PkgConfig REQUIRED)
10
-pkg_check_modules (MAA maa>=0.2.1)
10
+pkg_check_modules (MAA maa>=0.2.2)
11 11
 message (INFO " found libmaa version: ${MAA_VERSION}")
12 12
 
13 13
 set (CMAKE_SWIG_FLAGS "")

+ 3
- 0
examples/CMakeLists.txt View File

@@ -1,5 +1,8 @@
1 1
 add_executable (compass compass.cxx)
2
+add_executable (groveled groveled.cxx)
2 3
 
3 4
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
5
+include_directories (${PROJECT_SOURCE_DIR}/src/grove)
4 6
 
5 7
 target_link_libraries (compass hmc5883l)
8
+target_link_libraries (groveled grove)

+ 2
- 1
examples/compass.cxx View File

@@ -27,7 +27,8 @@
27 27
 int
28 28
 main(int argc, char **argv)
29 29
 {
30
-    upm::Hmc5883l* compass = new upm::Hmc5883l();                                                                                                      
30
+    // Use i2c device 0 all the time
31
+    upm::Hmc5883l* compass = new upm::Hmc5883l(0);
31 32
     fprintf(stdout, "heading: %f\n", compass->heading());
32 33
 
33 34
     return 0;

+ 43
- 0
examples/groveled.cxx View File

@@ -0,0 +1,43 @@
1
+/*
2
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3
+ * Copyright (c) 2014 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 "grove.h"
28
+
29
+int
30
+main(int argc, char **argv)
31
+{
32
+    // Use i2c device 0 all the time
33
+    upm::GroveLed* led = new upm::GroveLed(2);
34
+    std::cout << led->name() << std::endl;
35
+    for (int i=0; i < 10; i++) {
36
+        led->on();
37
+        sleep(1);
38
+        led->off();
39
+        sleep(1);
40
+    }
41
+
42
+    return 0;
43
+}

+ 1
- 0
src/CMakeLists.txt View File

@@ -1 +1,2 @@
1 1
 add_subdirectory (hmc5883l)
2
+add_subdirectory (grove)

+ 35
- 0
src/grove/CMakeLists.txt View File

@@ -0,0 +1,35 @@
1
+set (libname "grove")
2
+add_library (grove SHARED grove.cxx)
3
+include_directories (${MAA_INCLUDE_DIR})
4
+target_link_libraries (grove ${MAA_LIBRARIES})
5
+
6
+if (DOXYGEN_FOUND AND SWIG_FOUND)
7
+  find_package (PythonLibs)
8
+
9
+  include_directories (
10
+    ${PYTHON_INCLUDE_PATH}
11
+    ${PYTHON_INCLUDE_DIRS}
12
+    ${MAA_INCLUDE_DIR}
13
+    .
14
+  )
15
+
16
+  set_source_files_properties (pyupm_grove.i PROPERTIES CPLUSPLUS ON)
17
+  set_source_files_properties (jsupm_grove.i PROPERTIES CPLUSPLUS ON)
18
+
19
+  swig_add_module (pyupm_grove python pyupm_grove.i grove.cxx)
20
+  swig_add_module (jsupm_grove python jsupm_grove.i grove.cxx)
21
+  swig_link_libraries (pyupm_grove ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
22
+  swig_link_libraries (jsupm_grove ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
23
+
24
+  set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
25
+  add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
26
+    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
27
+      ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
28
+      ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
29
+      DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
30
+  )
31
+  add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i)
32
+  add_dependencies (${libname}doc_i doc)
33
+  add_dependencies (${SWIG_MODULE_pyupm_grove_REAL_NAME} ${libname}doc_i)
34
+
35
+endif ()

+ 58
- 0
src/grove/grove.cxx View File

@@ -0,0 +1,58 @@
1
+/*
2
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3
+ * Copyright (c) 2014 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 "grove.h"
26
+
27
+using namespace upm;
28
+
29
+GroveLed::GroveLed(int pin)
30
+{
31
+    maa_init();
32
+    m_gpio = maa_gpio_init(pin);
33
+    maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
34
+    m_name = "LED Socket";
35
+}
36
+
37
+GroveLed::~GroveLed()
38
+{
39
+    maa_gpio_close(m_gpio);
40
+}
41
+
42
+maa_result_t GroveLed::write(int value)
43
+{
44
+    if (value >= 1) {
45
+        return maa_gpio_write(m_gpio, 1);
46
+    }
47
+    return maa_gpio_write(m_gpio, 0);
48
+}
49
+
50
+maa_result_t GroveLed::on()
51
+{
52
+    return write(1);
53
+}
54
+
55
+maa_result_t GroveLed::off()
56
+{
57
+    return write(0);
58
+}

+ 53
- 0
src/grove/grove.h View File

@@ -0,0 +1,53 @@
1
+/*
2
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3
+ * Copyright (c) 2014 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 <maa/gpio.h>
28
+
29
+namespace upm {
30
+
31
+class Grove {
32
+    public:
33
+        virtual ~Grove() {}
34
+        std::string name()
35
+        {
36
+            return m_name;
37
+        }
38
+    protected:
39
+        std::string m_name;
40
+};
41
+
42
+class GroveLed: public Grove {
43
+    public:
44
+        GroveLed(int pin);
45
+        ~GroveLed();
46
+        maa_result_t write(int value);
47
+        maa_result_t off();
48
+        maa_result_t on();
49
+    private:
50
+        maa_gpio_context * m_gpio;
51
+};
52
+
53
+}

+ 7
- 0
src/grove/jsupm_grove.i View File

@@ -0,0 +1,7 @@
1
+%module jsupm_grove
2
+
3
+%{
4
+    #include "grove.h"
5
+%}
6
+
7
+%include "grove.h"

+ 12
- 0
src/grove/pyupm_grove.i View File

@@ -0,0 +1,12 @@
1
+%module pyupm_grove
2
+
3
+%feature("autodoc", "3");
4
+
5
+#ifdef DOXYGEN
6
+%include "grove_doc.i"
7
+#endif
8
+
9
+%include "grove.h"
10
+%{
11
+    #include "grove.h"
12
+%}

+ 2
- 2
src/hmc5883l/hmc5883l.cxx View File

@@ -77,9 +77,9 @@
77 77
 
78 78
 using namespace upm;
79 79
 
80
-Hmc5883l::Hmc5883l()
80
+Hmc5883l::Hmc5883l(int bus)
81 81
 {
82
-    m_i2c = maa_i2c_init();
82
+    m_i2c = maa_i2c_init(bus);
83 83
 
84 84
     maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
85 85
     m_rx_tx_buf[0] = HMC5883L_CONF_REG_B;

+ 1
- 1
src/hmc5883l/hmc5883l.h View File

@@ -32,7 +32,7 @@ namespace upm {
32 32
 class Hmc5883l {
33 33
 public:
34 34
     /// Creates a Hmc5883l object
35
-    Hmc5883l();
35
+    Hmc5883l(int bus);
36 36
 
37 37
     /// Returns the direction
38 38
     float direction();