0.1.4 MultiMap

This commit is contained in:
rob tillaart 2021-05-28 13:39:42 +02:00
parent c1a6d80098
commit e83ffeb82e
10 changed files with 45 additions and 11 deletions

View File

@ -2,7 +2,7 @@
// //
// FILE: MultiMap.h // FILE: MultiMap.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.3 // VERSION: 0.1.4
// DATE: 2011-01-26 // DATE: 2011-01-26
// PURPOSE: Arduino library for fast non-linear mapping or interpolation of values // PURPOSE: Arduino library for fast non-linear mapping or interpolation of values
// URL: https://github.com/RobTillaart/MultiMap // URL: https://github.com/RobTillaart/MultiMap
@ -15,9 +15,11 @@
// 0.1.1 2020-04-09 // 0.1.1 2020-04-09
// 0.1.2 2020-06-19 fix library.json // 0.1.2 2020-06-19 fix library.json
// 0.1.3 2021-01-02 add arduino-CI // 0.1.3 2021-01-02 add arduino-CI
// // 0.1.4 2021-05-27 fix arduino-lint
#define MULTIMAP_LIB_VERSION (F("0.1.4"))
#define MULTIMAP_LIB_VERSION "0.1.3"
#include "Arduino.h" #include "Arduino.h"
@ -90,4 +92,5 @@ T multiMap(T val, T* _in, T* _out, uint8_t size)
} }
*/ */
// -- END OF FILE -- // -- END OF FILE --

View File

@ -7,6 +7,7 @@
Arduino library for fast non-linear mapping or interpolation of values Arduino library for fast non-linear mapping or interpolation of values
## Description ## Description
In Arduino applications often the value of a sensor is mapped upon a more In Arduino applications often the value of a sensor is mapped upon a more
@ -35,12 +36,14 @@ points of the output\[\] array.
there is no such restriction for the **output\[\]** array. there is no such restriction for the **output\[\]** array.
- **Multimap()** automatically constrains the output to the first and last value in the **output\[\]** array. - **Multimap()** automatically constrains the output to the first and last value in the **output\[\]** array.
## Operation ## Operation
See examples See examples
Please note the fail example as this shows that in the intern math overflow can happen. Please note the fail example as this shows that in the intern math overflow can happen.
## TODO ## TODO
Investigate class implementation for performance. Investigate class implementation for performance.

View File

@ -7,6 +7,7 @@
// (c) : MIT // (c) : MIT
// //
#include "MultiMap.h" #include "MultiMap.h"
uint32_t start; uint32_t start;
@ -17,6 +18,7 @@ volatile float x, y, z;
// Note this is a bit an extreme example, // Note this is a bit an extreme example,
// normally you only make a multimap of the working range // normally you only make a multimap of the working range
float in[] = { float in[] = {
0, 1, 3, 8, 13, 20, 25, 32, 50, 60, 72, 85, 100, 145, 200, 250, 300, 400, 500, 600, 650, 700, 753, 800, 830, 870, 900, 936, 964, 985, 1000, 1017, 1023 0, 1, 3, 8, 13, 20, 25, 32, 50, 60, 72, 85, 100, 145, 200, 250, 300, 400, 500, 600, 650, 700, 753, 800, 830, 870, 900, 936, 964, 985, 1000, 1017, 1023
}; };
@ -27,6 +29,7 @@ float out[] = {
int sz = 33; int sz = 33;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -64,10 +67,12 @@ void setup()
} }
void loop() void loop()
{ {
} }
// NTC formula // NTC formula
float val(int sensorValueA1) float val(int sensorValueA1)
{ {
@ -80,4 +85,5 @@ float val(int sensorValueA1)
return Temp; return Temp;
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -23,6 +23,7 @@ uint32_t stop;
volatile float x, y, z; volatile float x, y, z;
int in[] = { int in[] = {
0, 1, 3, 8, 13, 20, 25, 32, 50, 60, 72, 85, 100, 145, 200, 250, 300, 400, 500, 600, 650, 700, 753, 800, 830, 870, 900, 936, 964, 985, 1000, 1017, 1023 0, 1, 3, 8, 13, 20, 25, 32, 50, 60, 72, 85, 100, 145, 200, 250, 300, 400, 500, 600, 650, 700, 753, 800, 830, 870, 900, 936, 964, 985, 1000, 1017, 1023
}; };
@ -33,6 +34,7 @@ int out[] = {
int sz = 33; int sz = 33;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -67,13 +69,14 @@ void setup()
Serial.print(z); Serial.print(z);
Serial.println(); Serial.println();
} }
} }
void loop() void loop()
{ {
} }
// NTC formula // NTC formula
float val(int sensorValueA1) float val(int sensorValueA1)
{ {
@ -86,4 +89,5 @@ float val(int sensorValueA1)
return Temp; return Temp;
} }
// -- END OF FILE --
// -- END OF FILE --

