update library.json, license, minor edits

This commit is contained in:
rob tillaart 2021-12-17 14:46:34 +01:00
parent 261976c1ff
commit a2228b5686
16 changed files with 122 additions and 63 deletions

View File

@ -2,6 +2,16 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms # Choosing to run compilation tests on 2 different Arduino platforms
platforms: platforms:
- uno - uno
- leonardo # - due
- due # - zero
- zero # - leonardo
- m4
- esp32
# - esp8266
# - mega2560
# Declaring Dependent Arduino Libraries (to be installed via the Arduino Library Manager)
libraries:
- "printHelpers"

View File

@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
arduino_ci: runTest:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: Arduino-CI/action@master - uses: ruby/setup-ruby@v1
# Arduino-CI/action@v0.1.1 with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -1,12 +1,13 @@
// //
// FILE: FastMap.cpp // FILE: FastMap.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.2 // VERSION: 0.3.3
// PURPOSE: class with fast map function - library for Arduino // PURPOSE: class with fast map function - library for Arduino
// URL: https://github.com/RobTillaart/FastMap // URL: https://github.com/RobTillaart/FastMap
// //
// HISTORY: // HISTORY:
// 0.3.2 2020-12-21 add arduino-CI + unit test // 0.3.3 2021-12-17 update library.json, license, minor edits
// 0.3.2 2020-12-21 add Arduino-CI + unit test
// 0.3.1 2020-08-31 updated documentation // 0.3.1 2020-08-31 updated documentation
// 0.3.0 2020-07-04 added fastMapDouble + test sketch. // 0.3.0 2020-07-04 added fastMapDouble + test sketch.
// 0.2.1 2020-06-10 fix library.json; rename license // 0.2.1 2020-06-10 fix library.json; rename license
@ -17,20 +18,22 @@
// 0.1.06 2015-03-08 replaced float by double (support ARM) // 0.1.06 2015-03-08 replaced float by double (support ARM)
// 0.1.05 2014-11-02 stripped of bit mask experimental code // 0.1.05 2014-11-02 stripped of bit mask experimental code
// 0.1.04 add back() - the inverse map // 0.1.04 add back() - the inverse map
// tested with bit mask for constrain code (Perfomance was killed) // tested with bit mask for constrain code (Performance was killed)
// 0.1.03 proper name // 0.1.03 proper name
// 0.1.02 sqeezed the code (first public version) // 0.1.02 squeezed the code (first public version)
// 0.1.01 refactor // 0.1.01 refactor
// 0.1.00 initial version // 0.1.00 initial version
//
#include "FastMap.h" #include "FastMap.h"
FastMap::FastMap() FastMap::FastMap()
{ {
init(0, 1, 0, 1); init(0, 1, 0, 1);
} }
void FastMap::init(float in_min, float in_max, float out_min, float out_max) void FastMap::init(float in_min, float in_max, float out_min, float out_max)
{ {
_in_min = in_min; _in_min = in_min;
@ -45,6 +48,7 @@ void FastMap::init(float in_min, float in_max, float out_min, float out_max)
_backbase = in_min - out_min * _backfactor; _backbase = in_min - out_min * _backfactor;
} }
float FastMap::constrainedMap(float value) float FastMap::constrainedMap(float value)
{ {
if (value <= _in_min) return _out_min; if (value <= _in_min) return _out_min;
@ -52,23 +56,27 @@ float FastMap::constrainedMap(float value)
return this->map(value); return this->map(value);
} }
float FastMap::lowerConstrainedMap(float value) float FastMap::lowerConstrainedMap(float value)
{ {
if (value <= _in_min) return _out_min; if (value <= _in_min) return _out_min;
return this->map(value); return this->map(value);
} }
float FastMap::upperConstrainedMap(float value) float FastMap::upperConstrainedMap(float value)
{ {
if (value >= _in_max) return _out_max; if (value >= _in_max) return _out_max;
return this->map(value); return this->map(value);
} }
FastMapDouble::FastMapDouble() FastMapDouble::FastMapDouble()
{ {
init(0, 1, 0, 1); init(0, 1, 0, 1);
} }
void FastMapDouble::init(double in_min, double in_max, double out_min, double out_max) void FastMapDouble::init(double in_min, double in_max, double out_min, double out_max)
{ {
_in_min = in_min; _in_min = in_min;
@ -83,6 +91,7 @@ void FastMapDouble::init(double in_min, double in_max, double out_min, double ou
_backbase = in_min - out_min * _backfactor; _backbase = in_min - out_min * _backfactor;
} }
double FastMapDouble::constrainedMap(double value) double FastMapDouble::constrainedMap(double value)
{ {
if (value <= _in_min) return _out_min; if (value <= _in_min) return _out_min;
@ -90,16 +99,20 @@ double FastMapDouble::constrainedMap(double value)
return this->map(value); return this->map(value);
} }
double FastMapDouble::lowerConstrainedMap(double value) double FastMapDouble::lowerConstrainedMap(double value)
{ {
if (value <= _in_min) return _out_min; if (value <= _in_min) return _out_min;
return this->map(value); return this->map(value);
} }
double FastMapDouble::upperConstrainedMap(double value) double FastMapDouble::upperConstrainedMap(double value)
{ {
if (value >= _in_max) return _out_max; if (value >= _in_max) return _out_max;
return this->map(value); return this->map(value);
} }
// END OF FILE
// -- END OF FILE --

View File

@ -2,17 +2,16 @@
// //
// FILE: FastMap.h // FILE: FastMap.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.2 // VERSION: 0.3.3
// PURPOSE: class with fast map function - library for Arduino // PURPOSE: class with fast map function - library for Arduino
// URL: https://github.com/RobTillaart/FastMap // URL: https://github.com/RobTillaart/FastMap
//
// HISTORY:
// see FastMap.cpp file
//
#include "Arduino.h" #include "Arduino.h"
#define FASTMAP_LIB_VERSION (F("0.3.2")) #define FASTMAP_LIB_VERSION (F("0.3.3"))
class FastMap class FastMap
{ {
@ -55,5 +54,5 @@ private:
}; };
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2010-2021 Rob Tillaart Copyright (c) 2010-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,15 +1,16 @@
// //
// FILE: constrainedMap.ino // FILE: constrainedMap.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo of FastMap class ==> merge map and constrain functions // PURPOSE: demo of FastMap class ==> merge map and constrain functions
// DATE: 2014-11-02 // DATE: 2014-11-02
// URL: https://github.com/RobTillaart/FastMap // URL: https://github.com/RobTillaart/FastMap
#include "FastMap.h" #include "FastMap.h"
FastMap mapper; FastMap mapper;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -39,8 +40,11 @@ void setup()
Serial.println("\ndone..."); Serial.println("\ndone...");
} }
void loop() void loop()
{ {
} }
// -- END OF FILE --

