mirror of
https://github.com/eclipse/upm.git
synced 2025-06-08 14:20:38 +03:00
sx6119: Initial implementation
This was tested with the Grove FM Receiver. Unfortunately, there is no documentation on how to control the device using the D1 and D2 pins that Seeed provides. There is a switch on the device that can control all of the elements, power, volume, and seek +/-. The supplied example can turn the device on, and do a seek, but not much else. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Zion Orent <zorent@ics.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
94da23a1fd
commit
34b28928de
@ -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})
|
||||
|
69
examples/c++/sx6119.cxx
Normal file
69
examples/c++/sx6119.cxx
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#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" <<endl;
|
||||
cout << "power on or off." << endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
bool doSeek = false;
|
||||
|
||||
if (argc > 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;
|
||||
}
|
53
examples/javascript/sx6119.js
Normal file
53
examples/javascript/sx6119.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
/*
|
||||
* Author: Zion Orent <zorent@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.
|
||||
*/
|
||||
|
||||
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");
|
50
examples/python/sx6119.py
Normal file
50
examples/python/sx6119.py
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Zion Orent <zorent@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.
|
||||
|
||||
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";
|
5
src/sx6119/CMakeLists.txt
Normal file
5
src/sx6119/CMakeLists.txt
Normal file
@ -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()
|
9
src/sx6119/jsupm_sx6119.i
Normal file
9
src/sx6119/jsupm_sx6119.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module jsupm_sx6119
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "sx6119.h"
|
||||
%}
|
||||
|
||||
%include "sx6119.h"
|
||||
|
11
src/sx6119/pyupm_sx6119.i
Normal file
11
src/sx6119/pyupm_sx6119.i
Normal file
@ -0,0 +1,11 @@
|
||||
%module pyupm_sx6119
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%{
|
||||
#include "sx6119.h"
|
||||
%}
|
||||
|
||||
%include "sx6119.h"
|
||||
|
76
src/sx6119/sx6119.cxx
Normal file
76
src/sx6119/sx6119.cxx
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@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 <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#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);
|
||||
}
|
87
src/sx6119/sx6119.h
Normal file
87
src/sx6119/sx6119.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@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 <iostream>
|
||||
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user