diff --git a/src/ds1307/ds1307.cxx b/src/ds1307/ds1307.cxx index bc748e6b..8c7b167e 100644 --- a/src/ds1307/ds1307.cxx +++ b/src/ds1307/ds1307.cxx @@ -50,10 +50,10 @@ DS1307::~DS1307() mraa_i2c_stop(m_i2c); } -mraa_result_t DS1307::writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len) +mraa::Result DS1307::writeBytes(uint8_t reg, uint8_t *buffer, int len) { if (!len || !buffer) - return MRAA_ERROR_INVALID_PARAMETER; + return mraa::ERROR_INVALID_PARAMETER; // create a buffer 1 byte larger than the supplied buffer, // store the register in the first byte @@ -67,10 +67,10 @@ mraa_result_t DS1307::writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len) mraa_i2c_address(m_i2c, DS1307_I2C_ADDR); - return mraa_i2c_write(m_i2c, buf2, len + 1); + return (mraa::Result) mraa_i2c_write(m_i2c, buf2, len + 1); } -uint8_t DS1307::readBytes(uint8_t reg, uint8_t *buffer, unsigned int len) +int DS1307::readBytes(uint8_t reg, uint8_t *buffer, int len) { if (!len || !buffer) return 0; @@ -166,7 +166,7 @@ bool DS1307::setTime() return writeBytes(0, buffer, 7); } -mraa_result_t DS1307::enableClock() +mraa::Result DS1307::enableClock() { // the oscillator enable bit is the high bit of reg 0 // so read it, clear it, and write it back. @@ -179,7 +179,7 @@ mraa_result_t DS1307::enableClock() return writeBytes(0, &buf, 1); } -mraa_result_t DS1307::disableClock() +mraa::Result DS1307::disableClock() { // the oscillator enable bit is the high bit of reg 0 // so read it, set it, and write it back. diff --git a/src/ds1307/ds1307.h b/src/ds1307/ds1307.h index be169bfd..376f3fb2 100644 --- a/src/ds1307/ds1307.h +++ b/src/ds1307/ds1307.h @@ -27,7 +27,7 @@ #pragma once #include -#include +#include #define DS1307_I2C_BUS 0 #define DS1307_I2C_ADDR 0x68 @@ -102,7 +102,7 @@ namespace upm { * * @return 0 (MRAA_SUCCESS) if successful; non-zero otherwise */ - mraa_result_t enableClock(); + mraa::Result enableClock(); /** * Disables the oscillator on the clock. This prevents the clock @@ -110,7 +110,7 @@ namespace upm { * * @return 0 (MRAA_SUCCESS) if successful; non-zero otherwise */ - mraa_result_t disableClock(); + mraa::Result disableClock(); /** * Writes value(s) into registers @@ -120,7 +120,7 @@ namespace upm { * @param len Number of bytes to write * @return 0 (MRAA_SUCCESS) if successful; non-zero otherwise */ - mraa_result_t writeBytes(uint8_t reg, uint8_t *buffer, unsigned int len); + mraa::Result writeBytes(uint8_t reg, uint8_t *buffer, int len); /** * Reads value(s) from registers @@ -130,7 +130,7 @@ namespace upm { * @param len Number of bytes to read * @return Number of bytes read */ - uint8_t readBytes(uint8_t reg, uint8_t *buffer, unsigned int len); + int readBytes(uint8_t reg, uint8_t *buffer, int len); /** * Converts a BCD value into decimal diff --git a/src/ds1307/javaupm_ds1307.i b/src/ds1307/javaupm_ds1307.i index 2171974a..4fecc345 100644 --- a/src/ds1307/javaupm_ds1307.i +++ b/src/ds1307/javaupm_ds1307.i @@ -1,24 +1,10 @@ %module javaupm_ds1307 %include "../upm.i" %include "arrays_java.i"; +%include "../java_buffer.i" %{ #include "ds1307.h" %} -%typemap(jni) (uint8_t *buffer, unsigned int len) "jbyteArray"; -%typemap(jtype) (uint8_t *buffer, unsigned int len) "byte[]"; -%typemap(jstype) (uint8_t *buffer, unsigned int len) "byte[]"; - -%typemap(javain) (uint8_t *buffer, unsigned int len) "$javainput"; - -%typemap(in) (uint8_t *buffer, unsigned int len) { - $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL); - $2 = JCALL1(GetArrayLength, jenv, $input); -} - -%typemap(freearg) (uint8_t *buffer, unsigned int len) { - JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); -} - %include "ds1307.h" diff --git a/src/gas/gas.cxx b/src/gas/gas.cxx index 64415f1d..1d256825 100644 --- a/src/gas/gas.cxx +++ b/src/gas/gas.cxx @@ -46,7 +46,7 @@ Gas::~Gas() { } int -Gas::getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples, +Gas::getSampledWindow (unsigned int freqMS, int numberOfSamples, uint16_t * buffer) { int sampleIdx = 0; @@ -70,7 +70,7 @@ Gas::getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples, int Gas::findThreshold (thresholdContext* ctx, unsigned int threshold, - uint16_t * buffer, unsigned int len) { + uint16_t * buffer, int len) { long sum = 0; for (unsigned int i = 0; i < len; i++) { sum += buffer[i]; diff --git a/src/gas/gas.h b/src/gas/gas.h index 13eb0b27..dbc68bbb 100644 --- a/src/gas/gas.h +++ b/src/gas/gas.h @@ -65,7 +65,7 @@ class Gas { * @param numberOfSamples Number of sample to sample for this window * @param buffer Buffer with sampled data */ - virtual int getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples, uint16_t * buffer); + virtual int getSampledWindow (unsigned int freqMS, int numberOfSamples, uint16_t * buffer); /** * Given the sampled buffer, this method returns TRUE/FALSE if the threshold @@ -76,7 +76,7 @@ class Gas { * @param buffer Buffer with samples * @param len Buffer length */ - virtual int findThreshold (thresholdContext* ctx, unsigned int threshold, uint16_t * buffer, unsigned int len); + virtual int findThreshold (thresholdContext* ctx, unsigned int threshold, uint16_t * buffer, int len); /** * Returns average data for the sampled window diff --git a/src/gas/javaupm_gas.i b/src/gas/javaupm_gas.i index ef7b03b6..78d38727 100644 --- a/src/gas/javaupm_gas.i +++ b/src/gas/javaupm_gas.i @@ -11,33 +11,33 @@ #include "tp401.h" %} -%typemap(jni) (uint16_t *buffer, unsigned int len) "jshortArray"; -%typemap(jtype) (uint16_t *buffer, unsigned int len) "short[]"; -%typemap(jstype) (uint16_t *buffer, unsigned int len) "short[]"; +%typemap(jni) (uint16_t *buffer, int len) "jshortArray"; +%typemap(jtype) (uint16_t *buffer, int len) "short[]"; +%typemap(jstype) (uint16_t *buffer, int len) "short[]"; -%typemap(javain) (uint16_t *buffer, unsigned int len) "$javainput"; +%typemap(javain) (uint16_t *buffer, int len) "$javainput"; -%typemap(in) (uint16_t *buffer, unsigned int len) { +%typemap(in) (uint16_t *buffer, int len) { $1 = (uint16_t *) JCALL2(GetShortArrayElements, jenv, $input, NULL); $2 = JCALL1(GetArrayLength, jenv, $input); } -%typemap(freearg) (uint16_t *buffer, unsigned int len) { +%typemap(freearg) (uint16_t *buffer, int len) { JCALL3(ReleaseShortArrayElements, jenv, $input, (jshort *)$1, 0); } -%typemap(jni) (unsigned int numberOfSamples, uint16_t *buffer) "jshortArray"; -%typemap(jtype) (unsigned int numberOfSamples, uint16_t *buffer) "short[]"; -%typemap(jstype) (unsigned int numberOfSamples, uint16_t *buffer) "short[]"; +%typemap(jni) (int numberOfSamples, uint16_t *buffer) "jshortArray"; +%typemap(jtype) (int numberOfSamples, uint16_t *buffer) "short[]"; +%typemap(jstype) (int numberOfSamples, uint16_t *buffer) "short[]"; -%typemap(javain) (unsigned int numberOfSamples, uint16_t *buffer) "$javainput"; +%typemap(javain) (int numberOfSamples, uint16_t *buffer) "$javainput"; -%typemap(in) (unsigned int numberOfSamples, uint16_t *buffer) { +%typemap(in) (int numberOfSamples, uint16_t *buffer) { $2 = (uint16_t *) JCALL2(GetShortArrayElements, jenv, $input, NULL); $1 = JCALL1(GetArrayLength, jenv, $input); } -%typemap(freearg) (unsigned int numberOfSamples, uint16_t *buffer) { +%typemap(freearg) (int numberOfSamples, uint16_t *buffer) { JCALL3(ReleaseShortArrayElements, jenv, $input, (jshort *)$2, 0); } diff --git a/src/grovemd/grovemd.cxx b/src/grovemd/grovemd.cxx index 2a965dd7..78a3eeba 100644 --- a/src/grovemd/grovemd.cxx +++ b/src/grovemd/grovemd.cxx @@ -45,12 +45,12 @@ GroveMD::GroveMD(int bus, uint8_t address) // this board *requires* 100Khz i2c bus only mraa_result_t rv; - if ( (rv = mraa_i2c_frequency(m_i2c, MRAA_I2C_STD)) != MRAA_SUCCESS ) - { - cerr << "GroveMD: Could not set i2c frequency (MRAA_I2C_STD). " << endl; - mraa_result_print(rv); - return; - } + //if ( (rv = mraa_i2c_frequency(m_i2c, MRAA_I2C_STD)) != MRAA_SUCCESS ) + //{ + //cerr << "GroveMD: Could not set i2c frequency (MRAA_I2C_STD). " << endl; + //mraa_result_print(rv); + //return; + //} if (mraa_i2c_address(m_i2c, m_addr)) { diff --git a/src/grovescam/grovescam.cxx b/src/grovescam/grovescam.cxx index 222848ce..18432399 100644 --- a/src/grovescam/grovescam.cxx +++ b/src/grovescam/grovescam.cxx @@ -105,7 +105,7 @@ bool GROVESCAM::dataAvailable(unsigned int millis) return false; } -int GROVESCAM::readData(uint8_t *buffer, size_t len) +int GROVESCAM::readData(uint8_t *buffer, int len) { if (m_ttyFd == -1) return(-1); @@ -118,7 +118,7 @@ int GROVESCAM::readData(uint8_t *buffer, size_t len) return rv; } -int GROVESCAM::writeData(uint8_t *buffer, size_t len) +int GROVESCAM::writeData(uint8_t *buffer, int len) { if (m_ttyFd == -1) return(-1); diff --git a/src/grovescam/grovescam.h b/src/grovescam/grovescam.h index 34b4e6f8..052cdba3 100644 --- a/src/grovescam/grovescam.h +++ b/src/grovescam/grovescam.h @@ -117,7 +117,7 @@ namespace upm { * @param len Length of the buffer * @return Number of bytes read */ - int readData(uint8_t *buffer, size_t len); + int readData(uint8_t *buffer, int len); /** * Writes the data in the buffer to the device @@ -126,7 +126,7 @@ namespace upm { * @param len Length of the buffer * @return Number of bytes written */ - int writeData(uint8_t *buffer, size_t len); + int writeData(uint8_t *buffer, int len); /** * Sets up proper tty I/O modes and the baud rate. For this device, the default diff --git a/src/grovescam/javaupm_grovescam.i b/src/grovescam/javaupm_grovescam.i index 5f8a789d..bd352b6e 100644 --- a/src/grovescam/javaupm_grovescam.i +++ b/src/grovescam/javaupm_grovescam.i @@ -1,23 +1,9 @@ %module javaupm_grovescam %include "../upm.i" +%include "../java_buffer.i" %{ #include "grovescam.h" %} -%typemap(jni) (uint8_t *buffer, size_t len) "jbyteArray"; -%typemap(jtype) (uint8_t *buffer, size_t len) "byte[]"; -%typemap(jstype) (uint8_t *buffer, size_t len) "byte[]"; - -%typemap(javain) (uint8_t *buffer, size_t len) "$javainput"; - -%typemap(in) (uint8_t *buffer, size_t len) { - $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL); - $2 = JCALL1(GetArrayLength, jenv, $input); -} - -%typemap(freearg) (uint8_t *buffer, size_t len) { - JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); -} - %include "grovescam.h" diff --git a/src/hm11/hm11.cxx b/src/hm11/hm11.cxx index e033eaf4..81e33be1 100644 --- a/src/hm11/hm11.cxx +++ b/src/hm11/hm11.cxx @@ -89,7 +89,7 @@ bool HM11::dataAvailable(unsigned int millis) return false; } -int HM11::readData(char *buffer, size_t len) +int HM11::readData(char *buffer, int len) { if (m_ttyFd == -1) return(-1); @@ -102,7 +102,7 @@ int HM11::readData(char *buffer, size_t len) return rv; } -int HM11::writeData(char *buffer, size_t len) +int HM11::writeData(char *buffer, int len) { if (m_ttyFd == -1) return(-1); diff --git a/src/hm11/hm11.h b/src/hm11/hm11.h index 59aef369..4b59f5f2 100644 --- a/src/hm11/hm11.h +++ b/src/hm11/hm11.h @@ -111,7 +111,7 @@ namespace upm { * @param len Length of the buffer * @return Number of bytes read */ - int readData(char *buffer, size_t len); + int readData(char *buffer, int len); /** * Writes the data in the buffer to the device @@ -120,7 +120,7 @@ namespace upm { * @param len Length of the buffer * @return Number of bytes written */ - int writeData(char *buffer, size_t len); + int writeData(char *buffer, int len); /** * Sets up proper tty I/O modes and the baud rate. For this device, the default diff --git a/src/hm11/javaupm_hm11.i b/src/hm11/javaupm_hm11.i index 17a3cbc9..7475551d 100644 --- a/src/hm11/javaupm_hm11.i +++ b/src/hm11/javaupm_hm11.i @@ -1,6 +1,7 @@ %module javaupm_hm11 %include "../upm.i" %include "carrays.i" +%include "../java_buffer.i" %{ #include "hm11.h" diff --git a/src/hmtrp/hmtrp.cxx b/src/hmtrp/hmtrp.cxx index cfc0b6b5..95722dc9 100644 --- a/src/hmtrp/hmtrp.cxx +++ b/src/hmtrp/hmtrp.cxx @@ -94,7 +94,7 @@ bool HMTRP::dataAvailable(unsigned int millis) return false; } -int HMTRP::readData(char *buffer, size_t len, int millis) +int HMTRP::readData(char *buffer, int len, int millis) { if (m_ttyFd == -1) return(-1); @@ -114,7 +114,7 @@ int HMTRP::readData(char *buffer, size_t len, int millis) return rv; } -int HMTRP::writeData(char *buffer, size_t len) +int HMTRP::writeData(char *buffer, int len) { if (m_ttyFd == -1) return(-1); diff --git a/src/hmtrp/hmtrp.h b/src/hmtrp/hmtrp.h index 9aa7b3d7..47d272e7 100644 --- a/src/hmtrp/hmtrp.h +++ b/src/hmtrp/hmtrp.h @@ -124,7 +124,7 @@ namespace upm { * waiting forever (default). * @return Number of bytes read; 0 if timed out and millis is >= 0 */ - int readData(char *buffer, size_t len, int millis=-1); + int readData(char *buffer, int len, int millis=-1); /** * Writes the data in the buffer to the device @@ -133,7 +133,7 @@ namespace upm { * @param len Length of the buffer * @return Number of bytes written */ - int writeData(char *buffer, size_t len); + int writeData(char *buffer, int len); /** * Sets up proper tty I/O modes and the baud rate. The default diff --git a/src/hmtrp/javaupm_hmtrp.i b/src/hmtrp/javaupm_hmtrp.i index 8f1d6caa..c02e34a1 100644 --- a/src/hmtrp/javaupm_hmtrp.i +++ b/src/hmtrp/javaupm_hmtrp.i @@ -2,6 +2,7 @@ %include "../upm.i" %include "stdint.i" %include "typemaps.i" +%include "../java_buffer.i" %apply uint32_t *OUTPUT { uint32_t *freq, uint32_t *dataRate }; %apply uint16_t *OUTPUT { uint16_t *rxBandwidth }; diff --git a/src/java_buffer.i b/src/java_buffer.i new file mode 100644 index 00000000..6fec084d --- /dev/null +++ b/src/java_buffer.i @@ -0,0 +1,45 @@ + +%typemap(jni) (uint8_t *buffer, int len) "jbyteArray"; +%typemap(jtype) (uint8_t *buffer, int len) "byte[]"; +%typemap(jstype) (uint8_t *buffer, int len) "byte[]"; + +%typemap(javain) (uint8_t *buffer, int len) "$javainput"; + +%typemap(in) (uint8_t *buffer, int len) { + $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL); + $2 = JCALL1(GetArrayLength, jenv, $input); +} + +%typemap(freearg) (uint8_t *buffer, int len) { + JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); +} + +%typemap(jni) (uint8_t *pkt, int len) "jbyteArray"; +%typemap(jtype) (uint8_t *pkt, int len) "byte[]"; +%typemap(jstype) (uint8_t *pkt, int len) "byte[]"; + +%typemap(javain) (uint8_t *pkt, int len) "$javainput"; + +%typemap(in) (uint8_t *pkt, int len) { + $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL); + $2 = JCALL1(GetArrayLength, jenv, $input); +} + +%typemap(freearg) (uint8_t *pkt, int len) { + JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); +} + +%typemap(jni) (char *buffer, int len) "jbyteArray"; +%typemap(jtype) (char *buffer, int len) "byte[]"; +%typemap(jstype) (char *buffer, int len) "byte[]"; + +%typemap(javain) (char *buffer, int len) "$javainput"; + +%typemap(in) (char *buffer, int len) { + $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, NULL); + $2 = JCALL1(GetArrayLength, jenv, $input); +} + +%typemap(freearg) (char *buffer, int len) { + JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); +} diff --git a/src/lcd/javaupm_i2clcd.i b/src/lcd/javaupm_i2clcd.i index 71839978..4d3cd20a 100644 --- a/src/lcd/javaupm_i2clcd.i +++ b/src/lcd/javaupm_i2clcd.i @@ -6,18 +6,6 @@ %apply signed char[] {uint8_t []}; -%{ - #include "lcd.h" - #include "ssd.h" - #include "ssd1327.h" - #include "ssd1308.h" - #include "eboled.h" - #include "lcm1602.h" - #include "jhd1313m1.h" - #include "sainsmartks.h" -%} - - %typemap(jni) (uint8_t *data, int bytes) "jbyteArray"; %typemap(jtype) (uint8_t *data, int bytes) "byte[]"; %typemap(jstype) (uint8_t *data, int bytes) "byte[]"; @@ -33,6 +21,17 @@ JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); } +%{ + #include "lcd.h" + #include "ssd.h" + #include "ssd1327.h" + #include "ssd1308.h" + #include "eboled.h" + #include "lcm1602.h" + #include "jhd1313m1.h" + #include "sainsmartks.h" +%} + %include "lcd.h" %include "ssd.h" %include "ssd1327.h" diff --git a/src/lsm9ds0/javaupm_lsm9ds0.i b/src/lsm9ds0/javaupm_lsm9ds0.i index ca63616d..efc15125 100644 --- a/src/lsm9ds0/javaupm_lsm9ds0.i +++ b/src/lsm9ds0/javaupm_lsm9ds0.i @@ -3,6 +3,7 @@ %include "cpointer.i" %include "typemaps.i" %include "arrays_java.i"; +%include "../java_buffer.i" %feature("director") IsrCallback; @@ -12,10 +13,6 @@ %apply int {mraa::Edge}; %apply float *INOUT { float *x, float *y, float *z }; -%{ - #include "lsm9ds0.h" -%} - %typemap(jni) float* "jfloatArray" %typemap(jstype) float* "float[]" %typemap(jtype) float* "float[]" @@ -46,19 +43,8 @@ %ignore getGyroscope(float *, float *, float *); %ignore getMagnetometer(float *, float *, float *); -%typemap(jni) (uint8_t *buf, int len) "jbyteArray"; -%typemap(jtype) (uint8_t *buf, int len) "byte[]"; -%typemap(jstype) (uint8_t *buf, int len) "byte[]"; - -%typemap(javain) (uint8_t *buf, int len) "$javainput"; - -%typemap(in) (uint8_t *buf, int len) { - $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL); - $2 = JCALL1(GetArrayLength, jenv, $input); -} - -%typemap(freearg) (uint8_t *buf, int len) { - JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); -} +%{ + #include "lsm9ds0.h" +%} %include "lsm9ds0.h" diff --git a/src/lsm9ds0/lsm9ds0.cxx b/src/lsm9ds0/lsm9ds0.cxx index 32e568cf..045dc633 100644 --- a/src/lsm9ds0/lsm9ds0.cxx +++ b/src/lsm9ds0/lsm9ds0.cxx @@ -287,7 +287,7 @@ uint8_t LSM9DS0::readReg(DEVICE_T dev, uint8_t reg) return device->readReg(reg); } -void LSM9DS0::readRegs(DEVICE_T dev, uint8_t reg, uint8_t *buf, int len) +void LSM9DS0::readRegs(DEVICE_T dev, uint8_t reg, uint8_t *buffer, int len) { mraa::I2c *device; @@ -302,7 +302,7 @@ void LSM9DS0::readRegs(DEVICE_T dev, uint8_t reg, uint8_t *buf, int len) // We need to set the high bit of the register to enable // auto-increment mode for reading multiple registers in one go. - device->readBytesReg(reg | m_autoIncrementMode, buf, len); + device->readBytesReg(reg | m_autoIncrementMode, buffer, len); } bool LSM9DS0::writeReg(DEVICE_T dev, uint8_t reg, uint8_t val) diff --git a/src/lsm9ds0/lsm9ds0.h b/src/lsm9ds0/lsm9ds0.h index 6580c25e..7b47fbbd 100644 --- a/src/lsm9ds0/lsm9ds0.h +++ b/src/lsm9ds0/lsm9ds0.h @@ -1126,7 +1126,7 @@ namespace upm { * @param len the number of registers to read * @return the value of the register */ - void readRegs(DEVICE_T dev, uint8_t reg, uint8_t *buf, int len); + void readRegs(DEVICE_T dev, uint8_t reg, uint8_t *buffer, int len); /** * write to a register diff --git a/src/m24lr64e/javaupm_m24lr64e.i b/src/m24lr64e/javaupm_m24lr64e.i index ae61d31d..78142030 100644 --- a/src/m24lr64e/javaupm_m24lr64e.i +++ b/src/m24lr64e/javaupm_m24lr64e.i @@ -2,24 +2,10 @@ %include "../upm.i" %include "stdint.i" %include "arrays_java.i"; +%include "../java_buffer.i" %{ #include "m24lr64e.h" %} -%typemap(jni) (uint8_t *buf, unsigned int len) "jbyteArray"; -%typemap(jtype) (uint8_t *buf, unsigned int len) "byte[]"; -%typemap(jstype) (uint8_t *buf, unsigned int len) "byte[]"; - -%typemap(javain) (uint8_t *buf, unsigned int len) "$javainput"; - -%typemap(in) (uint8_t *buf, unsigned int len) { - $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL); - $2 = JCALL1(GetArrayLength, jenv, $input); -} - -%typemap(freearg) (uint8_t *buf, unsigned int len) { - JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); -} - %include "m24lr64e.h" diff --git a/src/m24lr64e/m24lr64e.cxx b/src/m24lr64e/m24lr64e.cxx index 76355bf9..3fe9bcbd 100644 --- a/src/m24lr64e/m24lr64e.cxx +++ b/src/m24lr64e/m24lr64e.cxx @@ -163,9 +163,9 @@ uint8_t M24LR64E::getAFI() return EEPROM_Read_Byte(AFI_ADDR); } -void M24LR64E::getUID(uint8_t* buf) +void M24LR64E::getUID(uint8_t* buffer) { - EEPROM_Read_Bytes(UID_ADDR,buf,UID_LENGTH); + EEPROM_Read_Bytes(UID_ADDR, buffer, UID_LENGTH); } uint32_t M24LR64E::getMemorySize() @@ -184,14 +184,14 @@ void M24LR64E::clearMemory() } } -void M24LR64E::writeByte(unsigned int address, uint8_t data) +mraa::Result M24LR64E::writeByte(unsigned int address, uint8_t data) { - EEPROM_Write_Byte(address, data); + return EEPROM_Write_Byte(address, data); } -void M24LR64E::writeBytes(unsigned int address, uint8_t* buf, unsigned int len) +mraa::Result M24LR64E::writeBytes(unsigned int address, uint8_t* buffer, int len) { - EEPROM_Write_Bytes(address, buf, len); + return EEPROM_Write_Bytes(address, buffer, len); } uint8_t M24LR64E::readByte(unsigned int address) @@ -199,31 +199,34 @@ uint8_t M24LR64E::readByte(unsigned int address) return EEPROM_Read_Byte(address); } -void M24LR64E::readBytes(unsigned int address, uint8_t* buf, unsigned int len) +int M24LR64E::readBytes(unsigned int address, uint8_t* buffer, int len) { - EEPROM_Read_Bytes(address, buf, len); + return EEPROM_Read_Bytes(address, buffer, len); } -void M24LR64E::EEPROM_Write_Byte(unsigned int address, uint8_t data) +mraa::Result M24LR64E::EEPROM_Write_Byte(unsigned int address, uint8_t data) { const int pktLen = 3; uint8_t buf[pktLen]; + mraa::Result rv; buf[0] = ((address >> 8) & 0xff); buf[1] = (address & 0xff); buf[2] = data; - if (m_i2c.write(buf, pktLen)) + if ((rv = m_i2c.write(buf, pktLen))) cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl; usleep(I2C_WRITE_TIME * 1000); + return rv; } -void M24LR64E::EEPROM_Write_Bytes(unsigned int address, uint8_t* data, - unsigned int len) +mraa::Result M24LR64E::EEPROM_Write_Bytes(unsigned int address, uint8_t* data, + int len) { const int pktLen = 2 + len; uint8_t buf[pktLen]; + mraa::Result rv; buf[0] = ((address >> 8) & 0xff); buf[1] = (address & 0xff); @@ -231,10 +234,12 @@ void M24LR64E::EEPROM_Write_Bytes(unsigned int address, uint8_t* data, for (int i=0; i