浏览代码

a110x: Initial implementation

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Sarah Knepper <sarah.knepper@intel.com>
Jon Trulson 10 年前
父节点
当前提交
0b7547231f
共有 8 个文件被更改,包括 259 次插入0 次删除
  1. 3
    0
      examples/CMakeLists.txt
  2. 67
    0
      examples/a110x.cxx
  3. 47
    0
      examples/javascript/a110x.js
  4. 5
    0
      src/a110x/CMakeLists.txt
  5. 54
    0
      src/a110x/a110x.cxx
  6. 66
    0
      src/a110x/a110x.h
  7. 8
    0
      src/a110x/jsupm_a110x.i
  8. 9
    0
      src/a110x/pyupm_a110x.i

+ 3
- 0
examples/CMakeLists.txt 查看文件

@@ -55,6 +55,7 @@ add_executable (itg3200-example itg3200.cxx)
55 55
 add_executable (enc03r-example enc03r.cxx)
56 56
 add_executable (adc121c021-example adc121c021.cxx)
57 57
 add_executable (ds1307-example ds1307.cxx)
58
+add_executable (a110x-example a110x.cxx)
58 59
 
59 60
 include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
60 61
 include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@@ -97,6 +98,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/itg3200)
97 98
 include_directories (${PROJECT_SOURCE_DIR}/src/enc03r)
98 99
 include_directories (${PROJECT_SOURCE_DIR}/src/adc121c021)
99 100
 include_directories (${PROJECT_SOURCE_DIR}/src/ds1307)
101
+include_directories (${PROJECT_SOURCE_DIR}/src/a110x)
100 102
 
101 103
 target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
102 104
 target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@@ -155,3 +157,4 @@ target_link_libraries (itg3200-example itg3200 ${CMAKE_THREAD_LIBS_INIT})
155 157
 target_link_libraries (enc03r-example enc03r ${CMAKE_THREAD_LIBS_INIT})
156 158
 target_link_libraries (adc121c021-example adc121c021 ${CMAKE_THREAD_LIBS_INIT})
157 159
 target_link_libraries (ds1307-example ds1307 ${CMAKE_THREAD_LIBS_INIT})
160
+target_link_libraries (a110x-example a110x ${CMAKE_THREAD_LIBS_INIT})

+ 67
- 0
examples/a110x.cxx 查看文件

@@ -0,0 +1,67 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2014 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 "a110x.h"
29
+
30
+using namespace std;
31
+
32
+int shouldRun = true;
33
+
34
+void sig_handler(int signo)
35
+{
36
+  if (signo == SIGINT)
37
+    shouldRun = false;
38
+}
39
+
40
+
41
+int main ()
42
+{
43
+  signal(SIGINT, sig_handler);
44
+
45
+//! [Interesting]
46
+  // Instantiate an A110X sensor on digital pin D2
47
+  upm::A110X* hall = new upm::A110X(2);
48
+  
49
+  // check every second for the presence of a magnetic field (south
50
+  // polarity)
51
+  while (shouldRun)
52
+    {
53
+      bool val = hall->magnetDetected();
54
+      if (val)
55
+        cout << "Magnet (south polarity) detected." << endl;
56
+      else
57
+        cout << "No magnet detected." << endl;
58
+
59
+      sleep(1);
60
+    }
61
+//! [Interesting]
62
+
63
+  cout << "Exiting..." << endl;
64
+
65
+  delete hall;
66
+  return 0;
67
+}

+ 47
- 0
examples/javascript/a110x.js 查看文件

