Electromagnet: Remove Grove Dependency

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik
2016-09-13 11:58:56 -07:00
committed by Noel Eck
parent 84f402abd9
commit f4315db035
12 changed files with 52 additions and 52 deletions

View File

@ -0,0 +1,5 @@
upm_mixed_module_init (NAME electromagnet
DESCRIPTION "upm electromagnet sensor module"
CPP_HDR electromagnet.hpp
CPP_SRC electromagnet.cxx
REQUIRES mraa)

View File

@ -0,0 +1,62 @@
/*
* Author: Zion Orent <sorent@ics.com>
* Copyright (c) 2015 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 <string>
#include <stdexcept>
#include "electromagnet.hpp"
using namespace upm;
Electromagnet::Electromagnet(int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) )
{
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
}
Electromagnet::~Electromagnet()
{
mraa_gpio_close(m_gpio);
}
void Electromagnet::on()
{
mraa_result_t error = MRAA_SUCCESS;
error = mraa_gpio_write (m_gpio, HIGH);
if (error != MRAA_SUCCESS)
mraa_result_print(error);
}
void Electromagnet::off()
{
mraa_result_t error = MRAA_SUCCESS;
error = mraa_gpio_write (m_gpio, LOW);
if (error != MRAA_SUCCESS)
mraa_result_print(error);
}

View File

@ -0,0 +1,77 @@
/*
* Author: Zion Orent <sorent@ics.com>
* Copyright (c) 2015 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 <mraa/gpio.h>
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief Electromagnet library
* @defgroup electromagnet libupm-electromagnet
* @ingroup seeed gpio electric
*/
/**
* @library electromagnet
* @sensor electromagnet
* @comname Electromagnet
* @type electric
* @man seeed
* @con gpio
*
* @brief API for the Electromagnet
*
* The Electromagnet can hold up to 1 kg (approximately 2.2 lbs)
*
* @image html electromagnet.jpg
* @snippet electromagnet.cxx Interesting
*/
class Electromagnet {
public:
/**
* Electromagnet constructor
*
* @param pin Digital pin to use
*/
Electromagnet(int pin);
/**
* Electromagnet destructor
*/
~Electromagnet();
/**
* Turns the magnet on
*/
void on();
/**
* Turns the magnet off
*/
void off();
private:
mraa_gpio_context m_gpio;
};
}

View File

@ -0,0 +1,19 @@
%module javaupm_electromagnet
%include "../upm.i"
%{
#include "electromagnet.hpp"
%}
%include "electromagnet.hpp"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_electromagnet");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_electromagnet
%include "../upm.i"
%{
#include "electromagnet.hpp"
%}
%include "electromagnet.hpp"

View File

@ -0,0 +1,11 @@
// Include doxygen-generated documentation
%include "pyupm_doxy2swig.i"
%module pyupm_electromagnet
%include "../upm.i"
%feature("autodoc", "3");
%include "electromagnet.hpp"
%{
#include "electromagnet.hpp"
%}