grove: initial groveLED implementation and move to maa 0.2.2 api
authorBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 6 May 2014 13:27:16 +0000 (14:27 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 6 May 2014 14:59:23 +0000 (15:59 +0100)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
12 files changed:
CMakeLists.txt
examples/CMakeLists.txt
examples/compass.cxx
examples/groveled.cxx [new file with mode: 0644]
src/CMakeLists.txt
src/grove/CMakeLists.txt [new file with mode: 0644]
src/grove/grove.cxx [new file with mode: 0644]
src/grove/grove.h [new file with mode: 0644]
src/grove/jsupm_grove.i [new file with mode: 0644]
src/grove/pyupm_grove.i [new file with mode: 0644]
src/hmc5883l/hmc5883l.cxx
src/hmc5883l/hmc5883l.h

index 727010c..2f5d95d 100644 (file)
@@ -7,7 +7,7 @@ if (SWIG_FOUND)
 endif ()
 
 find_package (PkgConfig REQUIRED)
-pkg_check_modules (MAA maa>=0.2.1)
+pkg_check_modules (MAA maa>=0.2.2)
 message (INFO " found libmaa version: ${MAA_VERSION}")
 
 set (CMAKE_SWIG_FLAGS "")
index c06fc58..bfbbb2c 100644 (file)
@@ -1,5 +1,8 @@
 add_executable (compass compass.cxx)
+add_executable (groveled groveled.cxx)
 
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
+include_directories (${PROJECT_SOURCE_DIR}/src/grove)
 
 target_link_libraries (compass hmc5883l)
+target_link_libraries (groveled grove)
index c72337a..45aaa5e 100644 (file)
@@ -27,7 +27,8 @@
 int
 main(int argc, char **argv)
 {
-    upm::Hmc5883l* compass = new upm::Hmc5883l();                                                                                                      
+    // Use i2c device 0 all the time
+    upm::Hmc5883l* compass = new upm::Hmc5883l(0);
     fprintf(stdout, "heading: %f\n", compass->heading());
 
     return 0;
diff --git a/examples/groveled.cxx b/examples/groveled.cxx
new file mode 100644 (file)
index 0000000..59de305
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <iostream>
+#include "grove.h"
+
+int
+main(int argc, char **argv)
+{
+    // Use i2c device 0 all the time
+    upm::GroveLed* led = new upm::GroveLed(2);
+    std::cout << led->name() << std::endl;
+    for (int i=0; i < 10; i++) {
+        led->on();
+        sleep(1);
+        led->off();
+        sleep(1);
+    }
+
+    return 0;
+}
index d665c15..f2fc167 100644 (file)
@@ -1 +1,2 @@
 add_subdirectory (hmc5883l)
+add_subdirectory (grove)
diff --git a/src/grove/CMakeLists.txt b/src/grove/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f783527
--- /dev/null
@@ -0,0 +1,35 @@
+set (libname "grove")
+add_library (grove SHARED grove.cxx)
+include_directories (${MAA_INCLUDE_DIR})
+target_link_libraries (grove ${MAA_LIBRARIES})
+
+if (DOXYGEN_FOUND AND SWIG_FOUND)
+  find_package (PythonLibs)
+
+  include_directories (
+    ${PYTHON_INCLUDE_PATH}
+    ${PYTHON_INCLUDE_DIRS}
+    ${MAA_INCLUDE_DIR}
+    .
+  )
+
+  set_source_files_properties (pyupm_grove.i PROPERTIES CPLUSPLUS ON)
+  set_source_files_properties (jsupm_grove.i PROPERTIES CPLUSPLUS ON)
+
+  swig_add_module (pyupm_grove python pyupm_grove.i grove.cxx)
+  swig_add_module (jsupm_grove python jsupm_grove.i grove.cxx)
+  swig_link_libraries (pyupm_grove ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
+  swig_link_libraries (jsupm_grove ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
+
+  set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
+  add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
+    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
+      ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
+      ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
+      DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
+  )
+  add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i)
+  add_dependencies (${libname}doc_i doc)
+  add_dependencies (${SWIG_MODULE_pyupm_grove_REAL_NAME} ${libname}doc_i)
+
+endif ()
diff --git a/src/grove/grove.cxx b/src/grove/grove.cxx
new file mode 100644 (file)
index 0000000..13c71cc
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "grove.h"
+
+using namespace upm;
+
+GroveLed::GroveLed(int pin)
+{
+    maa_init();
+    m_gpio = maa_gpio_init(pin);
+    maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
+    m_name = "LED Socket";
+}
+
+GroveLed::~GroveLed()
+{
+    maa_gpio_close(m_gpio);
+}
+
+maa_result_t GroveLed::write(int value)
+{
+    if (value >= 1) {
+        return maa_gpio_write(m_gpio, 1);
+    }
+    return maa_gpio_write(m_gpio, 0);
+}
+
+maa_result_t GroveLed::on()
+{
+    return write(1);
+}
+
+maa_result_t GroveLed::off()
+{
+    return write(0);
+}
diff --git a/src/grove/grove.h b/src/grove/grove.h
new file mode 100644 (file)
index 0000000..5df27b8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <string>
+#include <maa/gpio.h>
+
+namespace upm {
+
+class Grove {
+    public:
+        virtual ~Grove() {}
+        std::string name()
+        {
+            return m_name;
+        }
+    protected:
+        std::string m_name;
+};
+
+class GroveLed: public Grove {
+    public:
+        GroveLed(int pin);
+        ~GroveLed();
+        maa_result_t write(int value);
+        maa_result_t off();
+        maa_result_t on();
+    private:
+        maa_gpio_context * m_gpio;
+};
+
+}
diff --git a/src/grove/jsupm_grove.i b/src/grove/jsupm_grove.i
new file mode 100644 (file)
index 0000000..97a17c2
--- /dev/null
@@ -0,0 +1,7 @@
+%module jsupm_grove
+
+%{
+    #include "grove.h"
+%}
+
+%include "grove.h"
diff --git a/src/grove/pyupm_grove.i b/src/grove/pyupm_grove.i
new file mode 100644 (file)
index 0000000..abb4c43
--- /dev/null
@@ -0,0 +1,12 @@
+%module pyupm_grove
+
+%feature("autodoc", "3");
+
+#ifdef DOXYGEN
+%include "grove_doc.i"
+#endif
+
+%include "grove.h"
+%{
+    #include "grove.h"
+%}
index 0fdbad6..6049d82 100644 (file)
@@ -77,9 +77,9 @@
 
 using namespace upm;
 
-Hmc5883l::Hmc5883l()
+Hmc5883l::Hmc5883l(int bus)
 {
-    m_i2c = maa_i2c_init();
+    m_i2c = maa_i2c_init(bus);
 
     maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
     m_rx_tx_buf[0] = HMC5883L_CONF_REG_B;
index 17fe157..45df0fd 100644 (file)
@@ -32,7 +32,7 @@ namespace upm {
 class Hmc5883l {
 public:
     /// Creates a Hmc5883l object
-    Hmc5883l();
+    Hmc5883l(int bus);
 
     /// Returns the direction
     float direction();