mirror of
https://github.com/jlengrand/cellar.git
synced 2026-03-10 08:01:19 +00:00
Merge pull request #2 from jlengrand/use-publication
Use publication version of cellar-driver
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -58,3 +58,4 @@ local.properties
|
||||
*.o
|
||||
/cellar-app/target/
|
||||
/cellar-driver/target/
|
||||
/.idea/
|
||||
|
||||
16
.idea/deployment.xml
generated
16
.idea/deployment.xml
generated
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PublishConfigData" autoUpload="Always" serverName="raspberrypi.local" autoUploadExternalChanges="true">
|
||||
<serverData>
|
||||
<paths name="raspberrypi.local">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping deploy="/" local="$PROJECT_DIR$" web="/" />
|
||||
<mapping deploy="/cellar-app" local="$PROJECT_DIR$/cellar-app" web="/cellar-app" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
</serverData>
|
||||
<option name="myAutoUpload" value="ALWAYS" />
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/encodings.xml
generated
7
.idea/encodings.xml
generated
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/cellar-app/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/cellar-app/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
18
.idea/misc.xml
generated
18
.idea/misc.xml
generated
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ElmWorkspace">
|
||||
<elmProjects />
|
||||
<settings binDirPath="" />
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
124
.idea/uiDesigner.xml
generated
124
.idea/uiDesigner.xml
generated
@@ -1,124 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
15
.idea/webServers.xml
generated
15
.idea/webServers.xml
generated
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="WebServers">
|
||||
<option name="servers">
|
||||
<webServer id="0bdb9d11-9101-4aa6-ba6c-e333ae36584c" name="raspberrypi.local" url="http://raspberrypi.local">
|
||||
<fileTransfer host="raspberrypi.local" port="22" rootFolder="/home/pi/projects/cellar" accessType="SFTP">
|
||||
<advancedOptions>
|
||||
<advancedOptions dataProtectionLevel="Private" passiveMode="true" shareSSLContext="true" />
|
||||
</advancedOptions>
|
||||
<option name="port" value="22" />
|
||||
</fileTransfer>
|
||||
</webServer>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
10
README.md
10
README.md
@@ -1,4 +1,4 @@
|
||||
# Robottle
|
||||
# Cellar
|
||||
|
||||
WIP: Don't expect any structure in there. As of now it's a collection of tryouts without particular shape
|
||||
|
||||
@@ -28,10 +28,14 @@ https://github.com/cory-johannsen/gradle-jni-example
|
||||
pi/robottle
|
||||
raspberrypi
|
||||
|
||||
ping raspberrypi.local
|
||||
ssh pi@raspberrypi.local
|
||||
|
||||
|
||||
http://hirt.se/blog/?p=1116
|
||||
https://github.com/fauna/faunadb-jvm/blob/master/docs/java.md
|
||||
|
||||
Stack Overflow Question : https://iot.stackexchange.com/questions/4662/in-what-form-should-i-store-data-in-the-cloud-for-a-single-device
|
||||
Stack Overflow Question : https://iot.stackexchange.com/questions/4662/in-what-form-should-i-store-data-in-the-cloud-for-a-single-device
|
||||
|
||||
# To run :
|
||||
|
||||
$ mvn clean package
|
||||
@@ -63,8 +63,8 @@
|
||||
<dependency>
|
||||
<groupId>nl.lengrand</groupId>
|
||||
<artifactId>cellar-driver</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<version>1.1</version>
|
||||
<classifier>jar-with-dependencies</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.faunadb</groupId>
|
||||
@@ -95,4 +95,12 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/jlengrand/cellar-driver</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
|
||||
@@ -11,7 +11,7 @@ public class CellarMonitor {
|
||||
|
||||
// From config
|
||||
private static final long START = 0;
|
||||
private static final long SPAN = 3;
|
||||
private static final long SPAN = 30;
|
||||
private static final TimeUnit UNIT = TimeUnit.MINUTES;
|
||||
|
||||
private ScheduledFuture monitorHandle;
|
||||
@@ -31,7 +31,7 @@ public class CellarMonitor {
|
||||
};
|
||||
|
||||
public void startMonitoring(){
|
||||
monitorHandle = scheduler.scheduleAtFixedRate(monitoring, START, SPAN, TimeUnit.MINUTES);
|
||||
monitorHandle = scheduler.scheduleAtFixedRate(monitoring, START, SPAN, UNIT);
|
||||
}
|
||||
|
||||
public void stopMonitoring(){
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package nl.lengrand;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.helidon.microprofile.server.RoutingPath;
|
||||
import io.helidon.security.SecurityContext;
|
||||
import io.helidon.webserver.Routing;
|
||||
import io.helidon.webserver.Service;
|
||||
|
||||
/**
|
||||
* TODO javadoc.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@RoutingPath("/reactive")
|
||||
public class ReactiveService implements Service {
|
||||
@Inject
|
||||
private SecurityContext securityContext;
|
||||
|
||||
@Override
|
||||
public void update(Routing.Rules rules) {
|
||||
rules.get("/", (req, res) -> res.send("Context: " + securityContext));
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>cellar</artifactId>
|
||||
<groupId>nl.lengrand</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cellar-driver</artifactId>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<compilerArgs>
|
||||
<arg>-h</arg>
|
||||
<arg>${project.basedir}/target/headers</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<workingDirectory>${project.basedir}/src/main/c</workingDirectory>
|
||||
<executable>make</executable>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>nl.lengrand.cellar.TestLib</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,29 +0,0 @@
|
||||
#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 void JNICALL Java_nl_lengrand_cellar_Dht11Driver_sayHello(JNIEnv *env, jobject thisObj) {
|
||||
printf("Hello JNI!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
JNIEXPORT jfloatArray JNICALL Java_nl_lengrand_cellar_Dht11Driver_getTemperatureAndHumidity(JNIEnv *env, jobject thisObj){
|
||||
float humidity = 0, temperature = 0;
|
||||
int sensor = 11; // Make those dynamic one day?
|
||||
int pin = 4; // Make those dynamic one day?
|
||||
int res = pi_2_dht_read(sensor, pin, &humidity, &temperature); // Might wanna do something with status one day
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-armhf
|
||||
INCLUDES = -I. -I../java -Iadafruit/Raspberry_Pi_2 -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
|
||||
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 move
|
||||
|
||||
program: Dht11Driver.c
|
||||
gcc -Wall $(INCLUDES) $(HEADERS) $(FILES) -o $(OUT)
|
||||
|
||||
library:
|
||||
gcc -shared -fPIC -o $(OUT).so $(INCLUDES) $(FILES)
|
||||
|
||||
move:
|
||||
-cp $(OUT).so ../resources/libs/raspberry/
|
||||
|
||||
clean:
|
||||
-rm -f $(OUT).so
|
||||
-rm -f $(OUT)
|
||||
@@ -1,10 +0,0 @@
|
||||
The code contained in the adafruit folder comes from https://github.com/adafruit/Adafruit_Python_DHT and will be used as driver
|
||||
|
||||
To run right now :
|
||||
|
||||
* Create h file from Java folder : javac -h . nl.lengrand.cellar.Dht11Driver.java
|
||||
* Make (check converted to tabs)
|
||||
* cp .so file in java folder
|
||||
* pi@raspberrypi:~/projects/cellar/cellar-driver/src/main/java $ javac nl.lengrand.cellar.Dht11Driver.java nl.lengrand.cellar.TestLib.java
|
||||
* pi@raspberrypi:~/projects/cellar/cellar-driver/src/main/java $ java -Djava.library.path=. nl.lengrand.cellar.TestLib
|
||||
* java -Djava.library.path=../src/main/c -jar cellar-driver-1.0-SNAPSHOT-jar-with-dependencies.jar
|
||||
@@ -1,158 +0,0 @@
|
||||
// Copyright (c) 2014 Adafruit Industries
|
||||
// Author: Tony DiCola
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "pi_2_dht_read.h"
|
||||
#include "pi_2_mmio.h"
|
||||
|
||||
// This is the only processor specific magic value, the maximum amount of time to
|
||||
// spin in a loop before bailing out and considering the read a timeout. This should
|
||||
// be a high value, but if you're running on a much faster platform than a Raspberry
|
||||
// Pi or Beaglebone Black then it might need to be increased.
|
||||
#define DHT_MAXCOUNT 32000
|
||||
|
||||
// Number of bit pulses to expect from the DHT. Note that this is 41 because
|
||||
// the first pulse is a constant 50 microsecond pulse, with 40 pulses to represent
|
||||
// the data afterwards.
|
||||
#define DHT_PULSES 41
|
||||
|
||||
int pi_2_dht_read(int type, int pin, float* humidity, float* temperature) {
|
||||
// Validate humidity and temperature arguments and set them to zero.
|
||||
if (humidity == NULL || temperature == NULL) {
|
||||
return DHT_ERROR_ARGUMENT;
|
||||
}
|
||||
*temperature = 0.0f;
|
||||
*humidity = 0.0f;
|
||||
|
||||
// Initialize GPIO library.
|
||||
if (pi_2_mmio_init() < 0) {
|
||||
return DHT_ERROR_GPIO;
|
||||
}
|
||||
|
||||
// Store the count that each DHT bit pulse is low and high.
|
||||
// Make sure array is initialized to start at zero.
|
||||
int pulseCounts[DHT_PULSES*2] = {0};
|
||||
|
||||
// Set pin to output.
|
||||
pi_2_mmio_set_output(pin);
|
||||
|
||||
// Bump up process priority and change scheduler to try to try to make process more 'real time'.
|
||||
set_max_priority();
|
||||
|
||||
// Set pin high for ~500 milliseconds.
|
||||
pi_2_mmio_set_high(pin);
|
||||
sleep_milliseconds(500);
|
||||
|
||||
// The next calls are timing critical and care should be taken
|
||||
// to ensure no unnecssary work is done below.
|
||||
|
||||
// Set pin low for ~20 milliseconds.
|
||||
pi_2_mmio_set_low(pin);
|
||||
busy_wait_milliseconds(20);
|
||||
|
||||
// Set pin at input.
|
||||
pi_2_mmio_set_input(pin);
|
||||
// Need a very short delay before reading pins or else value is sometimes still low.
|
||||
for (volatile int i = 0; i < 50; ++i) {
|
||||
}
|
||||
|
||||
// Wait for DHT to pull pin low.
|
||||
uint32_t count = 0;
|
||||
while (pi_2_mmio_input(pin)) {
|
||||
if (++count >= DHT_MAXCOUNT) {
|
||||
// Timeout waiting for response.
|
||||
set_default_priority();
|
||||
return DHT_ERROR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
// Record pulse widths for the expected result bits.
|
||||
for (int i=0; i < DHT_PULSES*2; i+=2) {
|
||||
// Count how long pin is low and store in pulseCounts[i]
|
||||
while (!pi_2_mmio_input(pin)) {
|
||||
if (++pulseCounts[i] >= DHT_MAXCOUNT) {
|
||||
// Timeout waiting for response.
|
||||
set_default_priority();
|
||||
return DHT_ERROR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
// Count how long pin is high and store in pulseCounts[i+1]
|
||||
while (pi_2_mmio_input(pin)) {
|
||||
if (++pulseCounts[i+1] >= DHT_MAXCOUNT) {
|
||||
// Timeout waiting for response.
|
||||
set_default_priority();
|
||||
return DHT_ERROR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done with timing critical code, now interpret the results.
|
||||
|
||||
// Drop back to normal priority.
|
||||
set_default_priority();
|
||||
|
||||
// Compute the average low pulse width to use as a 50 microsecond reference threshold.
|
||||
// Ignore the first two readings because they are a constant 80 microsecond pulse.
|
||||
uint32_t threshold = 0;
|
||||
for (int i=2; i < DHT_PULSES*2; i+=2) {
|
||||
threshold += pulseCounts[i];
|
||||
}
|
||||
threshold /= DHT_PULSES-1;
|
||||
|
||||
// Interpret each high pulse as a 0 or 1 by comparing it to the 50us reference.
|
||||
// If the count is less than 50us it must be a ~28us 0 pulse, and if it's higher
|
||||
// then it must be a ~70us 1 pulse.
|
||||
uint8_t data[5] = {0};
|
||||
for (int i=3; i < DHT_PULSES*2; i+=2) {
|
||||
int index = (i-3)/16;
|
||||
data[index] <<= 1;
|
||||
if (pulseCounts[i] >= threshold) {
|
||||
// One bit for long pulse.
|
||||
data[index] |= 1;
|
||||
}
|
||||
// Else zero bit for short pulse.
|
||||
}
|
||||
|
||||
// Useful debug info:
|
||||
//printf("Data: 0x%x 0x%x 0x%x 0x%x 0x%x\n", data[0], data[1], data[2], data[3], data[4]);
|
||||
|
||||
// Verify checksum of received data.
|
||||
if (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) {
|
||||
if (type == DHT11) {
|
||||
// Get humidity and temp for DHT11 sensor.
|
||||
*humidity = (float)data[0];
|
||||
*temperature = (float)data[2];
|
||||
}
|
||||
else if (type == DHT22) {
|
||||
// Calculate humidity and temp for DHT22 sensor.
|
||||
*humidity = (data[0] * 256 + data[1]) / 10.0f;
|
||||
*temperature = ((data[2] & 0x7F) * 256 + data[3]) / 10.0f;
|
||||
if (data[2] & 0x80) {
|
||||
*temperature *= -1.0f;
|
||||
}
|
||||
}
|
||||
return DHT_SUCCESS;
|
||||
}
|
||||
else {
|
||||
return DHT_ERROR_CHECKSUM;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2014 Adafruit Industries
|
||||
// Author: Tony DiCola
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
#ifndef PI_2_DHT_READ_H
|
||||
#define PI_2_DHT_READ_H
|
||||
|
||||
#include "../common_dht_read.h"
|
||||
|
||||
// Read DHT sensor connected to GPIO pin (using BCM numbering). Humidity and temperature will be
|
||||
// returned in the provided parameters. If a successfull reading could be made a value of 0
|
||||
// (DHT_SUCCESS) will be returned. If there was an error reading the sensor a negative value will
|
||||
// be returned. Some errors can be ignored and retried, specifically DHT_ERROR_TIMEOUT or DHT_ERROR_CHECKSUM.
|
||||
int pi_2_dht_read(int sensor, int pin, float* humidity, float* temperature);
|
||||
|
||||
#endif
|
||||
@@ -1,71 +0,0 @@
|
||||
// Copyright (c) 2014 Adafruit Industries
|
||||
// Author: Tony DiCola
|
||||
// Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pi_2_mmio.h"
|
||||
|
||||
#define GPIO_BASE_OFFSET 0x200000
|
||||
#define GPIO_LENGTH 4096
|
||||
|
||||
volatile uint32_t* pi_2_mmio_gpio = NULL;
|
||||
|
||||
int pi_2_mmio_init(void) {
|
||||
if (pi_2_mmio_gpio == NULL) {
|
||||
// Check for GPIO and peripheral addresses from device tree.
|
||||
// Adapted from code in the RPi.GPIO library at:
|
||||
// http://sourceforge.net/p/raspberry-gpio-python/
|
||||
FILE *fp = fopen("/proc/device-tree/soc/ranges", "rb");
|
||||
if (fp == NULL) {
|
||||
return MMIO_ERROR_OFFSET;
|
||||
}
|
||||
fseek(fp, 4, SEEK_SET);
|
||||
unsigned char buf[4];
|
||||
if (fread(buf, 1, sizeof(buf), fp) != sizeof(buf)) {
|
||||
return MMIO_ERROR_OFFSET;
|
||||
}
|
||||
uint32_t peri_base = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
|
||||
uint32_t gpio_base = peri_base + GPIO_BASE_OFFSET;
|
||||
fclose(fp);
|
||||
|
||||
int fd = open("/dev/gpiomem", O_RDWR | O_SYNC);
|
||||
if (fd == -1) {
|
||||
// Error opening /dev/gpiomem.
|
||||
return MMIO_ERROR_DEVMEM;
|
||||
}
|
||||
// Map GPIO memory to location in process space.
|
||||
pi_2_mmio_gpio = (uint32_t*)mmap(NULL, GPIO_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gpio_base);
|
||||
close(fd);
|
||||
if (pi_2_mmio_gpio == MAP_FAILED) {
|
||||
// Don't save the result if the memory mapping failed.
|
||||
pi_2_mmio_gpio = NULL;
|
||||
return MMIO_ERROR_MMAP;
|
||||
}
|
||||
}
|
||||
return MMIO_SUCCESS;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
// Copyright (c) 2014 Adafruit Industries
|
||||
// Author: Tony DiCola
|
||||
// Based on code from Gert van Loo & Dom: http://elinux.org/RPi_Low-level_peripherals#GPIO_Code_examples
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// Simple fast memory-mapped GPIO library for the Raspberry Pi.
|
||||
#ifndef PI_2_MMIO_H
|
||||
#define PI_2_MMIO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MMIO_SUCCESS 0
|
||||
#define MMIO_ERROR_DEVMEM -1
|
||||
#define MMIO_ERROR_MMAP -2
|
||||
#define MMIO_ERROR_OFFSET -3
|
||||
|
||||
extern volatile uint32_t* pi_2_mmio_gpio;
|
||||
|
||||
int pi_2_mmio_init(void);
|
||||
|
||||
static inline void pi_2_mmio_set_input(const int gpio_number) {
|
||||
// Set GPIO register to 000 for specified GPIO number.
|
||||
*(pi_2_mmio_gpio+((gpio_number)/10)) &= ~(7<<(((gpio_number)%10)*3));
|
||||
}
|
||||
|
||||
static inline void pi_2_mmio_set_output(const int gpio_number) {
|
||||
// First set to 000 using input function.
|
||||
pi_2_mmio_set_input(gpio_number);
|
||||
// Next set bit 0 to 1 to set output.
|
||||
*(pi_2_mmio_gpio+((gpio_number)/10)) |= (1<<(((gpio_number)%10)*3));
|
||||
}
|
||||
|
||||
static inline void pi_2_mmio_set_high(const int gpio_number) {
|
||||
*(pi_2_mmio_gpio+7) = 1 << gpio_number;
|
||||
}
|
||||
|
||||
static inline void pi_2_mmio_set_low(const int gpio_number) {
|
||||
*(pi_2_mmio_gpio+10) = 1 << gpio_number;
|
||||
}
|
||||
|
||||
static inline uint32_t pi_2_mmio_input(const int gpio_number) {
|
||||
return *(pi_2_mmio_gpio+13) & (1 << gpio_number);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,66 +0,0 @@
|
||||
// Copyright (c) 2014 Adafruit Industries
|
||||
// Author: Tony DiCola
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
#include <errno.h>
|
||||
#include <sched.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "common_dht_read.h"
|
||||
|
||||
void busy_wait_milliseconds(uint32_t millis) {
|
||||
// Set delay time period.
|
||||
struct timeval deltatime;
|
||||
deltatime.tv_sec = millis / 1000;
|
||||
deltatime.tv_usec = (millis % 1000) * 1000;
|
||||
struct timeval walltime;
|
||||
// Get current time and add delay to find end time.
|
||||
gettimeofday(&walltime, NULL);
|
||||
struct timeval endtime;
|
||||
timeradd(&walltime, &deltatime, &endtime);
|
||||
// Tight loop to waste time (and CPU) until enough time as elapsed.
|
||||
while (timercmp(&walltime, &endtime, <)) {
|
||||
gettimeofday(&walltime, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void sleep_milliseconds(uint32_t millis) {
|
||||
struct timespec sleep;
|
||||
sleep.tv_sec = millis / 1000;
|
||||
sleep.tv_nsec = (millis % 1000) * 1000000L;
|
||||
while (clock_nanosleep(CLOCK_MONOTONIC, 0, &sleep, &sleep) && errno == EINTR);
|
||||
}
|
||||
|
||||
void set_max_priority(void) {
|
||||
struct sched_param sched;
|
||||
memset(&sched, 0, sizeof(sched));
|
||||
// Use FIFO scheduler with highest priority for the lowest chance of the kernel context switching.
|
||||
sched.sched_priority = sched_get_priority_max(SCHED_FIFO);
|
||||
sched_setscheduler(0, SCHED_FIFO, &sched);
|
||||
}
|
||||
|
||||
void set_default_priority(void) {
|
||||
struct sched_param sched;
|
||||
memset(&sched, 0, sizeof(sched));
|
||||
// Go back to default scheduler with default 0 priority.
|
||||
sched.sched_priority = 0;
|
||||
sched_setscheduler(0, SCHED_OTHER, &sched);
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2014 Adafruit Industries
|
||||
// Author: Tony DiCola
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
#ifndef COMMON_DHT_READ_H
|
||||
#define COMMON_DHT_READ_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Define errors and return values.
|
||||
#define DHT_ERROR_TIMEOUT -1
|
||||
#define DHT_ERROR_CHECKSUM -2
|
||||
#define DHT_ERROR_ARGUMENT -3
|
||||
#define DHT_ERROR_GPIO -4
|
||||
#define DHT_SUCCESS 0
|
||||
|
||||
// Define sensor types.
|
||||
#define DHT11 11
|
||||
#define DHT22 22
|
||||
#define AM2302 22
|
||||
|
||||
// Busy wait delay for most accurate timing, but high CPU usage.
|
||||
// Only use this for short periods of time (a few hundred milliseconds at most)!
|
||||
void busy_wait_milliseconds(uint32_t millis);
|
||||
|
||||
// General delay that sleeps so CPU usage is low, but accuracy is potentially bad.
|
||||
void sleep_milliseconds(uint32_t millis);
|
||||
|
||||
// Increase scheduling priority and algorithm to try to get 'real time' results.
|
||||
void set_max_priority(void);
|
||||
|
||||
// Drop scheduling priority back to normal/default.
|
||||
void set_default_priority(void);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm testAdafruit;
|
||||
gcc -Wall -I. -Iadafruit/Raspberry_Pi_2 adafruit/common_dht_read.c adafruit/Raspberry_Pi_2/pi_2_mmio.c adafruit/Raspberry_Pi_2/pi_2_dht_read.c testAdafruit.c -o testAdafruit
|
||||
@@ -1,30 +0,0 @@
|
||||
#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" );
|
||||
|
||||
int i;
|
||||
int res;
|
||||
float humidity = 0, temperature = 0;
|
||||
int sensor = 11;
|
||||
int pin = 4;
|
||||
for (i = 1; i < 15; ++i){
|
||||
res = pi_2_dht_read(sensor, pin, &humidity, &temperature);
|
||||
if(res == 0){
|
||||
printf("Temperature : %f\n", temperature);
|
||||
printf("Humidity : %f\n", humidity);
|
||||
}
|
||||
else{
|
||||
printf("Error when reading from sensor : %d\n", res);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package nl.lengrand.cellar;
|
||||
|
||||
public class Dht11Driver {
|
||||
|
||||
static {
|
||||
System.loadLibrary("dht11");
|
||||
}
|
||||
|
||||
public native void sayHello();
|
||||
|
||||
public native float[] getTemperatureAndHumidity();
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package nl.lengrand.cellar;
|
||||
|
||||
import nl.lengrand.cellar.Dht11Driver;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class TestLib {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException, ExecutionException {
|
||||
Dht11Driver theDriver = new Dht11Driver();
|
||||
theDriver.sayHello();
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
float [] res = theDriver.getTemperatureAndHumidity();
|
||||
if(res[0] != 0 && res[1] != 0){
|
||||
System.out.println("Receiving " + res[0] + " " + res[1]);
|
||||
}
|
||||
else{
|
||||
System.out.println("Incorrect data!" + res[0] + " " + res[1]);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
5
pom.xml
5
pom.xml
@@ -10,12 +10,11 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>cellar-driver</module>
|
||||
<module>cellar-app</module>
|
||||
</modules>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user