grove: initial groveLED implementation and move to maa 0.2.2 api

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll 2014-05-06 14:27:16 +01:00
parent edf88ef6a7
commit 050d6553cd
12 changed files with 218 additions and 5 deletions

@ -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 "")

@ -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)

@ -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;

43
examples/groveled.cxx Normal file

@ -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;
}

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

35
src/grove/CMakeLists.txt Normal file

@ -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 ()

58
src/grove/grove.cxx Normal file

@ -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);
}

53
src/grove/grove.h Normal file

@ -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;
};
}

7
src/grove/jsupm_grove.i Normal file

@ -0,0 +1,7 @@
%module jsupm_grove
%{
#include "grove.h"
%}
%include "grove.h"

12
src/grove/pyupm_grove.i Normal file

@ -0,0 +1,12 @@
%module pyupm_grove
%feature("autodoc", "3");
#ifdef DOXYGEN
%include "grove_doc.i"
#endif
%include "grove.h"
%{
#include "grove.h"
%}

@ -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;

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