2014-12-10 16:17:15 -07:00
|
|
|
/*
|
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2014-12-10 16:17:15 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-12-10 16:17:15 -07:00
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <mraa/gpio.h>
|
2018-06-28 16:23:47 +03:00
|
|
|
#include <mraa/initio.hpp>
|
2018-06-12 18:46:49 +03:00
|
|
|
#include <interfaces/iHallEffect.hpp>
|
2014-12-10 16:17:15 -07:00
|
|
|
|
|
|
|
|
namespace upm {
|
2015-03-20 15:53:25 -07:00
|
|
|
/**
|
2018-02-14 10:36:46 -08:00
|
|
|
* @brief A110X Hall Effect Sensors
|
2015-03-20 15:53:25 -07:00
|
|
|
* @defgroup a110x libupm-a110x
|
2015-06-24 13:16:52 -07:00
|
|
|
* @ingroup seeed gpio electric robok
|
2015-03-20 15:53:25 -07:00
|
|
|
*/
|
2014-12-10 16:17:15 -07:00
|
|
|
|
|
|
|
|
/**
|
2015-03-20 15:53:25 -07:00
|
|
|
* @library a110x
|
|
|
|
|
* @sensor a110x
|
2016-12-15 15:15:21 -08:00
|
|
|
* @comname Hall Effect Sensor
|
2015-06-01 15:44:07 -07:00
|
|
|
* @altname Grove Hall Sensor
|
2015-06-23 10:52:56 -07:00
|
|
|
* @altid A1101, A1102, A1103, A1004, A1106
|
2015-03-20 15:53:25 -07:00
|
|
|
* @type electric
|
|
|
|
|
* @man seeed
|
|
|
|
|
* @web http://www.allegromicro.com/en/Products/Magnetic-Digital-Position-Sensor-ICs/Hall-Effect-Unipolar-Switches/A1101-2-3-4-6.aspx
|
|
|
|
|
* @con gpio
|
2015-06-23 16:35:50 -07:00
|
|
|
* @kit robok
|
2015-03-20 15:53:25 -07:00
|
|
|
*
|
2015-06-01 10:56:03 -07:00
|
|
|
* @brief API for the A110X Hall Effect sensors
|
2014-12-10 16:17:15 -07:00
|
|
|
*
|
2015-03-20 15:53:25 -07:00
|
|
|
* UPM module for the A110X (A1101, A1102, A1103, A1104, and A1106)
|
2014-12-10 16:17:15 -07:00
|
|
|
* Hall Effect sensors. It outputs a digital signal indicating
|
|
|
|
|
* whether it is detecting a magnetic field with south polarity
|
|
|
|
|
* perpendicular to the sensor element.
|
|
|
|
|
*
|
2015-05-22 01:31:14 -07:00
|
|
|
* @image html a110x.jpg
|
2015-05-26 15:58:34 -07:00
|
|
|
* An example showing a simple test for the presence of a field
|
2014-12-10 16:17:15 -07:00
|
|
|
* @snippet a110x.cxx Interesting
|
2015-03-25 12:58:02 -06:00
|
|
|
* An example demonstrating the use of an interrupt handler to count pulses
|
|
|
|
|
* @snippet a110x-intr.cxx Interesting
|
2014-12-10 16:17:15 -07:00
|
|
|
*/
|
2018-06-12 18:46:49 +03:00
|
|
|
class A110X : virtual public iHallEffect {
|
2014-12-10 16:17:15 -07:00
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* A110x digital sensor constructor
|
|
|
|
|
*
|
2015-08-07 20:33:46 +03:00
|
|
|
* @param pin Digital pin to use
|
2014-12-10 16:17:15 -07:00
|
|
|
*/
|
|
|
|
|
A110X(int pin);
|
2018-06-28 16:23:47 +03:00
|
|
|
/**
|
|
|
|
|
* Instantiates A110x digital sensor based on a given string.
|
|
|
|
|
*
|
|
|
|
|
* @param initStr string containing specific information for A110X initialization.
|
|
|
|
|
*/
|
|
|
|
|
A110X(std::string initStr);
|
|
|
|
|
|
2014-12-10 16:17:15 -07:00
|
|
|
/**
|
2015-08-07 20:33:46 +03:00
|
|
|
* A110X destructor
|
2014-12-10 16:17:15 -07:00
|
|
|
*/
|
|
|
|
|
~A110X();
|
|
|
|
|
/**
|
2015-08-07 20:33:46 +03:00
|
|
|
* Determines whether a magnetic field of south polarity has been detected
|
2014-12-10 16:17:15 -07:00
|
|
|
*
|
|
|
|
|
* @return True if magnetic field detected
|
|
|
|
|
*/
|
2018-06-12 18:46:49 +03:00
|
|
|
virtual bool magnetDetected();
|
2014-12-10 16:17:15 -07:00
|
|
|
|
2015-03-25 12:58:02 -06:00
|
|
|
/**
|
2015-08-07 20:33:46 +03:00
|
|
|
* Installs an interrupt service routine (ISR) to be called when
|
|
|
|
|
* the appropriate magnetic field is detected
|
2015-03-25 12:58:02 -06:00
|
|
|
*
|
2017-04-10 16:59:39 -07:00
|
|
|
* @param isr Pointer to a function to be called on interrupt
|
2015-08-07 20:33:46 +03:00
|
|
|
* @param arg Pointer to an object to be supplied as an
|
|
|
|
|
* argument to the ISR.
|
2015-03-25 12:58:02 -06:00
|
|
|
*/
|
|
|
|
|
void installISR(void (*isr)(void *), void *arg);
|
2018-01-08 11:36:05 -08:00
|
|
|
|
2015-03-25 12:58:02 -06:00
|
|
|
/**
|
2015-08-07 20:33:46 +03:00
|
|
|
* Uninstalls the previously installed ISR
|
2015-03-25 12:58:02 -06:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void uninstallISR();
|
|
|
|
|
|
2014-12-10 16:17:15 -07:00
|
|
|
private:
|
2015-08-19 19:27:16 +03:00
|
|
|
|
2015-03-25 12:58:02 -06:00
|
|
|
bool m_isrInstalled;
|
2018-06-28 16:23:47 +03:00
|
|
|
mraa::MraaIo mraaIo;
|
2014-12-10 16:17:15 -07:00
|
|
|
mraa_gpio_context m_gpio;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|