티스토리 뷰
728x90
출처
- JNI 헤더 만들기 :: CheatSheet
- How to pass C structs back and forth to Java code in JNI? - Stack Overflow
- JNI Types and Data Structures - Oracle Docs
- double 데이터형 값 주고 받기 | JNI Tutorial - skyfe79
- JNI(Java Native Interface) 이용 방법 (2/6) - 3.1~3.2 - Daum 블로그
- 강좌와 팁 - JNI programming - (2) 기본 변수형 다루기 - 임베디드 리눅스 시스템 포럼 embedded linux system
- Hwp 수식을 latex로(hml Equation Parser) – Wonno's Note – Daily Study Note
- GitHub - johnhuang-cn/jpserve: Calling Python from JAVA
py_pwm.h
typedef struct { //PyObject_HEAD unsigned int gpio; float freq; float dutycycle; } PWMObject; int PWM_init(PWMObject *self, int channel, float frequency); void PWM_start(PWMObject *self, float dutycycle); int PWM_ChangeDutyCycle(PWMObject *self, float dutycycle);
PWMObject.java
package com.pi4j.wiringpi; public class PWMObject { public int gpio; public float freq; public float dutycycle; public PWMObject() { } public int getGpio() { return gpio; } public void setGpio(int gpio) { this.gpio = gpio; } public float getFreq() { return freq; } public void setFreq(float freq) { this.freq = freq; } public float getDutycycle() { return dutycycle; } public void setDutycycle(float dutycycle) { this.dutycycle = dutycycle; } }
com_pi4j_wiringpi_ASUSGpio.h
#include <jni.h> /* Header for class com_pi4j_wiringpi_ASUSGpio */ #ifndef _Included_com_pi4j_wiringpi_ASUSGpio #define _Included_com_pi4j_wiringpi_ASUSGpio #ifdef __cplusplus extern "C" { #endif #undef com_pi4j_wiringpi_ASUSGpio_ASUS #define com_pi4j_wiringpi_ASUSGpio_ASUS 13L #undef com_pi4j_wiringpi_ASUSGpio_OUTPUT #define com_pi4j_wiringpi_ASUSGpio_OUTPUT 1L JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pySetmode (JNIEnv *, jclass, jint); JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pySetupChannel (JNIEnv *, jclass, jint, jint); JNIEXPORT jobject JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pwmInit (JNIEnv *, jclass, jint, jfloat); JNIEXPORT void JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pwmStart (JNIEnv *, jclass, jobject, jfloat); JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pwmChangeDutyCycle (JNIEnv *, jclass, jobject, jfloat); #ifdef __cplusplus } #endif #endif
com_pi4j_wiringpi_ASUSGpio.c
#include <stdio.h> #include <jni.h> #include <wiringPi.h> #include <RKIO.h> #include <wiringTB.h> #include <constants.h> #include <common.h> #include <c_gpio.h> #include <py_gpio.h> #include <py_pwm.h> #include "com_pi4j_wiringpi_ASUSGpio.h" void setPwmObject(JNIEnv *env, jclass targetClass, jobject newObject, PWMObject pwm) { jfieldID fid; // JniObject 객체의 intField 필드값 설정 fid = (*env)->GetFieldID(env, targetClass, "gpio", "I"); (*env)->SetIntField(env, newObject, fid, pwm.gpio); // JniObject 객체의 intField 필드값 설정 fid = (*env)->GetFieldID(env, targetClass, "freq", "F"); (*env)->SetFloatField(env, newObject, fid, pwm.freq); // JniObject 객체의 intField 필드값 설정 fid = (*env)->GetFieldID(env, targetClass, "dutycycle", "F"); (*env)->SetFloatField(env, newObject, fid, pwm.dutycycle); } void getPwmObject(JNIEnv *env, jclass targetClass, jobject newObject, PWMObject *pwm) { jfieldID fid; // JniObject 객체의 intField 필드값 설정 fid = (*env)->GetFieldID(env, targetClass, "gpio", "I"); pwm->gpio = (*env)->GetIntField(env, newObject, fid); // JniObject 객체의 intField 필드값 설정 fid = (*env)->GetFieldID(env, targetClass, "freq", "F"); pwm->freq = (*env)->GetFloatField(env, newObject, fid); // JniObject 객체의 intField 필드값 설정 fid = (*env)->GetFieldID(env, targetClass, "dutycycle", "F"); pwm->dutycycle = (*env)->GetFloatField(env, newObject, fid); } JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pySetmode (JNIEnv *env, jclass obj, jint new_mode) { return py_setmode(new_mode); } JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pySetupChannel (JNIEnv *env, jclass obj, jint channel, jint direction) { return py_setup_channel(channel, direction); } JNIEXPORT jobject JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pwmInit (JNIEnv *env, jclass obj, jint channel, jfloat frequency) { //pwm = GPIO.PWM(myservo,50) # 50hz yani 20mslik periyod PWMObject pwm; PWM_init(&pwm, channel, frequency); //printf("pwm.gpio = %d\n", pwm.gpio); // jclass targetClass = (*env)->FindClass(env, "com/pi4j/wiringpi/PWMObject"); // 생성자 찾기 jmethodID mid = (*env)->GetMethodID(env, targetClass, "<init>", "()V"); // 객체 생성(객체 레퍼런스 반환) jobject newObject = (*env)->NewObject(env, targetClass, mid, "()V"); setPwmObject(env, targetClass, newObject, pwm); return newObject; } JNIEXPORT void JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pwmStart (JNIEnv *env, jclass obj, jobject thiz, jfloat dutycycle) { PWMObject pwm; // jclass targetClass = (*env)->FindClass(env, "com/pi4j/wiringpi/PWMObject"); getPwmObject(env, targetClass, thiz, &pwm); PWM_start(&pwm, dutycycle); setPwmObject(env, targetClass, thiz, pwm); } JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_ASUSGpio_pwmChangeDutyCycle (JNIEnv *env, jclass obj, jobject thiz, jfloat dutycycle) { PWMObject pwm; // jclass targetClass = (*env)->FindClass(env, "com/pi4j/wiringpi/PWMObject"); getPwmObject(env, targetClass, thiz, &pwm); int result = PWM_ChangeDutyCycle(&pwm, dutycycle); setPwmObject(env, targetClass, thiz, pwm); return result; }
ASUSGpio.java
package com.pi4j.wiringpi; import com.pi4j.util.NativeLibraryLoader; public class ASUSGpio { // private constructor private ASUSGpio() { // forbid object construction } public static final int ASUS = 13; public static final int OUTPUT = 1; static { // Load the platform library NativeLibraryLoader.load("libpi4j.so"); } public static native int pySetmode(int new_mode); public static native int pySetupChannel(int channel, int direction); public static native PWMObject pwmInit(int channel, float frequency); public static native void pwmStart(PWMObject self, float dutycycle); public static native int pwmChangeDutyCycle(PWMObject self, float dutycycle); }
빌드
$ export SimulatedPlatform="TinkerBoard GPIO Provider" $ mvn clean install
-----------------
hml-equation-parser 패키지를 설치
$ sudo apt-get install pandoc $ sudo pip3 install typing $ sudo pip3 install hml_equation_parser
jpserve 패키지를 설치
$ sudo pip install jpserve
jython 설치
$ java -jar jython-installer-2.7.0.jar
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Linux
- JavaScript
- ffmpeg
- 레이싱모델 익스트림 포토 페스티벌
- 지스타2007
- Spring
- android
- NDK
- Spring MVC
- flex
- 일본여행
- 서울오토살롱
- 전예희
- 튜닝쇼 2008
- MySQL
- SAS
- Xcode
- BPI-M4
- Delphi
- Delphi Tip
- koba2010
- Mac
- sas2009
- KOBA
- ble
- 송주경
- 동경
- oracle
- ubuntu
- Java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함