SWIGJAVA: Remove the last JAVA ifdefs from src

Removed all references to #ifdef SWIGJAVA and JAVACALLBACK from the
library source.  All java-specific source code has been moved to the
corresponding library's .i file for java.

    * Update library source
    * Update examples where necessary
    * The function pointer methodology has been remove from libraries
      which provided callbacks as both a class and a function pointer
      implementation.  Examples were updated to use the class version
      of callbacks.
    * Updated documentation for SWIGJAVA

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2018-01-23 11:58:12 -08:00
parent d49ab2ac95
commit 666452e873
44 changed files with 280 additions and 509 deletions

View File

@ -46,22 +46,33 @@ sig_handler(int signo)
}
//! [Interesting]
void
nrf_handler()
class mycb : public virtual Callback
{
std::cout << "Reciever :: " << *((uint32_t*) &(comm.m_rxBuffer[0])) << std::endl;
}
public:
mycb(upm::NRF24L01 *com) : _com(com) {}
virtual void run()
{
if (_com != NULL)
std::cout << "Reciever :: " << *((uint32_t*) &(_com->m_rxBuffer[0])) << std::endl;
else
std::cout << "Example callback!" << std::endl;
}
private:
upm::NRF24L01* _com;
};
int
main(int argc, char** argv)
{
mycb cb(&comm);
comm.setSourceAddress((uint8_t*) local_address);
comm.setDestinationAddress((uint8_t*) broadcast_address);
comm.setPayload(MAX_BUFFER);
comm.configure();
comm.setSpeedRate(upm::NRF_250KBPS);
comm.setChannel(99);
comm.setDataReceivedHandler(nrf_handler);
comm.setDataReceivedHandler(&cb);
signal(SIGINT, sig_handler);

View File

@ -46,10 +46,21 @@ sig_handler(int signo)
}
}
void
nrf_handler()
class mycb : public virtual Callback
{
}
public:
mycb(upm::NRF24L01 *com) : _com(com) {}
virtual void run()
{
if (_com != NULL)
std::cout << "Reciever :: " << *((uint32_t*) &(_com->m_rxBuffer[0])) << std::endl;
else
std::cout << "Example callback!" << std::endl;
}
private:
upm::NRF24L01* _com;
};
int
main(int argc, char** argv)
@ -57,12 +68,14 @@ main(int argc, char** argv)
//! [Interesting]
uint32_t dummyData = 0;
upm::NRF24L01 comm(7, 8);
mycb cb(&comm);
comm.setSourceAddress((uint8_t*) srcAddress);
comm.setDestinationAddress((uint8_t*) destAddress);
comm.setPayload(MAX_BUFFER);
comm.setChannel(99);
comm.configure();
comm.setDataReceivedHandler(nrf_handler);
comm.setDataReceivedHandler(&cb);
signal(SIGINT, sig_handler);

View File

@ -42,17 +42,24 @@ sig_handler(int signo)
}
}
void
handler(clbk_data data)
//! [Interesting]
class mycb : public virtual Callback
{
printf("callback data (%d)\n", data.is_heart_beat);
}
public:
virtual void run(clbk_data arg)
{
printf("callback data (%d)\n", arg.is_heart_beat);
}
};
int
main(int argc, char** argv)
{
mycb cb;
//! [Interesting]
Pulsensor sensor(handler);
Pulsensor sensor(&cb);
sensor.start_sampler();
while (!doWork) {

View File

@ -23,12 +23,14 @@
*/
//NOT TESTED!!!
import java.util.AbstractList;
import java.lang.Float;
public class H3LIS331DLSample {
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
int[] val;
float[] accel;
// Instantiate an H3LIS331DL on I2C bus 0
upm_h3lis331dl.H3LIS331DL sensor = new upm_h3lis331dl.H3LIS331DL(0);
@ -39,14 +41,14 @@ public class H3LIS331DLSample {
while(true){
sensor.update();
val = sensor.getRawXYZ();
System.out.println( "Raw: X: " + val[0] + " Y: " + val[1] + " Z: " + val[2] );
upm_h3lis331dl.IntVector val = sensor.getRawXYZ();
System.out.println( "Raw: X: " + val.get(0) + " Y: " + val.get(1) + " Z: " + val.get(2) );
accel = sensor.getAcceleration();
System.out.println( "Acceleration: X: " + accel[0] + " Y: " + accel[1] + " Z: " + accel[2] );
upm_h3lis331dl.FloatVector accel = sensor.getAcceleration();
System.out.println( "Acceleration: X: " + accel.get(0) + " Y: " + accel.get(1) + " Z: " + accel.get(2) );
Thread.sleep(1000);
}
//! [Interesting]
}
}
}

View File

@ -28,15 +28,14 @@ public class MMA7455Sample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
upm_mma7455.MMA7455 sensor = new upm_mma7455.MMA7455(0);
short[] val;
while (true) {
val = sensor.readData();
System.out.println("Accelerometer X: " + val[0] + ", Y: " + val[1] + ", Z: " + val[2]);
upm_mma7455.ShortVector val = sensor.readData();
System.out.println("Accelerometer X: " + val.get(0) + ", Y: " + val.get(1) + ", Z: " + val.get(2));
Thread.sleep(1000);
}
// ! [Interesting]
}
}
}

View File

@ -44,13 +44,13 @@ public class MMA7660Sample
while (true)
{
float acceleration[] = accel.getAcceleration();
upm_mma7660.FloatVector acceleration = accel.getAcceleration();
System.out.println("Acceleration: x = "
+ acceleration[0]
+ acceleration.get(0)
+ " y = "
+ acceleration[1]
+ acceleration.get(1)
+ " x = "
+ acceleration[2]);
+ acceleration.get(2));
System.out.println();

View File

@ -43,9 +43,8 @@ public class MPU9150Sample {
// System.out.println("Gryoscope: " + "GX: " + gyro[0] + " GY: " + gyro[1] + " GZ: "
// + gyro[2]);
float[] magn = sensor.getMagnetometer();
System.out.println("Magnetometer: " + "MX: " + magn[0] + " MY: " + magn[1] + " MZ: "
+ magn[2]);
upm_mpu9150.FloatVector magn = sensor.getMagnetometer();
System.out.println("Magnetometer: " + "MX: " + magn.get(0) + " MY: " + magn.get(1) + " MZ: " + magn.get(2));
Thread.sleep(1000);
}