diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index ef4395ae..bd0b14a2 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -114,6 +114,7 @@ add_executable (zfm20-register-example zfm20-register.cxx) add_executable (uln200xa-example uln200xa.cxx) add_executable (grovewfs-example grovewfs.cxx) add_executable (isd1820-example isd1820.cxx) +add_executable (sx6119-example sx6119.cxx) include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l) include_directories (${PROJECT_SOURCE_DIR}/src/grove) @@ -206,6 +207,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/zfm20) include_directories (${PROJECT_SOURCE_DIR}/src/uln200xa) include_directories (${PROJECT_SOURCE_DIR}/src/grovewfs) include_directories (${PROJECT_SOURCE_DIR}/src/isd1820) +include_directories (${PROJECT_SOURCE_DIR}/src/sx6119) target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT}) @@ -321,3 +323,4 @@ target_link_libraries (zfm20-register-example zfm20 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (uln200xa-example uln200xa ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (grovewfs-example grovewfs ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (isd1820-example isd1820 ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries (sx6119-example sx6119 ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/c++/sx6119.cxx b/examples/c++/sx6119.cxx new file mode 100644 index 00000000..2608387b --- /dev/null +++ b/examples/c++/sx6119.cxx @@ -0,0 +1,69 @@ +/* + * Author: Jon Trulson + * 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 +#include +#include +#include "sx6119.h" + +using namespace std; + +int main (int argc, char **argv) +{ +//! [Interesting] + // Instantiate a SX6119 on digital pins 2 (power) and 3 (seek) + // This example was tested on the Grove FM Receiver. + + upm::SX6119* radio = new upm::SX6119(2, 3); + + // if an argument was specified (any argument), seek to the next + // station, else just toggle the power. + + + cout << "Supply any argument to the command line to seek to the" << endl; + cout << "next station." << endl; + cout << "Running the example without an argument will toggle the" < 1) + doSeek = true; + + // depending on what was selected, do it + + if (doSeek) + radio->seek(); + else + radio->togglePower(); + +//! [Interesting] + + cout << "Exiting..." << endl; + + delete radio; + return 0; +} diff --git a/examples/javascript/sx6119.js b/examples/javascript/sx6119.js new file mode 100644 index 00000000..6833fc0c --- /dev/null +++ b/examples/javascript/sx6119.js @@ -0,0 +1,53 @@ +/*jslint node:true, vars:true, bitwise:true, unparam:true */ +/*jshint unused:true */ +/* +* Author: Zion Orent +* 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. +*/ + +var FM_receiver_lib = require('jsupm_sx6119'); + +// Instantiate a SX6119 on digital pins 2 (power) and 3 (seek) +// This example was tested on the Grove FM Receiver. +var myFM_receiver_obj = new FM_receiver_lib.SX6119(2, 3); + +// if an argument was specified (any argument), seek to the next +// station, else just toggle the power. + + +console.log("Supply any argument to the command line to seek to the"); +console.log("next station."); +console.log("Running the example without an argument will toggle the"); +console.log("power on or off.\n"); + +var doSeek = false; + +if (process.argv.length > 2) + doSeek = true; + +// depending on what was selected, do it +if (doSeek) + myFM_receiver_obj.seek(); +else + myFM_receiver_obj.togglePower(); + +console.log("Exiting"); diff --git a/examples/python/sx6119.py b/examples/python/sx6119.py new file mode 100644 index 00000000..a8498365 --- /dev/null +++ b/examples/python/sx6119.py @@ -0,0 +1,50 @@ +#!/usr/bin/python +# Author: Zion Orent +# 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. + +import sys +import pyupm_sx6119 as upmSx6119 + +# Instantiate a SX6119 on digital pins 2 (power) and 3 (seek) +# This example was tested on the Grove FM Receiver. +myFM_receiver_obj = upmSx6119.SX6119(2, 3) + +# if an argument was specified (any argument), seek to the next +# station, else just toggle the power. + +print "Supply any argument to the command line to seek to the" +print "next station." +print "Running the example without an argument will toggle the" +print "power on or off.\n" + +doSeek = False + +if (len(sys.argv) > 1): + doSeek = True + +# depending on what was selected, do it +if (doSeek): + myFM_receiver_obj.seek() +else: + myFM_receiver_obj.togglePower() + +print "Exiting"; diff --git a/src/sx6119/CMakeLists.txt b/src/sx6119/CMakeLists.txt new file mode 100644 index 00000000..6effe43d --- /dev/null +++ b/src/sx6119/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "sx6119") +set (libdescription "upm grove FM receiver") +set (module_src ${libname}.cxx) +set (module_h ${libname}.h) +upm_module_init() diff --git a/src/sx6119/jsupm_sx6119.i b/src/sx6119/jsupm_sx6119.i new file mode 100644 index 00000000..807008f3 --- /dev/null +++ b/src/sx6119/jsupm_sx6119.i @@ -0,0 +1,9 @@ +%module jsupm_sx6119 +%include "../upm.i" + +%{ + #include "sx6119.h" +%} + +%include "sx6119.h" + diff --git a/src/sx6119/pyupm_sx6119.i b/src/sx6119/pyupm_sx6119.i new file mode 100644 index 00000000..131b009c --- /dev/null +++ b/src/sx6119/pyupm_sx6119.i @@ -0,0 +1,11 @@ +%module pyupm_sx6119 +%include "../upm.i" + +%feature("autodoc", "3"); + +%{ + #include "sx6119.h" +%} + +%include "sx6119.h" + diff --git a/src/sx6119/sx6119.cxx b/src/sx6119/sx6119.cxx new file mode 100644 index 00000000..402627dc --- /dev/null +++ b/src/sx6119/sx6119.cxx @@ -0,0 +1,76 @@ +/* + * Author: Jon Trulson + * 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 +#include + +#include "sx6119.h" + +using namespace upm; +using namespace std; + +SX6119::SX6119(int powerPin, int seekPin) +{ + if ( !(m_gpioPower = mraa_gpio_init(powerPin)) ) + { + cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl; + return; + } + + mraa_gpio_dir(m_gpioPower, MRAA_GPIO_OUT); + mraa_gpio_write(m_gpioPower, 1); + + if ( !(m_gpioSeek = mraa_gpio_init(seekPin)) ) + { + cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl; + return; + } + + mraa_gpio_dir(m_gpioSeek, MRAA_GPIO_OUT); + mraa_gpio_write(m_gpioSeek, 1); +} + +SX6119::~SX6119() +{ + mraa_gpio_close(m_gpioPower); + mraa_gpio_close(m_gpioSeek); +} + +void SX6119::togglePower() +{ + // this is just a toggle -- we set LOW for one second and power will + // be turned on or off depending on the previous condition. + mraa_gpio_write(m_gpioPower, 0); + sleep(1); + mraa_gpio_write(m_gpioPower, 1); +} + +void SX6119::seek() +{ + // this is just a trigger -- we set LOW for 500ms to seek to the + // next available station, wrapping around when we reach the end. + mraa_gpio_write(m_gpioSeek, 0); + usleep(500000); + mraa_gpio_write(m_gpioSeek, 1); +} diff --git a/src/sx6119/sx6119.h b/src/sx6119/sx6119.h new file mode 100644 index 00000000..7a541d84 --- /dev/null +++ b/src/sx6119/sx6119.h @@ -0,0 +1,87 @@ +/* + * Author: Jon Trulson + * 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 + +#include + +namespace upm { + /** + * @brief UPM support for the SX6119 based FM Receiver + * @defgroup sx6119 libupm-sx6119 + * @ingroup seeed gpio sound + */ + + /** + * @sensor sx6119 + * @library sx6119 + * @comname Grove FM Receiver v1.0 + * @type sound + * @man seeed + * @con gpio + * + * @brief C++ API support for the SX6119 based Grove FM Receiver + * + * This class implements support for the FM Receiver. There are + * two digital pins, one that toggles power on/off, and one that + * does a seek to the next station. + * + * @snippet sx6119.cxx Interesting + */ + class SX6119 { + public: + + /** + * SX6119 module constructor + * + * @param powerPin the pin to use for recording + * @param seekPin the pin to use to seek to the next station + */ + SX6119(int powerPin, int seekPin); + + /** + * SX6119 module Destructor + */ + ~SX6119(); + + /** + * Toggle the device power on or off + * + */ + void togglePower(); + + /** + * Seek to the next station + * + */ + void seek(); + + private: + mraa_gpio_context m_gpioPower; + mraa_gpio_context m_gpioSeek; + }; +} + +