Skip to content

Commit 31789ab

Browse files
committed
close connection method added, open connection default iin constructor
1 parent 070d8d3 commit 31789ab

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

library/jni/I2cPortJava.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ JNIEXPORT jbyte JNICALL Java_com_cacaosd_i2c_core_I2cPort_openConnection
1212
i2c.openConnection();
1313
}
1414

15+
JNIEXPORT jbyte JNICALL Java_com_cacaosd_i2c_core_I2cPort_closeConnection
16+
(JNIEnv *env, jobject obj) {
17+
i2c.closeConnection();
18+
}
19+
1520
JNIEXPORT void JNICALL Java_com_cacaosd_i2c_core_I2cPort_setDeviceAddress(
1621
JNIEnv *env, jobject obj, jbyte device_address) {
1722
i2c.setDeviceAddress(device_address);

library/jni/I2cPortJava.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ extern "C" {
2020
JNIEXPORT jbyte JNICALL Java_com_cacaosd_i2c_core_I2cPort_openConnection
2121
(JNIEnv *, jobject);
2222

23+
/*
24+
* Class: com_cacaosd_i2c_core_I2cPort
25+
* Method: closeConnection
26+
* Signature: ()V
27+
*/
28+
JNIEXPORT jbyte JNICALL Java_com_cacaosd_i2c_core_I2cPort_closeConnection
29+
(JNIEnv *, jobject);
30+
2331
/*
2432
* Class: com_cacaosd_i2c_core_I2cPort
2533
* Method: setDeviceAddress

library/src/com/cacaosd/i2c/core/I2cPort.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ public class I2cPort {
2828
public I2cPort(byte device_address, byte bus) {
2929
setBusAddress(bus);
3030
setDeviceAddress(device_address);
31+
openConnection();
3132
}
3233

3334
/**
3435
* Open I2C connection.
3536
*/
3637
public native void openConnection();
3738

39+
/**
40+
* Close I2C connection.
41+
*/
42+
public native void closeConnection();
43+
3844
/**
3945
* Set slave device address.
4046
*

0 commit comments

Comments
 (0)