Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <jni.h>
#include "../../../target/headers/nl_lengrand_cellar_Dht11Driver.h"
#include "adafruit/Raspberry_Pi_2/pi_2_dht_read.h"
JNIEXPORT jfloatArray JNICALL Java_nl_lengrand_cellar_Dht11Driver_getTemperatureAndHumidity(JNIEnv *env, jobject thisObj){
float humidity = 0, temperature = 0;
int sensor = 11; int pin = 4;
pi_2_dht_read(sensor, pin, &humidity, &temperature);
jfloat* values = (jfloat *) malloc(2*sizeof(jfloat));
values[0] = temperature;
values[1] = humidity;
jfloatArray outJNIArray = (*env)->NewFloatArray(env, 2);
if (NULL == outJNIArray) return NULL;
(*env)->SetFloatArrayRegion(env, outJNIArray, 0, 2, (const jfloat*)values);
return outJNIArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment