Commit 7a293255 authored by Martin Deinhofer's avatar Martin Deinhofer
Browse files

Removed c-file for exercise 2; Adapted makefile to use libpifacecad to set a...

Removed c-file for exercise 2; Adapted makefile to use libpifacecad to set a text on the display; --> adapted -I and linker options
parent d7e66191
......@@ -2,8 +2,16 @@
#include <stdio.h>
#include "HelloJNI.h"
//include libpifacecad
#include "pifacecad.h"
// Implementation of native method sayHello() of HelloJNI class
JNIEXPORT void JNICALL Java_java_1exercises8_11_11_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
printf("Hello World!\n");
printf("Java SE Embedded rocks!\n");
pifacecad_open();
pifacecad_lcd_backlight_on();
pifacecad_lcd_write("Java SE Embedded rocks");
pifacecad_close();
return;
}
#include <jni.h>
#include <stdio.h>
#include "java_exercises7_2_1_HelloJNI.h"
// Implementation of native method sayHello() of HelloJNI class
JNIEXPORT void JNICALL Java_java_1exercises7_11_11_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
printf("Hello World!\n");
return;
}
/*
* Class: java_exercises7_2_1_HelloJNI
* Method: intMethod
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_java_1exercises7_12_11_HelloJNI_intMethod
(JNIEnv *env, jobject thisObj, jint n) {
return n*n;
}
/*
* Class: java_exercises7_2_1_HelloJNI
* Method: booleanMethod
* Signature: (Z)Z
*/
JNIEXPORT jboolean JNICALL Java_java_1exercises7_12_11_HelloJNI_booleanMethod
(JNIEnv *env, jobject thisObj, jboolean bool) {
return !bool;
}
/*
* Class: java_exercises7_2_1_HelloJNI
* Method: stringMethod
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_java_1exercises7_12_11_HelloJNI_stringMethod
(JNIEnv *env, jobject thisObj, jstring text) {
// Step 1: Convert the JNI String (jstring) into C-String (char*)
char *inCStr = (char*)(*env)->GetStringUTFChars(env, text, NULL);
if (NULL == inCStr) return NULL;
// Step 2: Perform its intended operations
printf("In C, the received string is: %s\n", inCStr);
inCStr[0]++;
jstring returnToken=(*env)->NewStringUTF(env, inCStr);
(*env)->ReleaseStringUTFChars(env, text, inCStr); // release resources
return returnToken;
}
# Define a variable for classpath
# Define common variables
CLASS_PATH = ../bin
JAVA_SRC_PATH = ../src
JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/
#Paths to libmcp23s17 and libpifacecad
LIB_MCP23S17=../../libmcp23s17
LIB_PIFACECAD=../../libpifacecad
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
......@@ -18,27 +22,15 @@ java_exercises8_1_1/HelloJNI.class:
# Targets for java_exercises8_1_1
# $@ matches the target, $< matches the first dependancy
libhello.so : HelloJNI.o
gcc -shared -o $@ $<
gcc -shared -o $@ $< -L$(LIB_PIFACECAD) -lpifacecad -L$(LIB_MCP23S17) -lmcp23s17
# $@ matches the target, $< matches the first dependancy
HelloJNI.o : HelloJNI.c HelloJNI.h
gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -c $< -o $@
gcc -Wall -fPIC -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I$(LIB_PIFACECAD)/src -I$(LIB_MCP23S17)/src -c $< -o $@ -L$(LIB_PIFACECAD) -lpifacecad -L$(LIB_MCP23S17) -lmcp23s17
# $* matches the target filename without the extension
HelloJNI.h : java_exercises8_1_1/HelloJNI.class
javah -o HelloJNI.h -classpath $(CLASS_PATH) java_exercises8_1_1.$*
# Targets for java_exercises_7_2_1
# $@ matches the target, $< matches the first dependancy
#java_exercises7_2_1_HelloJNI.dll : java_exercises7_2_1_HelloJNI.o
# gcc -Wl,--add-stdcall-alias -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
#java_exercises7_2_1_HelloJNI.o : java_exercises7_2_1_HelloJNI.c java_exercises7_2_1_HelloJNI.h
# gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -c $< -o $@
#java_exercises7_2_1_HelloJNI.h : java_exercises7_2_1/HelloJNI.class
# javah -classpath $(CLASS_PATH) java_exercises7_2_1.HelloJNI
clean :
rm HelloJNI.h HelloJNI.o hello.dll java_exercises7_2_1_HelloJNI.dll java_exercises7_2_1_HelloJNI.h java_exercises7_2_1_HelloJNI.o
\ No newline at end of file
rm HelloJNI.h HelloJNI.o libhello.so
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment