Grove: Reverted examples and Sources

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik
2016-09-13 17:29:02 -07:00
committed by Noel Eck
parent 4d39f1ee84
commit ea4b1b6aa7
88 changed files with 4447 additions and 0 deletions

View File

@ -0,0 +1,5 @@
set (libname "groveeldriver")
set (libdescription "upm groveeldriver sensor module")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
upm_module_init("-lrt")

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 "groveeldriver.hpp"
using namespace upm;
GroveElDriver::GroveElDriver(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);
}
GroveElDriver::~GroveElDriver()
{
mraa_gpio_close(m_gpio);
}
void GroveElDriver::on()
{
mraa_result_t error = MRAA_SUCCESS;
error = mraa_gpio_write (m_gpio, HIGH);
if (error != MRAA_SUCCESS)
mraa_result_print(error);
}
void GroveElDriver::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,78 @@
/*
* 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 Grove EL Driver Module library
* @defgroup groveeldriver libupm-groveeldriver
* @ingroup seeed gpio electric
*/
/**
* @library groveeldriver
* @sensor groveeldriver
* @comname Grove EL Driver
* @type electric
* @man seeed
* @con gpio
*
* @brief API for the Grove EL Driver Module
*
* The Grove EL Driver allows you to easily light up an
* EL wire with just one single Grove cable.
*
* @image html groveeldriver.jpg
* @snippet groveeldriver.cxx Interesting
*/
class GroveElDriver {
public:
/**
* Grove EL Driver constructor
*
* @param pin Digital pin to use
*/
GroveElDriver(int pin);
/**
* Grove EL Driver destructor
*/
~GroveElDriver();
/**
* Turns the EL wire on
*/
void on();
/**
* Turns the EL wire off
*/
void off();
private:
mraa_gpio_context m_gpio;
};
}

View File

@ -0,0 +1,19 @@
%module javaupm_groveeldriver
%include "../upm.i"
%{
#include "groveeldriver.hpp"
%}
%include "groveeldriver.hpp"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_groveeldriver");
} 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_groveeldriver
%include "../upm.i"
%{
#include "groveeldriver.hpp"
%}
%include "groveeldriver.hpp"

View File

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

View File

@ -0,0 +1,5 @@
set (libname "grovespeaker")
set (libdescription "upm grovespeaker speaker module")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
upm_module_init()

View File

