Skip to content

Commit

Permalink
Arduino ci (#1)
Browse files Browse the repository at this point in the history
* add arduino-ci
* add unit tests
  • Loading branch information
RobTillaart committed Dec 30, 2020
1 parent 9fc53ca commit 8da7b3c
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
13 changes: 13 additions & 0 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Arduino CI

on: [push, pull_request]

jobs:
arduino_ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
22 changes: 11 additions & 11 deletions Kelvin2RGB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Kelvin2RGB::Kelvin2RGB()
{
_temperature = 0;
_brightness = 0;
_brightness = 0; // default = darkness
_red = 0;
_green = 0;
_blue = 0;
Expand Down Expand Up @@ -45,15 +45,15 @@ void Kelvin2RGB::convert_TH(float temperature, float brightness)
}
else
{
_red = 329.698727466 * pow(t - 60, -0.1332047592);
_red = 329.698727466 * pow(t - 60, -0.1332047592);
_green = 288.1221695283 * pow(t - 60, -0.0755148492);
_blue = 255;
_blue = 255;
}
float f = 0.01 * _brightness;
_red = f * constrain(_red, 0, 255);
_green = f * constrain(_green, 0, 255);
_blue = f * constrain(_blue, 0, 255);
_rgb = round(_red) * 65536UL + round(_green) * 256UL + round(_blue);
_red = constrain(f * _red, 0, 255);
_green = constrain(f * _green, 0, 255);
_blue = constrain(f * _blue, 0, 255);
_rgb = round(_red) * 65536UL + round(_green) * 256UL + round(_blue);

// divide by 255 to get factors between 0..1
_red *= DIVIDE_255;
Expand Down Expand Up @@ -93,10 +93,10 @@ void Kelvin2RGB::convert_NB(float temperature, float brightness)
}

float f = 0.01 * _brightness;
_red = f * constrain(_red, 0, 255);
_green = f * constrain(_green, 0, 255);
_blue = f * constrain(_blue, 0, 255);
_rgb = round(_red) * 65536UL + round(_green) * 256UL + round(_blue);
_red = constrain(f * _red, 0, 255);
_green = constrain(f * _green, 0, 255);
_blue = constrain(f * _blue, 0, 255);
_rgb = round(_red) * 65536UL + round(_green) * 256UL + round(_blue);

// divide by 255 to get factors between 0..1
_red *= DIVIDE_255;
Expand Down
38 changes: 36 additions & 2 deletions Kelvin2RGB.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: Kelvin2RGB.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// DATE: 2018-01-31
// PURPOSE: Arduino library for converting temperature to RGB values
// URL: https://github.com/RobTillaart/Kelvin2RGB
Expand All @@ -12,16 +12,19 @@
// http://www.zombieprototypes.com/?p=210
// https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting

#define KELVIN2RGB_LIB_VERSION "0.1.0"
#define KELVIN2RGB_LIB_VERSION "0.1.1"

#include "Arduino.h"

// based on https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting
// TODO a memory efficient storage -> uint8_t 17 .. 255 (factor 100)
// how? hash function? parameter settings convert(dayLightSetting)
// enum DLS ?

/*
NAME TEMPERATURE
=============================
dark = 0;
match = 1700;
sodiumLamp = 1700;
candleFlame = 1850;
Expand All @@ -47,6 +50,37 @@
polewardSky3 = 27000;
*/

//
// based on https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting
//
// DAY LIGHT SETTING TEMPERATURE
//
#define DLS_dark 0
#define DLS_match 1700
#define DLS_sodiumLamp 1700
#define DLS_candleFlame 1850
#define DLS_sunrise 1850
#define DLS_sunset 1850
#define DLS_bulb 2400
#define DLS_bulbSoftWhite 2550
#define DLS_LEDlamp 2700
#define DLS_warmWhite 3000
#define DLS_studioLight 3200
#define DLS_studioCPlight 3350
#define DLS_daylightHorizon 5000
#define DLS_flashLight 5700
#define DLS_xenonLight 6200
#define DLS_dayLightBright 6500
#define DLS_normal 6500
#define DLS_screenlow 6500
#define DLS_screenMed 8000
#define DLS_screenHigh 9500
#define DLS_polewardSky0 15000
#define DLS_polewardSky1 19000
#define DLS_polewardSky2 23000
#define DLS_polewardSky3 27000