View File

@ -1,11 +1,11 @@
// //
// FILE: fastMapDemo.ino // FILE: fastMapDemo.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.02
// PURPOSE: demo of FastMap class ==> a faster map function // PURPOSE: demo of FastMap class ==> a faster map function
// DATE: 2014-11-02 // DATE: 2014-11-02
// URL: https://github.com/RobTillaart/FastMap // URL: https://github.com/RobTillaart/FastMap
#include "FastMap.h" #include "FastMap.h"
uint32_t start; uint32_t start;
@ -17,6 +17,7 @@ volatile float x;
FastMap mapper; FastMap mapper;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -59,9 +60,11 @@ void setup()
Serial.println(reference/(stop-start)); Serial.println(reference/(stop-start));
} }
void loop() void loop()
{ {
} }
//
// END OF FILE
// // -- END OF FILE --

View File

@ -1,16 +1,17 @@
// //
// FILE: fastMapDemo2.ino // FILE: fastMapDemo2.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.02
// PURPOSE: demo of FastMap class ==> a faster map function // PURPOSE: demo of FastMap class ==> a faster map function
// DATE: 2014-11-02 // DATE: 2014-11-02
// URL: https://github.com/RobTillaart/FastMap // URL: https://github.com/RobTillaart/FastMap
#include "FastMap.h" #include "FastMap.h"
FastMap CtoF; FastMap CtoF;
FastMap FtoC; FastMap FtoC;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -25,17 +26,18 @@ void setup()
Serial.print(f); Serial.print(f);
Serial.print(char(223)); Serial.print(char(223));
Serial.println('C'); Serial.println('C');
float c = CtoF.map(f); float c = CtoF.map(f);
Serial.print(c); Serial.print(c);
Serial.print(char(223)); Serial.print(char(223));
Serial.println('F'); Serial.println('F');
} }
void loop() void loop()
{ {
} }
//
// END OF FILE
// // -- END OF FILE --

View File

@ -1,15 +1,16 @@
// FILE: fastMapDemo3.ino // FILE: fastMapDemo3.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo of FastMap class ==> a faster map function // PURPOSE: demo of FastMap class ==> a faster map function
// DATE: 2014-11-02 // DATE: 2014-11-02
// URL: https://github.com/RobTillaart/FastMap // URL: https://github.com/RobTillaart/FastMap
// http://forum.arduino.cc/index.php?topic=276194 // http://forum.arduino.cc/index.php?topic=276194
#include "FastMap.h" #include "FastMap.h"
FastMap CtoF; FastMap CtoF;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -38,12 +39,12 @@ void setup()
Serial.print(f); Serial.print(f);
Serial.print(char(176)); Serial.print(char(176));
Serial.println('C'); Serial.println('C');
} }
void loop() void loop()
{ {
} }
//
// END OF FILE
// // -- END OF FILE --

View File

@ -1,11 +1,11 @@
// //
// FILE: fastMapDemo4.ino // FILE: fastMapDemo4.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo of FastMap class ==> a faster map function // PURPOSE: demo of FastMap class ==> a faster map function
// DATE: 2014-11-02 // DATE: 2014-11-02
// URL: https://github.com/RobTillaart/FastMap // URL: https://github.com/RobTillaart/FastMap
#include "FastMap.h" #include "FastMap.h"
uint32_t start; uint32_t start;
@ -17,6 +17,7 @@ volatile float x;
FastMap mapper; FastMap mapper;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -60,7 +61,7 @@ void setup()
Serial.print("Performance factor: "); Serial.print("Performance factor: ");
Serial.println((float)reference/(stop-start)); Serial.println((float)reference/(stop-start));
Serial.println(); Serial.println();
// constrainedMap // constrainedMap
mapper.init(0, 1023, yy, zz); mapper.init(0, 1023, yy, zz);
start = micros(); start = micros();
@ -118,13 +119,14 @@ void setup()
Serial.println((float)reference/(stop-start)); Serial.println((float)reference/(stop-start));
Serial.println(); Serial.println();
Serial.println("done..."); Serial.println("done...");
} }
void loop() void loop()
{ {
} }
//
// END OF FILE
// // -- END OF FILE --

View File

@ -1,7 +1,6 @@
// //
// FILE: fastMapDouble.ino // FILE: fastMapDouble.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo of FastMapDouble class // PURPOSE: demo of FastMapDouble class
// DATE: 2020-07-04 // DATE: 2020-07-04
// URL: https://github.com/RobTillaart/FastMap // URL: https://github.com/RobTillaart/FastMap
@ -19,6 +18,7 @@ volatile double x;
FastMapDouble mapper; FastMapDouble mapper;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -59,8 +59,11 @@ void setup()
Serial.println("\nDone..."); Serial.println("\nDone...");
} }
void loop() void loop()
{ {
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,7 +1,9 @@
# Syntax Coloring Map For FastMap # Syntax Colouring Map For FastMap
# Datatypes (KEYWORD1)
# Data types (KEYWORD1)
FastMap KEYWORD1 FastMap KEYWORD1
FastMapDouble KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)

View File

@ -15,8 +15,9 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/FastMap" "url": "https://github.com/RobTillaart/FastMap"
}, },
"version": "0.3.2", "version": "0.3.3",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*",
"headers": "FastMap.h"
} }

