mirror of
https://github.com/formtapez/ZigUP.git
synced 2025-02-23 09:34:50 +01:00
implemented setcolor for ws2812b
This commit is contained in:
14
README.md
14
README.md
@@ -16,8 +16,6 @@ CC2530 based multi-purpose ZigBee Relais, Switch, Sensor and Router
|
||||
* Output for one normal LED or up to 10 WS2812B/Neopixel RGB-LEDs (controllable via ZigBee)
|
||||
* Analog input to measure voltages of up to 32 Volt. (Voltage will be reported via ZigBee)
|
||||
|
||||
Hi! I'm your first Markdown file in **StackEdit**. If you want to learn about StackEdit, you can read me. If you want to play with Markdown, you can edit me. Once you have finished with me, you can create new files by opening the **file explorer** on the left corner of the navigation bar.
|
||||
|
||||
|
||||
# Connection diagrams
|
||||
|
||||
@@ -34,12 +32,14 @@ Hi! I'm your first Markdown file in **StackEdit**. If you want to learn about St
|
||||
|
||||
1. Get **Z-Stack Home 1.2.2a.44539** from http://www.ti.com/tool/Z-STACK-ARCHIVE
|
||||
2. Get **IAR Embedded Workbench for 8051** from https://www.iar.com/iar-embedded-workbench (you can use the free trial version for one month)
|
||||
3. Clone ZigUP source to **\Z-Stack Home 1.2.2a.44539\Projects\zstack\HomeAutomation\ZigUP\\**
|
||||
4. Start **\ZigUP\CC2530DB\ZigUP.ewp** to load project in IAR
|
||||
3. Clone ZigUP source to **\Projects\zstack\HomeAutomation\ZigUP\\**
|
||||
4. Start **\ZigUP\CC2530DB\ZigUP.eww** to load project in IAR
|
||||
5. Set project configuration to "Router".
|
||||
6. Compile
|
||||
6. Edit **\Projects\zstack\Tools\CC2530DB\f8wConfig.cfg** to use all 2.4 GHz channels:
|
||||
>-DDEFAULT_CHANLIST=0x07FFF800
|
||||
7. Compile
|
||||
|
||||
# Flashing with CC Debugger
|
||||
1. Get **SmartRF Flash Programmer v1.12.8 (not v2.x!)** from https://www.ti.com/tool/flash-programmer
|
||||
2. Load HEX-File and click "flash"
|
||||
|
||||
2. Select "Program CCxxxx..." and "System-on-Chip" tab
|
||||
3. Load HEX-File and perform "Erase, program and verify" action
|
||||
|
||||
@@ -4722,6 +4722,12 @@
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Source\ws2812.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\..\..\..\Components\stack\zcl\zcl_lighting.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\..\..\..\..\Components\stack\zcl\zcl_lighting.h</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Source\zcl_zigup.c</name>
|
||||
</file>
|
||||
|
||||
@@ -30,53 +30,56 @@ void WS2812_SendLED(uint8 red, uint8 green, uint8 blue)
|
||||
// delete buffer
|
||||
for (uint16 i=0; i<WS2812_buffersize; i++) WS2812_buffer[i] = 0;
|
||||
|
||||
uint8 i;
|
||||
uint8 i,j;
|
||||
|
||||
for (i=8; i; i--)
|
||||
for (j=0; j<10; j++) // send identical data 10 times for up to 10 LEDs in a row
|
||||
{
|
||||
if ((green >> (i-1)) & 1)
|
||||
for (i=8; i; i--)
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
if ((green >> (i-1)) & 1)
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
for (i=8; i; i--)
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
WS2812_StoreBit(0);
|
||||
if ((red >> (i-1)) & 1)
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
}
|
||||
for (i=8; i; i--)
|
||||
{
|
||||
if ((blue >> (i-1)) & 1)
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i=8; i; i--)
|
||||
{
|
||||
if ((red >> (i-1)) & 1)
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
}
|
||||
for (i=8; i; i--)
|
||||
{
|
||||
if ((blue >> (i-1)) & 1)
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
WS2812_StoreBit(1);
|
||||
WS2812_StoreBit(0);
|
||||
WS2812_StoreBit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// SPI method - a little bit jittery, but LED-Stripes seem to be okay with it
|
||||
for (uint16 j=0; j<WS2812_buffersize; j++)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// buffersize = num_leds * 24 bits * 3 bits per bit / 8 bit
|
||||
#define WS2812_buffersize 9
|
||||
#define WS2812_buffersize 90
|
||||
|
||||
void WS2812_StoreBit(uint8 bit);
|
||||
void WS2812_SendLED(uint8 red, uint8 green, uint8 blue);
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "zcl_lighting.h"
|
||||
#include "zcl_zigup.h"
|
||||
#include "zcl.h"
|
||||
#include "zcl_ha.h"
|
||||
#include "zcl_diagnostic.h"
|
||||
|
||||
#include "onboard.h"
|
||||
#include "ZDSecMgr.h"
|
||||
#include "bitmasks.h"
|
||||
@@ -24,12 +28,6 @@
|
||||
|
||||
afAddrType_t zclZigUP_DstAddr;
|
||||
|
||||
uint16 bindingInClusters[] =
|
||||
{
|
||||
ZCL_CLUSTER_ID_GEN_ON_OFF
|
||||
};
|
||||
#define ZCLZIGUP_BINDINGLIST (sizeof(bindingInClusters) / sizeof(bindingInClusters[0]))
|
||||
|
||||
// Test Endpoint to allow SYS_APP_MSGs
|
||||
static endPointDesc_t ZigUP_TestEp =
|
||||
{
|
||||
@@ -141,6 +139,50 @@ static zclGeneral_AppCallbacks_t zclZigUP_CmdCallbacks =
|
||||
NULL // RSSI Location Response command
|
||||
};
|
||||
|
||||
|
||||
|
||||
static zclLighting_AppCallbacks_t zclZigUP_LightingCmdCBs =
|
||||
{
|
||||
NULL, //Move To Hue Command
|
||||
NULL, //Move Hue Command
|
||||
NULL, //Step Hue Command
|
||||
NULL, //Move To Saturation Command
|
||||
NULL, //Move Saturation Command
|
||||
NULL, //Step Saturation Command
|
||||
NULL, //Move To Hue And Saturation Command
|
||||
zclZigUP_MoveToColorCB, // Move To Color Command
|
||||
NULL, // Move Color Command
|
||||
NULL, // STEP To Color Command
|
||||
NULL, // Move To Color Temperature Command
|
||||
NULL,// Enhanced Move To Hue
|
||||
NULL, // Enhanced Move Hue;
|
||||
NULL, // Enhanced Step Hue;
|
||||
NULL, // Enhanced Move To Hue And Saturation;
|
||||
NULL, // Color Loop Set Command
|
||||
NULL, // Stop Move Step;
|
||||
|
||||
|
||||
/*
|
||||
zclColor_MoveToHueCB, //Move To Hue Command
|
||||
zclColor_MoveHueCB, //Move Hue Command
|
||||
zclColor_StepHueCB, //Step Hue Command
|
||||
zclColor_MoveToSaturationCB, //Move To Saturation Command
|
||||
zclColor_MoveSaturationCB, //Move Saturation Command
|
||||
zclColor_StepSaturationCB, //Step Saturation Command
|
||||
zclColor_MoveToHueAndSaturationCB, //Move To Hue And Saturation Command
|
||||
zclColor_MoveToColorCB, // Move To Color Command
|
||||
zclColor_MoveColorCB, // Move Color Command
|
||||
zclColor_StepColorCB, // STEP To Color Command
|
||||
NULL, // Move To Color Temperature Command
|
||||
zclColor_EnhMoveToHueCB,// Enhanced Move To Hue
|
||||
zclColor_MoveEnhHueCB, // Enhanced Move Hue;
|
||||
zclColor_StepEnhHueCB, // Enhanced Step Hue;
|
||||
zclColor_MoveToEnhHueAndSaturationCB, // Enhanced Move To Hue And Saturation;
|
||||
zclColor_SetColorLoopCB, // Color Loop Set Command
|
||||
zclColor_StopCB, // Stop Move Step;
|
||||
*/
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* @fn zclZigUP_Init
|
||||
*
|
||||
@@ -165,6 +207,9 @@ void zclZigUP_Init( byte task_id )
|
||||
|
||||
// Register the ZCL General Cluster Library callback functions
|
||||
zclGeneral_RegisterCmdCallbacks( ZIGUP_ENDPOINT, &zclZigUP_CmdCallbacks );
|
||||
|
||||
// Register the ZCL Lighting Cluster Library callback functions
|
||||
zclLighting_RegisterCmdCallbacks( ZIGUP_ENDPOINT, &zclZigUP_LightingCmdCBs );
|
||||
|
||||
// Register the application's attribute list
|
||||
zcl_registerAttrList( ZIGUP_ENDPOINT, zclZigUP_NumAttributes, zclZigUP_Attrs );
|
||||
@@ -236,7 +281,7 @@ void zclZigUP_Init( byte task_id )
|
||||
else UART_String("Sensor: Low.");
|
||||
|
||||
|
||||
osal_start_reload_timer( zclZigUP_TaskID, ZIGUP_REPORTING_EVT, ZIGUP_REPORTING_INTERVAL );
|
||||
// osal_start_reload_timer( zclZigUP_TaskID, ZIGUP_REPORTING_EVT, ZIGUP_REPORTING_INTERVAL );
|
||||
|
||||
|
||||
UART_String("Init done.");
|
||||
@@ -415,6 +460,12 @@ static void zclZigUP_OnOffCB( uint8 cmd )
|
||||
{
|
||||
afIncomingMSGPacket_t *pPtr = zcl_getRawAFMsg();
|
||||
zclZigUP_DstAddr.addr.shortAddr = pPtr->srcAddr.addr.shortAddr;
|
||||
|
||||
|
||||
char buffer[100];
|
||||
sprintf(buffer, "CMD: %u\n", cmd);
|
||||
UART_String(buffer);
|
||||
|
||||
|
||||
// Turn on the light
|
||||
if ( cmd == COMMAND_ON )
|
||||
@@ -433,6 +484,81 @@ static void zclZigUP_OnOffCB( uint8 cmd )
|
||||
}
|
||||
}
|
||||
|
||||
ZStatus_t zclZigUP_MoveToColorCB( zclCCMoveToColor_t *pCmd )
|
||||
{
|
||||
// Converts CIE color space to RGB color space
|
||||
// from https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
|
||||
|
||||
char buffer[100];
|
||||
sprintf(buffer, "Light-CMD: x: %u // y: %u\n", pCmd->colorX, pCmd->colorY);
|
||||
UART_String(buffer);
|
||||
|
||||
float x = pCmd->colorX/ 65536.0; // the given x value
|
||||
float y = pCmd->colorY/ 65536.0; // the given y value
|
||||
|
||||
float z = 1.0 - x - y;
|
||||
float Y = 1.0;
|
||||
float X = (Y / y) * x;
|
||||
float Z = (Y / y) * z;
|
||||
|
||||
//Convert to RGB using Wide RGB D65 conversion
|
||||
float red = X * 1.656492 - Y * 0.354851 - Z * 0.255038;
|
||||
float green = -X * 0.707196 + Y * 1.655397 + Z * 0.036152;
|
||||
float blue = X * 0.051713 - Y * 0.121364 + Z * 1.011530;
|
||||
|
||||
//If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
|
||||
if (red > blue && red > green && red > 1.0)
|
||||
{
|
||||
green = green / red;
|
||||
blue = blue / red;
|
||||
red = 1.0;
|
||||
}
|
||||
else if (green > blue && green > red && green > 1.0)
|
||||
{
|
||||
red = red / green;
|
||||
blue = blue / green;
|
||||
green = 1.0;
|
||||
}
|
||||
else if (blue > red && blue > green && blue > 1.0)
|
||||
{
|
||||
red = red / blue;
|
||||
green = green / blue;
|
||||
blue = 1.0;
|
||||
}
|
||||
|
||||
//Reverse gamma correction
|
||||
red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * pow(red, (1.0 / 2.4)) - 0.055;
|
||||
green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * pow(green, (1.0 / 2.4)) - 0.055;
|
||||
blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * pow(blue, (1.0 / 2.4)) - 0.055;
|
||||
|
||||
|
||||
//Convert normalized decimal to decimal
|
||||
red *= 255;
|
||||
green *= 255;
|
||||
blue *= 255;
|
||||
|
||||
uint8 r = (uint8)red;
|
||||
uint8 g = (uint8)green;
|
||||
uint8 b = (uint8)blue;
|
||||
|
||||
if (red > 254.5) r = 255;
|
||||
else if (red < 0.5) r = 0;
|
||||
|
||||
if (green > 254.5) g = 255;
|
||||
else if (green < 0.5) g = 0;
|
||||
|
||||
if (blue > 254.5) b = 255;
|
||||
else if (blue < 0.5) b = 0;
|
||||
|
||||
sprintf(buffer, "Light-CMD: r: %u // g: %u // b: %u\n", r, g, b);
|
||||
UART_String(buffer);
|
||||
|
||||
WS2812_SendLED(r, g, b);
|
||||
|
||||
return ( ZSuccess );
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Functions for processing ZCL Foundation incoming Command/Response messages
|
||||
|
||||
@@ -8,7 +8,7 @@ extern "C"
|
||||
|
||||
#include "zcl.h"
|
||||
#include "zcl_general.h"
|
||||
|
||||
#include "zcl_lighting.h"
|
||||
|
||||
#define ZIGUP_ENDPOINT 8
|
||||
|
||||
@@ -56,8 +56,12 @@ static void zclZigUP_BasicResetCB( void );
|
||||
static void zclZigUP_IdentifyCB( zclIdentify_t *pCmd );
|
||||
static void zclZigUP_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp );
|
||||
static void zclZigUP_OnOffCB( uint8 cmd );
|
||||
ZStatus_t zclZigUP_MoveToColorCB( zclCCMoveToColor_t *pCmd );
|
||||
|
||||
|
||||
static void zclZigUP_ProcessIdentifyTimeChange( void );
|
||||
|
||||
|
||||
// Functions to process ZCL Foundation incoming Command/Response messages
|
||||
static void zclZigUP_ProcessIncomingMsg( zclIncomingMsg_t *msg );
|
||||
#ifdef ZCL_READ
|
||||
|
||||
@@ -42,7 +42,7 @@ uint8 zclZigUP_DeviceEnable = DEVICE_ENABLED;
|
||||
uint16 zclZigUP_IdentifyTime = 0;
|
||||
|
||||
// On/Off Cluster
|
||||
uint8 zclZigUP_OnOff = LIGHT_OFF;
|
||||
uint8 zclZigUP_OnOff = LIGHT_OFF;
|
||||
|
||||
#if ZCL_DISCOVER
|
||||
CONST zclCommandRec_t zclZigUP_Cmds[] =
|
||||
@@ -182,7 +182,21 @@ CONST zclAttrRec_t zclZigUP_Attrs[] =
|
||||
ACCESS_CONTROL_READ,
|
||||
(void *)&zclZigUP_OnOff
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// *** Color control Cluster Attributes ***
|
||||
{
|
||||
ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
|
||||
{ // Attribute record
|
||||
ATTRID_LIGHTING_COLOR_CONTROL_CURRENT_X,
|
||||
ZCL_DATATYPE_UINT16,
|
||||
(ACCESS_CONTROL_READ | ACCESS_CONTROL_WRITE),
|
||||
(void *)&zclZigUP_OnOff // TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
uint8 CONST zclZigUP_NumAttributes = ( sizeof(zclZigUP_Attrs) / sizeof(zclZigUP_Attrs[0]) );
|
||||
@@ -190,30 +204,29 @@ uint8 CONST zclZigUP_NumAttributes = ( sizeof(zclZigUP_Attrs) / sizeof(zclZigUP_
|
||||
/*********************************************************************
|
||||
* SIMPLE DESCRIPTOR
|
||||
*/
|
||||
// This is the Cluster ID List and should be filled with Application
|
||||
// specific cluster IDs.
|
||||
// This is the Cluster ID List and should be filled with Application specific cluster IDs.
|
||||
const cId_t zclZigUP_InClusterList[] =
|
||||
{
|
||||
ZCL_CLUSTER_ID_GEN_BASIC,
|
||||
ZCL_CLUSTER_ID_GEN_IDENTIFY,
|
||||
ZCL_CLUSTER_ID_GEN_GROUPS,
|
||||
ZCL_CLUSTER_ID_GEN_SCENES,
|
||||
ZCL_CLUSTER_ID_GEN_ON_OFF
|
||||
ZCL_CLUSTER_ID_GEN_ON_OFF,
|
||||
ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL
|
||||
};
|
||||
// work-around for compiler bug... IAR can't calculate size of array with #if options.
|
||||
#define ZCLZIGUP_MAX_INCLUSTERS 5
|
||||
#define ZCLZIGUP_MAX_INCLUSTERS (sizeof(zclZigUP_InClusterList) / sizeof(zclZigUP_InClusterList[0]))
|
||||
|
||||
const cId_t zclZigUP_OutClusterList[] =
|
||||
{
|
||||
ZCL_CLUSTER_ID_GEN_BASIC
|
||||
};
|
||||
#define ZCLZIGUP_MAX_OUTCLUSTERS (sizeof(zclZigUP_OutClusterList) / sizeof(zclZigUP_OutClusterList[0]))
|
||||
#define ZCLZIGUP_MAX_OUTCLUSTERS (sizeof(zclZigUP_OutClusterList) / sizeof(zclZigUP_OutClusterList[0]))
|
||||
|
||||
SimpleDescriptionFormat_t zclZigUP_SimpleDesc[1] = {
|
||||
{
|
||||
ZIGUP_ENDPOINT, // int Endpoint;
|
||||
ZCL_HA_PROFILE_ID, // uint16 AppProfId;
|
||||
ZCL_HA_DEVICEID_ON_OFF_LIGHT, // uint16 AppDeviceId;
|
||||
ZCL_HA_PROFILE_ID, // uint16 AppProfId;
|
||||
ZCL_HA_DEVICEID_ON_OFF_LIGHT, // uint16 AppDeviceId;
|
||||
ZIGUP_DEVICE_VERSION, // int AppDevVer:4;
|
||||
ZIGUP_FLAGS, // int AppFlags:4;
|
||||
ZCLZIGUP_MAX_INCLUSTERS, // byte AppNumInClusters;
|
||||
|
||||
Reference in New Issue
Block a user