mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
grove: rotary angle sensor
Signed-off-by: Mihai Tudor Panu <mihai.t.panu@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:

committed by
Brendan Le Foll

parent
e91b69230c
commit
b2ffcdd9ea
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Contributions: Mihai Tudor Panu <mihai.t.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -115,3 +116,47 @@ float GroveLight::raw_value()
|
||||
{
|
||||
return (float) mraa_aio_read(m_aio);
|
||||
}
|
||||
|
||||
//// GroveRotary ////
|
||||
|
||||
GroveRotary::GroveRotary(unsigned int pin)
|
||||
{
|
||||
mraa_init();
|
||||
m_aio = mraa_aio_init(pin);
|
||||
m_name = "Rotary Angle Sensor";
|
||||
}
|
||||
|
||||
GroveRotary::~GroveRotary()
|
||||
{
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
float GroveRotary::abs_value()
|
||||
{
|
||||
return (float) mraa_aio_read(m_aio);
|
||||
}
|
||||
|
||||
float GroveRotary::abs_deg()
|
||||
{
|
||||
return GroveRotary::abs_value() * (float) m_max_angle / 1023.0;
|
||||
}
|
||||
|
||||
float GroveRotary::abs_rad()
|
||||
{
|
||||
return GroveRotary::abs_deg() * M_PI / 180.0;
|
||||
}
|
||||
|
||||
float GroveRotary::rel_value()
|
||||
{
|
||||
return GroveRotary::abs_value() - 512.0;
|
||||
}
|
||||
|
||||
float GroveRotary::rel_deg()
|
||||
{
|
||||
return GroveRotary::rel_value() * (float) m_max_angle / 1023.0;
|
||||
}
|
||||
|
||||
float GroveRotary::rel_rad()
|
||||
{
|
||||
return GroveRotary::rel_deg() * M_PI / 180.0;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Contributions: Mihai Tudor Panu <mihai.t.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -135,4 +136,68 @@ class GroveLight: public Grove {
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for Grove Rotary Angle Sensor (Knob)
|
||||
*
|
||||
* Very basic UPM module for Grove rotary angle sensor (knob) on analog. Provides
|
||||
* a set of functions to read the absolute pin value, degrees or radians and another
|
||||
* to do the same relative to the center of the knob's range.
|
||||
*
|
||||
* @ingroup grove analog
|
||||
* @snippet groverotary.cxx Interesting
|
||||
* @image html groverotary.jpeg
|
||||
*/
|
||||
class GroveRotary: public Grove {
|
||||
public:
|
||||
/**
|
||||
* Grove rotary angle sensor constructor
|
||||
*
|
||||
* @param pin number of analog pin to use
|
||||
*/
|
||||
GroveRotary(unsigned int pin);
|
||||
/**
|
||||
* GroveRotary Destructor
|
||||
*/
|
||||
~GroveRotary();
|
||||
/**
|
||||
* Get absolute raw value from AIO pin
|
||||
*
|
||||
* @return the unsigned value from the ADC
|
||||
*/
|
||||
float abs_value();
|
||||
/**
|
||||
* Get absolute raw degrees from AIO pin
|
||||
*
|
||||
* @return the unsigned degrees from the ADC
|
||||
*/
|
||||
float abs_deg();
|
||||
/**
|
||||
* Get absolute raw radians from AIO pin
|
||||
*
|
||||
* @return the unsigned radians from the ADC
|
||||
*/
|
||||
float abs_rad();
|
||||
/**
|
||||
* Get the relative value from the pin
|
||||
*
|
||||
* @return the signed value from the ADC
|
||||
*/
|
||||
float rel_value();
|
||||
/**
|
||||
* Get relative degrees from AIO pin
|
||||
*
|
||||
* @return the signed degrees from the ADC
|
||||
*/
|
||||
float rel_deg();
|
||||
/**
|
||||
* Get relative radians from AIO pin
|
||||
*
|
||||
* @return the signed radians from the ADC
|
||||
*/
|
||||
float rel_rad();
|
||||
private:
|
||||
mraa_aio_context m_aio;
|
||||
static const int m_max_angle = 300;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user