Feature/raspberry pi blinkt color objects (#503)

* fixed BACnetXYcolor and BACnetColorCommand encode and decoding and improved unit test coverage. Refactored BACnetXYcolor to/from ascii into lighting module.

* added to the color, color temperature, and lighting output objects a fade/ramp/step engine.  Added color and color command coercion into the channel object and enabled color temperature object coercion.  Added CreateObject and DeleteObject service handling to the color, color temperature, lighting output, and channel objects.

* added blinkt demo app for Raspberry Pi [WIP]

* updated gitignore to simplify handling of apps folder contents

* fixed piface demo build

* added RaspiOS to pipeline for piface and blinkt! demo builds

* added device object timer function for child object types into example Device object.  Refactored device object to increment database revision for create or delete object services.   Refactored example app/server to use mstimer library and device child object timers.

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-09-28 10:50:32 -05:00
committed by GitHub
parent b0749572f6
commit da2dc9841a
64 changed files with 8012 additions and 1637 deletions
+90 -32
View File
@@ -8,6 +8,9 @@
*
* SPDX-License-Identifier: MIT
*/
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <zephyr/ztest.h>
#include <bacnet/basic/sys/color_rgb.h>
@@ -16,34 +19,69 @@
* @{
*/
/**
* @brief compare two floating point values to 3 decimal places
*
* @param x1 - first comparison value
* @param x2 - second comparison value
* @return true if the value is the same to 3 decimal points
*/
static bool is_float_equal(float x1, float x2)
{
return fabs(x1 - x2) < 0.001;
}
/**
* Unit Test for sRGB to CIE xy
*/
static void test_color_rgb_xy_unit(
uint8_t red, uint8_t green, uint8_t blue,
float x_coordinate, float y_coordinate,
static void test_color_rgb_xy_gamma_unit(uint8_t red,
uint8_t green,
uint8_t blue,
float x_coordinate,
float y_coordinate,
uint8_t brightness)
{
float test_x_coordinate = 0.0, test_y_coordinate = 0.0;
uint8_t test_brightness = 0;
uint8_t test_red = 0, test_green = 0, test_blue = 0;
/* functions with gamma correction */
color_rgb_to_xy_gamma(red, green, blue, &test_x_coordinate,
&test_y_coordinate, &test_brightness);
color_rgb_from_xy_gamma(&test_red, &test_green, &test_blue, x_coordinate,
y_coordinate, brightness);
zassert_true(is_float_equal(x_coordinate, test_x_coordinate),
"(x=%.3f,test_x=%.3f)", x_coordinate, test_x_coordinate);
zassert_true(is_float_equal(y_coordinate, test_y_coordinate),
"(y=%.3f,test_y=%.3f)", y_coordinate, test_y_coordinate);
zassert_equal(brightness, test_brightness, "b=%u, test_b=%u", brightness,
test_brightness);
}
/**
* Unit Test for sRGB to CIE xy
*/
static void test_color_rgb_xy_unit(uint8_t red,
uint8_t green,
uint8_t blue,
float x_coordinate,
float y_coordinate,
uint8_t brightness)
{
float test_x_coordinate = 0.0, test_y_coordinate = 0.0;
uint8_t test_brightness = 0;
uint8_t test_red = 0, test_green = 0, test_blue = 0;
printf("test value:(%u,%u,%u)=(%.3f,%.3f,%u)\n",
(unsigned)red, (unsigned)green, (unsigned)blue,
x_coordinate, y_coordinate, (unsigned)brightness);
color_rgb_to_xy(red, green, blue, &test_x_coordinate, &test_y_coordinate,
&test_brightness);
color_rgb_from_xy(&test_red, &test_green, &test_blue,
x_coordinate, y_coordinate, brightness);
printf("calculated:(%u,%u,%u)=(%.3f,%.3f,%u)\n",
(unsigned)test_red, (unsigned)test_green, (unsigned)test_blue,
test_x_coordinate, test_y_coordinate, (unsigned)test_brightness);
//zassert_equal(x_coordinate, test_x_coordinate, NULL);
//zassert_equal(y_coordinate, test_y_coordinate, NULL);
//zassert_equal(brightness, test_brightness, NULL);
//zassert_equal(red, test_red, NULL);
//zassert_equal(green, test_green, NULL);
//zassert_equal(blue, test_blue, NULL);
color_rgb_from_xy(&test_red, &test_green, &test_blue, x_coordinate,
y_coordinate, brightness);
zassert_true(is_float_equal(x_coordinate, test_x_coordinate),
"(x=%.3f,test_x=%.3f)", x_coordinate, test_x_coordinate);
zassert_true(is_float_equal(y_coordinate, test_y_coordinate),
"(y=%.3f,test_y=%.3f)", y_coordinate, test_y_coordinate);
zassert_equal(brightness, test_brightness, "b=%u, test_b=%u", brightness,
test_brightness);
}
/**
@@ -55,17 +93,40 @@ ZTEST(color_rgb_tests, test_color_rgb_xy)
static void test_color_rgb_xy(void)
#endif
{
test_color_rgb_xy_unit(0, 0, 0, 0.0, 0.0, 0);
test_color_rgb_xy_unit(255, 255, 255, 0.323, 0.329, 255);
test_color_rgb_xy_unit(0, 0, 255, 0.136, 0.04, 12);
test_color_rgb_xy_unit(0, 255, 0, 0.172, 0.747, 170);
test_color_rgb_xy_unit(255, 0, 0, 0.701, 0.299, 72);
test_color_rgb_xy_unit(128, 0, 0, 0.701, 0.299, 16);
uint8_t red, green, blue;
/* functions without gamma correction */
color_rgb_from_ascii(&red, &green, &blue, "black");
test_color_rgb_xy_unit(red, green, blue, 0.0, 0.0, 0);
color_rgb_from_ascii(&red, &green, &blue, "white");
test_color_rgb_xy_unit(red, green, blue, 0.313, 0.329, 255);
color_rgb_from_ascii(&red, &green, &blue, "blue");
test_color_rgb_xy_unit(red, green, blue, 0.157, 0.017, 5);
color_rgb_from_ascii(&red, &green, &blue, "green");
test_color_rgb_xy_unit(red, green, blue, 0.115, 0.826, 95);
color_rgb_from_ascii(&red, &green, &blue, "red");
test_color_rgb_xy_unit(red, green, blue, 0.735, 0.265, 59);
color_rgb_from_ascii(&red, &green, &blue, "maroon");
test_color_rgb_xy_unit(red, green, blue, 0.735, 0.265, 29);
/* functions with gamma correction */
color_rgb_from_ascii(&red, &green, &blue, "black");
test_color_rgb_xy_gamma_unit(red, green, blue, 0.0, 0.0, 0);
color_rgb_from_ascii(&red, &green, &blue, "white");
test_color_rgb_xy_gamma_unit(red, green, blue, 0.313, 0.329, 255);
color_rgb_from_ascii(&red, &green, &blue, "blue");
test_color_rgb_xy_gamma_unit(red, green, blue, 0.157, 0.017, 5);
color_rgb_from_ascii(&red, &green, &blue, "green");
test_color_rgb_xy_gamma_unit(red, green, blue, 0.115, 0.826, 40);
color_rgb_from_ascii(&red, &green, &blue, "red");
test_color_rgb_xy_gamma_unit(red, green, blue, 0.735, 0.265, 59);
color_rgb_from_ascii(&red, &green, &blue, "maroon");
test_color_rgb_xy_gamma_unit(red, green, blue, 0.735, 0.265, 12);
}
/**
* Unit Test for sRGB to CIE xy
*/
* Unit Test for sRGB to CIE xy
*/
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST(color_rgb_tests, test_color_rgb_ascii)
#else
@@ -85,8 +146,8 @@ static void test_color_rgb_ascii(void)
for (unsigned i = 0; i < count; i++) {
name = color_rgb_from_index(i, &red, &green, &blue);
zassert_not_null(name, NULL);
test_index = color_rgb_from_ascii(&test_red, &test_green, &test_blue,
name);
test_index =
color_rgb_from_ascii(&test_red, &test_green, &test_blue, name);
zassert_equal(i, test_index, NULL);
zassert_equal(red, test_red, NULL);
zassert_equal(green, test_green, NULL);
@@ -100,16 +161,13 @@ static void test_color_rgb_ascii(void)
* @}
*/
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(color_rgb_tests, NULL, NULL, NULL, NULL, NULL);
#else
void test_main(void)
{
ztest_test_suite(color_rgb_tests,
ztest_unit_test(test_color_rgb_ascii),
ztest_unit_test(test_color_rgb_xy)
);
ztest_test_suite(color_rgb_tests, ztest_unit_test(test_color_rgb_ascii),
ztest_unit_test(test_color_rgb_xy));
ztest_run_test_suite(color_rgb_tests);
}
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(test_${basename}
VERSION 1.0.0
LANGUAGES C)
string(REGEX REPLACE
"/test/bacnet/[a-zA-Z_/-]*$"
"/src"
SRC_DIR
${CMAKE_CURRENT_SOURCE_DIR})
string(REGEX REPLACE
"/test/bacnet/[a-zA-Z_/-]*$"
"/test"
TST_DIR
${CMAKE_CURRENT_SOURCE_DIR})
set(ZTST_DIR "${TST_DIR}/ztest/src")
add_compile_definitions(
BIG_ENDIAN=0
CONFIG_ZTEST=1
)
include_directories(
${SRC_DIR}
${TST_DIR}/ztest/include
)
add_executable(${PROJECT_NAME}
# File(s) under test
${SRC_DIR}/bacnet/basic/sys/linear.c
# Support files and stubs (pathname alphabetical)
# Test and test library files
./src/main.c
${ZTST_DIR}/ztest_mock.c
${ZTST_DIR}/ztest.c
)
target_link_libraries(${PROJECT_NAME} PRIVATE
m)
+136
View File
@@ -0,0 +1,136 @@
/**
* @file
* @brief test linear interpolation APIs
* @date 2010
*
* @section LICENSE
* Copyright (c) 2010 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*/
#include <zephyr/ztest.h>
#include <bacnet/basic/sys/linear.h>
/**
* @addtogroup bacnet_tests
* @{
*/
/**
* Unit Test for linear interpolation of floating point values, rounded
*/
void testLinearInterpolateRound(void)
{
uint16_t x2 = 0;
uint16_t y1 = 0;
uint16_t y2 = 0;
uint16_t y3 = 0;
uint16_t x2_test = 0;
y2 = linear_interpolate_round(1, 1, 65535, 1, 100);
zassert_equal(y2, 1, NULL);
y2 = linear_interpolate_round(1, 1, 65535, 100, 1);
zassert_equal(y2, 100, NULL);
y2 = linear_interpolate_round(1, 65535, 65535, 1, 100);
zassert_equal(y2, 100, NULL);
y2 = linear_interpolate_round(1, 65535, 65535, 100, 1);
zassert_equal(y2, 1, NULL);
y2 = linear_interpolate_round(1, (65535 / 2), 65535, 1, 100);
zassert_equal(y2, 50, NULL);
y2 = linear_interpolate_round(1, (65535 / 4), 65535, 1, 100);
zassert_equal(y2, 26, NULL);
y2 = linear_interpolate_round(1, ((65535 * 3) / 4), 65535, 1, 100);
zassert_equal(y2, 75, NULL);
y2 = linear_interpolate_round(1, 1, 100, 1, 65535);
zassert_equal(y2, 1, NULL);
y2 = linear_interpolate_round(1, 100, 100, 1, 65535);
zassert_equal(y2, 65535, NULL);
y2 = linear_interpolate_round(1, 100 / 2, 100, 1, 65535);
zassert_equal(y2, 32437, NULL);
/* scaling from percent to steps and back */
for (x2 = 1; x2 <= 100; x2++) {
y2 = linear_interpolate_round(1, x2, 100, 1, 65535);
x2_test = linear_interpolate_round(1, y2, 65535, 1, 100);
zassert_equal(x2, x2_test, NULL);
}
/* test for low-trim, high-trim and scaling from percent to steps */
for (x2 = 1; x2 <= 100; x2++) {
y1 = linear_interpolate_round(1, 20, 100, 1, 65535);
y3 = linear_interpolate_round(1, 80, 100, 1, 65535);
y2 = linear_interpolate_round(1, x2, 100, y1, y3);
x2_test = linear_interpolate_round(y1, y2, y3, 1, 100);
zassert_equal(x2, x2_test, "x2=%hu x2_test=%hu\n", x2, x2_test);
}
y2 = linear_interpolate_round(1, 1, 65535, 20, 80);
zassert_equal(y2, 20, NULL);
y2 = linear_interpolate_round(1, 1, 65535, 80, 20);
zassert_equal(y2, 80, NULL);
y2 = linear_interpolate_round(1, 65535, 65535, 20, 80);
zassert_equal(y2, 80, NULL);
y2 = linear_interpolate_round(1, 65535, 65535, 80, 20);
zassert_equal(y2, 20, NULL);
}
/**
* Unit Test for linear interpolation of integers
*/
void testLinearInterpolateInt(void)
{
uint16_t y2 = 0;
y2 = linear_interpolate_int(1, 1, 65535, 1, 100);
zassert_equal(y2, 1, NULL);
y2 = linear_interpolate_int(1, 1, 65535, 100, 1);
zassert_equal(y2, 100, NULL);
y2 = linear_interpolate_int(1, 65535, 65535, 1, 100);
zassert_equal(y2, 100, NULL);
y2 = linear_interpolate_int(1, 65535, 65535, 100, 1);
zassert_equal(y2, 1, NULL);
y2 = linear_interpolate_int(1, (65535 / 4), 65535, 1, 100);
zassert_equal(y2, 25, NULL);
y2 = linear_interpolate_int(1, (65535 / 2), 65535, 1, 100);
zassert_equal(y2, 50, NULL);
y2 = linear_interpolate_int(1, ((65535 * 3) / 4), 65535, 1, 100);
zassert_equal(y2, 75, NULL);
y2 = linear_interpolate_int(1, 1, 100, 1, 65535);
zassert_equal(y2, 1, NULL);
y2 = linear_interpolate_int(1, 100, 100, 1, 65535);
zassert_equal(y2, 65535, NULL);
y2 = linear_interpolate_int(1, 100 / 2, 100, 1, 65535);
zassert_equal(y2, 32437, NULL);
}
/**
* @}
*/
#if defined(CONFIG_ZTEST_NEW_API)
ZTEST_SUITE(Linear_Interpolate, NULL, NULL, NULL, NULL, NULL);
#else
void test_main(void)
{
ztest_test_suite(Linear_Interpolate,
ztest_unit_test(testLinearInterpolateRound),
ztest_unit_test(testLinearInterpolateInt)
);
ztest_run_test_suite(Linear_Interpolate);
}
#endif