kx122: Add Java/Javascript/Python examples

Implemented a swig interface file for the kx122 and added corresponding
swig language examples.  Also added an STL vector flavor for getting
acceleration values from the kx122.

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2018-02-26 14:25:25 -08:00
parent 1be36ec1df
commit a43bcfe8d2
7 changed files with 205 additions and 0 deletions

View File

@ -76,6 +76,14 @@ void KX122::getAccelerationData(float *x, float *y, float *z)
}
}
std::vector<float> KX122::getAccelerationDataVector()
{
std::vector<float> xyz(3);
getAccelerationData(&xyz[0], &xyz[1], &xyz[2]);
return xyz;
}
void KX122::softwareReset()
{
if(kx122_sensor_software_reset(m_kx122)){

View File

@ -22,6 +22,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <vector>
#include <mraa/gpio.hpp>
#include "kx122.h"
@ -105,6 +106,14 @@ namespace upm{
*/
void getAccelerationData(float *x, float *y, float *z);
/**
Gets converted (m/s^2) accelerometer data from the sensor.
@return Acceleration vector [X, Y, Z]
@throws std::runtime_error on failure.
*/
std::vector<float> getAccelerationDataVector();
/**
Performs a sensor software reset. The software reset clears the RAM of the sensor and resets all registers
to pre-defined values.

20
src/kx122/kx122.i Normal file
View File

@ -0,0 +1,20 @@
%include "../common_top.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
JAVA_JNI_LOADLIBRARY(javaupm_kx122)
#endif
/* END Java syntax */
/* BEGIN Common SWIG syntax ------------------------------------------------- */
%include "std_vector.i"
%template(floatVector) std::vector<float>;
%apply float *OUTPUT {float *x, float *y, float *z};
%{
#include "kx122.hpp"
%}
%include "kx122.h"
%include "kx122.hpp"
/* END Common SWIG syntax */