enc03r: C port; FTI; C++ wraps C

The API for this driver has changed.  See docs/apichanges.md.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2017-01-27 17:58:35 -07:00
parent f914159e21
commit 1bbb9386b7
15 changed files with 758 additions and 165 deletions

View File

@@ -1,6 +1,6 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
* Copyright (c) 2014-2017 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -24,92 +24,116 @@
#pragma once
#include <string>
#include <mraa/aio.h>
#include "enc03r.h"
namespace upm {
/**
* @brief ENC03R Single Axis Gyro library
* @defgroup enc03r libupm-enc03r
* @ingroup seeed analog compass robok
*/
/**
* @library enc03r
* @sensor enc03r
* @comname ENC03R Single Axis Gyro
* @altname Grove Single Axis Analog Gyro
* @type compass
* @man seeed
* @con analog
* @kit robok
*
* @brief API for the ENC03R Single Axis Analog Gyro
*
* UPM module for the ENC03R single axis analog gyro.
* This gyroscope measures x-axis angular velocity, that is
* how fast the sensor is rotating around the x-axis.
* Calibration of the sensor is necessary for accurate readings.
*
* @image html enc03r.jpg
* @snippet enc03r.cxx Interesting
*/
class ENC03R {
public:
/**
* @brief ENC03R Single Axis Gyro library
* @defgroup enc03r libupm-enc03r
* @ingroup seeed analog compass robok
*/
/**
* ENC03R sensor constructor
* @library enc03r
* @sensor enc03r
* @comname ENC03R Single Axis Gyro
* @altname Grove Single Axis Analog Gyro
* @type compass
* @man seeed
* @con analog
* @kit robok
*
* @param pin Analog pin to use
* @param vref Reference voltage to use; default is 5.0 V
*/
ENC03R(int pin, float vref=5.0);
/**
* ENC03R destructor
*/
~ENC03R();
/**
* Calibrates the sensor by determining an analog reading over many
* samples with no movement of the sensor. This must be done
* before attempting to use the sensor.
* @brief API for the ENC03R Single Axis Analog Gyro
*
* @param samples Number of samples to use for calibration
*/
void calibrate(unsigned int samples);
/**
* Returns the raw value of the sensor
* UPM module for the ENC03R single axis analog gyro.
* This gyroscope measures x-axis angular velocity, that is
* how fast the sensor is rotating around the x-axis.
* Calibration of the sensor is necessary for accurate readings.
*
* @return Raw value of the sensor
* @image html enc03r.jpg
* @snippet enc03r.cxx Interesting
*/
unsigned int value();
class ENC03R {
public:
/**
* Returns the currently stored calibration value
*
* @return Current calibration value
*/
float calibrationValue() { return m_calibrationValue; };
/**
* ENC03R sensor constructor
*
* @param pin Analog pin to use
* @param vref Reference voltage to use; default is 5.0 V
*/
ENC03R(int pin, float aref=5.0);
/**
* Computes angular velocity based on the value and stored calibration
* reference.
*
* @param val Value to use to compute angular velocity
* @return Computed angular velocity
*/
double angularVelocity(unsigned int val);
/**
* ENC03R destructor
*/
~ENC03R();
private:
// determined by calibrate();
float m_calibrationValue;
/**
* Calibrates the sensor by determining an analog reading over many
* samples with no movement of the sensor. This must be done
* before attempting to use the sensor.
*
* @param samples Number of samples to use for calibration
*/
void calibrate(unsigned int samples);
// reference voltage
float m_vref;
mraa_aio_context m_aio;
};
/**
* Update the internal state with the current reading. This
* function must be called prior to calling
* angularVelocity().
*
* @param dev Device context
*/
void update();
/**
* Returns the currently stored calibration value
*
* @return Current calibration value
*/
float calibrationValue() { return enc03r_calibration_value(m_enc03r); };
/**
* Computes angular velocity based on the value and stored calibration
* reference.
*
* @param val Value to use to compute angular velocity
* @return Computed angular velocity
*/
float angularVelocity();
/**
* Set sensor offset. The offste is applied to the return value
* before scaling. Default is 0.
*
* @param scale Scale to apply to value
*/
void setOffset(float offset);
/**
* Set sensor scale. The return value is scaled by this value
* before the offset is applied. Default is 1.0.
*
* @param dev Device context
* @param scale Offset to apply to value
*/
void setScale(float scale);
/**
* Get a normalized ADC value from the sensor. The return
* value will be between 0.0 (indicating no voltage) and 1.0
* indicating max voltage (aref). update() must be called
* prior to calling this function.
*
* @return The normalized reading from the ADC.
*/
float getNormalized();
protected:
enc03r_context m_enc03r;
private:
};
}