View File

@ -1,4 +1,3 @@
// //
// FILE: multimap_distance.ino // FILE: multimap_distance.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
@ -7,8 +6,10 @@
// DATE: 2020-04-09 // DATE: 2020-04-09
// //
#include "MultiMap.h" #include "MultiMap.h"
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -26,6 +27,7 @@ void setup()
Serial.println("Done..."); Serial.println("Done...");
} }
void loop() void loop()
{ {
} }
@ -44,4 +46,5 @@ float sharp2cm(int val)
return dist; return dist;
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -10,6 +10,7 @@
#include "MultiMap.h" #include "MultiMap.h"
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -27,11 +28,12 @@ void setup()
Serial.println("\nDone..."); Serial.println("\nDone...");
} }
void loop() void loop()
{ {
} }
void test_normal_distribution() void test_normal_distribution()
{ {
// sort of normal distribution // sort of normal distribution
@ -48,6 +50,7 @@ void test_normal_distribution()
} }
} }
void test_sinus() void test_sinus()
{ {
// one sinus wave, amplitudo 1023 // one sinus wave, amplitudo 1023
@ -64,6 +67,7 @@ void test_sinus()
} }
} }
void lest_log10() void lest_log10()
{ {
// log10 * 100 // log10 * 100
@ -80,6 +84,7 @@ void lest_log10()
} }
} }
void test_exp2() void test_exp2()
{ {
// 2^x // 2^x
@ -96,6 +101,7 @@ void test_exp2()
} }
} }
void test_exp3() void test_exp3()
{ {
// 3^x // 3^x
@ -112,6 +118,7 @@ void test_exp3()
} }
} }
void test_sawtooth() void test_sawtooth()
{ {
long sawtooth[] = { 0, 1000, 0, -1000, 0, 1000, -1000, 0 }; // size 8 long sawtooth[] = { 0, 1000, 0, -1000, 0, 1000, -1000, 0 }; // size 8
@ -127,4 +134,5 @@ void test_sawtooth()
} }
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -19,6 +19,7 @@ float fout[] = {111, 222, 555};
uint32_t start; uint32_t start;
uint32_t stop; uint32_t stop;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -40,9 +41,10 @@ void setup()
Serial.println(y, 4); Serial.println(y, 4);
} }
void loop() void loop()
{ {
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -15,7 +15,8 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/MultiMap.git" "url": "https://github.com/RobTillaart/MultiMap.git"
}, },
"version":"0.1.3", "version": "0.1.4",
"license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*"
} }

View File

@ -1,11 +1,11 @@
name=MultiMap name=MultiMap
version=0.1.3 version=0.1.4
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for fast non-linear interpolation by means of two arrays. sentence=Library for fast non-linear interpolation by means of two arrays.
paragraph= paragraph=
category=Data Processing category=Data Processing
url=https://github.com/RobTillaart/Arduino/MultiMap url=https://github.com/RobTillaart/MultiMap
architectures=* architectures=*
includes=MultiMap.h includes=MultiMap.h
depends= depends=

View File

@ -39,6 +39,7 @@ unittest_setup()
{ {
} }
unittest_teardown() unittest_teardown()
{ {
} }
@ -56,6 +57,7 @@ unittest(test_new_operator)
} }
*/ */
unittest(test_all) unittest(test_all)
{ {
fprintf(stderr, "VERSION: %s\n", MULTIMAP_LIB_VERSION); fprintf(stderr, "VERSION: %s\n", MULTIMAP_LIB_VERSION);
@ -75,6 +77,8 @@ unittest(test_all)
assertEqualFloat(20.0000, multiMap<float>(600, in, out, 14), 0.001); assertEqualFloat(20.0000, multiMap<float>(600, in, out, 14), 0.001);
} }
unittest_main() unittest_main()
// -------- // --------