Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Compiling

julien Lengrand-Lambert jlengrand

💭
Compiling
View GitHub Profile
View githuactions.yaml
name: Java CI with Maven
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
View pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>nl.lengrand</groupId>
<version>1.1</version>
<modelVersion>4.0.0</modelVersion>
<artifactId>cellar-driver</artifactId>
View Makefile
INCLUDES = -I. -I../java -Iadafruit/Raspberry_Pi_2 -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I$(JAVA_HOME)/include/darwin
HEADERS = ../../../target/headers/nl_lengrand_cellar_Dht11Driver.h adafruit/common_dht_read.h adafruit/Raspberry_Pi_2/pi_2_mmio.h adafruit/Raspberry_Pi_2/pi_2_dht_read.h
FILES = adafruit/common_dht_read.c adafruit/Raspberry_Pi_2/pi_2_mmio.c adafruit/Raspberry_Pi_2/pi_2_dht_read.c Dht11Driver.c
OUT = libdht11
default: library copy
program: Dht11Driver.c
arm-linux-gnueabihf-gcc -Wall $(INCLUDES) $(HEADERS) $(FILES) -o $(OUT)
View TestLib.java
package nl.lengrand.cellar;
public class TestLib {
public static void main(String[] args) throws InterruptedException {
Dht11Driver theDriver = new Dht11Driver();
System.out.println("Hello JNI!");
for (int i = 0; i < 5; i++) {
float [] res = theDriver.getTemperatureAndHumidity();
View Dht11Driver.c
#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;
View dht11.java
package nl.lengrand.cellar;
public class Dht11Driver {
static {
System.loadLibrary("dht11");
}
public native float[] getTemperatureAndHumidity();
}
View dht11.c
float humidity = 0, temperature = 0;
int sensor = 11;int pin = 4;
pi_2_dht_read(sensor, pin, &humidity, &temperature);
printf("Temperature : %f\n", temperature);
printf("Humidity : %f\n", humidity);
@jlengrand
jlengrand / testAdafruit.c
Created Jul 8, 2020
simple C code to test the lib from Adafruit
View testAdafruit.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include "adafruit/Raspberry_Pi_2/pi_2_dht_read.h"
int main( void )
{
printf( "Raspberry Pi 2 DHT11 test program\n" );
@jlengrand
jlengrand / dht11.java
Last active Jul 8, 2020
dht11 using pi4J
View dht11.java
import com.pi4j.wiringpi.Gpio;
import com.pi4j.wiringpi.GpioUtil;
public class DHT11 {
private static final int MAXTIMINGS = 85;
private final int[] dht11_dat = { 0, 0, 0, 0, 0 };
public DHT11() {
GpioUtil.export(3, GpioUtil.DIRECTION_OUT);
@jlengrand
jlengrand / java-jpackage-versions.sh
Created Apr 3, 2020
Checking java and jpackage versions in terminal
View java-jpackage-versions.sh
$ java -version
openjdk version "14" 2020-03-17
OpenJDK Runtime Environment AdoptOpenJDK (build 14+36)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14+36, mixed mode, sharing)
$ jpackage
WARNING: Using incubator modules: jdk.incubator.jpackage
Usage: jpackage <options>
Use jpackage --help (or -h) for a list of possible options
You can’t perform that action at this time.