class Kelvin2RGB
{
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

[![Arduino CI](https://github.com/RobTillaart/Kelvin2RGB/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Kelvin2RGB/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Kelvin2RGB.svg?maxAge=3600)](https://github.com/RobTillaart/Kelvin2RGB/releases)


# Kelvin2RGB

Arduino library for converting temperature to RGB values
Expand All @@ -15,7 +21,7 @@ however these are not investigated.

## Description

The library converts a temperature in Kelvin and an brightness (0..100%)
The library converts a temperature in Kelvin and a brightness (0..100%)
to 3 numbers red, green and blue.
These numbers are weights can be used to correct a colorimage for virtual white temperature.

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/Kelvin2RGB.git"
},
"version":"0.1.0",
"version":"0.1.1",
"frameworks": "*",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Kelvin2RGB
version=0.1.0
version=0.1.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for converting temperature to RGB values
Expand Down
111 changes: 111 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2020-12-30
// PURPOSE: unit tests for the Kelvin2RGB library
// https://github.com/RobTillaart/Kelvin2RGB
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//

// supported assertions
// ----------------------------
// assertEqual(expected, actual); // a == b
// assertNotEqual(unwanted, actual); // a != b
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
// assertLess(upperBound, actual); // a < b
// assertMore(lowerBound, actual); // a > b
// assertLessOrEqual(upperBound, actual); // a <= b
// assertMoreOrEqual(lowerBound, actual); // a >= b
// assertTrue(actual);
// assertFalse(actual);
// assertNull(actual);

// // special cases for floats
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
// assertInfinity(actual); // isinf(a)
// assertNotInfinity(actual); // !isinf(a)
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)

#include <ArduinoUnitTests.h>

#define assertEqualFloat(arg1, arg2, arg3) assertOp("assertEqualFloat", "expected", fabs(arg1 - arg2), compareLessOrEqual, "<=", "actual", arg3)
// #define assertEqualINF(arg) assertOp("assertEqualINF", "expected", INFINITY, compareEqual, "==", "actual", arg)
// #define assertEqualNAN(arg) assertOp("assertEqualNAN", "expected", true, compareEqual, "==", "actual", isnan(arg))


#include "Arduino.h"
#include "Kelvin2RGB.h"


unittest_setup()
{
}

unittest_teardown()
{
}

/*
unittest(test_new_operator)
{
assertEqualINF(exp(800));
assertEqualINF(0.0/0.0);
assertEqualINF(42);
assertEqualNAN(INFINITY - INFINITY);
assertEqualNAN(0.0/0.0);
assertEqualNAN(42);
}
*/

unittest(test_constructor)
{
fprintf(stderr, "VERSION: %s\n", KELVIN2RGB_LIB_VERSION);

Kelvin2RGB tempColor;

assertEqualFloat(0, tempColor.temperature(), 0.0001);
assertEqualFloat(0, tempColor.brightness(), 0.0001);
assertEqualFloat(0, tempColor.red(), 0.0001);
assertEqualFloat(0, tempColor.green(), 0.0001);
assertEqualFloat(0, tempColor.blue(), 0.0001);
assertEqualFloat(0, tempColor.RGB(), 0.0001);
}


unittest(test_Tanner_Helland)
{
Kelvin2RGB tempColor;

fprintf(stderr, "DLS_warmWhite\n");
tempColor.convert_TH(DLS_warmWhite, 100);

assertEqualFloat(3000, tempColor.temperature(), 0.0001);
assertEqualFloat(100, tempColor.brightness(), 0.0001);
assertEqualFloat(1, tempColor.red(), 0.0001);
assertEqualFloat(0.694903, tempColor.green(), 0.0001);
assertEqualFloat(0.431048, tempColor.blue(), 0.0001);
assertEqual(16757102, tempColor.RGB());
}

unittest(test_Neil_Bartlett)
{
Kelvin2RGB tempColor;

fprintf(stderr, "DLS_warmWhite\n");
tempColor.convert_NB(DLS_warmWhite, 100);

assertEqualFloat(3000, tempColor.temperature(), 0.0001);
assertEqualFloat(100, tempColor.brightness(), 0.0001);
assertEqualFloat(1, tempColor.red(), 0.0001);
assertEqualFloat(0.707636, tempColor.green(), 0.0001);
assertEqualFloat(0.424804, tempColor.blue(), 0.0001);
assertEqual(16757868, tempColor.RGB());
}

unittest_main()

// --------

0 comments on commit 8da7b3c

Please sign in to comment.