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
+4 -8
View File
@@ -1208,9 +1208,9 @@ uint32_t Analog_Output_Create(uint32_t object_instance)
return BACNET_MAX_INSTANCE;
} else if (object_instance == BACNET_MAX_INSTANCE) {
/* wildcard instance */
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
the object identifier is a local matter.*/
object_instance = Keylist_Next_Empty_Key(Object_List, 1);
}
@@ -1235,9 +1235,7 @@ uint32_t Analog_Output_Create(uint32_t object_instance)
pObject->Max_Pres_Value = 100;
/* add to list */
index = Keylist_Data_Add(Object_List, object_instance, pObject);
if (index >= 0) {
Device_Inc_Database_Revision();
} else {
if (index < 0) {
free(pObject);
return BACNET_MAX_INSTANCE;
}
@@ -1263,7 +1261,6 @@ bool Analog_Output_Delete(uint32_t object_instance)
if (pObject) {
free(pObject);
status = true;
Device_Inc_Database_Revision();
}
return status;
@@ -1281,7 +1278,6 @@ void Analog_Output_Cleanup(void)
pObject = Keylist_Data_Pop(Object_List);
if (pObject) {
free(pObject);
Device_Inc_Database_Revision();
}
} while (pObject);
Keylist_Delete(Object_List);
+4 -8
View File
@@ -990,9 +990,9 @@ uint32_t bacfile_create(uint32_t object_instance)
return BACNET_MAX_INSTANCE;
} else if (object_instance == BACNET_MAX_INSTANCE) {
/* wildcard instance */
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
the object identifier is a local matter.*/
object_instance = Keylist_Next_Empty_Key(Object_List, 1);
}
@@ -1010,9 +1010,7 @@ uint32_t bacfile_create(uint32_t object_instance)
pObject->File_Access_Stream = true;
/* add to list */
index = Keylist_Data_Add(Object_List, object_instance, pObject);
if (index >= 0) {
Device_Inc_Database_Revision();
} else {
if (index < 0) {
free(pObject);
return BACNET_MAX_INSTANCE;
}
@@ -1038,7 +1036,6 @@ bool bacfile_delete(uint32_t object_instance)
if (pObject) {
free(pObject);
status = true;
Device_Inc_Database_Revision();
}
return status;
@@ -1056,7 +1053,6 @@ void bacfile_cleanup(void)
pObject = Keylist_Data_Pop(Object_List);
if (pObject) {
free(pObject);
Device_Inc_Database_Revision();
}
} while (pObject);
Keylist_Delete(Object_List);
+4 -8
View File
@@ -1183,9 +1183,9 @@ uint32_t Binary_Output_Create(uint32_t object_instance)
return BACNET_MAX_INSTANCE;
} else if (object_instance == BACNET_MAX_INSTANCE) {
/* wildcard instance */
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
the object identifier is a local matter.*/
object_instance = Keylist_Next_Empty_Key(Object_List, 1);
}
@@ -1202,9 +1202,7 @@ uint32_t Binary_Output_Create(uint32_t object_instance)
pObject->Changed = false;
/* add to list */
index = Keylist_Data_Add(Object_List, object_instance, pObject);
if (index >= 0) {
Device_Inc_Database_Revision();
} else {
if (index < 0) {
free(pObject);
return BACNET_MAX_INSTANCE;
}
@@ -1228,7 +1226,6 @@ void Binary_Output_Cleanup(void)
pObject = Keylist_Data_Pop(Object_List);
if (pObject) {
free(pObject);
Device_Inc_Database_Revision();
}
} while (pObject);
Keylist_Delete(Object_List);
@@ -1248,7 +1245,6 @@ bool Binary_Output_Delete(uint32_t object_instance)
if (pObject) {
free(pObject);
status = true;
Device_Inc_Database_Revision();
}
return status;
File diff suppressed because it is too large Load Diff
+139 -145
View File
@@ -7,8 +7,8 @@
* @section DESCRIPTION
*
* The Channel object is a command object without a priority array, and the
* present-value property uses a priority array and a single precision floating point
* data type.
* present-value property uses a priority array and a single precision floating
* point data type.
*
* @section LICENSE
*
@@ -42,31 +42,21 @@
#include "bacnet/wp.h"
#include "bacnet/basic/object/lo.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* BACNET_CHANNEL_VALUE decodes WriteProperty service requests
Choose the datatypes that your application supports */
#if !(defined(CHANNEL_NUMERIC) || \
defined(CHANNEL_NULL) || \
defined(CHANNEL_BOOLEAN) || \
defined(CHANNEL_UNSIGNED) || \
defined(CHANNEL_SIGNED) || \
defined(CHANNEL_REAL) || \
defined(CHANNEL_DOUBLE) || \
defined(CHANNEL_OCTET_STRING) || \
defined(CHANNEL_CHARACTER_STRING) || \
defined(CHANNEL_BIT_STRING) || \
defined(CHANNEL_ENUMERATED) || \
defined(CHANNEL_DATE) || \
defined(CHANNEL_TIME) || \
defined(CHANNEL_OBJECT_ID) || \
defined(CHANNEL_LIGHTING_COMMAND))
#if !(defined(CHANNEL_NUMERIC) || defined(CHANNEL_NULL) || \
defined(CHANNEL_BOOLEAN) || defined(CHANNEL_UNSIGNED) || \
defined(CHANNEL_SIGNED) || defined(CHANNEL_REAL) || \
defined(CHANNEL_DOUBLE) || defined(CHANNEL_OCTET_STRING) || \
defined(CHANNEL_CHARACTER_STRING) || defined(CHANNEL_BIT_STRING) || \
defined(CHANNEL_ENUMERATED) || defined(CHANNEL_DATE) || \
defined(CHANNEL_TIME) || defined(CHANNEL_OBJECT_ID) || \
defined(CHANNEL_LIGHTING_COMMAND) || defined(CHANNEL_XY_COLOR) || \
defined(CHANNEL_COLOR_COMMAND))
#define CHANNEL_NUMERIC
#endif
#if defined (CHANNEL_NUMERIC)
#if defined(CHANNEL_NUMERIC)
#define CHANNEL_NULL
#define CHANNEL_BOOLEAN
#define CHANNEL_UNSIGNED
@@ -75,152 +65,156 @@ extern "C" {
#define CHANNEL_DOUBLE
#define CHANNEL_ENUMERATED
#define CHANNEL_LIGHTING_COMMAND
#define CHANNEL_COLOR_COMMAND
#define CHANNEL_XY_COLOR
#endif
typedef struct BACnet_Channel_Value_t {
uint8_t tag;
union {
/* NULL - not needed as it is encoded in the tag alone */
#if defined (CHANNEL_BOOLEAN)
bool Boolean;
typedef struct BACnet_Channel_Value_t {
uint8_t tag;
union {
/* NULL - not needed as it is encoded in the tag alone */
#if defined(CHANNEL_BOOLEAN)
bool Boolean;
#endif
#if defined (CHANNEL_UNSIGNED)
uint32_t Unsigned_Int;
#if defined(CHANNEL_UNSIGNED)
uint32_t Unsigned_Int;
#endif
#if defined (CHANNEL_SIGNED)
int32_t Signed_Int;
#if defined(CHANNEL_SIGNED)
int32_t Signed_Int;
#endif
#if defined (CHANNEL_REAL)
float Real;
#if defined(CHANNEL_REAL)
float Real;
#endif
#if defined (CHANNEL_DOUBLE)
double Double;
#if defined(CHANNEL_DOUBLE)
double Double;
#endif
#if defined (CHANNEL_OCTET_STRING)
BACNET_OCTET_STRING Octet_String;
#if defined(CHANNEL_OCTET_STRING)
BACNET_OCTET_STRING Octet_String;
#endif
#if defined (CHANNEL_CHARACTER_STRING)
BACNET_CHARACTER_STRING Character_String;
#if defined(CHANNEL_CHARACTER_STRING)
BACNET_CHARACTER_STRING Character_String;
#endif
#if defined (CHANNEL_BIT_STRING)
BACNET_BIT_STRING Bit_String;
#if defined(CHANNEL_BIT_STRING)
BACNET_BIT_STRING Bit_String;
#endif
#if defined (CHANNEL_ENUMERATED)
uint32_t Enumerated;
#if defined(CHANNEL_ENUMERATED)
uint32_t Enumerated;
#endif
#if defined (CHANNEL_DATE)
BACNET_DATE Date;
#if defined(CHANNEL_DATE)
BACNET_DATE Date;
#endif
#if defined (CHANNEL_TIME)
BACNET_TIME Time;
#if defined(CHANNEL_TIME)
BACNET_TIME Time;
#endif
#if defined (CHANNEL_OBJECT_ID)
BACNET_OBJECT_ID Object_Id;
#if defined(CHANNEL_OBJECT_ID)
BACNET_OBJECT_ID Object_Id;
#endif
#if defined (CHANNEL_LIGHTING_COMMAND)
BACNET_LIGHTING_COMMAND Lighting_Command;
#if defined(CHANNEL_LIGHTING_COMMAND)
BACNET_LIGHTING_COMMAND Lighting_Command;
#endif
} type;
/* simple linked list if needed */
struct BACnet_Channel_Value_t *next;
} BACNET_CHANNEL_VALUE;
#if defined(CHANNEL_COLOR_COMMAND)
BACNET_COLOR_COMMAND Color_Command;
#endif
#if defined(CHANNEL_XY_COLOR)
BACNET_XY_COLOR XY_Color;
#endif
} type;
/* simple linked list if needed */
struct BACnet_Channel_Value_t *next;
} BACNET_CHANNEL_VALUE;
BACNET_STACK_EXPORT
void Channel_Property_Lists(const int **pRequired,
const int **pOptional,
const int **pProprietary);
BACNET_STACK_EXPORT
bool Channel_Valid_Instance(uint32_t object_instance);
BACNET_STACK_EXPORT
unsigned Channel_Count(void);
BACNET_STACK_EXPORT
uint32_t Channel_Index_To_Instance(unsigned index);
BACNET_STACK_EXPORT
unsigned Channel_Instance_To_Index(uint32_t instance);
BACNET_STACK_EXPORT
bool Channel_Object_Instance_Add(uint32_t instance);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
BACNET_STACK_EXPORT
void Channel_Property_Lists(
const int **pRequired, const int **pOptional, const int **pProprietary);
BACNET_STACK_EXPORT
bool Channel_Valid_Instance(uint32_t object_instance);
BACNET_STACK_EXPORT
unsigned Channel_Count(void);
BACNET_STACK_EXPORT
uint32_t Channel_Index_To_Instance(unsigned index);
BACNET_STACK_EXPORT
unsigned Channel_Instance_To_Index(uint32_t instance);
BACNET_STACK_EXPORT
bool Channel_Object_Instance_Add(uint32_t instance);
BACNET_STACK_EXPORT
bool Channel_Object_Name(uint32_t object_instance,
BACNET_CHARACTER_STRING * object_name);
BACNET_STACK_EXPORT
bool Channel_Name_Set(uint32_t object_instance,
char *new_name);
BACNET_STACK_EXPORT
bool Channel_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name);
BACNET_STACK_EXPORT
bool Channel_Name_Set(uint32_t object_instance, char *new_name);
BACNET_STACK_EXPORT
int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata);
BACNET_STACK_EXPORT
bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data);
BACNET_STACK_EXPORT
int Channel_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata);
BACNET_STACK_EXPORT
bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
BACNET_STACK_EXPORT
BACNET_CHANNEL_VALUE * Channel_Present_Value(uint32_t object_instance);
BACNET_STACK_EXPORT
bool Channel_Present_Value_Set(
BACNET_WRITE_PROPERTY_DATA * wp_data,
BACNET_APPLICATION_DATA_VALUE * value);
BACNET_STACK_EXPORT
BACNET_CHANNEL_VALUE *Channel_Present_Value(uint32_t object_instance);
BACNET_STACK_EXPORT
bool Channel_Present_Value_Set(
BACNET_WRITE_PROPERTY_DATA *wp_data, BACNET_APPLICATION_DATA_VALUE *value);
BACNET_STACK_EXPORT
bool Channel_Out_Of_Service(uint32_t object_instance);
BACNET_STACK_EXPORT
void Channel_Out_Of_Service_Set(uint32_t object_instance,
bool oos_flag);
BACNET_STACK_EXPORT
bool Channel_Out_Of_Service(uint32_t object_instance);
BACNET_STACK_EXPORT
void Channel_Out_Of_Service_Set(uint32_t object_instance, bool oos_flag);
BACNET_STACK_EXPORT
unsigned Channel_Last_Priority(uint32_t object_instance);
BACNET_STACK_EXPORT
BACNET_WRITE_STATUS Channel_Write_Status(uint32_t object_instance);
uint16_t Channel_Number(uint32_t object_instance);
BACNET_STACK_EXPORT
bool Channel_Number_Set(uint32_t object_instance, uint16_t value);
BACNET_STACK_EXPORT
unsigned Channel_Last_Priority(uint32_t object_instance);
BACNET_STACK_EXPORT
BACNET_WRITE_STATUS Channel_Write_Status(uint32_t object_instance);
uint16_t Channel_Number(uint32_t object_instance);
BACNET_STACK_EXPORT
bool Channel_Number_Set(uint32_t object_instance, uint16_t value);
BACNET_STACK_EXPORT
unsigned Channel_Reference_List_Member_Count(uint32_t object_instance);
BACNET_STACK_EXPORT
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *
Channel_Reference_List_Member_Element(uint32_t object_instance,
unsigned element);
BACNET_STACK_EXPORT
bool Channel_Reference_List_Member_Element_Set(uint32_t object_instance,
unsigned array_index,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMemberSrc);
BACNET_STACK_EXPORT
unsigned Channel_Reference_List_Member_Element_Add(uint32_t object_instance,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMemberSrc);
BACNET_STACK_EXPORT
unsigned Channel_Reference_List_Member_Local_Add(
uint32_t object_instance,
BACNET_OBJECT_TYPE type,
uint32_t instance,
BACNET_PROPERTY_ID propertyIdentifier,
uint32_t arrayIndex);
BACNET_STACK_EXPORT
uint16_t Channel_Control_Groups_Element(
uint32_t object_instance,
int32_t array_index);
BACNET_STACK_EXPORT
bool Channel_Control_Groups_Element_Set(
uint32_t object_instance,
int32_t array_index,
uint16_t value);
BACNET_STACK_EXPORT
bool Channel_Value_Copy(BACNET_CHANNEL_VALUE * cvalue,
BACNET_APPLICATION_DATA_VALUE * value);
BACNET_STACK_EXPORT
int Channel_Value_Encode(uint8_t *apdu, int apdu_max,
BACNET_CHANNEL_VALUE * value);
BACNET_STACK_EXPORT
int Channel_Coerce_Data_Encode(
uint8_t * apdu,
unsigned max_apdu,
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_APPLICATION_TAG tag);
BACNET_STACK_EXPORT
bool Channel_Write_Member_Value(
BACNET_WRITE_PROPERTY_DATA * wp_data,
BACNET_APPLICATION_DATA_VALUE * value);
BACNET_STACK_EXPORT
unsigned Channel_Reference_List_Member_Count(uint32_t object_instance);
BACNET_STACK_EXPORT
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *Channel_Reference_List_Member_Element(
uint32_t object_instance, unsigned element);
BACNET_STACK_EXPORT
bool Channel_Reference_List_Member_Element_Set(uint32_t object_instance,
unsigned array_index,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMemberSrc);
BACNET_STACK_EXPORT
unsigned Channel_Reference_List_Member_Element_Add(uint32_t object_instance,
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMemberSrc);
BACNET_STACK_EXPORT
uint16_t Channel_Control_Groups_Element(
uint32_t object_instance, int32_t array_index);
BACNET_STACK_EXPORT
bool Channel_Control_Groups_Element_Set(
uint32_t object_instance, int32_t array_index, uint16_t value);
BACNET_STACK_EXPORT
bool Channel_Value_Copy(
BACNET_CHANNEL_VALUE *cvalue, BACNET_APPLICATION_DATA_VALUE *value);
BACNET_STACK_EXPORT
int Channel_Value_Encode(
uint8_t *apdu, int apdu_max, BACNET_CHANNEL_VALUE *value);
BACNET_STACK_EXPORT
int Channel_Coerce_Data_Encode(uint8_t *apdu,
size_t apdu_size,
BACNET_APPLICATION_DATA_VALUE *value,
BACNET_APPLICATION_TAG tag);
BACNET_STACK_EXPORT
bool Channel_Write_Member_Value(
BACNET_WRITE_PROPERTY_DATA *wp_data, BACNET_APPLICATION_DATA_VALUE *value);
BACNET_STACK_EXPORT
void Channel_Init(void);
BACNET_STACK_EXPORT
void Channel_Write_Property_Internal_Callback_Set(
write_property_function cb);
BACNET_STACK_EXPORT
uint32_t Channel_Create(uint32_t object_instance);
BACNET_STACK_EXPORT
bool Channel_Delete(uint32_t object_instance);
BACNET_STACK_EXPORT
void Channel_Cleanup(void);
BACNET_STACK_EXPORT
void Channel_Init(void);
#ifdef __cplusplus
}
+31 -3
View File
@@ -118,7 +118,7 @@ static object_functions_t Object_Table[] = {
NULL /* Value_Lists */, NULL /* COV */, NULL /* COV Clear */,
NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
#if (BACNET_PROTOCOL_REVISION >= 17)
{ OBJECT_NETWORK_PORT, Network_Port_Init, Network_Port_Count,
Network_Port_Index_To_Instance, Network_Port_Valid_Instance,
@@ -127,7 +127,7 @@ static object_functions_t Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
#endif
{ MAX_BACNET_OBJECT_TYPE, NULL /* Init */, NULL /* Count */,
NULL /* Index_To_Instance */, NULL /* Valid_Instance */,
@@ -137,7 +137,7 @@ static object_functions_t Object_Table[] = {
NULL /* COV */, NULL /* COV Clear */,
NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
};
/** Glue function to let the Device object, when called by a handler,
@@ -1042,6 +1042,34 @@ int Device_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
return apdu_len;
}
/**
* @brief Updates all the object timers with elapsed milliseconds
* @param milliseconds - number of milliseconds elapsed
*/
void Device_Timer(
uint16_t milliseconds)
{
struct object_functions *pObject;
unsigned count = 0;
uint32_t instance;
pObject = Object_Table;
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
if (pObject->Object_Count) {
count = pObject->Object_Count();
}
while (count) {
count--;
if ((pObject->Object_Timer) &&
(pObject->Object_Index_To_Instance)) {
instance = pObject->Object_Index_To_Instance(count);
pObject->Object_Timer(instance, milliseconds);
}
}
pObject++;
}
}
/** Initialize the Device Object.
Initialize the group of object helper functions for any supported Object.
Initialize each of the Device Object child Object instances.
+343 -39
View File
@@ -39,18 +39,29 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/keylist.h"
#include "bacnet/basic/sys/linear.h"
/* me! */
#include "color_object.h"
#include "bacnet/basic/object/color_object.h"
struct object_data {
bool Changed : 1;
bool Write_Enabled : 1;
/* indicate the target color value for the color output */
BACNET_XY_COLOR Present_Value;
/* indicates the components of the object's actual color output */
BACNET_XY_COLOR Tracking_Value;
/* used to request specific behaviors */
BACNET_COLOR_COMMAND Color_Command;
/* indicates that there may be processes in the color object that may
cause the Tracking_Value and Present_Value to differ temporarily. */
BACNET_COLOR_OPERATION_IN_PROGRESS In_Progress;
/* the color to be used for the color output when the device is restarted
until such time as Present_Value or Color_Command are written */
BACNET_XY_COLOR Default_Color;
/* indicates the amount of time in milliseconds over which changes
to the color output reflected in the Tracking_Value property */
uint32_t Default_Fade_Time;
/* The transition may be NONE or FADE. */
BACNET_COLOR_TRANSITION Transition;
const char *Object_Name;
const char *Description;
@@ -198,10 +209,10 @@ bool Color_Present_Value_Set(uint32_t object_instance, BACNET_XY_COLOR *value)
}
/**
* For a given object instance-number, sets the present-value
* For a given object instance-number, writes to the present-value
*
* @param object_instance - object-instance number of the object
* @param value - floating point Color
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
@@ -216,23 +227,21 @@ static bool Color_Present_Value_Write(uint32_t object_instance,
{
bool status = false;
struct object_data *pObject;
BACNET_XY_COLOR old_value = { 0.0, 0.0 };
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
xy_color_copy(&old_value, &pObject->Present_Value);
xy_color_copy(&pObject->Present_Value, value);
if (Color_Write_Present_Value_Callback) {
Color_Write_Present_Value_Callback(
object_instance, &old_value, value);
}
status = true;
xy_color_copy(&pObject->Present_Value, value);
/* configure the color-command to perform the transition */
if (pObject->Transition == BACNET_COLOR_TRANSITION_FADE) {
pObject->Color_Command.transit.fade_time =
pObject->Default_Fade_Time;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
pObject->Color_Command.transit.fade_time = 0;
}
pObject->Color_Command.operation = BACNET_COLOR_OPERATION_FADE_TO_COLOR;
xy_color_copy(&pObject->Color_Command.target.color, value);
status = true;
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
@@ -326,6 +335,44 @@ bool Color_Command_Set(uint32_t object_instance, BACNET_COLOR_COMMAND *value)
return status;
}
/**
* For a given object instance-number, writes to the present-value
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Command_Write(uint32_t object_instance,
BACNET_COLOR_COMMAND *value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
color_command_copy(&pObject->Color_Command, value);
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, gets the property value
*
@@ -413,11 +460,50 @@ bool Color_Default_Color_Set(uint32_t object_instance, BACNET_XY_COLOR *value)
return status;
}
/**
* Handle a WriteProperty to a specific property.
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Default_Color_Write(uint32_t object_instance,
BACNET_XY_COLOR *value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
xy_color_copy(&pObject->Default_Color, value);
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, gets the property value
*
* @param object_instance - object-instance number of the object
* @return property value
* @return the amount of time in milliseconds over which changes
* to the Color reflected in the Tracking_Value property
*/
uint32_t Color_Default_Fade_Time(uint32_t object_instance)
{
@@ -436,7 +522,8 @@ uint32_t Color_Default_Fade_Time(uint32_t object_instance)
* For a given object instance-number, sets the property value
*
* @param object_instance - object-instance number of the object
* @param value - BACNET_COLOR_OPERATION_IN_PROGRESS
* @param value - the amount of time in milliseconds over which changes
* to the Color reflected in the Tracking_Value property
* @return true if values are within range and value is set.
*/
bool Color_Default_Fade_Time_Set(uint32_t object_instance, uint32_t value)
@@ -457,6 +544,51 @@ bool Color_Default_Fade_Time_Set(uint32_t object_instance, uint32_t value)
return status;
}
/**
* Handle a WriteProperty to a specific property.
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Default_Fade_Time_Write(uint32_t object_instance,
BACNET_UNSIGNED_INTEGER value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
if ((value == 0) ||
((value >= BACNET_COLOR_FADE_TIME_MIN) &&
(value <= BACNET_COLOR_FADE_TIME_MAX))) {
pObject->Default_Fade_Time = value;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, gets the property value
*
@@ -500,6 +632,49 @@ bool Color_Transition_Set(
return status;
}
/**
* Handle a WriteProperty to a specific property.
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Transition_Write(uint32_t object_instance,
uint32_t value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
if (value < BACNET_COLOR_TRANSITION_MAX) {
pObject->Transition = value;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, loads the object-name into
* a characterstring. Note that the object name must be unique
@@ -618,6 +793,95 @@ bool Color_Description_Set(uint32_t object_instance, char *new_name)
return status;
}
/**
* Updates the color object tracking value while fading
*
* Transitioning from one color to another is supported by writing a
* FADE_TO_COLOR command to the property Color_Command.
* The current color is always indicated in the
* Tracking_Value property. If a color command is
* currently in progress and the Present_Value is written,
* the color command shall be halted.
*
* @param object_instance - object-instance number of the object
* @param milliseconds - number of milliseconds elapsed
*/
static void Color_Fade_To_Color_Handler(
uint32_t object_instance, uint16_t milliseconds)
{
BACNET_XY_COLOR old_value;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (!pObject) {
return;
}
xy_color_copy(&old_value, &pObject->Tracking_Value);
if (milliseconds >= pObject->Color_Command.transit.fade_time) {
/* stop fading */
xy_color_copy(
&pObject->Tracking_Value, &pObject->Color_Command.target.color);
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
pObject->Color_Command.operation = BACNET_COLOR_OPERATION_STOP;
pObject->Color_Command.transit.fade_time = 0;
} else {
if (xy_color_same(&old_value, &pObject->Color_Command.target.color)) {
/* stop fading */
xy_color_copy(
&pObject->Tracking_Value, &pObject->Color_Command.target.color);
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
pObject->Color_Command.operation = BACNET_COLOR_OPERATION_STOP;
pObject->Color_Command.transit.fade_time = 0;
} else {
/* fading */
pObject->Tracking_Value.x_coordinate = linear_interpolate(0,
milliseconds, pObject->Color_Command.transit.fade_time,
old_value.x_coordinate,
pObject->Color_Command.target.color.x_coordinate);
pObject->Tracking_Value.y_coordinate = linear_interpolate(0,
milliseconds, pObject->Color_Command.transit.fade_time,
old_value.y_coordinate,
pObject->Color_Command.target.color.y_coordinate);
pObject->Color_Command.transit.fade_time -= milliseconds;
pObject->In_Progress =
BACNET_COLOR_OPERATION_IN_PROGRESS_FADE_ACTIVE;
}
}
if (Color_Write_Present_Value_Callback) {
Color_Write_Present_Value_Callback(
object_instance, &old_value, &pObject->Tracking_Value);
}
}
/**
* Updates the color object tracking value per ramp or fade
*
* @param object_instance - object-instance number of the object
* @param milliseconds - number of milliseconds elapsed
*/
void Color_Timer(uint32_t object_instance, uint16_t milliseconds)
{
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
switch (pObject->Color_Command.operation) {
case BACNET_COLOR_OPERATION_NONE:
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
break;
case BACNET_COLOR_OPERATION_FADE_TO_COLOR:
Color_Fade_To_Color_Handler(
object_instance, milliseconds);
break;
case BACNET_COLOR_OPERATION_STOP:
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
break;
default:
break;
}
}
}
/**
* ReadProperty handler for this object. For the given ReadProperty
* data, the application_data is loaded or the error flags are set.
@@ -725,10 +989,14 @@ bool Color_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
bool status = false; /* return value */
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
int apdu_size = 0;
uint8_t *apdu = NULL;
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data, wp_data->application_data_len, &value);
apdu = wp_data->application_data;
apdu_size = wp_data->application_data_len;
len = bacapp_decode_known_property(apdu, apdu_size, &value,
wp_data->object_type, wp_data->object_property);
/* FIXME: len < application_data_len: more data? */
if (len < 0) {
/* error while decoding - a value larger than we can handle */
@@ -747,17 +1015,55 @@ bool Color_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
switch (wp_data->object_property) {
case PROP_PRESENT_VALUE:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_REAL);
wp_data, &value, BACNET_APPLICATION_TAG_XY_COLOR);
if (status) {
status = Color_Present_Value_Write(wp_data->object_instance,
&value.type.XY_Color, wp_data->priority,
&wp_data->error_class, &wp_data->error_code);
}
break;
case PROP_COLOR_COMMAND:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_COLOR_COMMAND);
if (status) {
status = Color_Command_Write(wp_data->object_instance,
&value.type.Color_Command, wp_data->priority,
&wp_data->error_class, &wp_data->error_code);
}
break;
case PROP_DEFAULT_COLOR:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_XY_COLOR);
if (status) {
status = Color_Default_Color_Write(wp_data->object_instance,
&value.type.XY_Color, wp_data->priority,
&wp_data->error_class, &wp_data->error_code);
}
break;
case PROP_DEFAULT_FADE_TIME:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
status = Color_Default_Fade_Time_Write(wp_data->object_instance,
value.type.Unsigned_Int, wp_data->priority,
&wp_data->error_class, &wp_data->error_code);
}
break;
case PROP_TRANSITION:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_ENUMERATED);
if (status) {
status = Color_Transition_Write(wp_data->object_instance,
value.type.Enumerated, wp_data->priority,
&wp_data->error_class, &wp_data->error_code);
}
break;
case PROP_OBJECT_IDENTIFIER:
case PROP_OBJECT_TYPE:
case PROP_OBJECT_NAME:
case PROP_DESCRIPTION:
case PROP_TRACKING_VALUE:
case PROP_IN_PROGRESS:
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
break;
@@ -840,9 +1146,9 @@ uint32_t Color_Create(uint32_t object_instance)
return BACNET_MAX_INSTANCE;
} else if (object_instance == BACNET_MAX_INSTANCE) {
/* wildcard instance */
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
the object identifier is a local matter.*/
object_instance = Keylist_Next_Empty_Key(Object_List, 1);
}
@@ -851,23 +1157,26 @@ uint32_t Color_Create(uint32_t object_instance)
pObject = calloc(1, sizeof(struct object_data));
if (pObject) {
pObject->Object_Name = NULL;
pObject->Present_Value.x_coordinate = 0.0;
pObject->Present_Value.y_coordinate = 0.0;
pObject->Tracking_Value.x_coordinate = 0.0;
pObject->Tracking_Value.y_coordinate = 0.0;
pObject->Color_Command.operation = BACNET_COLOR_OPERATION_NONE;
/* color defaults */
xy_color_set(&pObject->Present_Value, 0.0, 0.0);
xy_color_set(&pObject->Tracking_Value, 0.0, 0.0);
xy_color_set(&pObject->Default_Color, 1.0, 1.0);
pObject->Default_Fade_Time = BACNET_COLOR_FADE_TIME_MIN;
/* at powerup - fade to default color */
xy_color_copy(
&pObject->Color_Command.target.color, &pObject->Default_Color);
pObject->Color_Command.operation =
BACNET_COLOR_OPERATION_FADE_TO_COLOR;
pObject->Color_Command.transit.fade_time =
pObject->Default_Fade_Time;
/* initialize all the status */
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
pObject->Default_Color.x_coordinate = 1.0;
pObject->Default_Color.y_coordinate = 1.0;
pObject->Default_Fade_Time = 0;
pObject->Transition = BACNET_COLOR_TRANSITION_NONE;
pObject->Transition = BACNET_COLOR_TRANSITION_FADE;
pObject->Changed = false;
pObject->Write_Enabled = false;
/* add to list */
index = Keylist_Data_Add(Object_List, object_instance, pObject);
if (index >= 0) {
Device_Inc_Database_Revision();
} else {
if (index < 0) {
free(pObject);
return BACNET_MAX_INSTANCE;
}
@@ -893,7 +1202,6 @@ bool Color_Delete(uint32_t object_instance)
if (pObject) {
free(pObject);
status = true;
Device_Inc_Database_Revision();
}
return status;
@@ -911,7 +1219,6 @@ void Color_Cleanup(void)
pObject = Keylist_Data_Pop(Object_List);
if (pObject) {
free(pObject);
Device_Inc_Database_Revision();
}
} while (pObject);
Keylist_Delete(Object_List);
@@ -925,7 +1232,4 @@ void Color_Cleanup(void)
void Color_Init(void)
{
Object_List = Keylist_Create();
if (Object_List) {
atexit(Color_Cleanup);
}
}
+4 -1
View File
@@ -29,7 +29,7 @@
#include "bacnet/wp.h"
/**
* @brief Callback for gateway write present value request
* @brief Callback for tracking value
* @param object_instance - object-instance number of the object
* @param old_value - BACnetXYColor value prior to write
* @param value - BACnetXYColor value of the write
@@ -118,6 +118,9 @@ void Color_Write_Enable(uint32_t instance);
BACNET_STACK_EXPORT
void Color_Write_Disable(uint32_t instance);
BACNET_STACK_EXPORT
void Color_Timer(uint32_t object_instance, uint16_t milliseconds);
BACNET_STACK_EXPORT
uint32_t Color_Create(uint32_t object_instance);
BACNET_STACK_EXPORT
+580 -29
View File
@@ -39,6 +39,7 @@
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/sys/keylist.h"
#include "bacnet/basic/sys/linear.h"
/* me! */
#include "color_temperature.h"
@@ -207,7 +208,7 @@ bool Color_Temperature_Present_Value_Set(
* For a given object instance-number, sets the present-value
*
* @param object_instance - object-instance number of the object
* @param value - floating point Color
* @param value - property value to write
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
@@ -222,22 +223,34 @@ static bool Color_Temperature_Present_Value_Write(uint32_t object_instance,
{
bool status = false;
struct object_data *pObject;
uint32_t old_value = 0;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
old_value = pObject->Present_Value;
if ((value >= BACNET_COLOR_TEMPERATURE_MIN) &&
(value <= BACNET_COLOR_TEMPERATURE_MAX)) {
pObject->Present_Value = value;
if (Color_Temperature_Write_Present_Value_Callback) {
Color_Temperature_Write_Present_Value_Callback(
object_instance, old_value, value);
/* configure the color-command to perform the transition */
if (pObject->Transition == BACNET_COLOR_TRANSITION_FADE) {
pObject->Color_Command.transit.fade_time =
pObject->Default_Fade_Time;
pObject->Color_Command.operation =
BACNET_COLOR_OPERATION_FADE_TO_CCT;
} else if (pObject->Transition == BACNET_COLOR_TRANSITION_RAMP) {
pObject->Color_Command.transit.ramp_rate =
pObject->Default_Ramp_Rate;
pObject->Color_Command.operation =
BACNET_COLOR_OPERATION_RAMP_TO_CCT;
} else {
pObject->Color_Command.transit.fade_time = 0;
pObject->Color_Command.operation =
BACNET_COLOR_OPERATION_FADE_TO_CCT;
}
pObject->Color_Command.target.color_temperature = value;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
@@ -506,6 +519,50 @@ bool Color_Temperature_Default_Color_Temperature_Set(
return status;
}
/**
* Handle a WriteProperty to a specific property.
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Temperature_Default_Write(uint32_t object_instance,
BACNET_UNSIGNED_INTEGER value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
if ((value >= BACNET_COLOR_TEMPERATURE_MIN) &&
(value <= BACNET_COLOR_TEMPERATURE_MAX)) {
pObject->Default_Color_Temperature = value;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, gets the property value
*
@@ -551,6 +608,51 @@ bool Color_Temperature_Default_Fade_Time_Set(
return status;
}
/**
* Handle a WriteProperty to a specific property.
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Temperature_Default_Fade_Time_Write(uint32_t object_instance,
BACNET_UNSIGNED_INTEGER value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
if ((value == 0) ||
((value >= BACNET_COLOR_FADE_TIME_MIN) &&
(value <= BACNET_COLOR_FADE_TIME_MAX))) {
pObject->Default_Fade_Time = value;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, gets the property value
*
@@ -592,6 +694,51 @@ bool Color_Temperature_Default_Ramp_Rate_Set(
return status;
}
/**
* Handle a WriteProperty to a specific property.
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Temperature_Default_Ramp_Rate_Write(uint32_t object_instance,
BACNET_UNSIGNED_INTEGER value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
if ((value == 0) ||
((value >= BACNET_COLOR_RAMP_RATE_MIN) &&
(value <= BACNET_COLOR_RAMP_RATE_MAX))) {
pObject->Default_Fade_Time = value;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, gets the property value
*
@@ -633,6 +780,52 @@ bool Color_Temperature_Default_Step_Increment_Set(
return status;
}
/**
* Handle a WriteProperty to a specific property.
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Temperature_Default_Step_Increment_Write(
uint32_t object_instance,
BACNET_UNSIGNED_INTEGER value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
if ((value == 0) ||
((value >= BACNET_COLOR_STEP_INCREMENT_MIN) &&
(value <= BACNET_COLOR_STEP_INCREMENT_MAX))) {
pObject->Default_Fade_Time = value;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, gets the property value
*
@@ -676,6 +869,49 @@ bool Color_Temperature_Transition_Set(
return status;
}
/**
* Handle a WriteProperty to a specific property.
*
* @param object_instance - object-instance number of the object
* @param value - property value to be written
* @param priority - priority-array index value 1..16
* @param error_class - the BACnet error class
* @param error_code - BACnet Error code
*
* @return true if values are within range and present-value is set.
*/
static bool Color_Transition_Write(uint32_t object_instance,
uint32_t value,
uint8_t priority,
BACNET_ERROR_CLASS *error_class,
BACNET_ERROR_CODE *error_code)
{
bool status = false;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if (pObject->Write_Enabled) {
if (value < BACNET_COLOR_TRANSITION_MAX) {
pObject->Transition = value;
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
}
} else {
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
}
} else {
*error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
}
return status;
}
/**
* For a given object instance-number, loads the object-name into
* a characterstring. Note that the object name must be unique
@@ -795,6 +1031,265 @@ bool Color_Temperature_Description_Set(uint32_t object_instance, char *new_name)
return status;
}
/**
* Updates the color object tracking value while fading
*
* The fade operation changes the output color temperature
* from its current value to target-color-temperature, over
* a period of time defined by fade-time. While the fade
* operation is executing, In_Progress shall be set to FADE_ACTIVE,
* and Tracking_Value shall be updated to reflect the current
* progress of the fade. <target-color-temperature> shall be clamped
* to Min_Pres_Value and Max_Pres_Value
*
* @param object_instance - object-instance number of the object
* @param milliseconds - number of milliseconds elapsed
*/
static void Color_Temperature_Fade_To_CCT_Handler(
uint32_t object_instance, uint16_t milliseconds)
{
uint32_t old_value, target_value, min_value, max_value;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (!pObject) {
return;
}
old_value = pObject->Tracking_Value;
min_value = pObject->Present_Value_Minimum;
max_value = pObject->Present_Value_Maximum;
target_value = pObject->Color_Command.target.color_temperature;
/* clamp target within min/max, if needed */
if (target_value > max_value) {
target_value = max_value;
}
if (target_value < min_value) {
target_value = min_value;
}
if (milliseconds >= pObject->Color_Command.transit.fade_time) {
/* done fading */
pObject->Tracking_Value = target_value;
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
pObject->Color_Command.operation = BACNET_COLOR_OPERATION_STOP;
pObject->Color_Command.transit.fade_time = 0;
} else {
if (old_value == target_value) {
/* stop fading */
pObject->Tracking_Value = target_value;
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
pObject->Color_Command.operation = BACNET_COLOR_OPERATION_STOP;
pObject->Color_Command.transit.fade_time = 0;
} else {
/* fading */
pObject->Tracking_Value = linear_interpolate_int(0, milliseconds,
pObject->Color_Command.transit.fade_time, old_value,
target_value);
pObject->Color_Command.transit.fade_time -= milliseconds;
pObject->In_Progress =
BACNET_COLOR_OPERATION_IN_PROGRESS_FADE_ACTIVE;
}
}
if (Color_Temperature_Write_Present_Value_Callback) {
Color_Temperature_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value);
}
}
/**
* Updates the color object tracking value while ramping
*
* Commands Present_Value to ramp from the current Tracking_Value to the
* target-color-temperature specified in the command. The ramp operation
* changes the output color temperature from its current value to
* target-color-temperature, at a particular Kelvin per second defined by
* ramp-rate. While the ramp operation is executing, In_Progress shall be set
* to RAMP_ACTIVE, and Tracking_Value shall be updated to reflect the current
* progress of the fade. <target-color-temperature> shall be clamped to
* Min_Pres_Value and Max_Pres_Value
*
* @param object_instance - object-instance number of the object
* @param milliseconds - number of milliseconds elapsed
*/
static void Color_Temperature_Ramp_To_CCT_Handler(
uint32_t object_instance, uint16_t milliseconds)
{
uint16_t old_value, target_value, min_value, max_value, step_value, steps;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (!pObject) {
return;
}
old_value = pObject->Tracking_Value;
min_value = pObject->Present_Value_Minimum;
max_value = pObject->Present_Value_Maximum;
target_value = pObject->Color_Command.target.color_temperature;
/* clamp target within min/max, if needed */
if (target_value > max_value) {
target_value = max_value;
}
if (target_value < min_value) {
target_value = min_value;
}
/* determine the number of K steps */
if (milliseconds <= 1000) {
/* K per second */
steps = linear_interpolate_int(
0, milliseconds, 1000, 0, pObject->Color_Command.transit.ramp_rate);
} else {
steps =
(milliseconds * pObject->Color_Command.transit.ramp_rate) / 1000;
}
if (old_value == target_value) {
pObject->Tracking_Value = target_value;
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
pObject->Color_Command.operation = BACNET_COLOR_OPERATION_STOP;
} else {
if (old_value < target_value) {
step_value = old_value + steps;
} else if (old_value > target_value) {
if (steps > old_value) {
step_value = old_value - steps;
} else {
step_value = target_value;
}
} else {
step_value = target_value;
}
/* clamp target within min/max, if needed */
if (step_value > max_value) {
step_value = max_value;
}
if (step_value < min_value) {
step_value = min_value;
}
pObject->Tracking_Value = step_value;
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_FADE_ACTIVE;
}
if (Color_Temperature_Write_Present_Value_Callback) {
Color_Temperature_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value);
}
}
/**
* Updates the color object tracking value while stepping
*
* Commands Present_Value to a value equal to the Tracking_Value
* plus the step-increment. The resulting sum shall be clamped to
* Min_Pres_Value and Max_Pres_Value
*
* @param object_instance - object-instance number of the object
*/
static void Color_Temperature_Step_Up_CCT_Handler(uint32_t object_instance)
{
uint16_t old_value, target_value, min_value, max_value, step_value;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (!pObject) {
return;
}
old_value = target_value = pObject->Tracking_Value;
min_value = pObject->Present_Value_Minimum;
max_value = pObject->Present_Value_Maximum;
step_value = pObject->Color_Command.transit.step_increment;
target_value += step_value;
/* clamp target within min/max, if needed */
if (target_value > max_value) {
target_value = max_value;
}
if (target_value < min_value) {
target_value = min_value;
}
pObject->Present_Value = target_value;
pObject->Tracking_Value = target_value;
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
if (Color_Temperature_Write_Present_Value_Callback) {
Color_Temperature_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value);
}
}
/**
* Updates the color object tracking value while stepping
*
* Commands Present_Value to a value equal to the Tracking_Value
* plus the step-increment. The resulting sum shall be clamped to
* Min_Pres_Value and Max_Pres_Value
*
* @param object_instance - object-instance number of the object
*/
static void Color_Temperature_Step_Down_CCT_Handler(uint32_t object_instance)
{
uint16_t old_value, target_value, min_value, max_value, step_value;
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (!pObject) {
return;
}
old_value = target_value = pObject->Tracking_Value;
min_value = pObject->Present_Value_Minimum;
max_value = pObject->Present_Value_Maximum;
step_value = pObject->Color_Command.transit.step_increment;
if (target_value >= step_value) {
target_value -= step_value;
} else {
target_value = 0;
}
/* clamp target within min/max, if needed */
if (target_value > max_value) {
target_value = max_value;
}
if (target_value < min_value) {
target_value = min_value;
}
pObject->Present_Value = target_value;
pObject->Tracking_Value = target_value;
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
if (Color_Temperature_Write_Present_Value_Callback) {
Color_Temperature_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value);
}
}
/**
* Updates the color temperature tracking value per ramp or fade
*
* @param object_instance - object-instance number of the object
* @param milliseconds - number of milliseconds elapsed
*/
void Color_Temperature_Timer(uint32_t object_instance, uint16_t milliseconds)
{
struct object_data *pObject;
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
switch (pObject->Color_Command.operation) {
case BACNET_COLOR_OPERATION_FADE_TO_CCT:
Color_Temperature_Fade_To_CCT_Handler(
object_instance, milliseconds);
break;
case BACNET_COLOR_OPERATION_RAMP_TO_CCT:
Color_Temperature_Ramp_To_CCT_Handler(
object_instance, milliseconds);
break;
case BACNET_COLOR_OPERATION_STEP_UP_CCT:
Color_Temperature_Step_Up_CCT_Handler(object_instance);
break;
case BACNET_COLOR_OPERATION_STEP_DOWN_CCT:
Color_Temperature_Step_Down_CCT_Handler(object_instance);
break;
case BACNET_COLOR_OPERATION_NONE:
case BACNET_COLOR_OPERATION_STOP:
default:
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
break;
}
}
}
/**
* ReadProperty handler for this object. For the given ReadProperty
* data, the application_data is loaded or the error flags are set.
@@ -918,11 +1413,14 @@ bool Color_Temperature_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
bool status = false; /* return value */
int len = 0;
BACNET_APPLICATION_DATA_VALUE value;
int apdu_size = 0;
uint8_t *apdu = NULL;
/* decode the some of the request */
len = bacapp_decode_application_data(
wp_data->application_data, wp_data->application_data_len, &value);
/* FIXME: len < application_data_len: more data? */
apdu = wp_data->application_data;
apdu_size = wp_data->application_data_len;
len = bacapp_decode_known_property(apdu, apdu_size, &value,
wp_data->object_type, wp_data->object_property);
if (len < 0) {
/* error while decoding - a value larger than we can handle */
wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -948,10 +1446,64 @@ bool Color_Temperature_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
&wp_data->error_code);
}
break;
case PROP_DEFAULT_COLOR_TEMPERATURE:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
status =
Color_Temperature_Default_Write(wp_data->object_instance,
value.type.Unsigned_Int, wp_data->priority,
&wp_data->error_class, &wp_data->error_code);
}
break;
case PROP_DEFAULT_FADE_TIME:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
status = Color_Temperature_Default_Fade_Time_Write(
wp_data->object_instance, value.type.Unsigned_Int,
wp_data->priority, &wp_data->error_class,
&wp_data->error_code);
}
break;
case PROP_TRANSITION:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_ENUMERATED);
if (status) {
status = Color_Transition_Write(wp_data->object_instance,
value.type.Enumerated, wp_data->priority,
&wp_data->error_class, &wp_data->error_code);
}
break;
case PROP_DEFAULT_RAMP_RATE:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
status = Color_Temperature_Default_Ramp_Rate_Write(
wp_data->object_instance, value.type.Unsigned_Int,
wp_data->priority, &wp_data->error_class,
&wp_data->error_code);
}
break;
case PROP_DEFAULT_STEP_INCREMENT:
status = write_property_type_valid(
wp_data, &value, BACNET_APPLICATION_TAG_UNSIGNED_INT);
if (status) {
status = Color_Temperature_Default_Step_Increment_Write(
wp_data->object_instance, value.type.Unsigned_Int,
wp_data->priority, &wp_data->error_class,
&wp_data->error_code);
}
break;
case PROP_OBJECT_IDENTIFIER:
case PROP_OBJECT_TYPE:
case PROP_OBJECT_NAME:
case PROP_DESCRIPTION:
case PROP_TRACKING_VALUE:
case PROP_COLOR_COMMAND:
case PROP_IN_PROGRESS:
case PROP_MAX_PRES_VALUE:
case PROP_MIN_PRES_VALUE:
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
break;
@@ -1034,9 +1586,9 @@ uint32_t Color_Temperature_Create(uint32_t object_instance)
return BACNET_MAX_INSTANCE;
} else if (object_instance == BACNET_MAX_INSTANCE) {
/* wildcard instance */
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
the object identifier is a local matter.*/
object_instance = Keylist_Next_Empty_Key(Object_List, 1);
}
@@ -1047,22 +1599,26 @@ uint32_t Color_Temperature_Create(uint32_t object_instance)
pObject->Object_Name = NULL;
pObject->Present_Value = 0;
pObject->Tracking_Value = 0;
pObject->Color_Command.operation = BACNET_COLOR_OPERATION_NONE;
pObject->In_Progress = BACNET_COLOR_OPERATION_IN_PROGRESS_IDLE;
pObject->Default_Color_Temperature = 5000;
pObject->Default_Fade_Time = 0;
pObject->Default_Ramp_Rate = 0;
pObject->Default_Step_Increment = 0;
pObject->Transition = BACNET_COLOR_TRANSITION_NONE;
pObject->Present_Value_Minimum = 0;
pObject->Present_Value_Maximum = 0;
pObject->Default_Fade_Time = BACNET_COLOR_FADE_TIME_MIN;
pObject->Default_Ramp_Rate = BACNET_COLOR_RAMP_RATE_MIN;
pObject->Default_Step_Increment = BACNET_COLOR_STEP_INCREMENT_MIN;
pObject->Transition = BACNET_COLOR_TRANSITION_FADE;
pObject->Present_Value_Minimum = BACNET_COLOR_TEMPERATURE_MIN;
pObject->Present_Value_Maximum = BACNET_COLOR_TEMPERATURE_MAX;
/* configure to transition from power up values */
pObject->Color_Command.operation =
BACNET_COLOR_OPERATION_FADE_TO_CCT;
pObject->Color_Command.transit.fade_time =
pObject->Default_Fade_Time;
pObject->Color_Command.target.color_temperature =
pObject->Default_Color_Temperature;
pObject->Changed = false;
pObject->Write_Enabled = false;
/* add to list */
index = Keylist_Data_Add(Object_List, object_instance, pObject);
if (index >= 0) {
Device_Inc_Database_Revision();
} else {
if (index < 0) {
free(pObject);
return BACNET_MAX_INSTANCE;
}
@@ -1088,7 +1644,6 @@ bool Color_Temperature_Delete(uint32_t object_instance)
if (pObject) {
free(pObject);
status = true;
Device_Inc_Database_Revision();
}
return status;
@@ -1106,7 +1661,6 @@ void Color_Temperature_Cleanup(void)
pObject = Keylist_Data_Pop(Object_List);
if (pObject) {
free(pObject);
Device_Inc_Database_Revision();
}
} while (pObject);
Keylist_Delete(Object_List);
@@ -1120,7 +1674,4 @@ void Color_Temperature_Cleanup(void)
void Color_Temperature_Init(void)
{
Object_List = Keylist_Create();
if (Object_List) {
atexit(Color_Temperature_Cleanup);
}
}
+4 -1
View File
@@ -29,7 +29,7 @@
#include "bacnet/wp.h"
/**
* @brief Callback for gateway write present value request
* @brief Callback for write present value request
* @param object_instance - object-instance number of the object
* @param old_value - 32-bit value prior to write
* @param value - 32-bit value of the write
@@ -150,6 +150,9 @@ void Color_Temperature_Write_Enable(uint32_t instance);
BACNET_STACK_EXPORT
void Color_Temperature_Write_Disable(uint32_t instance);
BACNET_STACK_EXPORT
void Color_Temperature_Timer(uint32_t object_instance, uint16_t milliseconds);
BACNET_STACK_EXPORT
uint32_t Color_Temperature_Create(uint32_t object_instance);
BACNET_STACK_EXPORT
+63 -31
View File
@@ -99,7 +99,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* Value_Lists */, NULL /* COV */, NULL /* COV Clear */,
NULL /* Intrinsic Reporting */, NULL /* Add_List_Element */,
NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
#if (BACNET_PROTOCOL_REVISION >= 17)
{ OBJECT_NETWORK_PORT, Network_Port_Init, Network_Port_Count,
Network_Port_Index_To_Instance, Network_Port_Valid_Instance,
@@ -108,7 +108,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */ , NULL /* Timer */},
#endif
{ OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count,
Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance,
@@ -118,7 +118,7 @@ static object_functions_t My_Object_Table[] = {
Analog_Input_Encode_Value_List, Analog_Input_Change_Of_Value,
Analog_Input_Change_Of_Value_Clear, Analog_Input_Intrinsic_Reporting,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */ , NULL /* Timer */},
{ OBJECT_ANALOG_OUTPUT, Analog_Output_Init, Analog_Output_Count,
Analog_Output_Index_To_Instance, Analog_Output_Valid_Instance,
Analog_Output_Object_Name, Analog_Output_Read_Property,
@@ -126,7 +126,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
Analog_Output_Create, Analog_Output_Delete},
Analog_Output_Create, Analog_Output_Delete, NULL /* Timer */},
{ OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count,
Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance,
Analog_Value_Object_Name, Analog_Value_Read_Property,
@@ -135,7 +135,7 @@ static object_functions_t My_Object_Table[] = {
Analog_Value_Encode_Value_List, Analog_Value_Change_Of_Value,
Analog_Value_Change_Of_Value_Clear, Analog_Value_Intrinsic_Reporting,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
{ OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count,
Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance,
Binary_Input_Object_Name, Binary_Input_Read_Property,
@@ -144,7 +144,7 @@ static object_functions_t My_Object_Table[] = {
Binary_Input_Encode_Value_List, Binary_Input_Change_Of_Value,
Binary_Input_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
{ OBJECT_BINARY_OUTPUT, Binary_Output_Init, Binary_Output_Count,
Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance,
Binary_Output_Object_Name, Binary_Output_Read_Property,
@@ -152,7 +152,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
Binary_Output_Create, Binary_Output_Delete},
Binary_Output_Create, Binary_Output_Delete, NULL /* Timer */},
{ OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count,
Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance,
Binary_Value_Object_Name, Binary_Value_Read_Property,
@@ -160,7 +160,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
{ OBJECT_CHARACTERSTRING_VALUE, CharacterString_Value_Init,
CharacterString_Value_Count, CharacterString_Value_Index_To_Instance,
CharacterString_Value_Valid_Instance, CharacterString_Value_Object_Name,
@@ -172,14 +172,14 @@ static object_functions_t My_Object_Table[] = {
CharacterString_Value_Change_Of_Value_Clear,
NULL /* Intrinsic Reporting */, NULL /* Add_List_Element */,
NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
{ OBJECT_COMMAND, Command_Init, Command_Count, Command_Index_To_Instance,
Command_Valid_Instance, Command_Object_Name, Command_Read_Property,
Command_Write_Property, Command_Property_Lists,
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
{ OBJECT_INTEGER_VALUE, Integer_Value_Init, Integer_Value_Count,
Integer_Value_Index_To_Instance, Integer_Value_Valid_Instance,
Integer_Value_Object_Name, Integer_Value_Read_Property,
@@ -187,7 +187,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
#if defined(INTRINSIC_REPORTING)
{ OBJECT_NOTIFICATION_CLASS, Notification_Class_Init,
Notification_Class_Count, Notification_Class_Index_To_Instance,
@@ -198,7 +198,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
Notification_Class_Add_List_Element,
Notification_Class_Remove_List_Element,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
#endif
{ OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init, Life_Safety_Point_Count,
Life_Safety_Point_Index_To_Instance, Life_Safety_Point_Valid_Instance,
@@ -207,7 +207,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */ , NULL /* Timer */},
{ OBJECT_LOAD_CONTROL, Load_Control_Init, Load_Control_Count,
Load_Control_Index_To_Instance, Load_Control_Valid_Instance,
Load_Control_Object_Name, Load_Control_Read_Property,
@@ -215,7 +215,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */ , NULL /* Timer */},
{ OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, Multistate_Input_Count,
Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance,
Multistate_Input_Object_Name, Multistate_Input_Read_Property,
@@ -223,7 +223,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */ , NULL /* Timer */},
{ OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init,
Multistate_Output_Count, Multistate_Output_Index_To_Instance,
Multistate_Output_Valid_Instance, Multistate_Output_Object_Name,
@@ -232,7 +232,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */,
NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
Multistate_Output_Create, Multistate_Output_Delete},
Multistate_Output_Create, Multistate_Output_Delete, NULL /* Timer */},
{ OBJECT_MULTI_STATE_VALUE, Multistate_Value_Init, Multistate_Value_Count,
Multistate_Value_Index_To_Instance, Multistate_Value_Valid_Instance,
Multistate_Value_Object_Name, Multistate_Value_Read_Property,
@@ -241,7 +241,7 @@ static object_functions_t My_Object_Table[] = {
Multistate_Value_Encode_Value_List, Multistate_Value_Change_Of_Value,
Multistate_Value_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */ , NULL /* Timer */},
{ OBJECT_TRENDLOG, Trend_Log_Init, Trend_Log_Count,
Trend_Log_Index_To_Instance, Trend_Log_Valid_Instance,
Trend_Log_Object_Name, Trend_Log_Read_Property,
@@ -249,7 +249,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */,
NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */ , NULL /* Timer */},
#if (BACNET_PROTOCOL_REVISION >= 14)
{ OBJECT_LIGHTING_OUTPUT, Lighting_Output_Init, Lighting_Output_Count,
Lighting_Output_Index_To_Instance, Lighting_Output_Valid_Instance,
@@ -258,14 +258,14 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
Lighting_Output_Create, Lighting_Output_Delete, Lighting_Output_Timer},
{ OBJECT_CHANNEL, Channel_Init, Channel_Count, Channel_Index_To_Instance,
Channel_Valid_Instance, Channel_Object_Name, Channel_Read_Property,
Channel_Write_Property, Channel_Property_Lists,
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
Channel_Create, Channel_Delete, NULL /* Timer */ },
#endif
#if (BACNET_PROTOCOL_REVISION >= 24)
{ OBJECT_COLOR, Color_Init, Color_Count, Color_Index_To_Instance,
@@ -274,7 +274,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */,
NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
Color_Create, Color_Delete},
Color_Create, Color_Delete, Color_Timer},
{ OBJECT_COLOR_TEMPERATURE, Color_Temperature_Init, Color_Temperature_Count,
Color_Temperature_Index_To_Instance, Color_Temperature_Valid_Instance,
Color_Temperature_Object_Name, Color_Temperature_Read_Property,
@@ -282,7 +282,8 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
Color_Temperature_Create, Color_Temperature_Delete},
Color_Temperature_Create, Color_Temperature_Delete,
Color_Temperature_Timer},
#endif
#if defined(BACFILE)
{ OBJECT_FILE, bacfile_init, bacfile_count, bacfile_index_to_instance,
@@ -291,7 +292,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
bacfile_create, bacfile_delete},
bacfile_create, bacfile_delete, NULL /* Timer */},
#endif
{ OBJECT_OCTETSTRING_VALUE, OctetString_Value_Init, OctetString_Value_Count,
OctetString_Value_Index_To_Instance, OctetString_Value_Valid_Instance,
@@ -300,7 +301,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
{ OBJECT_POSITIVE_INTEGER_VALUE, PositiveInteger_Value_Init,
PositiveInteger_Value_Count, PositiveInteger_Value_Index_To_Instance,
PositiveInteger_Value_Valid_Instance, PositiveInteger_Value_Object_Name,
@@ -310,7 +311,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */,
NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
{ OBJECT_SCHEDULE, Schedule_Init, Schedule_Count,
Schedule_Index_To_Instance, Schedule_Valid_Instance,
Schedule_Object_Name, Schedule_Read_Property, Schedule_Write_Property,
@@ -318,7 +319,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* Value_Lists */, NULL /* COV */, NULL /* COV Clear */,
NULL /* Intrinsic Reporting */, NULL /* Add_List_Element */,
NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
{ OBJECT_ACCUMULATOR, Accumulator_Init, Accumulator_Count,
Accumulator_Index_To_Instance, Accumulator_Valid_Instance,
Accumulator_Object_Name, Accumulator_Read_Property,
@@ -326,7 +327,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */ , NULL /* Timer */},
{ MAX_BACNET_OBJECT_TYPE, NULL /* Init */, NULL /* Count */,
NULL /* Index_To_Instance */, NULL /* Valid_Instance */,
NULL /* Object_Name */, NULL /* Read_Property */,
@@ -334,7 +335,7 @@ static object_functions_t My_Object_Table[] = {
NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */,
NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */,
NULL /* Add_List_Element */, NULL /* Remove_List_Element */,
NULL /* Create */, NULL /* Delete */ },
NULL /* Create */, NULL /* Delete */, NULL /* Timer */ },
};
/** Glue function to let the Device object, when called by a handler,
@@ -545,7 +546,7 @@ bool Device_Reinitialize(BACNET_REINITIALIZE_DEVICE_DATA *rd_data)
bool status = false;
/* From 16.4.1.1.2 Password
This optional parameter shall be a CharacterString of up to
This optional parameter shall be a CharacterString of up to
20 characters. For those devices that require the password as a
protection, the service request shall be denied if the parameter
is absent or if the password is incorrect. For those devices that
@@ -554,7 +555,7 @@ bool Device_Reinitialize(BACNET_REINITIALIZE_DEVICE_DATA *rd_data)
rd_data->error_class = ERROR_CLASS_SERVICES;
rd_data->error_code = ERROR_CODE_PARAMETER_OUT_OF_RANGE;
} else if (characterstring_ansi_same(&rd_data->password, Reinit_Password)) {
/* Note: you could use a mix of state and password to
/* Note: you could use a mix of state and password to
accomplish multiple things before restarting */
switch (rd_data->state) {
case BACNET_REINIT_COLDSTART:
@@ -1976,6 +1977,7 @@ bool Device_Create_Object(
} else {
/* required by ACK */
data->object_instance = object_instance;
Device_Inc_Database_Revision();
status = true;
}
}
@@ -2013,7 +2015,9 @@ bool Device_Delete_Object(
pObject->Object_Valid_Instance(data->object_instance)) {
/* The object being deleted must already exist */
status = pObject->Object_Delete(data->object_instance);
if (!status) {
if (status) {
Device_Inc_Database_Revision();
} else {
/* The object exists but cannot be deleted. */
data->error_class = ERROR_CLASS_OBJECT;
data->error_code = ERROR_CODE_OBJECT_DELETION_NOT_PERMITTED;
@@ -2154,6 +2158,34 @@ bool DeviceGetRRInfo(BACNET_READ_RANGE_DATA *pRequest, /* Info on the request */
return status;
}
/**
* @brief Updates all the object timers with elapsed milliseconds
* @param milliseconds - number of milliseconds elapsed
*/
void Device_Timer(
uint16_t milliseconds)
{
struct object_functions *pObject;
unsigned count = 0;
uint32_t instance;
pObject = Object_Table;
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
if (pObject->Object_Count) {
count = pObject->Object_Count();
}
while (count) {
count--;
if ((pObject->Object_Timer) &&
(pObject->Object_Index_To_Instance)) {
instance = pObject->Object_Index_To_Instance(count);
pObject->Object_Timer(instance, milliseconds);
}
}
pObject++;
}
}
#ifdef BAC_ROUTING
/****************************************************************************
************* BACnet Routing Functionality (Optional) **********************
+13
View File
@@ -142,6 +142,14 @@ typedef void (
*object_intrinsic_reporting_function) (
uint32_t object_instance);
/**
* @brief Updates the object with the elapsed milliseconds
* @param object_instance - object-instance number of the object
* @param milliseconds - number of milliseconds elapsed
*/
typedef void (
*object_timer_function) (
uint32_t object_instance, uint16_t milliseconds);
/** Defines the group of object helper functions for any supported Object.
* @ingroup ObjHelpers
@@ -172,6 +180,7 @@ typedef struct object_functions {
list_element_function Object_Remove_List_Element;
create_object_function Object_Create;
delete_object_function Object_Delete;
object_timer_function Object_Timer;
} object_functions_t;
/* String Lengths - excluding any nul terminator */
@@ -233,6 +242,10 @@ extern "C" {
void Device_Init(
object_functions_t * object_table);
BACNET_STACK_EXPORT
void Device_Timer(
uint16_t milliseconds);
BACNET_STACK_EXPORT
bool Device_Reinitialize(
BACNET_REINITIALIZE_DEVICE_DATA * rd_data);
+1485 -291
View File
File diff suppressed because it is too large Load Diff
+54
View File
@@ -33,6 +33,15 @@
#include "bacnet/rp.h"
#include "bacnet/wp.h"
/**
* @brief Callback for write present value request
* @param object_instance - object-instance number of the object
* @param old_value - value prior to write
* @param value - value of the write
*/
typedef void (*lighting_output_write_present_value_callback)(
uint32_t object_instance, float old_value, float value);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -193,6 +202,14 @@ extern "C" {
uint32_t object_instance,
float step_increment);
BACNET_STACK_EXPORT
BACNET_LIGHTING_TRANSITION Lighting_Output_Transition(
uint32_t object_instance);
BACNET_STACK_EXPORT
bool Lighting_Output_Transition_Set(
uint32_t object_instance,
BACNET_LIGHTING_TRANSITION value);
BACNET_STACK_EXPORT
unsigned Lighting_Output_Default_Priority(
uint32_t object_instance);
@@ -201,10 +218,47 @@ extern "C" {
uint32_t object_instance,
unsigned priority);
BACNET_STACK_EXPORT
bool Lighting_Output_Color_Override(
uint32_t object_instance);
BACNET_STACK_EXPORT
bool Lighting_Output_Color_Override_Set(
uint32_t object_instance,
bool value);
BACNET_STACK_EXPORT
bool Lighting_Output_Color_Reference(
uint32_t object_instance,
BACNET_OBJECT_ID *value);
BACNET_STACK_EXPORT
bool Lighting_Output_Color_Reference_Set(
uint32_t object_instance,
BACNET_OBJECT_ID *value);
BACNET_STACK_EXPORT
bool Lighting_Output_Override_Color_Reference(
uint32_t object_instance,
BACNET_OBJECT_ID *value);
BACNET_STACK_EXPORT
bool Lighting_Output_Override_Color_Reference_Set(
uint32_t object_instance,
BACNET_OBJECT_ID *value);
BACNET_STACK_EXPORT
void Lighting_Output_Timer(
uint32_t object_instance,
uint16_t milliseconds);
BACNET_STACK_EXPORT
void Lighting_Output_Write_Present_Value_Callback_Set(
lighting_output_write_present_value_callback cb);
BACNET_STACK_EXPORT
uint32_t Lighting_Output_Create(uint32_t object_instance);
BACNET_STACK_EXPORT
bool Lighting_Output_Delete(uint32_t object_instance);
BACNET_STACK_EXPORT
void Lighting_Output_Cleanup(void);
BACNET_STACK_EXPORT
void Lighting_Output_Init(
void);
+4 -8
View File
@@ -1164,9 +1164,9 @@ uint32_t Multistate_Output_Create(uint32_t object_instance)
return BACNET_MAX_INSTANCE;
} else if (object_instance == BACNET_MAX_INSTANCE) {
/* wildcard instance */
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
/* the Object_Identifier property of the newly created object
shall be initialized to a value that is unique within the
responding BACnet-user device. The method used to generate
the object identifier is a local matter.*/
object_instance = Keylist_Next_Empty_Key(Object_List, 1);
}
@@ -1186,9 +1186,7 @@ uint32_t Multistate_Output_Create(uint32_t object_instance)
pObject->Relinquish_Default = 1;
/* add to list */
index = Keylist_Data_Add(Object_List, object_instance, pObject);
if (index >= 0) {
Device_Inc_Database_Revision();
} else {
if (index < 0) {
free(pObject);
return BACNET_MAX_INSTANCE;
}
@@ -1214,7 +1212,6 @@ bool Multistate_Output_Delete(uint32_t object_instance)
if (pObject) {
free(pObject);
status = true;
Device_Inc_Database_Revision();
}
return status;
@@ -1232,7 +1229,6 @@ void Multistate_Output_Cleanup(void)
pObject = Keylist_Data_Pop(Object_List);
if (pObject) {
free(pObject);
Device_Inc_Database_Revision();
}
} while (pObject);
Keylist_Delete(Object_List);
+115 -23
View File
@@ -41,14 +41,16 @@ static double clamp(double d, double min, double max)
* @param x_coordinate - return x of CIE xy 0.0..1.0
* @param y_coordinate - return y of CIE xy 0.0..1.0
* @param brightness - return brightness of the CIE xy color 0..255
* @param gamma_correction - true if gamma correction is applied
* @note http://en.wikipedia.org/wiki/Srgb
*/
void color_rgb_to_xy(uint8_t r,
static void color_rgb_to_xy_gamma_correction(uint8_t r,
uint8_t g,
uint8_t b,
float *x_coordinate,
float *y_coordinate,
uint8_t *brightness)
uint8_t *brightness,
bool gamma_correction)
{
float X, Y, Z;
float x, y;
@@ -63,18 +65,20 @@ void color_rgb_to_xy(uint8_t r,
green /= 255.0f;
blue /= 255.0f;
/* Apply a gamma correction to the RGB values,
which makes the color more vivid and more the
like the color displayed on the screen of your device.
This gamma correction is also applied to the screen
of your computer or phone, thus we need this to create
the same color on the light as on screen. */
red = (red > 0.04045f) ? pow((red + 0.055f) / (1.0f + 0.055f), 2.4f)
: (red / 12.92f);
green = (green > 0.04045f) ? pow((green + 0.055f) / (1.0f + 0.055f), 2.4f)
: (green / 12.92f);
blue = (blue > 0.04045f) ? pow((blue + 0.055f) / (1.0f + 0.055f), 2.4f)
: (blue / 12.92f);
if (gamma_correction) {
/* Apply a gamma correction to the RGB values,
which makes the color more vivid and more the
like the color displayed on the screen of your device.
This gamma correction is also applied to the screen
of your computer or phone, thus we need this to create
the same color on the light as on screen. */
red = (red > 0.04045f) ? pow((red + 0.055f) / (1.0f + 0.055f), 2.4f)
: (red / 12.92f);
green = (green > 0.04045f) ? pow((green + 0.055f) / (1.0f + 0.055f), 2.4f)
: (green / 12.92f);
blue = (blue > 0.04045f) ? pow((blue + 0.055f) / (1.0f + 0.055f), 2.4f)
: (blue / 12.92f);
}
/* Convert the RGB values to XYZ using the
Wide RGB D65 conversion formula */
@@ -107,6 +111,48 @@ void color_rgb_to_xy(uint8_t r,
}
}
/**
* @brief Convert sRGB to CIE xy
* @param r - R value of sRGB 0..255
* @param g - G value of sRGB 0..255
* @param b - B value of sRGB 0..255
* @param x_coordinate - return x of CIE xy 0.0..1.0
* @param y_coordinate - return y of CIE xy 0.0..1.0
* @param brightness - return brightness of the CIE xy color 0..255
* @note http://en.wikipedia.org/wiki/Srgb
*/
void color_rgb_to_xy(uint8_t r,
uint8_t g,
uint8_t b,
float *x_coordinate,
float *y_coordinate,
uint8_t *brightness)
{
color_rgb_to_xy_gamma_correction(r, g, b,
x_coordinate, y_coordinate, brightness, false);
}
/**
* @brief Convert sRGB to CIE xy, with gamma correction
* @param r - R value of sRGB 0..255
* @param g - G value of sRGB 0..255
* @param b - B value of sRGB 0..255
* @param x_coordinate - return x of CIE xy 0.0..1.0
* @param y_coordinate - return y of CIE xy 0.0..1.0
* @param brightness - return brightness of the CIE xy color 0..255
* @note http://en.wikipedia.org/wiki/Srgb
*/
void color_rgb_to_xy_gamma(uint8_t r,
uint8_t g,
uint8_t b,
float *x_coordinate,
float *y_coordinate,
uint8_t *brightness)
{
color_rgb_to_xy_gamma_correction(r, g, b,
x_coordinate, y_coordinate, brightness, true);
}
/**
* @brief Convert sRGB from CIE xy and brightness
* @param red - return R value of sRGB
@@ -115,14 +161,16 @@ void color_rgb_to_xy(uint8_t r,
* @param x_coordinate - x of CIE xy
* @param y_coordinate - y of CIE xy
* @param brightness - brightness of the CIE xy color
* @param gamma_correction - true if gamma correction is needed
* @note http://en.wikipedia.org/wiki/Srgb
*/
void color_rgb_from_xy(uint8_t *red,
static void color_rgb_from_xy_gamma_correction(uint8_t *red,
uint8_t *green,
uint8_t *blue,
float x_coordinate,
float y_coordinate,
uint8_t brightness)
uint8_t brightness,
bool gamma_correction)
{
float r, g, b;
float x, y, z, X, Y, Z;
@@ -142,13 +190,15 @@ void color_rgb_from_xy(uint8_t *red,
g = -X * 0.5217933f + Y * 1.4472381f + Z * 0.0677227f;
b = X * 0.0349342f - Y * 0.0968930f + Z * 1.2884099f;
/* Apply reverse gamma correction */
r = r <= 0.0031308f ? 12.92f * r
: (1.0f + 0.055f) * pow(r, (1.0f / 2.4f)) - 0.055f;
g = g <= 0.0031308f ? 12.92f * g
: (1.0f + 0.055f) * pow(g, (1.0f / 2.4f)) - 0.055f;
b = b <= 0.0031308f ? 12.92f * b
: (1.0f + 0.055f) * pow(b, (1.0f / 2.4f)) - 0.055f;
if (gamma_correction) {
/* Apply reverse gamma correction */
r = r <= 0.0031308f ? 12.92f * r
: (1.0f + 0.055f) * pow(r, (1.0f / 2.4f)) - 0.055f;
g = g <= 0.0031308f ? 12.92f * g
: (1.0f + 0.055f) * pow(g, (1.0f / 2.4f)) - 0.055f;
b = b <= 0.0031308f ? 12.92f * b
: (1.0f + 0.055f) * pow(b, (1.0f / 2.4f)) - 0.055f;
}
/* Convert the RGB values to your color object
The rgb values from the above formulas are
@@ -171,6 +221,48 @@ void color_rgb_from_xy(uint8_t *red,
}
}
/**
* @brief Convert sRGB from CIE xy and brightness
* @param red - return R value of sRGB
* @param green - return G value of sRGB
* @param blue - return B value of sRGB
* @param x_coordinate - x of CIE xy
* @param y_coordinate - y of CIE xy
* @param brightness - brightness of the CIE xy color
* @note http://en.wikipedia.org/wiki/Srgb
*/
void color_rgb_from_xy(uint8_t *red,
uint8_t *green,
uint8_t *blue,
float x_coordinate,
float y_coordinate,
uint8_t brightness)
{
color_rgb_from_xy_gamma_correction(red, green, blue,
x_coordinate, y_coordinate, brightness, false);
}
/**
* @brief Convert sRGB from CIE xy and brightness, with gamma correction
* @param red - return R value of sRGB
* @param green - return G value of sRGB
* @param blue - return B value of sRGB
* @param x_coordinate - x of CIE xy
* @param y_coordinate - y of CIE xy
* @param brightness - brightness of the CIE xy color
* @note http://en.wikipedia.org/wiki/Srgb
*/
void color_rgb_from_xy_gamma(uint8_t *red,
uint8_t *green,
uint8_t *blue,
float x_coordinate,
float y_coordinate,
uint8_t brightness)
{
color_rgb_from_xy_gamma_correction(red, green, blue,
x_coordinate, y_coordinate, brightness, true);
}
/* table for converting RGB to and from ASCII color names */
struct css_color_rgb {
const char *name;
+7
View File
@@ -22,6 +22,13 @@ BACNET_STACK_EXPORT
void color_rgb_from_xy(uint8_t *red, uint8_t *green, uint8_t *blue,
float x_coordinate, float y_coordinate, uint8_t brightness);
BACNET_STACK_EXPORT
void color_rgb_to_xy_gamma(uint8_t r, uint8_t g, uint8_t b,
float *x_coordinate, float *y_coordinate, uint8_t *brightness);
BACNET_STACK_EXPORT
void color_rgb_from_xy_gamma(uint8_t *red, uint8_t *green, uint8_t *blue,
float x_coordinate, float y_coordinate, uint8_t brightness);
BACNET_STACK_EXPORT
const char * color_rgb_to_ascii(uint8_t red, uint8_t green, uint8_t blue);
BACNET_STACK_EXPORT
+128
View File
@@ -0,0 +1,128 @@
/**
* @file
* @author Steve Karg
* @date 2011
* @brief Performs linear interpolation using single precision floating
* point math or integer math, or a mixture of both.
*
* @section LICENSE
*
* Copyright (C) 2011 Steve Karg <skarg@users.sourceforge.net>
*
* 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.
*
* @section DESCRIPTION
*
* Performs linear interpolation using single precision floating
* point math or integer math, or a mixture of both.
* Linear interpolation is a method of constructing new data
* points within the range of a discrete set of known data points.
*/
#include <stdbool.h>
#include <stdint.h>
#include "linear.h"
/**
* Linearly Interpolate the values between y1 and y3 based on x.
*
* @param x1 - first x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param x2 - intermediate x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param x3 - last x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param y1 - first y value, where y1 <= y2 <= y3 or y1 >= y2 >= y3
* @param y3 - last y value, where y1 <= y2 <= y3 or y1 >= y2 >= y3
* @return y2 - an intermediate y value y1 <= y2 <= y3 or y1 >= y2 >= y3
* and the y value is linearly proportional to x1, x2, and x2.
*/
float linear_interpolate(float x1,
float x2,
float x3,
float y1,
float y3)
{
float y2;
if (y3 > y1) {
y2 = y1 + (((x2 - x1) * (y3 - y1)) / (x3 - x1));
} else {
y2 = y1 - (((x2 - x1) * (y1 - y3)) / (x3 - x1));
}
return y2;
}
/**
* Linearly Interpolate the values between y1 and y3 based on x
* and round up the result. Useful for integer interpolation.
*
* @param x1 - first x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param x2 - intermediate x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param x3 - last x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param y1 - first y value, where y1 <= y2 <= y3 or y1 >= y2 >= y3
* @param y3 - last y value, where y1 <= y2 <= y3 or y1 >= y2 >= y3
* @return y2 - an intermediate y value y1 <= y2 <= y3 or y1 >= y2 >= y3
* and the y value is linearly proportional to x1, x2, and x2.
*/
float linear_interpolate_round(float x1,
float x2,
float x3,
float y1,
float y3)
{
float y2;
y2 = linear_interpolate(x1, x2, x3, y1, y3);
/* round away from zero */
if (y2 > 0.0) {
y2 += 0.5;
} else if (y2 < 0.0) {
y2 -= 0.5;
}
return y2;
}
/**
* Linearly Interpolate the values between y1 and y3 based on x
* using integer math.
*
* @param x1 - first x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param x2 - intermediate x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param x3 - last x value, where x1 <= x2 <= x3 or x1 >= x2 >= x3
* @param y1 - first y value, where y1 <= y2 <= y3 or y1 >= y2 >= y3
* @param y3 - last y value, where y1 <= y2 <= y3 or y1 >= y2 >= y3
* @return y2 - an intermediate y value y1 <= y2 <= y3 or y1 >= y2 >= y3
* and the y value is linearly proportional to x1, x2, and x2.
*/
long linear_interpolate_int(long x1,
long x2,
long x3,
long y1,
long y3)
{
long y2;
if (y3 > y1) {
y2 = y1 + (((x2 - x1) * (y3 - y1)) / (x3 - x1));
} else {
y2 = y1 - (((x2 - x1) * (y1 - y3)) / (x3 - x1));
}
return y2;
}
+34
View File
@@ -0,0 +1,34 @@
/**
* @file
* @author Steve Karg
* @date 2011
*/
#ifndef LINEAR_H
#define LINEAR_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
float linear_interpolate(float x1,
float x2,
float x3,
float y1,
float y3);
float linear_interpolate_round(float x1,
float x2,
float x3,
float y1,
float y3);
long linear_interpolate_int(long x1,
long x2,
long x3,
long y1,
long y3);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif