Skip to content

Commit e3db40b

Browse files
authored
update library.json, readme, license, minor edits (#5)
* update library.json, readme, license, minor edits
1 parent 2261c86 commit e3db40b

File tree

11 files changed

+70
-44
lines changed

11 files changed

+70
-44
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2011-2021 Rob Tillaart
3+
Copyright (c) 2011-2022 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

MultiMap.h

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,47 @@
22
//
33
// FILE: MultiMap.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.4
5+
// VERSION: 0.1.5
66
// DATE: 2011-01-26
77
// PURPOSE: Arduino library for fast non-linear mapping or interpolation of values
88
// URL: https://github.com/RobTillaart/MultiMap
99
// URL: http://playground.arduino.cc/Main/MultiMap
1010
//
1111
// HISTORY:
1212
// 0.0.1 2011-01-26 initial version (see forum)
13-
// .....
13+
// ..... eons passed ...
1414
// 0.1.0 2015-03-29
1515
// 0.1.1 2020-04-09
1616
// 0.1.2 2020-06-19 fix library.json
17-
// 0.1.3 2021-01-02 add arduino-CI
18-
// 0.1.4 2021-05-27 fix arduino-lint
17+
// 0.1.3 2021-01-02 add Arduino-CI
18+
// 0.1.4 2021-05-27 fix Arduino-lint
19+
// 0.1.5 2021-12-22 update library.json, readme, license, minor edits
1920

2021

21-
#define MULTIMAP_LIB_VERSION (F("0.1.4"))
22+
#define MULTIMAP_LIB_VERSION (F("0.1.5"))
2223

2324

2425
#include "Arduino.h"
2526

27+
2628
// note: the in array should have increasing values
2729
template<typename T>
28-
T multiMap(T val, T* _in, T* _out, uint8_t size)
30+
T multiMap(T value, T* _in, T* _out, uint8_t size)
2931
{
3032
// take care the value is within range
31-
// val = constrain(val, _in[0], _in[size-1]);
32-
if (val <= _in[0]) return _out[0];
33-
if (val >= _in[size-1]) return _out[size-1];
33+
// value = constrain(value, _in[0], _in[size-1]);
34+
if (value <= _in[0]) return _out[0];
35+
if (value >= _in[size-1]) return _out[size-1];
3436

3537
// search right interval
36-
uint8_t pos = 1; // _in[0] allready tested
37-
while(val > _in[pos]) pos++;
38+
uint8_t pos = 1; // _in[0] already tested
39+
while(value > _in[pos]) pos++;
3840

3941
// this will handle all exact "points" in the _in array
40-
if (val == _in[pos]) return _out[pos];
42+
if (value == _in[pos]) return _out[pos];
4143

4244
// interpolate in the right segment for the rest
43-
return (val - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1];
45+
return (value - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1];
4446
}
4547

4648

@@ -50,42 +52,42 @@ T multiMap(T val, T* _in, T* _out, uint8_t size)
5052
// note: the in array should have increasing values
5153
5254
template<typename T>
53-
T multiMap(T val, T* _in, T* _out, uint8_t size)
55+
T multiMap(T value, T* _in, T* _out, uint8_t size)
5456
{
5557
static T lastvalue = -1;
5658
static T cache = -1;
5759
58-
if (val == lastvalue)
60+
if (value == lastvalue)
5961
{
6062
return cache;
6163
}
62-
lastvalue = val;
64+
lastvalue = value;
6365
6466
// take care the value is within range
65-
// val = constrain(val, _in[0], _in[size-1]);
66-
if (val <= _in[0])
67+
// value = constrain(value, _in[0], _in[size-1]);
68+
if (value <= _in[0])
6769
{
6870
cache = _out[0];
6971
}
70-
else if (val >= _in[size-1])
72+
else if (value >= _in[size-1])
7173
{
7274
cache = _out[size-1];
7375
}
7476
else
7577
{
7678
// search right interval; index 0 _in[0] already tested
7779
uint8_t pos = 1;
78-
while(val > _in[pos]) pos++;
80+
while(value > _in[pos]) pos++;
7981
8082
// this will handle all exact "points" in the _in array
81-
if (val == _in[pos])
83+
if (value == _in[pos])
8284
{
8385
cache = _out[pos];
8486
}
8587
else
8688
{
8789
// interpolate in the right segment for the rest
88-
cache = (val - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1];
90+
cache = (value - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1];
8991
}
9092
}
9193
return cache;
@@ -94,3 +96,4 @@ T multiMap(T val, T* _in, T* _out, uint8_t size)
9496

9597

9698
// -- END OF FILE --
99+

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Arduino library for fast non-linear mapping or interpolation of values
1515

1616
In Arduino applications often the value of a sensor is mapped upon a more
1717
usable value. E.g. the value of analogRead() is mapped onto 0 .. 5.0 Volt.
18-
This is done by the map function which does a linear interpolation. This means
18+
This is done by the map function which does a linear interpolation.
19+
This means in code:
1920

2021
```cpp
2122
output = C1 + input * C2
@@ -28,14 +29,15 @@ two variables runtime from two given mappings.
2829
output = map(input, I1, I2, O1, O2):
2930
```
3031

31-
In many cases when there is no linear mapping possible, as the 'points' are not on a single line.
32-
One needs non-linear math to calculate the output, **Multimap()** just does that.
32+
In many cases when there is no linear mapping possible, as the 'points' are not on a single straight line.
33+
One needs non-linear math to calculate the output, **Multimap()** just simulates that.
3334

34-
**out = Multimap(value, input, output, size)** needs two equal sized arrays of reference 'points', **input\[\]** and **output\[\]**, it looks up the
35+
**out = Multimap(value, input, output, size)** needs two equal sized arrays of reference 'points',
36+
**input\[\]** and **output\[\]**, it looks up the
3537
input value in the input\[\] array and if needed it linear interpolates between two
3638
points of the output\[\] array.
3739

38-
- The **input\[\]** array must have increasing values,
40+
- The **input\[\]** array must have increasing values,
3941
there is no such restriction for the **output\[\]** array.
4042
- **Multimap()** automatically constrains the output to the first and last value in the **output\[\]** array.
4143

@@ -52,7 +54,10 @@ Please note the fail example as this shows that in the intern math overflow can
5254
- Investigate class implementation for performance / footprint
5355
- flag if input value was "IN_MIN" < input < "IN_MAX",
5456
now it is constrained without user being informed.
57+
- extend unit tests
58+
59+
60+
**wont**
5561
- should the lookup tables be merged into one array of pairs?
56-
- you cannot reuse e.g. the input array then.
57-
-
58-
-
62+
- you cannot reuse e.g. the input array then. (memory footprint)
63+

examples/multimap_NTC/multimap_NTC.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//
22
// FILE: multimap_NTC.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
54
// PURPOSE: demo
65
// DATE: 2020-04-09
76
// (c) : MIT
@@ -90,3 +89,4 @@ float val(int sensorValueA1)
9089

9190

9291
// -- END OF FILE --
92+

examples/multimap_NTC_int_FAIL/multimap_NTC_int_FAIL.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
//
22
// FILE: multimap_NTC_int_FAIL.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
54
// PURPOSE: demo of faulty optimizing
65
// DATE: 2020-04-09
76
// (c) : MIT
87
//
9-
8+
//
109
// NOTE:
1110
// use integers instead of floats to minimize RAM. uses ~320 bytes PROGMEM ~120 bytes RAM less on UNO than float version
1211
//
13-
// this example is added to show how to reduce memory but also how it can FAIL due to math overflow
12+
// this example is added to show how to reduce memory but also how it can FAIL due to math overflow
1413
// E.g. see around 196-200; 340-400
1514
// to prevent this one must have more values which increases the memory usage again.
1615
//
@@ -92,3 +91,4 @@ float val(int sensorValueA1)
9291

9392

9493
// -- END OF FILE --
94+

examples/multimap_distance/multimap_distance.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//
22
// FILE: multimap_distance.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
54
// PURPOSE: demo
65
// DATE: 2020-04-09
76
//
@@ -49,3 +48,4 @@ float sharp2cm(int val)
4948

5049

5150
// -- END OF FILE --
51+

examples/multimap_functions/multimap_functions.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//
22
// FILE: multimap_functions.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
54
// PURPOSE: demo (use serial plotter)...
65
// DATE: 2020-04-09
76
// (c) : MIT
@@ -55,7 +54,7 @@ void test_normal_distribution()
5554

5655
void test_sinus()
5756
{
58-
// one sinus wave, amplitudo 1023
57+
// one sinus wave, amplitude 1023
5958
long sinus[] = {0, 316, 601, 827, 972, 1023, 972, 827, 601, 316, 0, -316, -601, -827, -972, -1023, -972, -827, -601, -316, 0 }; //21
6059
long in[21];
6160
for (int i = 0; i < 21; i++) in[i] = round(i * 1000.0 / 20);
@@ -138,3 +137,4 @@ void test_sawtooth()
138137

139138

140139
// -- END OF FILE --
140+

examples/multimap_timing/multimap_timing.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//
22
// FILE: multimap_timing.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
54
// PURPOSE: demo
65
// DATE: 2020-04-09
76
// (c) : MIT
@@ -54,3 +53,4 @@ void loop()
5453

5554

5655
// -- END OF FILE --
56+

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/MultiMap.git"
1717
},
18-
"version": "0.1.4",
18+
"version": "0.1.5",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=MultiMap
2-
version=0.1.4
2+
version=0.1.5
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Library for fast non-linear interpolation by means of two arrays.

0 commit comments

Comments
 (0)