Browse Source

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>
Jon Trulson 9 years ago
parent
commit
34b28928de

+ 3
- 0
examples/c++/CMakeLists.txt View File

114
 add_executable (uln200xa-example uln200xa.cxx)
114
 add_executable (uln200xa-example uln200xa.cxx)
115
 add_executable (grovewfs-example grovewfs.cxx)
115
 add_executable (grovewfs-example grovewfs.cxx)
116
 add_executable (isd1820-example isd1820.cxx)
116
 add_executable (isd1820-example isd1820.cxx)
117
+add_executable (sx6119-example sx6119.cxx)
117
 
118
 
118
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
119
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
119
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
120
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
206
 include_directories (${PROJECT_SOURCE_DIR}/src/uln200xa)
207
 include_directories (${PROJECT_SOURCE_DIR}/src/uln200xa)
207
 include_directories (${PROJECT_SOURCE_DIR}/src/grovewfs)
208
 include_directories (${PROJECT_SOURCE_DIR}/src/grovewfs)
208
 include_directories (${PROJECT_SOURCE_DIR}/src/isd1820)
209
 include_directories (${PROJECT_SOURCE_DIR}/src/isd1820)
210
+include_directories (${PROJECT_SOURCE_DIR}/src/sx6119)
209
 
211
 
210
 target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
212
 target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
211
 target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
213
 target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
321
 target_link_libraries (uln200xa-example uln200xa ${CMAKE_THREAD_LIBS_INIT})
323
 target_link_libraries (uln200xa-example uln200xa ${CMAKE_THREAD_LIBS_INIT})
322
 target_link_libraries (grovewfs-example grovewfs ${CMAKE_THREAD_LIBS_INIT})
324
 target_link_libraries (grovewfs-example grovewfs ${CMAKE_THREAD_LIBS_INIT})
323
 target_link_libraries (isd1820-example isd1820 ${CMAKE_THREAD_LIBS_INIT})
325
 target_link_libraries (isd1820-example isd1820 ${CMAKE_THREAD_LIBS_INIT})
326
+target_link_libraries (sx6119-example sx6119 ${CMAKE_THREAD_LIBS_INIT})

+ 69
- 0
examples/c++/sx6119.cxx View File

1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2015 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <unistd.h>
26
+#include <iostream>
27
+#include <signal.h>
28
+#include "sx6119.h"
29
+
30
+using namespace std;
31
+
32
+int main (int argc, char **argv)
33
+{
34
+//! [Interesting]
35
+  // Instantiate a SX6119 on digital pins 2 (power) and 3 (seek)
36
+  // This example was tested on the Grove FM Receiver.
37
+
38
+  upm::SX6119* radio = new upm::SX6119(2, 3);
39
+  
40
+  // if an argument was specified (any argument), seek to the next
41
+  // station, else just toggle the power.
42
+
43
+
44
+  cout << "Supply any argument to the command line to seek to the" << endl;
45
+  cout << "next station." << endl;
46
+  cout << "Running the example without an argument will toggle the" <<endl;
47
+  cout << "power on or off." << endl;
48
+
49
+  cout << endl;
50
+
51
+  bool doSeek = false;
52
+
53
+  if (argc > 1)
54
+    doSeek = true;
55
+  
56
+  // depending on what was selected, do it
57
+
58
+  if (doSeek)
59
+    radio->seek();
60
+  else
61
+    radio->togglePower();
62
+    
63
+//! [Interesting]
64
+
65
+  cout << "Exiting..." << endl;
66
+
67
+  delete radio;
68
+  return 0;
69
+}

+ 53
- 0
examples/javascript/sx6119.js View File

