• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
30 #include "../IsrCallback.h"
31 #endif
32 
33 namespace upm {
34   /**
35    * @brief A110X Hall Effect library
36    * @defgroup a110x libupm-a110x
37    * @ingroup seeed gpio electric robok
38    */
39 
40   /**
41    * @library a110x
42    * @sensor a110x
43    * @comname A110X Hall Effect Sensor
44    * @altname Grove Hall Sensor
45    * @altid A1101, A1102, A1103, A1004, A1106
46    * @type electric
47    * @man seeed
48    * @web http://www.allegromicro.com/en/Products/Magnetic-Digital-Position-Sensor-ICs/Hall-Effect-Unipolar-Switches/A1101-2-3-4-6.aspx
49    * @con gpio
50    * @kit robok
51    *
52    * @brief API for the A110X Hall Effect sensors
53    *
54    * UPM module for the A110X (A1101, A1102, A1103, A1104, and A1106)
55    * Hall Effect sensors.  It outputs a digital signal indicating
56    * whether it is detecting a magnetic field with south polarity
57    * perpendicular to the sensor element.
58    *
59    * @image html a110x.jpg
60    * An example showing a simple test for the presence of a field
61    * @snippet a110x.cxx Interesting
62    * An example demonstrating the use of an interrupt handler to count pulses
63    * @snippet a110x-intr.cxx Interesting
64    */
65   class A110X {
66   public:
67     /**
68      * A110x digital sensor constructor
69      *
70      * @param pin Digital pin to use
71      */
72     A110X(int pin);
73     /**
74      * A110X destructor
75      */
76     ~A110X();
77     /**
78      * Determines whether a magnetic field of south polarity has been detected
79      *
80      * @return True if magnetic field detected
81      */
82     bool magnetDetected();
83 
84     /**
85      * Installs an interrupt service routine (ISR) to be called when
86      * the appropriate magnetic field is detected
87      *
88      * @param fptr Pointer to a function to be called on interrupt
89      * @param arg Pointer to an object to be supplied as an
90      * argument to the ISR.
91      */
92 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
93     void installISR(IsrCallback *cb);
94 #else
95     void installISR(void (*isr)(void *), void *arg);
96 #endif
97     /**
98      * Uninstalls the previously installed ISR
99      *
100      */
101     void uninstallISR();
102 
103   private:
104 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
105     void installISR(void (*isr)(void *), void *arg);
106 #endif
107 
108     bool m_isrInstalled;
109     mraa_gpio_context m_gpio;
110   };
111 }
112 
113 
114