From 92e93933c29a4071c11a2a1b831951e1dbe5458b Mon Sep 17 00:00:00 2001 From: Ta180m Date: Fri, 21 Feb 2020 21:36:47 -0600 Subject: Fixed libraries --- libraries/detectorBuilding/detectorBuilding.cpp | 64 --------------------- libraries/detectorBuilding/detectorBuilding.h | 28 --------- libraries/detectorBuilding/keywords.txt | 3 +- libraries/detectorBuilding/library.properties | 10 ++++ .../detectorBuilding/src/detectorBuilding.cpp | 67 ++++++++++++++++++++++ libraries/detectorBuilding/src/detectorBuilding.h | 31 ++++++++++ 6 files changed, 109 insertions(+), 94 deletions(-) delete mode 100644 libraries/detectorBuilding/detectorBuilding.cpp delete mode 100644 libraries/detectorBuilding/detectorBuilding.h create mode 100644 libraries/detectorBuilding/library.properties create mode 100644 libraries/detectorBuilding/src/detectorBuilding.cpp create mode 100644 libraries/detectorBuilding/src/detectorBuilding.h diff --git a/libraries/detectorBuilding/detectorBuilding.cpp b/libraries/detectorBuilding/detectorBuilding.cpp deleted file mode 100644 index 6a06bae..0000000 --- a/libraries/detectorBuilding/detectorBuilding.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - detectorBuilding.cpp - Library for Detector Building utility functions - Created by Anthony Wang, February 21, 2020. - Released into the public domain. -*/ - -#include "Arduino.h" -#include "detectorBuilding.h" - -const int LED_R = 4, LED_G = 3, LED_B = 2, THERM = 0; // Device component pins -const double R_k = 10000, V_in = 5, analog_max = 1023; // Device constants - -// Temperature conversions -inline double f2c(double f) { return (f - 32) * 5 / 9; } // Fahrenheit to Celsius -inline double c2f(double c) { return c * 9 / 5 + 32; } // Celsius to Fahrenheit -inline double k2c(double k) { return k - 273.15; } // Kelvin to Celsius -inline double c2k(double c) { return c + 273.15; } // Celsius to Kelvin -inline double f2k(double f) { return c2k(f2c(f)); } // Fahrenheit to Kelvin -inline double k2f(double k) { return c2f(k2c(k)); } // Kelvin to Fahrenheit - -// Analog to digital conversion -inline double a2d(int a) { return V_in * a / analog_max; } -inline int d2a(double d) { return d * analog_max / V_in; } - -// Voltage to resistance conversion -inline double v2r(double V_out) { return R_k * (V_in / V_out - 1); } - -// Utility functions -// No C++ standard library :( -void sort(double a[], int n) { - // Bubble sort - // Slow but n < 30 so OK - // Too lazy to implement a fast sort - for (int i = 0; i < n; i++) { - for (int j = 0; j < n - 1; j++) { - if (a[j] > a[j + 1]) { - double tmp = a[j]; - a[j] = a[j + 1]; - a[j + 1] = tmp; - } - } - } -} - -// Calculations: Steinhart-hart stuff -// Probably unused but can include anyways -void calculate() { - sort(V, n); - sort(T, n); - double R[n], L[n], Y[n], G[n]; - for (int i = 0; i < n; i++) R[i] = R_k * (V_in / V[i] - 1); - for (int i = 0; i < n; i++) L[i] = log(R[i]); - for (int i = 0; i < n; i++) Y[i] = 1 / c2k(T[i]); - for (int i = 0; i < n; i += 3) { - G[i + 1] = (Y[i + 1] - Y[i]) / (L[i + 1] - L[i]); - G[i + 2] = (Y[i + 2] - Y[i]) / (L[i + 2] - L[i]); - } - for (int i = 0; i < n; i += 3) { // Don't ask how this works - C[i / 3] = (G[i + 2] - G[i + 1]) / (L[i + 2] - L[i + 1]) / (L[i] + L[i + 1] + L[i + 2]); - B[i / 3] = G[i + 1] - C[i / 3] * (L[i] * L[i] + L[i] * L[i + 1] + L[i + 1] * L[i + 1]); - A[i / 3] = Y[i] - L[i] * (B[i / 3] + L[i] * L[i] * C[i / 3]); - } - for (int i = 0; i < n; i += 3) V_mid[i / 3] = (i ? (V[i - 1] + V[i]) / 2 : V[i]); -} \ No newline at end of file diff --git a/libraries/detectorBuilding/detectorBuilding.h b/libraries/detectorBuilding/detectorBuilding.h deleted file mode 100644 index 668048c..0000000 --- a/libraries/detectorBuilding/detectorBuilding.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - detectorBuilding.h - Library for Detector Building utility functions - Created by Anthony Wang, February 21, 2020. - Released into the public domain. -*/ - -#ifndef detectorBuilding_h -#define detectorBuilding_h - -#include "Arduino.h" - -inline double f2c(double f); -inline double c2f(double c); -inline double k2c(double k); -inline double c2k(double c); -inline double f2k(double f); -inline double k2f(double k); - -inline double a2d(int a); -inline int d2a(double d); - -inline double v2r(double V_out); - -void sort(double a[], int n); - -void calculate(); - -#endif \ No newline at end of file diff --git a/libraries/detectorBuilding/keywords.txt b/libraries/detectorBuilding/keywords.txt index ee7800a..894f3c0 100644 --- a/libraries/detectorBuilding/keywords.txt +++ b/libraries/detectorBuilding/keywords.txt @@ -7,5 +7,4 @@ k2f KEYWORD2 a2d KEYWORD2 d2a KEYWORD2 v2r KEYWORD2 -sort KEYWORD2 -calculate KEYWORD2 \ No newline at end of file +sort KEYWORD2 \ No newline at end of file diff --git a/libraries/detectorBuilding/library.properties b/libraries/detectorBuilding/library.properties new file mode 100644 index 0000000..5b7c9af --- /dev/null +++ b/libraries/detectorBuilding/library.properties @@ -0,0 +1,10 @@ +name=DetectorBuilding +version=1.0 +author=unixkcd +maintainer=unixkcd +sentence=Detector building utility code +paragraph=Some detector building utility code +url=https://github.com/Ta180m/Detector-Building +includes=detectorBuilding.h +category=Data Processing +architectures=* diff --git a/libraries/detectorBuilding/src/detectorBuilding.cpp b/libraries/detectorBuilding/src/detectorBuilding.cpp new file mode 100644 index 0000000..3bca44c --- /dev/null +++ b/libraries/detectorBuilding/src/detectorBuilding.cpp @@ -0,0 +1,67 @@ +/* + detectorBuilding.cpp - Library for Detector Building utility functions + Created by Anthony Wang, February 21, 2020. + Released into the public domain. +*/ + + +#include "Arduino.h" +#include "detectorBuilding.h" + + +// Temperature conversions +inline double f2c(double f) { return (f - 32) * 5 / 9; } // Fahrenheit to Celsius +inline double c2f(double c) { return c * 9 / 5 + 32; } // Celsius to Fahrenheit +inline double k2c(double k) { return k - 273.15; } // Kelvin to Celsius +inline double c2k(double c) { return c + 273.15; } // Celsius to Kelvin +inline double f2k(double f) { return c2k(f2c(f)); } // Fahrenheit to Kelvin +inline double k2f(double k) { return c2f(k2c(k)); } // Kelvin to Fahrenheit + + +// Analog to digital conversion +inline double a2d(int a) { return V_in * a / analog_max; } +inline int d2a(double d) { return d * analog_max / V_in; } + + +// Voltage to resistance conversion +inline double v2r(double V_out) { return R_k * (V_in / V_out - 1); } + + +// Utility functions +// No C++ standard library :( +void sort(double a[], int n) { + // Bubble sort + // Slow but n < 30 so OK + // Too lazy to implement a fast sort + for (int i = 0; i < n; i++) { + for (int j = 0; j < n - 1; j++) { + if (a[j] > a[j + 1]) { + double tmp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = tmp; + } + } + } +} + + +// Calculations: Steinhart-hart stuff +// Probably unused but can include anyways +/*void calculate() { + sort(V, n); + sort(T, n); + double R[n], L[n], Y[n], G[n]; + for (int i = 0; i < n; i++) R[i] = R_k * (V_in / V[i] - 1); + for (int i = 0; i < n; i++) L[i] = log(R[i]); + for (int i = 0; i < n; i++) Y[i] = 1 / c2k(T[i]); + for (int i = 0; i < n; i += 3) { + G[i + 1] = (Y[i + 1] - Y[i]) / (L[i + 1] - L[i]); + G[i + 2] = (Y[i + 2] - Y[i]) / (L[i + 2] - L[i]); + } + for (int i = 0; i < n; i += 3) { // Don't ask how this works + C[i / 3] = (G[i + 2] - G[i + 1]) / (L[i + 2] - L[i + 1]) / (L[i] + L[i + 1] + L[i + 2]); + B[i / 3] = G[i + 1] - C[i / 3] * (L[i] * L[i] + L[i] * L[i + 1] + L[i + 1] * L[i + 1]); + A[i / 3] = Y[i] - L[i] * (B[i / 3] + L[i] * L[i] * C[i / 3]); + } + for (int i = 0; i < n; i += 3) V_mid[i / 3] = (i ? (V[i - 1] + V[i]) / 2 : V[i]); +}*/ \ No newline at end of file diff --git a/libraries/detectorBuilding/src/detectorBuilding.h b/libraries/detectorBuilding/src/detectorBuilding.h new file mode 100644 index 0000000..b82cc35 --- /dev/null +++ b/libraries/detectorBuilding/src/detectorBuilding.h @@ -0,0 +1,31 @@ +/* + detectorBuilding.h - Library for Detector Building utility functions + Created by Anthony Wang, February 21, 2020. + Released into the public domain. +*/ + +#ifndef detectorBuilding_h +#define detectorBuilding_h + +#include "Arduino.h" + +const int LED_R = 4, LED_G = 3, LED_B = 2, THERM = 0; // Device component pins +const double R_k = 10000, V_in = 5, analog_max = 1023; // Device constants + +inline double f2c(double f); +inline double c2f(double c); +inline double k2c(double k); +inline double c2k(double c); +inline double f2k(double f); +inline double k2f(double k); + +inline double a2d(int a); +inline int d2a(double d); + +inline double v2r(double V_out); + +void sort(double a[], int n); + +//void calculate(); + +#endif \ No newline at end of file -- cgit v1.2.3-70-g09d2