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
platforms:
- uno
- leonardo
- due
- zero
# - due
# - 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]
jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -1,12 +1,13 @@
//
// FILE: FastMap.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.2
// VERSION: 0.3.3
// PURPOSE: class with fast map function - library for Arduino
// URL: https://github.com/RobTillaart/FastMap
//
// 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.0 2020-07-04 added fastMapDouble + test sketch.
// 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.05 2014-11-02 stripped of bit mask experimental code
// 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.02 sqeezed the code (first public version)
// 0.1.02 squeezed the code (first public version)
// 0.1.01 refactor
// 0.1.00 initial version
//
#include "FastMap.h"
FastMap::FastMap()
{
init(0, 1, 0, 1);
}
void FastMap::init(float in_min, float in_max, float out_min, float out_max)
{
_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;
}
float FastMap::constrainedMap(float value)
{
if (value <= _in_min) return _out_min;
@ -52,23 +56,27 @@ float FastMap::constrainedMap(float value)
return this->map(value);
}
float FastMap::lowerConstrainedMap(float value)
{
if (value <= _in_min) return _out_min;
return this->map(value);
}
float FastMap::upperConstrainedMap(float value)
{
if (value >= _in_max) return _out_max;
return this->map(value);
}
FastMapDouble::FastMapDouble()
{
init(0, 1, 0, 1);
}
void FastMapDouble::init(double in_min, double in_max, double out_min, double out_max)
{
_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;
}
double FastMapDouble::constrainedMap(double value)
{
if (value <= _in_min) return _out_min;
@ -90,16 +99,20 @@ double FastMapDouble::constrainedMap(double value)
return this->map(value);
}
double FastMapDouble::lowerConstrainedMap(double value)
{
if (value <= _in_min) return _out_min;
return this->map(value);
}
double FastMapDouble::upperConstrainedMap(double value)
{
if (value >= _in_max) return _out_max;
return this->map(value);
}
// END OF FILE
// -- END OF FILE --

View File

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

View File

@ -1,6 +1,6 @@
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
of this software and associated documentation files (the "Software"), to deal

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
name=FastMap
version=0.3.2
version=0.3.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
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-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)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/FastMap.svg?maxAge=3600)](https://github.com/RobTillaart/FastMap/releases)
# FastMap
Fast mapping and constraining
Fast mapping and constraining.
## 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.
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()**
function.
## Performance notes
(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.
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.
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.
The implementation uses floats (typical 32 bits) which might result in more memory usage and loss of precision
for mapping of larger values, especially 32 and 64 bit integers. This is caused by the limits of the mantissa
(~23 bits) of the standard 4 byte float.
The implementation of **fastMap()** uses floats (typical 32 bits) which might result in more memory usage
and loss of precision for mapping of larger values, especially 32 and 64 bit integers.
This is caused by the limits of the mantissa (~23 bits) of the standard 4 byte float.
## 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 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.
@ -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 back(float value)** does the inverse mapping
### Constrains
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 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
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.
To display doubles one might need the **sci()** function of my **printHelpers** class.
https://github.com/RobTillaart/printHelpers
## Usage
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()
{
fprintf(stderr, "FASTMAP_LIB_VERSION: %s\n", (char *) FASTMAP_LIB_VERSION);
}
@ -42,7 +43,6 @@ unittest(test_map)
{
FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42);
assertEqualFloat(11.6429, fm.map(-5), 0.001);
@ -58,7 +58,6 @@ unittest(test_back)
{
FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42);
assertEqualFloat(-14.32, fm.back(-5), 0.001);
@ -75,7 +74,6 @@ unittest(test_constrainedMap)
{
FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42);
assertEqualFloat(17, fm.constrainedMap(-5), 0.001);
@ -91,7 +89,6 @@ unittest(test_lowerConstrainedMap)
{
FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42);
assertEqualFloat(17, fm.lowerConstrainedMap(-5), 0.001);
@ -107,7 +104,6 @@ unittest(test_upperConstrainedMap)
{
FastMap fm;
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42);
assertEqualFloat(11.6429, fm.upperConstrainedMap(-5), 0.001);
@ -121,10 +117,10 @@ unittest(test_upperConstrainedMap)
unittest(test_map_double)
{
fprintf(stderr, "FAST MAP DOUBLE\n");
FastMapDouble fm;
fprintf(stderr, "FAST MAP DOUBLE\n");
fprintf(stderr, "VERSION:\t%s\n", FASTMAP_LIB_VERSION);
fm.init(-2, 12, 17, 42);
assertEqualFloat(11.6429, fm.map(-5), 0.001);