mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 map2colour
This commit is contained in:
parent
5f1faef934
commit
f97f14dfd9
11
libraries/map2colour/.arduino-ci.yml
Normal file
11
libraries/map2colour/.arduino-ci.yml
Normal file
@ -0,0 +1,11 @@
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
13
libraries/map2colour/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/map2colour/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
17
libraries/map2colour/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/map2colour/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
18
libraries/map2colour/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/map2colour/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
21
libraries/map2colour/LICENSE
Normal file
21
libraries/map2colour/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
69
libraries/map2colour/README.md
Normal file
69
libraries/map2colour/README.md
Normal file
@ -0,0 +1,69 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/map2colour/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/map2colour/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/map2colour/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/map2colour/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/map2colour/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/map2colour/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/map2colour.svg?maxAge=3600)](https://github.com/RobTillaart/map2colour/releases)
|
||||
|
||||
|
||||
# map2colour
|
||||
|
||||
Arduino library for mapping a float to colour spectrum
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
The map2colour library is used to make map a reading from a sensor, e.g. temperature or pressure,
|
||||
to a colour in the RGB spectrum.
|
||||
|
||||
The initial release uses 7 floats values that describe the range being mapped.
|
||||
These are passed to the library with **begin()**.
|
||||
These 7 floats must be in ascending order and are mapped upon the following colour array.
|
||||
|
||||
```cpp
|
||||
uint32_t colours[] =
|
||||
{
|
||||
// BLACK RED YELLOW GREEN ?? BLUE WHITE
|
||||
0x00000000, 0x00FF0000, 0x00FFFF00, 0x0000FF00, 0x0000FFFF, 0x000000FF, 0x00FFFFFF
|
||||
}
|
||||
```
|
||||
|
||||
New values will be linear interpolated between the two points when needed.
|
||||
|
||||
Assume you initialize a float array
|
||||
```cpp
|
||||
float tempArray[] = { -10, -10, 5, 15, 30, 60, 125 }; // note the double -10
|
||||
```
|
||||
A temperature of 0°C will be mapped between the 2nd and 3rd element so somewhere
|
||||
between RED and YELLOW.
|
||||
A temperature between 60°C and 125°C will be mapped between BLUE and WHITE.
|
||||
|
||||
This first version is to get hands on experience, a later version should
|
||||
support user defined colour maps.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
- **map2colour()** constructor.
|
||||
- **bool begin(float \* ar)** load the array with 7 boundaries.
|
||||
- **uint32_t map2RGB(float value)** returns RGB colour packed in an uint32_t. **0x00RRGGBB**
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See examples.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- update documentation
|
||||
|
||||
**0.2.0** thoughts
|
||||
- make the colour map user defined - like multi-map
|
||||
- between BLACK and a single colour. - intensity
|
||||
- between a number of colours e.g. RED YELLOW GREEN or GREEN YELLOW RED
|
||||
- fixed number of points is flex enough
|
||||
- example with double entries
|
||||
- temp -10, 5, 10, 30, 35, 60, 120
|
||||
- Red yellow black black yellow red red
|
||||
- middle area 10..30 has no colour.
|
@ -0,0 +1,51 @@
|
||||
//
|
||||
// FILE: map2colour_demo01.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: map2colour demo
|
||||
// DATE: 2021-12-04
|
||||
// URL: https://github.com/RobTillaart/map2colour
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "map2colour.h"
|
||||
|
||||
map2colour mc;
|
||||
|
||||
// should be in increasing order
|
||||
float values[7] = { 0, 32, 64, 128, 256, 512, 1024 };
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
// load the values array
|
||||
mc.begin(values);
|
||||
|
||||
// show the interpolating
|
||||
for (float i = 0; i < 1024; i += 10)
|
||||
{
|
||||
uint32_t rgb = mc.map2RGB(i);
|
||||
Serial.print(i);
|
||||
Serial.print("\t");
|
||||
Serial.println(rgb, HEX);
|
||||
}
|
||||
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
int x = analogRead(0); // UNO returns between 0..1023; adapt if needed.
|
||||
uint32_t rgb = mc.map2RGB(x);
|
||||
Serial.print(x);
|
||||
Serial.print("\t");
|
||||
Serial.println(rgb, HEX);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,46 @@
|
||||
//
|
||||
// FILE: map2colour_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: map2colour demo
|
||||
// DATE: 2021-12-04
|
||||
// URL: https://github.com/RobTillaart/map2colour
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "map2colour.h"
|
||||
|
||||
map2colour mc;
|
||||
|
||||
// should be in increasing order
|
||||
float values[7] = { 0, 32, 64, 128, 256, 512, 1024 };
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
mc.begin(values);
|
||||
|
||||
for (float i = 0; i < 1024; i += 10)
|
||||
{
|
||||
uint32_t start = micros();
|
||||
uint32_t rgb = mc.map2RGB(i);
|
||||
uint32_t stop = micros();
|
||||
Serial.print(stop - start); // 120 - 172 us
|
||||
Serial.print("\t");
|
||||
Serial.print(i);
|
||||
Serial.print("\t");
|
||||
Serial.println(rgb, HEX);
|
||||
}
|
||||
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
15
libraries/map2colour/keywords.txt
Normal file
15
libraries/map2colour/keywords.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# Syntax Colouring Map For map2colour
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
map2colour KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
KEYWORD2
|
||||
KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
|
||||
|
||||
|
23
libraries/map2colour/library.json
Normal file
23
libraries/map2colour/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "map2colour",
|
||||
"keywords": "",
|
||||
"description": "Arduino library for mapping a float to colour spectrum.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/map2colour.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"headers": "map2colour.h"
|
||||
}
|
11
libraries/map2colour/library.properties
Normal file
11
libraries/map2colour/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=map2colour
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for mapping a float to colour spectrum
|
||||
paragraph=
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/map2colour
|
||||
architectures=*
|
||||
includes=map2colour.h
|
||||
depends=
|
53
libraries/map2colour/map2colour.cpp
Normal file
53
libraries/map2colour/map2colour.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// FILE: map2colour.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library for mapping a float to colour spectrum
|
||||
// URL: https://github.com/RobTillaart/map2colour
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2021-12-04 initial version
|
||||
|
||||
|
||||
#include "map2colour.h"
|
||||
|
||||
|
||||
map2colour::map2colour()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool map2colour::begin(float * values)
|
||||
{
|
||||
_values = values;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t map2colour::map2RGB(float value)
|
||||
{
|
||||
int index = 1;
|
||||
float factor = 0;
|
||||
uint8_t R = _Red[0];
|
||||
uint8_t G = _Green[0];
|
||||
uint8_t B = _Blue[0];
|
||||
|
||||
if ( (_values[0] < value) && (value <= _values[6] ))
|
||||
{
|
||||
while ((index < 7) && (_values[index] < value)) index++;
|
||||
factor = 1 - (_values[index] - value) / (_values[index] - _values[index-1]);
|
||||
R = _Red[index - 1] + factor * (_Red[index] - _Red[index - 1]);
|
||||
G = _Green[index - 1] + factor * (_Green[index] - _Green[index - 1]);
|
||||
B = _Blue[index - 1] + factor * (_Blue[index] - _Blue[index - 1]);
|
||||
}
|
||||
uint32_t colour = R;
|
||||
colour <<= 8;
|
||||
colour |= G;
|
||||
colour <<= 8;
|
||||
colour |= B;
|
||||
return colour;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
37
libraries/map2colour/map2colour.h
Normal file
37
libraries/map2colour/map2colour.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: map2colour.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library for mapping a float to colour spectrum
|
||||
// URL: https://github.com/RobTillaart/map2colour
|
||||
//
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define MAP2COLOUR_LIB_VERSION (F("0.1.0"))
|
||||
|
||||
|
||||
class map2colour
|
||||
{
|
||||
public:
|
||||
map2colour();
|
||||
|
||||
// values is an array of 7 values
|
||||
bool begin(float * values);
|
||||
|
||||
uint32_t map2RGB(float value);
|
||||
|
||||
private:
|
||||
float * _values;
|
||||
uint8_t _Red[7] = { 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF };
|
||||
uint8_t _Green[7] = { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF };
|
||||
uint8_t _Blue[7] = { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
|
||||
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
48
libraries/map2colour/test/unit_test_001.cpp
Normal file
48
libraries/map2colour/test/unit_test_001.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-12-04
|
||||
// PURPOSE: unit tests for the map2colour library
|
||||
// https://github.com/RobTillaart/map2colour
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual)
|
||||
// assertNotEqual(expected, actual)
|
||||
// assertLess(expected, actual)
|
||||
// assertMore(expected, actual)
|
||||
// assertLessOrEqual(expected, actual)
|
||||
// assertMoreOrEqual(expected, actual)
|
||||
// assertTrue(actual)
|
||||
// assertFalse(actual)
|
||||
// assertNull(actual)
|
||||
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "map2colour.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
}
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
fprintf(stderr, "MAP2COLOUR_LIB_VERSION: %s\n", (char *) MAP2COLOUR_LIB_VERSION);
|
||||
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
Loading…
x
Reference in New Issue
Block a user