From 1a1bca09b1ca8978b875de3782259c228df61e73 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Fri, 17 Jul 2020 13:28:53 +0200 Subject: [PATCH 1/4] Clean up --- .idea/codeStyles/Project.xml | 7 ++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++ .idea/jarRepositories.xml | 20 ++++++++++ .idea/misc.xml | 7 ++-- .idea/sshConfigs.xml | 8 ++++ .idea/webServers.xml | 5 +-- README.md | 10 +++-- .../main/java/nl/lengrand/CellarMonitor.java | 4 +- .../java/nl/lengrand/ReactiveService.java | 39 ------------------- cellar-driver/pom.xml | 4 +- cellar-driver/src/main/c/Dht11Driver.c | 1 + 11 files changed, 57 insertions(+), 53 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/sshConfigs.xml delete mode 100644 cellar-app/src/main/java/nl/lengrand/ReactiveService.java diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index fa521b3..5fcf588 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,10 +1,9 @@ - - - - + + + diff --git a/cellar-driver/pom.xml b/cellar-driver/pom.xml deleted file mode 100644 index a5dd42f..0000000 --- a/cellar-driver/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - cellar - nl.lengrand - 1.0-SNAPSHOT - - 4.0.0 - - cellar-driver - - - - - maven-compiler-plugin - 3.7.0 - - - -h - ${project.basedir}/target/headers - - - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - compile - - exec - - - ${project.basedir}/src/main/c - make - - - - - - maven-assembly-plugin - - - - nl.lengrand.cellar.TestLib - - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - - - - - \ No newline at end of file diff --git a/cellar-driver/src/main/c/Dht11Driver.c b/cellar-driver/src/main/c/Dht11Driver.c deleted file mode 100644 index 1608d5f..0000000 --- a/cellar-driver/src/main/c/Dht11Driver.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include -#include -#include -#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; - -} \ No newline at end of file diff --git a/cellar-driver/src/main/c/Makefile b/cellar-driver/src/main/c/Makefile deleted file mode 100644 index 5cebfd8..0000000 --- a/cellar-driver/src/main/c/Makefile +++ /dev/null @@ -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) \ No newline at end of file diff --git a/cellar-driver/src/main/c/README.md b/cellar-driver/src/main/c/README.md deleted file mode 100644 index 8f5bd34..0000000 --- a/cellar-driver/src/main/c/README.md +++ /dev/null @@ -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 \ No newline at end of file diff --git a/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_dht_read.c b/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_dht_read.c deleted file mode 100644 index dd0b9e1..0000000 --- a/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_dht_read.c +++ /dev/null @@ -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 -#include - -#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; - } -} diff --git a/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_dht_read.h b/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_dht_read.h deleted file mode 100644 index 89d5dce..0000000 --- a/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_dht_read.h +++ /dev/null @@ -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 diff --git a/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_mmio.c b/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_mmio.c deleted file mode 100644 index 4c40fe8..0000000 --- a/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_mmio.c +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include - -#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; -} diff --git a/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_mmio.h b/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_mmio.h deleted file mode 100644 index cda66db..0000000 --- a/cellar-driver/src/main/c/adafruit/Raspberry_Pi_2/pi_2_mmio.h +++ /dev/null @@ -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 - -#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 diff --git a/cellar-driver/src/main/c/adafruit/common_dht_read.c b/cellar-driver/src/main/c/adafruit/common_dht_read.c deleted file mode 100644 index 3bbb663..0000000 --- a/cellar-driver/src/main/c/adafruit/common_dht_read.c +++ /dev/null @@ -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 -#include -#include -#include -#include - -#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); -} diff --git a/cellar-driver/src/main/c/adafruit/common_dht_read.h b/cellar-driver/src/main/c/adafruit/common_dht_read.h deleted file mode 100644 index bb56c67..0000000 --- a/cellar-driver/src/main/c/adafruit/common_dht_read.h +++ /dev/null @@ -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 - -// 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 diff --git a/cellar-driver/src/main/c/compile.sh b/cellar-driver/src/main/c/compile.sh deleted file mode 100755 index 5a7f763..0000000 --- a/cellar-driver/src/main/c/compile.sh +++ /dev/null @@ -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 \ No newline at end of file diff --git a/cellar-driver/src/main/c/testAdafruit.c b/cellar-driver/src/main/c/testAdafruit.c deleted file mode 100644 index d5f5f7b..0000000 --- a/cellar-driver/src/main/c/testAdafruit.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include -#include - -#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; -} \ No newline at end of file diff --git a/cellar-driver/src/main/java/nl/lengrand/cellar/Dht11Driver.java b/cellar-driver/src/main/java/nl/lengrand/cellar/Dht11Driver.java deleted file mode 100644 index 8257f8f..0000000 --- a/cellar-driver/src/main/java/nl/lengrand/cellar/Dht11Driver.java +++ /dev/null @@ -1,12 +0,0 @@ -package nl.lengrand.cellar; - -public class Dht11Driver { - - static { - System.loadLibrary("dht11"); - } - - public native void sayHello(); - - public native float[] getTemperatureAndHumidity(); -} \ No newline at end of file diff --git a/cellar-driver/src/main/java/nl/lengrand/cellar/TestLib.java b/cellar-driver/src/main/java/nl/lengrand/cellar/TestLib.java deleted file mode 100644 index 74d854b..0000000 --- a/cellar-driver/src/main/java/nl/lengrand/cellar/TestLib.java +++ /dev/null @@ -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); - } - } -} \ No newline at end of file diff --git a/cellar-driver/src/main/resources/libs/raspberry/.containerFolder b/cellar-driver/src/main/resources/libs/raspberry/.containerFolder deleted file mode 100644 index e69de29..0000000 diff --git a/pom.xml b/pom.xml index 4f9988b..a23cc0d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,12 +10,11 @@ 1.0-SNAPSHOT - 1.8 - 1.8 + 1.11 + 1.11 - cellar-driver cellar-app From 1799df95ec1ef2379d5b40ce1a7b185f4ffc9ace Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Fri, 17 Jul 2020 16:20:15 +0200 Subject: [PATCH 3/4] Using proper version of the library --- cellar-app/pom.xml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cellar-app/pom.xml b/cellar-app/pom.xml index a0755d2..58271cc 100644 --- a/cellar-app/pom.xml +++ b/cellar-app/pom.xml @@ -63,8 +63,8 @@ nl.lengrand cellar-driver - 1.0-SNAPSHOT - compile + 1.1 + jar-with-dependencies com.faunadb @@ -95,4 +95,12 @@ + + + + github + GitHub Packages + https://maven.pkg.github.com/jlengrand/cellar-driver + + From 813b32072759bf05320dc39ca21f106a86b27d2f Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Mon, 20 Jul 2020 21:50:09 +0200 Subject: [PATCH 4/4] Fix java version in pom and remove .idea folder --- .gitignore | 1 + .idea/codeStyles/Project.xml | 7 -- .idea/codeStyles/codeStyleConfig.xml | 5 -- .idea/deployment.xml | 16 ---- .idea/encodings.xml | 7 -- .idea/jarRepositories.xml | 20 ----- .idea/misc.xml | 22 ----- .idea/sshConfigs.xml | 8 -- .idea/uiDesigner.xml | 124 --------------------------- .idea/vcs.xml | 6 -- .idea/webServers.xml | 14 --- pom.xml | 4 +- 12 files changed, 3 insertions(+), 231 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 .idea/deployment.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/sshConfigs.xml delete mode 100644 .idea/uiDesigner.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/webServers.xml diff --git a/.gitignore b/.gitignore index 4331f0d..c778fea 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ local.properties *.o /cellar-app/target/ /cellar-driver/target/ +/.idea/ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 919ce1f..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index a55e7a1..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/deployment.xml b/.idea/deployment.xml deleted file mode 100644 index 789a642..0000000 --- a/.idea/deployment.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 172f12c..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 0fdde56..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/sshConfigs.xml b/.idea/sshConfigs.xml deleted file mode 100644 index db4a24d..0000000 --- a/.idea/sshConfigs.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/webServers.xml b/.idea/webServers.xml deleted file mode 100644 index 1f5e8b5..0000000 --- a/.idea/webServers.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index a23cc0d..52466da 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ 1.0-SNAPSHOT - 1.11 - 1.11 + 11 + 11