Skip to content

Commit

Permalink
C and JNI
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier LeDiouris committed Aug 4, 2017
1 parent 8fa583f commit ce5f8be
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
41 changes: 41 additions & 0 deletions C/getenv.c
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

int nativeDebugEnabled() {
char * nativeDebug = "NATIVEDEBUG";
int debug = FALSE;
if (getenv(nativeDebug)) {
if (strcmp("true", getenv(nativeDebug)) == 0) {
debug = TRUE;
}
}
return debug;
}

int main () {
char * user = "USER";
char * shell = "SHELL";

fprintf(stdout, "User:%s, Shell:%s\n", getenv(user), getenv(shell));

char * olivDebug = "OLIVDEBUG";
int debug = FALSE;
if (getenv(olivDebug)) {
if (strcmp("true", getenv(olivDebug)) == 0) {
debug = TRUE;
}
}
fprintf(stdout, "%s is %sset.\n", olivDebug, (debug ? "" : "not "));

fprintf(stdout, "NATIVEDEBUG is %sset\n", (nativeDebugEnabled() ? "" : "not "));

return 0;
}
4 changes: 2 additions & 2 deletions I2C.SPI/src/lcd/oled/SSD1306.java
Expand Up @@ -59,7 +59,7 @@ public class SSD1306 {
private int width = 128,
height = 32;
private int clockHertz = 8_000_000; // 8 MHz
private int vccstate = 0;
private int vccstate = 0; // or SSD1306_EXTERNALVCC
private int pages = 0;
private int[] buffer = null;

Expand Down Expand Up @@ -351,7 +351,7 @@ private void initialize() { // SPI, 128x32
else
this.command(0x14);
this.command(SSD1306_MEMORYMODE); // 0x20
this.command(0x00); // 0x0 act like ks0108
this.command(0x00); // 0x0 act like ks0108
this.command(SSD1306_SEGREMAP | 0x1);
this.command(SSD1306_COMSCANDEC);
this.command(SSD1306_SETCOMPINS); // 0xDA
Expand Down
2 changes: 1 addition & 1 deletion JNISample/C/HelloWorld.c
Expand Up @@ -24,7 +24,7 @@ JNIEXPORT void JNICALL Java_jnisample_HelloWorld_print (JNIEnv * env, jobject ob
JNIEXPORT jint JNICALL Java_jnisample_HelloWorld_manageObject (JNIEnv * env, jobject obj1, jobject obj2) {
printf("C receiving Java Object\n");
jclass objClass = (*env)->GetObjectClass(env, obj2);
jfieldID fidInt = (*env)->GetFieldID(env, objClass, "someNumber", "I");
jfieldID fidInt = (*env)->GetFieldID(env, objClass, "someNumber", "I");
jint iVal = (*env)->GetIntField(env, obj2, fidInt);
printf("- Value: %d\n", iVal);

Expand Down

0 comments on commit ce5f8be

Please sign in to comment.