Skip to content

Instantly share code, notes, and snippets.

@jlengrand
Created July 29, 2020 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlengrand/c22920cedeab3ec0600dd1552237972d to your computer and use it in GitHub Desktop.
Save jlengrand/c22920cedeab3ec0600dd1552237972d to your computer and use it in GitHub Desktop.
#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