1
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
2
+/*jshint unused:true */
3
+/*
4
+* Author: Zion Orent <zorent@ics.com>
5
+* Copyright (c) 2015 Intel Corporation.
6
+*
7
+* Permission is hereby granted, free of charge, to any person obtaining
8
+* a copy of this software and associated documentation files (the
9
+* "Software"), to deal in the Software without restriction, including
10
+* without limitation the rights to use, copy, modify, merge, publish,
11
+* distribute, sublicense, and/or sell copies of the Software, and to
12
+* permit persons to whom the Software is furnished to do so, subject to
13
+* the following conditions:
14
+*
15
+* The above copyright notice and this permission notice shall be
16
+* included in all copies or substantial portions of the Software.
17
+*
18
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+*/
26
+
27
+var FM_receiver_lib = require('jsupm_sx6119');
28
+
29
+// Instantiate a SX6119 on digital pins 2 (power) and 3 (seek)
30
+// This example was tested on the Grove FM Receiver.
31
+var myFM_receiver_obj = new FM_receiver_lib.SX6119(2, 3);
32
+
33
+// if an argument was specified (any argument), seek to the next
34
+// station, else just toggle the power.
35
+
36
+
37
+console.log("Supply any argument to the command line to seek to the");
38
+console.log("next station.");
39
+console.log("Running the example without an argument will toggle the");
40
+console.log("power on or off.\n");
41
+
42
+var doSeek = false;
43
+
44
+if (process.argv.length > 2)
45
+	doSeek = true;
46
+
47
+// depending on what was selected, do it
48
+if (doSeek)
49
+	myFM_receiver_obj.seek();
50
+else
51
+	myFM_receiver_obj.togglePower();
52
+
53
+console.log("Exiting");

+ 50
- 0
examples/python/sx6119.py View File

1
+#!/usr/bin/python
2
+# Author: Zion Orent <zorent@ics.com>
3
+# Copyright (c) 2015 Intel Corporation.
4
+#
5
+# Permission is hereby granted, free of charge, to any person obtaining
6
+# a copy of this software and associated documentation files (the
7
+# "Software"), to deal in the Software without restriction, including
8
+# without limitation the rights to use, copy, modify, merge, publish,
9
+# distribute, sublicense, and/or sell copies of the Software, and to
10
+# permit persons to whom the Software is furnished to do so, subject to
11
+# the following conditions:
12
+#
13
+# The above copyright notice and this permission notice shall be
14
+# included in all copies or substantial portions of the Software.
15
+#
16
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+import sys
25
+import pyupm_sx6119 as upmSx6119
26
+
27
+# Instantiate a SX6119 on digital pins 2 (power) and 3 (seek)
28
+# This example was tested on the Grove FM Receiver.
29
+myFM_receiver_obj = upmSx6119.SX6119(2, 3)
30
+
31
+# if an argument was specified (any argument), seek to the next
32
+# station, else just toggle the power.
33
+
34
+print "Supply any argument to the command line to seek to the"
35
+print "next station."
36
+print "Running the example without an argument will toggle the"
37
+print "power on or off.\n"
38
+
39
+doSeek = False
40
+
41
+if (len(sys.argv) > 1):
42
+	doSeek = True
43
+
44
+# depending on what was selected, do it
45
+if (doSeek):
46
+	myFM_receiver_obj.seek()
47
+else:
48
+	myFM_receiver_obj.togglePower()
49
+
50
+print "Exiting";

+ 5
- 0
src/sx6119/CMakeLists.txt View File

1
+set (libname "sx6119")
2
+set (libdescription "upm grove FM receiver")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 9
- 0
src/sx6119/jsupm_sx6119.i View File

1
+%module jsupm_sx6119
2
+%include "../upm.i"
3
+
4
+%{
5
+    #include "sx6119.h"
6
+%}
7
+
8
+%include "sx6119.h"
9
+

+ 11
- 0
src/sx6119/pyupm_sx6119.i View File

1
+%module pyupm_sx6119
2
+%include "../upm.i"
3
+
4
+%feature("autodoc", "3");
5
+
6
+%{
7
+    #include "sx6119.h"
8
+%}
9
+
10
+%include "sx6119.h"
11
+

+ 76
- 0
src/sx6119/sx6119.cxx View File

1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2015 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <unistd.h>
26
+#include <iostream>
27
+
28
+#include "sx6119.h"
29
+
30
+using namespace upm;
31
+using namespace std;
32
+
33
+SX6119::SX6119(int powerPin, int seekPin)
34
+{
35
+  if ( !(m_gpioPower = mraa_gpio_init(powerPin)) )
36
+    {
37
+      cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl;
38
+      return;
39
+    }
40
+
41
+  mraa_gpio_dir(m_gpioPower, MRAA_GPIO_OUT);
42
+  mraa_gpio_write(m_gpioPower, 1);
43
+
44
+  if ( !(m_gpioSeek = mraa_gpio_init(seekPin)) )
45
+    {
46
+      cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl;
47
+      return;
48
+    }
49
+
50
+  mraa_gpio_dir(m_gpioSeek, MRAA_GPIO_OUT);
51
+  mraa_gpio_write(m_gpioSeek, 1);
52
+}
53
+
54
+SX6119::~SX6119()
55
+{
56
+  mraa_gpio_close(m_gpioPower);
57
+  mraa_gpio_close(m_gpioSeek);
58
+}
59
+
60
+void SX6119::togglePower()
61
+{
62
+  // this is just a toggle -- we set LOW for one second and power will
63
+  // be turned on or off depending on the previous condition.
64
+  mraa_gpio_write(m_gpioPower, 0);
65
+  sleep(1);
66
+  mraa_gpio_write(m_gpioPower, 1);
67
+}
68
+
69
+void SX6119::seek()
70
+{
71
+  // this is just a trigger -- we set LOW for 500ms to seek to the
72
+  // next available station, wrapping around when we reach the end.
73
+  mraa_gpio_write(m_gpioSeek, 0);
74
+  usleep(500000);
75
+  mraa_gpio_write(m_gpioSeek, 1);
76
+}

+ 87
- 0
src/sx6119/sx6119.h View File

1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2015 Intel Corporation.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+#pragma once
25
+
26
+#include <iostream>
27
+
28
+#include <mraa/gpio.h>
29
+
30
+namespace upm {
31
+    /**
32
+     * @brief UPM support for the SX6119 based FM Receiver
33
+     * @defgroup sx6119 libupm-sx6119
34
+     * @ingroup seeed gpio sound
35
+     */
36
+
37
+    /**
38
+     * @sensor sx6119
39
+     * @library sx6119
40
+     * @comname Grove FM Receiver v1.0
41
+     * @type sound
42
+     * @man seeed
43
+     * @con gpio
44
+     *
45
+     * @brief C++ API support for the SX6119 based Grove FM Receiver
46
+     *
47
+     * This class implements support for the FM Receiver.  There are
48
+     * two digital pins, one that toggles power on/off, and one that
49
+     * does a seek to the next station.
50
+     *
51
+     * @snippet sx6119.cxx Interesting
52
+     */
53
+  class SX6119 {
54
+  public:
55
+
56
+    /**
57
+     * SX6119 module constructor
58
+     *
59
+     * @param powerPin the pin to use for recording
60
+     * @param seekPin the pin to use to seek to the next station
61
+     */
62
+    SX6119(int powerPin, int seekPin);
63
+
64
+    /**
65
+     * SX6119 module Destructor
66
+     */
67
+    ~SX6119();
68
+
69
+    /**
70
+     * Toggle the device power on or off
71
+     *
72
+     */
73
+    void togglePower();
74
+
75
+    /**
76
+     * Seek to the next station
77
+     *
78
+     */
79
+    void seek();
80
+
81
+  private:
82
+    mraa_gpio_context m_gpioPower;
83
+    mraa_gpio_context m_gpioSeek;
84
+  };
85
+}
86
+
87
+