View File

@ -1,5 +1,5 @@
name=FastMap name=FastMap
version=0.3.2 version=0.3.3
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 with fast map function for Arduino. sentence=Library with fast map function for Arduino.

View File

@ -1,15 +1,19 @@
[![Arduino CI](https://github.com/RobTillaart/FastMap/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino CI](https://github.com/RobTillaart/FastMap/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/FastMap/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/FastMap/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/FastMap/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/FastMap/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/FastMap/blob/master/LICENSE) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/FastMap/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/FastMap.svg?maxAge=3600)](https://github.com/RobTillaart/FastMap/releases) [![GitHub release](https://img.shields.io/github/release/RobTillaart/FastMap.svg?maxAge=3600)](https://github.com/RobTillaart/FastMap/releases)
# FastMap # FastMap
Fast mapping and constraining Fast mapping and constraining.
## Description ## Description
FastMap is an object that precalculates (internal) floats to make a mapping function especially for floats. FastMap is an object that pre-calculates (internal) floats to make a mapping function especially for floats.
The Fastmap also provides a **back()** function to reverse the mapping. The Fastmap also provides a **back()** function to reverse the mapping.
This only works well with floats, so use with care. This only works well with floats, so use with care.
@ -17,6 +21,7 @@ An important difference with the traditional **map()** function is that both **i
accepts floats as parameters, allowing mapping that would be hard to achieve with the normal **map()** accepts floats as parameters, allowing mapping that would be hard to achieve with the normal **map()**
function. function.
## Performance notes ## Performance notes
(based upon tests https://github.com/RobTillaart/FastMap/issues/4 ) (based upon tests https://github.com/RobTillaart/FastMap/issues/4 )
@ -27,18 +32,19 @@ function.
To see the actual gain in your project on your hardware you should test and compare. To see the actual gain in your project on your hardware you should test and compare.
FastMap is faster when mapping floats as it uses less float operations than the standard map formula does. FastMap is faster when mapping floats as it uses less float operations than the standard map formula does.
The perfomance results from precalculating values in the **init()** function so actual mapping needs only The performance results from pre-calculating values in the **init()** function so actual mapping needs only
one multiply and add, where the standard **map()** function uses four adds, a multiplication and a division. one multiply and add, where the standard **map()** function uses four adds, a multiplication and a division.
The precalculation in **init()** should be taken in account and if every **map()** call needs an **init()** The pre-calculation in **init()** should be taken in account and if every **map()** call needs an **init()**
there will be no gain, on contrary. there will be no gain, on contrary.
The implementation uses floats (typical 32 bits) which might result in more memory usage and loss of precision The implementation of **fastMap()** uses floats (typical 32 bits) which might result in more memory usage
for mapping of larger values, especially 32 and 64 bit integers. This is caused by the limits of the mantissa and loss of precision for mapping of larger values, especially 32 and 64 bit integers.
(~23 bits) of the standard 4 byte float. This is caused by the limits of the mantissa (~23 bits) of the standard 4 byte float.
## Interface ## Interface
- **void init(in_min, in_max, out_min, out_max);** defines the linear mapping parameters. - **void init(float in_min, float in_max, float out_min, float out_max);** defines the linear mapping parameters.
The **init()** function calculates all needed values for the **map()**, the **back()** call and the **constrainXX()** functions. The **init()** function calculates all needed values for the **map()**, the **back()** call and the **constrainXX()** functions.
The **init()** function can be called again with new values when needed to do other mapping, The **init()** function can be called again with new values when needed to do other mapping,
although it will give less overhead if you create an fastMap object per conversion needed. although it will give less overhead if you create an fastMap object per conversion needed.
@ -46,7 +52,9 @@ Note: **init()** does not check for a divide by zero (out_max == out_min) or (in
- **float map(float value)** maps the parameter. - **float map(float value)** maps the parameter.
- **float back(float value)** does the inverse mapping - **float back(float value)** does the inverse mapping
### Constrains ### Constrains
FastMap supports three versions of constraining the map function, based upon the parameters of **init()** FastMap supports three versions of constraining the map function, based upon the parameters of **init()**
- **float constrainedMap(float value);** returns a value between outMin .. outMax - **float constrainedMap(float value);** returns a value between outMin .. outMax
- **float lowerConstrainedMap(float value);** returns a value between outMin .. inf (No upper limit) - **float lowerConstrainedMap(float value);** returns a value between outMin .. inf (No upper limit)
@ -59,11 +67,22 @@ Note there are **NO** constrain-versions for **back(value)** function.
## FastMapDouble ## FastMapDouble
Version 3.0 adds **fastMapDouble** which has the same interface. Version 3.0 adds **fastMapDouble** which has the same interface as **fastMap()**.
This class is meant to support 8 bytes doubles in their native accuracy and precision. This class is meant to support 8 bytes doubles in their native accuracy and precision.
To display doubles one might need the **sci()** function of my **printHelpers** class. To display doubles one might need the **sci()** function of my **printHelpers** class.
https://github.com/RobTillaart/printHelpers https://github.com/RobTillaart/printHelpers
## Usage ## Usage
See examples. See examples.
## Future
- update documentation
- investigate map function for complex numbers? / coordinates?
- can fastMap and fastMapDouble be in a class hierarchy? gain?
- Template class?
- test performance fastMapDouble on ESP32.

View File

@ -30,6 +30,7 @@
unittest_setup() unittest_setup()
{ {
fprintf(stderr, "FASTMAP_LIB_VERSION: %s\n", (char *) FASTMAP_LIB_VERSION);
} }
@ -42,7 +43,6 @@ unittest(test_map)
{ {
FastMap fm; FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42); fm.init(-2, 12, 17, 42);
assertEqualFloat(11.6429, fm.map(-5), 0.001); assertEqualFloat(11.6429, fm.map(-5), 0.001);
@ -58,7 +58,6 @@ unittest(test_back)
{ {
FastMap fm; FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42); fm.init(-2, 12, 17, 42);
assertEqualFloat(-14.32, fm.back(-5), 0.001); assertEqualFloat(-14.32, fm.back(-5), 0.001);
@ -75,7 +74,6 @@ unittest(test_constrainedMap)
{ {
FastMap fm; FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42); fm.init(-2, 12, 17, 42);
assertEqualFloat(17, fm.constrainedMap(-5), 0.001); assertEqualFloat(17, fm.constrainedMap(-5), 0.001);
@ -91,7 +89,6 @@ unittest(test_lowerConstrainedMap)
{ {
FastMap fm; FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42); fm.init(-2, 12, 17, 42);
assertEqualFloat(17, fm.lowerConstrainedMap(-5), 0.001); assertEqualFloat(17, fm.lowerConstrainedMap(-5), 0.001);
@ -107,7 +104,6 @@ unittest(test_upperConstrainedMap)
{ {
FastMap fm; FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42); fm.init(-2, 12, 17, 42);
assertEqualFloat(11.6429, fm.upperConstrainedMap(-5), 0.001); assertEqualFloat(11.6429, fm.upperConstrainedMap(-5), 0.001);
@ -121,10 +117,10 @@ unittest(test_upperConstrainedMap)
unittest(test_map_double) unittest(test_map_double)
{ {
fprintf(stderr, "FAST MAP DOUBLE\n");
FastMapDouble fm; FastMapDouble fm;
fprintf(stderr, "FAST MAP DOUBLE\n");
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42); fm.init(-2, 12, 17, 42);
assertEqualFloat(11.6429, fm.map(-5), 0.001); assertEqualFloat(11.6429, fm.map(-5), 0.001);