@ -0,0 +1,150 @@
/*
* Author: Zion Orent <sorent@ics.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 <iostream>
#include <string>
#include <stdexcept>
#include "grovespeaker.hpp"
using namespace upm;
GroveSpeaker::GroveSpeaker(int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) )
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
m_note_list['a'] = storeNote(1136, 1073, 568, 536, 284, 268);
m_note_list['b'] = storeNote(1012, 0, 506, 0, 253, 0);
m_note_list['c'] = storeNote(1911, 1804, 956, 902, 478, 451);
m_note_list['d'] = storeNote(1703, 1607, 851, 804, 426, 402);
m_note_list['e'] = storeNote(1517, 0, 758, 0, 379, 0);
m_note_list['f'] = storeNote(1432, 1351, 716, 676, 358, 338);
m_note_list['g'] = storeNote(1276, 1204, 638, 602, 319, 301);
}
GroveSpeaker::~GroveSpeaker()
{
mraa_gpio_close(m_gpio);
}
NoteData GroveSpeaker::storeNote(int noteDelayLow, int noteDelayLowSharp,
int noteDelayMed, int noteDelayMedSharp,
int noteDelayHigh, int noteDelayHighSharp)
{
NoteData note;
note.delayTimeLow = noteDelayLow;
note.delayTimeLowSharp = noteDelayLowSharp;
note.delayTimeMed = noteDelayMed;
note.delayTimeMedSharp = noteDelayMedSharp;
note.delayTimeHigh = noteDelayHigh;
note.delayTimeHighSharp = noteDelayHighSharp;
return note;
}
void GroveSpeaker::playAll()
{
playSound('c', false, "low");
usleep(200000);
playSound('d', false, "low");
usleep(200000);
playSound('e', false, "low");
usleep(200000);
playSound('f', false, "low");
usleep(200000);
playSound('g', false, "low");
usleep(500000);
playSound('a', false, "low");
usleep(500000);
playSound('b', false, "low");
usleep(500000);
}
void GroveSpeaker::playSound(char letter, bool sharp, std::string vocalWeight)
{
std::map<char, NoteData>::iterator it = m_note_list.find(letter);
if(it == m_note_list.end())
{
std::cout << "The key " << letter << " doesn't exist." << std::endl;
return;
}
NoteData nd = it->second;
int delayTime;
if (sharp)
{
if (vocalWeight.compare("low") == 0)
delayTime = nd.delayTimeLowSharp;
else if (vocalWeight.compare("med") == 0)
delayTime = nd.delayTimeMedSharp;
else if (vocalWeight.compare("high") == 0)
delayTime = nd.delayTimeHighSharp;
else
{
std::cout << "Correct voice weight values are low, med, or high"
<< std::endl;
return;
}
}
else
{
if (vocalWeight.compare("low") == 0)
delayTime = nd.delayTimeLow;
else if (vocalWeight.compare("med") == 0)
delayTime = nd.delayTimeMed;
else if (vocalWeight.compare("high") == 0)
delayTime = nd.delayTimeHigh;
else
{
std::cout << "Correct voice weight values are low, med, or high"
<< std::endl;
return;
}
}
// If delayTime is zero, that means you tried to choose a sharp note
// for a note that has no sharp
if (sharp && !delayTime)
{
std::cout << "The key " << letter << " doesn't have a sharp note."
<< std::endl;
return;
}
sound(delayTime);
}
void GroveSpeaker::sound(int note_delay)
{
mraa_result_t error = MRAA_SUCCESS;
for (int i = 0; i < 100; i++)
{
error = mraa_gpio_write (m_gpio, HIGH);
usleep(note_delay);
error = mraa_gpio_write (m_gpio, LOW);
usleep(note_delay);
}
if (error != MRAA_SUCCESS)
mraa_result_print(error);
}

View File

@ -0,0 +1,103 @@
/*
* Author: Zion Orent <sorent@ics.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 <map>
#include <unistd.h>
#include <mraa/gpio.h>
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief Grove Speaker library
* @defgroup grovespeaker libupm-grovespeaker
* @ingroup seeed gpio sound hak
*/
typedef struct
{
int delayTimeLow;
int delayTimeLowSharp;
int delayTimeMed;
int delayTimeMedSharp;
int delayTimeHigh;
int delayTimeHighSharp;
} NoteData;
/**
* @library grovespeaker
* @sensor grovespeaker
* @comname Grove Speaker
* @type sound
* @man seeed
* @con gpio
* @kit hak
*
* @brief API for the Grove Speaker
*
* UPM module for the Grove Speaker.
* This sensor can generate different tones and sounds depending on the
* frequency of the input signal.
*
* @image html grovespeaker.jpg
* @snippet grovespeaker.cxx Interesting
*/
class GroveSpeaker {
public:
/**
* Grove Speaker constructor
*
* @param pin Digital pin to use
*/
GroveSpeaker(int pin);
/**
* GroveSpeaker destructor
*/
~GroveSpeaker();
/**
* Plays all alto notes (lowest notes)
*
*/
void playAll();
/**
* Plays a sound and a note whether it's sharp or not
*
* @param letter Character name of the note
* ('a', 'b', 'c', 'd', 'e', 'f', or 'g')
* @param sharp If true, plays a sharp version of the note; otherwise, does not play the note
* @param vocalWeight String to determine whether to play a low ("low"),
* a medium ("med"), or a high ("high") note
*/
void playSound(char letter, bool sharp, std::string vocalWeight);
private:
mraa_gpio_context m_gpio;
std::map <char, NoteData> m_note_list;
void sound(int note_delay);
NoteData storeNote(int noteDelayLow, int noteDelayLowSharp,
int noteDelayMed, int noteDelayMedSharp,
int noteDelayHigh, int noteDelayHighSharp);
};
}

View File

@ -0,0 +1,19 @@
%module javaupm_grovespeaker
%include "../upm.i"
%{
#include "grovespeaker.hpp"
%}
%include "grovespeaker.hpp"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_grovespeaker");
} 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_grovespeaker
%include "../upm.i"
%{
#include "grovespeaker.hpp"
%}
%include "grovespeaker.hpp"

View File

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