mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
curieimu: modify calls to use update methodology to fix python/java/js API
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
parent
61dbfe4f23
commit
ee19daedee
@ -155,8 +155,26 @@ CurieImu::processResponse()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getAccel()
|
||||||
|
{
|
||||||
|
return &accel[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getGyro()
|
||||||
|
{
|
||||||
|
return &gyro[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getMotion()
|
||||||
|
{
|
||||||
|
return &motion[0];
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CurieImu::readAccelerometer(int *xVal, int *yVal, int *zVal)
|
CurieImu::updateAccel()
|
||||||
{
|
{
|
||||||
char message[4];
|
char message[4];
|
||||||
message[0] = FIRMATA_START_SYSEX;
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
@ -172,9 +190,9 @@ CurieImu::readAccelerometer(int *xVal, int *yVal, int *zVal)
|
|||||||
|
|
||||||
waitForResponse();
|
waitForResponse();
|
||||||
|
|
||||||
*xVal = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
accel[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
*yVal = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
accel[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
*zVal = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
accel[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
|
||||||
delete m_results;
|
delete m_results;
|
||||||
unlock();
|
unlock();
|
||||||
@ -183,7 +201,7 @@ CurieImu::readAccelerometer(int *xVal, int *yVal, int *zVal)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CurieImu::readGyro(int *xVal, int *yVal, int *zVal)
|
CurieImu::updateGyro()
|
||||||
{
|
{
|
||||||
char message[4];
|
char message[4];
|
||||||
message[0] = FIRMATA_START_SYSEX;
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
@ -199,9 +217,39 @@ CurieImu::readGyro(int *xVal, int *yVal, int *zVal)
|
|||||||
|
|
||||||
waitForResponse();
|
waitForResponse();
|
||||||
|
|
||||||
*xVal = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
gyro[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
*yVal = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
gyro[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
*zVal = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
gyro[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::updateMotion()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_MOTION;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
motion[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
motion[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
|
motion[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
motion[3] = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
|
||||||
|
motion[4] = ((m_results[11] & 0x7f) | ((m_results[12] & 0x7f) << 7));
|
||||||
|
motion[5] = ((m_results[13] & 0x7f) | ((m_results[13] & 0x7f) << 7));
|
||||||
|
|
||||||
delete m_results;
|
delete m_results;
|
||||||
unlock();
|
unlock();
|
||||||
@ -236,36 +284,6 @@ CurieImu::getTemperature()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
CurieImu::readMotion(int *xA, int *yA, int *zA, int *xG, int *yG, int *zG)
|
|
||||||
{
|
|
||||||
char message[4];
|
|
||||||
message[0] = FIRMATA_START_SYSEX;
|
|
||||||
message[1] = FIRMATA_CURIE_IMU;
|
|
||||||
message[2] = FIRMATA_CURIE_IMU_READ_MOTION;
|
|
||||||
message[3] = FIRMATA_END_SYSEX;
|
|
||||||
|
|
||||||
lock();
|
|
||||||
|
|
||||||
mraa_firmata_response_stop(m_firmata);
|
|
||||||
mraa_firmata_response(m_firmata, handleSyncResponse);
|
|
||||||
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
|
||||||
|
|
||||||
waitForResponse();
|
|
||||||
|
|
||||||
*xA = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
|
||||||
*yA = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
|
||||||
*zA = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
|
||||||
*xG = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
|
|
||||||
*yG = ((m_results[11] & 0x7f) | ((m_results[12] & 0x7f) << 7));
|
|
||||||
*zG = ((m_results[13] & 0x7f) | ((m_results[13] & 0x7f) << 7));
|
|
||||||
|
|
||||||
delete m_results;
|
|
||||||
unlock();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CurieImu::enableShockDetection(bool enable)
|
CurieImu::enableShockDetection(bool enable)
|
||||||
{
|
{
|
||||||
|
@ -85,6 +85,20 @@ class CurieImu {
|
|||||||
*/
|
*/
|
||||||
~CurieImu();
|
~CurieImu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
void updateAccel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void updateGyro();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void updateMotion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read accelerometer X, Y, and Z axis
|
* Read accelerometer X, Y, and Z axis
|
||||||
*
|
*
|
||||||
@ -92,7 +106,7 @@ class CurieImu {
|
|||||||
* @param yVal Pointer to returned Y-axis value
|
* @param yVal Pointer to returned Y-axis value
|
||||||
* @param zVal Pointer to returned Z-axis value
|
* @param zVal Pointer to returned Z-axis value
|
||||||
*/
|
*/
|
||||||
void readAccelerometer(int *xVal, int *yVal, int *zVal);
|
int16_t* getAccel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read gyroscope X, Y, and Z axis
|
* Read gyroscope X, Y, and Z axis
|
||||||
@ -101,7 +115,7 @@ class CurieImu {
|
|||||||
* @param yVal Pointer to returned Y-axis value
|
* @param yVal Pointer to returned Y-axis value
|
||||||
* @param zVal Pointer to returned Z-axis value
|
* @param zVal Pointer to returned Z-axis value
|
||||||
*/
|
*/
|
||||||
void readGyro(int *xVal, int *yVal, int *zVal);
|
int16_t* getGyro();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the internal temperature
|
* Reads the internal temperature
|
||||||
@ -120,7 +134,7 @@ class CurieImu {
|
|||||||
* @param yG Pointer to returned Y-axis value of Gyroscope
|
* @param yG Pointer to returned Y-axis value of Gyroscope
|
||||||
* @param zG Pointer to returned Z-axis value of Gyroscope
|
* @param zG Pointer to returned Z-axis value of Gyroscope
|
||||||
*/
|
*/
|
||||||
void readMotion(int *xA, int *yA, int *zA, int *xG, int *yG, int *zG);
|
int16_t* getMotion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns shock detection notifications on/off
|
* Turns shock detection notifications on/off
|
||||||
@ -230,6 +244,10 @@ class CurieImu {
|
|||||||
std::queue<IMUDataItem*> m_shockData;
|
std::queue<IMUDataItem*> m_shockData;
|
||||||
std::queue<int> m_stepData;
|
std::queue<int> m_stepData;
|
||||||
std::queue<IMUDataItem*> m_tapData;
|
std::queue<IMUDataItem*> m_tapData;
|
||||||
|
|
||||||
|
int16_t accel[3];
|
||||||
|
int16_t gyro[3];
|
||||||
|
int16_t motion[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,29 @@
|
|||||||
#include "curieimu.hpp"
|
#include "curieimu.hpp"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%typemap(jni) int16_t* "jshortArray"
|
||||||
|
%typemap(jstype) int16_t* "short[]"
|
||||||
|
%typemap(jtype) int16_t* "short[]"
|
||||||
|
|
||||||
|
%typemap(javaout) int16_t* {
|
||||||
|
return $jnicall;
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getAccel {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 3);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getGyro {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 3);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getMotion {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 6);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 6, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
%include "curieimu.hpp"
|
%include "curieimu.hpp"
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
%pragma(java) jniclasscode=%{
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
%module jsupm_curieimu
|
%module jsupm_curieimu
|
||||||
%include "../upm.i"
|
%include "../upm.i"
|
||||||
|
%include "../carrays_int16_t.i"
|
||||||
|
|
||||||
|
// Adding this typemap because SWIG is converting int16 into a short by default
|
||||||
|
// This forces SWIG to convert it correctly
|
||||||
|
%typemap(out) int16_t* {
|
||||||
|
jsresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 );
|
||||||
|
}
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include "curieimu.hpp"
|
#include "curieimu.hpp"
|
||||||
|
@ -2,9 +2,19 @@
|
|||||||
%include "pyupm_doxy2swig.i"
|
%include "pyupm_doxy2swig.i"
|
||||||
%module pyupm_curieimu
|
%module pyupm_curieimu
|
||||||
%include "../upm.i"
|
%include "../upm.i"
|
||||||
|
%include "../carrays_int16_t.i"
|
||||||
%include "stdint.i"
|
%include "stdint.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
%include "curieupm_doc.i"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
%typemap(out) int16_t* {
|
||||||
|
$result = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 );
|
||||||
|
}
|
||||||
|
|
||||||
%include "curieimu.hpp"
|
%include "curieimu.hpp"
|
||||||
%{
|
%{
|
||||||
#include "curieimu.hpp"
|
#include "curieimu.hpp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user