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 "")
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)
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;
--- /dev/null
+/*
+ * 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;
+}
add_subdirectory (hmc5883l)
+add_subdirectory (grove)
--- /dev/null
+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 ()
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+};
+
+}
--- /dev/null
+%module jsupm_grove
+
+%{
+ #include "grove.h"
+%}
+
+%include "grove.h"
--- /dev/null
+%module pyupm_grove
+
+%feature("autodoc", "3");
+
+#ifdef DOXYGEN
+%include "grove_doc.i"
+#endif
+
+%include "grove.h"
+%{
+ #include "grove.h"
+%}
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;
class Hmc5883l {
public:
/// Creates a Hmc5883l object
- Hmc5883l();
+ Hmc5883l(int bus);
/// Returns the direction
float direction();