@@ -0,0 +1,47 @@
1
+/*jslint node:true, vars:true, bitwise:true, unparam:true */
2
+/*jshint unused:true */
3
+/*global */
4
+/*
5
+* Author: Zion Orent <zorent@ics.com>
6
+* Copyright (c) 2014 Intel Corporation.
7
+*
8
+* Permission is hereby granted, free of charge, to any person obtaining
9
+* a copy of this software and associated documentation files (the
10
+* "Software"), to deal in the Software without restriction, including
11
+* without limitation the rights to use, copy, modify, merge, publish,
12
+* distribute, sublicense, and/or sell copies of the Software, and to
13
+* permit persons to whom the Software is furnished to do so, subject to
14
+* the following conditions:
15
+*
16
+* The above copyright notice and this permission notice shall be
17
+* included in all copies or substantial portions of the Software.
18
+*
19
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+*/
27
+
28
+var hallEffectSensor = require('jsupm_a110x');
29
+
30
+// Instantiate a Hall Effect magnet sensor on digital pin D2
31
+var myHallEffectSensor = new hallEffectSensor.A110X(2);
32
+
33
+// Check every second for the presence of a magnetic field (south polarity)
34
+setInterval(function()
35
+{
36
+	if (myHallEffectSensor.magnetDetected())
37
+		console.log("Magnet (south polarity) detected.");
38
+	else
39
+		console.log("No magnet detected.");
40
+}, 1000);
41
+
42
+// Print message when exiting
43
+process.on('SIGINT', function()
44
+{
45
+	console.log("Exiting...");
46
+	process.exit(0);
47
+});

+ 5
- 0
src/a110x/CMakeLists.txt 查看文件

@@ -0,0 +1,5 @@
1
+set (libname "a110x")
2
+set (libdescription "upm a110x sensor module")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 54
- 0
src/a110x/a110x.cxx 查看文件

@@ -0,0 +1,54 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2014 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 <iostream>
26
+
27
+#include "a110x.h"
28
+
29
+using namespace upm;
30
+using namespace std;
31
+
32
+A110X::A110X(int pin)
33
+{
34
+  mraa_init();
35
+
36
+  if ( !(m_gpio = mraa_gpio_init(pin)) )
37
+    {
38
+      cerr << __FUNCTION__ << ": mraa_gpio_init() failed" << endl;
39
+      return;
40
+    }
41
+
42
+  mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
43
+}
44
+
45
+A110X::~A110X()
46
+{
47
+  mraa_gpio_close(m_gpio);
48
+}
49
+
50
+bool A110X::magnetDetected()
51
+{
52
+  return (!mraa_gpio_read(m_gpio) ? true : false);
53
+}
54
+

+ 66
- 0
src/a110x/a110x.h 查看文件

@@ -0,0 +1,66 @@
1
+/*
2
+ * Author: Jon Trulson <jtrulson@ics.com>
3
+ * Copyright (c) 2014 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 <string>
27
+#include <mraa/gpio.h>
28
+
29
+namespace upm {
30
+
31
+  /**
32
+   * @brief C++ API for the A110x Hall Effect sensors
33
+   *
34
+   * UPM module for the A110x (A1101, A1102, A1103, A1104, and A1106)
35
+   * Hall Effect sensors.  It outputs a digital signal indicating
36
+   * whether it is detecting a magnetic field with south polarity
37
+   * perpendicular to the sensor element.
38
+   *
39
+   * @ingroup gpio
40
+   * @snippet a110x.cxx Interesting
41
+   */
42
+  class A110X {
43
+  public:
44
+    /**
45
+     * A110x digital sensor constructor
46
+     *
47
+     * @param pin digital pin to use
48
+     */
49
+    A110X(int pin);
50
+    /**
51
+     * A110X Destructor
52
+     */
53
+    ~A110X();
54
+    /**
55
+     * Determine whether a magnetic field of south polarity has been detected
56
+     *
57
+     * @return True if magnetic field detected
58
+     */
59
+    bool magnetDetected();
60
+
61
+  private:
62
+    mraa_gpio_context m_gpio;
63
+  };
64
+}
65
+
66
+

+ 8
- 0
src/a110x/jsupm_a110x.i 查看文件

@@ -0,0 +1,8 @@
1
+%module jsupm_a110x
2
+%include "../upm.i"
3
+
4
+%{
5
+    #include "a110x.h"
6
+%}
7
+
8
+%include "a110x.h"

+ 9
- 0
src/a110x/pyupm_a110x.i 查看文件

@@ -0,0 +1,9 @@
1
+%module pyupm_a110x
2
+%include "../upm.i"
3
+
4
+%feature("autodoc", "3");
5
+
6
+%include "a110x.h"
7
+%{
8
+    #include "a110x.h"
9
+%}