Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
89eb1e07
Commit
89eb1e07
authored
Sep 21, 2020
by
陈伟灿
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'cwc' into 'master'
【修改内容】支持彩带灯模式的设置和RGB色的设置 See merge request chenweican/k-sdk!19
parents
47e91b73
6e3c8b10
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
207 additions
and
165 deletions
+207
-165
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_color_space.c
...form/zigbee/app/builder/Z3GatewayHost/ZB/kk_color_space.c
+96
-83
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_color_space.h
...form/zigbee/app/builder/Z3GatewayHost/ZB/kk_color_space.h
+33
-31
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.c
...bee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.c
+56
-41
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
...zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
+19
-8
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.h
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.h
+3
-2
No files found.
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_color_space.c
View file @
89eb1e07
#include "kk_color_space.h"
static
float
hue_to_rgb
(
float
m1
,
float
m2
,
float
h
)
void
RGB_to_HSL_base
(
unsigned
char
red
,
unsigned
char
green
,
unsigned
char
blue
,
double
*
H
,
double
*
S
,
double
*
L
)
{
h
=
(
h
<
0
)
?
h
+
1
:
((
h
>
1
)
?
h
-
1
:
h
);
if
(
h
*
6
<
1
)
{
return
(
m1
+
(
m2
-
m1
)
*
h
*
6
);
}
else
if
(
h
*
2
<
1
)
{
return
m2
;
}
else
if
(
h
*
3
<
2
)
{
return
m1
+
(
m2
-
m1
)
*
(
0
.
66666
-
h
)
*
6
;
double
min
=
0
,
max
=
0
,
delta
=
0
;
double
R
=
0
,
G
=
0
,
B
=
0
;
R
=
red
/
255
.
0
;
G
=
green
/
255
.
0
;
B
=
blue
/
255
.
0
;
min
=
(
R
<
G
)
?
((
R
<
B
)
?
R
:
B
)
:
((
G
<
B
)
?
G
:
B
);
max
=
(
R
>
G
)
?
((
R
>
B
)
?
R
:
B
)
:
((
G
>
B
)
?
G
:
B
);
delta
=
max
-
min
;
*
L
=
(
min
+
max
)
/
2
.
0
;
if
(
*
L
==
0
.
0
||
(
max
-
min
)
==
0
.
0
){
*
S
=
0
;
}
else
if
(
*
L
>
0
.
5
){
*
S
=
delta
/
(
2
-
2
*
*
L
);
}
else
{
*
S
=
delta
/
(
2
*
*
L
);
}
else
{
return
m1
;
if
((
max
-
min
)
==
0
.
0
){
*
H
=
0
;
}
else
if
((
max
-
R
==
0
.
0
)
&&
(
G
>=
B
)){
*
H
=
(
G
-
B
)
/
delta
;
}
else
if
((
max
-
R
==
0
.
0
)
&&
(
G
<
B
)){
*
H
=
(
G
-
B
)
/
delta
+
6
;
}
else
if
((
max
-
G
)
==
0
.
0
){
*
H
=
(
B
-
R
)
/
delta
+
2
;
}
else
if
((
max
-
B
)
==
0
.
0
){
*
H
=
(
R
-
G
)
/
delta
+
4
;
}
else
{
}
*
H
/=
6
.
0
;
}
void
RGB_to_HSL
(
unsigned
char
red
,
unsigned
char
green
,
unsigned
char
blue
,
unsigned
short
*
H
,
unsigned
char
*
S
,
unsigned
char
*
L
)
{
double
h
,
s
,
l
;
RGB_to_HSL_base
(
red
,
green
,
blue
,
&
h
,
&
s
,
&
l
);
*
H
=
h
*
360
+
((
int
)(
h
*
3600
)
%
10
>=
5
?
1
:
0
);
*
S
=
s
*
100
+
((
int
)(
s
*
1000
)
%
10
>=
5
?
1
:
0
);
*
L
=
l
*
100
+
((
int
)(
l
*
1000
)
%
10
>=
5
?
1
:
0
);
}
void
hsl_to_rgb
(
float
h
,
float
s
,
float
l
,
unsigned
char
*
r
,
unsigned
char
*
g
,
unsigned
char
*
b
)
double
HSL_convert_color_to_RGB
(
double
p
,
double
q
,
double
tC
)
{
float
m1
,
m2
;
tC
=
(
tC
<
0
)
?
(
tC
+
1
)
:
((
tC
>
1
)
?
(
tC
-
1
)
:
tC
);
m2
=
(
l
<=
0
.
5
)
?
l
*
(
s
+
1
)
:
l
+
s
-
l
*
s
;
m1
=
l
*
2
-
m2
;
*
r
=
255
*
hue_to_rgb
(
m1
,
m2
,
h
+
0
.
33333
);
*
g
=
255
*
hue_to_rgb
(
m1
,
m2
,
h
);
*
b
=
255
*
hue_to_rgb
(
m1
,
m2
,
h
-
0
.
33333
);
if
(
tC
*
6
<
1
){
return
(
p
+
(
q
-
p
)
*
6
*
tC
);
}
else
if
(
tC
*
2
<
1
){
return
q
;
}
else
if
(
tC
*
3
<
2
){
return
p
+
((
q
-
p
)
*
6
*
(
2
/
3
.
0
-
tC
));
}
else
{
return
p
;
}
}
void
rgb_to_hsl
(
unsigned
char
r
,
unsigned
char
g
,
unsigned
char
b
,
unsigned
short
*
H
,
unsigned
char
*
S
,
unsigned
char
*
L
)
void
HSL_to_RGB_base
(
double
H
,
double
S
,
double
L
,
unsigned
char
*
red
,
unsigned
char
*
green
,
unsigned
char
*
blue
)
{
float
min
=
0
,
max
=
0
,
delta
=
0
;
float
h
=
0
,
s
=
0
,
l
=
0
,
R
=
0
,
G
=
0
,
B
=
0
;
R
=
r
/
255
.
0
;
G
=
g
/
255
.
0
;
B
=
b
/
255
.
0
;
min
=
R
<
G
?
R
:
G
;
min
=
B
<
min
?
B
:
min
;
max
=
R
>
G
?
R
:
G
;
max
=
B
>
max
?
B
:
max
;
double
q
,
p
;
double
tR
,
tG
,
tB
;
double
r
,
g
,
b
;
delta
=
max
-
min
;
l
=
(
min
+
max
)
/
2
.
0
;
q
=
(
L
<=
0
.
5
)
?
L
*
(
S
+
1
)
:
L
+
S
-
(
L
*
S
);
p
=
2
*
L
-
q
;
s
=
0
;
if
(
l
>
0
&&
l
<
1
)
{
s
=
delta
/
(
l
<
0
.
5
?
(
2
*
l
)
:
(
2
-
2
*
l
));
}
tR
=
H
+
1
/
3
.
0
;
tG
=
H
;
tB
=
H
-
1
/
3
.
0
;
h
=
0
;
if
(
delta
>
0
)
{
if
(
max
==
R
&&
max
!=
G
)
{
h
+=
(
G
-
B
)
/
delta
;
}
else
if
(
max
==
G
&&
max
!=
B
)
{
h
+=
(
2
+
(
B
-
R
)
/
delta
);
}
else
if
(
max
==
B
&&
max
!=
R
)
{
h
+=
(
4
+
(
R
-
G
)
/
delta
);
}
r
=
255
*
HSL_convert_color_to_RGB
(
p
,
q
,
tR
);
g
=
255
*
HSL_convert_color_to_RGB
(
p
,
q
,
tG
);
b
=
255
*
HSL_convert_color_to_RGB
(
p
,
q
,
tB
);
{
h
/=
6
.
0
;
}
}
*
red
=
r
+
(((
int
)(
r
*
10
)
%
10
>=
5
)
?
1
:
0
);
*
green
=
g
+
(((
int
)(
g
*
10
)
%
10
>=
5
)
?
1
:
0
);
*
blue
=
b
+
(((
int
)(
b
*
10
)
%
10
>=
5
)
?
1
:
0
);
}
*
H
=
(
unsigned
char
)
h
;
*
S
=
(
unsigned
char
)
s
;
*
L
=
(
unsigned
char
)
l
;
void
HSL_to_RGB
(
unsigned
short
H
,
unsigned
char
S
,
unsigned
char
L
,
unsigned
char
*
red
,
unsigned
char
*
green
,
unsigned
char
*
blue
)
{
double
h
=
H
/
360
.
0
;
double
s
=
S
/
100
.
0
;
double
l
=
L
/
100
.
0
;
HSL_to_RGB_base
(
h
,
s
,
l
,
red
,
green
,
blue
);
}
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_color_space.h
View file @
89eb1e07
...
...
@@ -5,8 +5,10 @@
void
rgb_to_hsl
(
unsigned
char
r
,
unsigned
char
g
,
unsigned
char
b
,
unsigned
short
*
H
,
unsigned
char
*
S
,
unsigned
char
*
L
);
void
hsl_to_rgb
(
float
h
,
float
s
,
float
l
,
unsigned
char
*
r
,
unsigned
char
*
g
,
unsigned
char
*
b
);
void
RGB_to_HSL_base
(
unsigned
char
red
,
unsigned
char
green
,
unsigned
char
blue
,
double
*
H
,
double
*
S
,
double
*
L
);
void
RGB_to_HSL
(
unsigned
char
red
,
unsigned
char
green
,
unsigned
char
blue
,
unsigned
short
*
H
,
unsigned
char
*
S
,
unsigned
char
*
L
);
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_report.c
View file @
89eb1e07
...
...
@@ -368,33 +368,13 @@ int kk_tsl_report_CO2(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId clusterId,Emb
return
kk_tsl_report_Concentration
(
eui64
,
EP
,
clusterId
,
attributeId
,
dataType
,
len
,
data
);
}
int
kk_tsl_report_colorControl_Brightness
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint8_t
value
=
data
[
0
];
emberAfAppPrintln
(
"[tsl report:kk_tsl_report_global_Brightness] value:%d
\n
"
,
value
);
if
(
dataType
==
ZCL_INT8U_ATTRIBUTE_TYPE
){
if
(
len
==
1
){
kk_tsl_report
(
eui64
,
EP
,
value
,
clusterId
,
attributeId
);
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_len
;
}
return
tsl_rpt_invaild_type
;
}
static
int
s_HSLCount
=
0
;
static
unsigned
short
s_H
=
0
;
static
unsigned
char
s_S
=
0
;
static
unsigned
char
s_L
=
0
;
COLOR_HSL
g_hsl
=
{
0
,
0
,
0
};
int
kk_tsl_report_colorControl_RGB
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
static
int
kk_tsl_report_colorControl_RGB_Str
(
EmberEUI64
eui64
)
{
uint8_t
value
=
data
[
0
];
kk_device_table_s
*
dev
;
kk_dev_config_map
*
dev_info
=
NULL
;
kk_dev_config_item
*
item
=
NULL
;
...
...
@@ -403,22 +383,14 @@ int kk_tsl_report_colorControl_RGB(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId
int
startIdx
=
0
;
cJSON
*
root_color
=
NULL
;
char
tmp_Identity
[
64
]
=
{
0
};
COLOR_RGB
g_rgb
=
{
0
,
0
,
0
}
;
unsigned
char
r
,
g
,
b
;
emberAfAppPrintln
(
"[tsl report:kk_tsl_report_global_RGB] value:%d
\n
"
,
value
);
if
(
dataType
==
ZCL_INT8U_ATTRIBUTE_TYPE
){
if
(
attributeId
==
0x0001
){
g_hsl
.
saturation
=
value
;
s_HSLCount
++
;
}
else
if
(
attributeId
==
0x0
){
g_hsl
.
hue
=
value
;
s_HSLCount
++
;
}
}
if
(
s_HSLCount
>=
2
){
if
(
s_HSLCount
>=
3
&&
s_H
!=
0
&&
s_S
!=
0
){
HSL_to_RGB
(
s_H
*
360
/
254
,
s_S
*
100
/
254
,
s_L
,
&
r
,
&
g
,
&
b
);
s_HSLCount
=
0
;
HSLtoRGB
(
&
g_hsl
,
&
g_rgb
);
s_H
=
0
;
s_S
=
0
;
//printf("[%s][%d]%d %d %d\n",__FUNCTION__,__LINE__,r,g,b);
dev
=
kk_device_find_by_mac
(
eui64
);
if
(
dev
==
NULL
){
return
tsl_rpt_err
;
...
...
@@ -436,7 +408,7 @@ int kk_tsl_report_colorControl_RGB(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId
rev
=
kk_tsl_utils_memtok
(
item
->
identity
,
'.'
,
1
,
&
startIdx
);
if
(
!
rev
){
memcpy
(
tmp_Identity
,
item
->
identity
,
startIdx
);
rpc_cJSON_AddNumberToObject
(
root_color
,
item
->
identity
+
1
+
startIdx
,
g_rgb
.
red
);
rpc_cJSON_AddNumberToObject
(
root_color
,
item
->
identity
+
1
+
startIdx
,
r
);
}
}
else
if
(
strstr
(
item
->
identity
,
".green"
)
!=
NULL
){
...
...
@@ -446,7 +418,7 @@ int kk_tsl_report_colorControl_RGB(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId
rev
=
kk_tsl_utils_memtok
(
item
->
identity
,
'.'
,
1
,
&
startIdx
);
if
(
!
rev
){
memcpy
(
tmp_Identity
,
item
->
identity
,
startIdx
);
rpc_cJSON_AddNumberToObject
(
root_color
,
item
->
identity
+
1
+
startIdx
,
g
_rgb
.
green
);
rpc_cJSON_AddNumberToObject
(
root_color
,
item
->
identity
+
1
+
startIdx
,
g
);
}
}
else
if
(
strstr
(
item
->
identity
,
".blue"
)
!=
NULL
){
...
...
@@ -456,7 +428,7 @@ int kk_tsl_report_colorControl_RGB(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId
rev
=
kk_tsl_utils_memtok
(
item
->
identity
,
'.'
,
1
,
&
startIdx
);
if
(
!
rev
){
memcpy
(
tmp_Identity
,
item
->
identity
,
startIdx
);
rpc_cJSON_AddNumberToObject
(
root_color
,
item
->
identity
+
1
+
startIdx
,
g_rgb
.
blue
);
rpc_cJSON_AddNumberToObject
(
root_color
,
item
->
identity
+
1
+
startIdx
,
b
);
}
}
item
=
item
->
next
;
...
...
@@ -469,6 +441,49 @@ int kk_tsl_report_colorControl_RGB(EmberEUI64 eui64,uint8_t EP,EmberAfClusterId
}
}
return
tsl_rpt_err
;
}
int
kk_tsl_report_colorControl_Brightness
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint8_t
value
=
data
[
0
];
emberAfAppPrintln
(
"[tsl report:kk_tsl_report_global_Brightness] value:%d
\n
"
,
value
);
if
(
dataType
==
ZCL_INT8U_ATTRIBUTE_TYPE
){
if
(
len
==
1
){
kk_tsl_report
(
eui64
,
EP
,
value
,
clusterId
,
attributeId
);
s_L
=
value
;
s_HSLCount
++
;
kk_tsl_report_colorControl_RGB_Str
(
eui64
);
if
(
s_HSLCount
>=
3
){
s_HSLCount
=
0
;
}
}
return
tsl_rpt_success
;
}
return
tsl_rpt_invaild_type
;
}
int
kk_tsl_report_colorControl_RGB
(
EmberEUI64
eui64
,
uint8_t
EP
,
EmberAfClusterId
clusterId
,
EmberAfAttributeId
attributeId
,
uint8_t
dataType
,
uint8_t
len
,
uint8_t
*
data
)
{
uint8_t
value
=
data
[
0
];
emberAfAppPrintln
(
"[tsl report:kk_tsl_report_global_RGB] value:%d
\n
"
,
value
);
if
(
dataType
==
ZCL_INT8U_ATTRIBUTE_TYPE
){
if
(
attributeId
==
0x0001
){
s_S
=
value
;
s_HSLCount
++
;
kk_tsl_report_colorControl_RGB_Str
(
eui64
);
}
else
if
(
attributeId
==
0x0
){
s_H
=
value
;
s_HSLCount
++
;
kk_tsl_report_colorControl_RGB_Str
(
eui64
);
}
}
return
tsl_rpt_success
;
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_tsl_property_set.c
View file @
89eb1e07
...
...
@@ -140,8 +140,10 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
}
else
{
propertyItem
=
rpc_cJSON_GetObjectItem
(
params
,
item
->
identity
);
if
(
propertyItem
!=
NULL
){
// printf("[%s][%d]item->identity:%s\n",__FUNCTION__,__LINE__,item->identity);
findFlag
=
1
;
}
}
...
...
@@ -154,7 +156,12 @@ cJSON *kk_tsl_property_operation(jrpc_context * ctx, cJSON *params, cJSON *id,cJ
value
=
propertyItem
->
valueint
;
}
func
=
item
->
controlFunc
;
if
(
func
!=
NULL
){
res
=
func
(
ctx
,
nodeId
,
item
->
endpoint
,
&
value
);
}
else
{
// printf("[%s][%d] can not find the func!!!\n",__FUNCTION__,__LINE__);
}
findFlag
=
0
;
}
item
=
item
->
next
;
...
...
@@ -302,21 +309,24 @@ error_return:
static
uint8_t
s_RgbCount
=
0
;
static
COLOR_RGB
s_rgb
;
static
int
kk_zclColorControlMovetohueandsat
(
EmberNodeId
node
,
unsigned
char
ep
)
{
int
h
,
s
,
l
;
unsigned
short
h
;
unsigned
short
s
,
l
;
COLOR_HSL
hsl
;
EmberStatus
status
=
0
;
if
(
s_RgbCount
>=
3
){
RGBtoHSL
(
&
s_rgb
,
&
hsl
);
//
RGBtoHSL(&s_rgb,&hsl);
emberAfAppPrintln
(
"[kk_zclColorControlMovetohueandsat]"
);
rgb_to_hsl
(
s_rgb
.
red
,
s_rgb
.
green
,
s_rgb
.
blue
,
h
,
s
,
l
);
status
=
zclColorControlMovetohueandsat
(
node
,
ep
,
h
*
254
,
s
*
254
,
0
,
0
,
0
,
0
);
RGB_to_HSL
(
s_rgb
.
red
,
s_rgb
.
green
,
s_rgb
.
blue
,
&
h
,
&
s
,
&
l
);
emberAfAppPrintln
(
"[kk_zclColorControlMovetohueandsat] h:%d,s:%d,l:%d
\n
,"
,
h
,
s
,
l
);
status
=
zclColorControlMovetohueandsat
(
node
,
ep
,
h
*
254
/
360
,
s
*
254
/
100
,
0
,
0
,
0
,
0
);
status
|=
zclLevel_MoveToLevel
(
node
,
ep
,
l
,
0
,
NULL
,
NULL
);
s_RgbCount
=
0
;
}
return
0
;
return
status
;
}
int
kk_tsl_set_colorlight_RGB_red
(
jrpc_context
*
ctx
,
EmberNodeId
node
,
unsigned
char
ep
,
void
*
data
)
{
...
...
@@ -384,6 +394,7 @@ int kk_tsl_set_colorlight_mode(jrpc_context * ctx,EmberNodeId node,unsigned char
mode
=
kk_find_extra_data
(
node
,
"Mode"
);
while
(
mode
!=
NULL
){
if
(
ix
++==
value
){
kk_global_len
=
mode
->
len
+
1
;
kk_global_buffer
[
0
]
=
mode
->
len
;
memcpy
(
&
kk_global_buffer
[
1
],
mode
->
data
,
kk_global_buffer
[
0
]
-
1
);
...
...
@@ -394,7 +405,7 @@ int kk_tsl_set_colorlight_mode(jrpc_context * ctx,EmberNodeId node,unsigned char
emberAfCorePrintln
(
"
\n
"
);
break
;
}
mode
->
next
;
mode
=
mode
->
next
;
}
...
...
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_zigbee_api.h
View file @
89eb1e07
...
...
@@ -26,13 +26,14 @@ void kk_rpc_test(void);
{
"kk_tsl_set_colorlight_RGB_green"
,
kk_tsl_set_colorlight_RGB_green
},
\
{
"kk_tsl_set_colorlight_RGB_blue"
,
kk_tsl_set_colorlight_RGB_blue
},
\
{
"kk_tsl_set_colorlight_Brightness"
,
kk_tsl_set_colorlight_Brightness
},
\
{
"kk_tsl_
report_colorControl
_mode"
,
kk_tsl_set_colorlight_mode
},
\
{
"kk_tsl_
set_colorlight
_mode"
,
kk_tsl_set_colorlight_mode
},
\
}
#define KK_RPC_REPORT_FUNCTION_TABLE {\
{
"kk_tsl_report_global_onoff"
,
kk_tsl_report_global_onoff
},
\
{
"kk_tsl_report_colorControl_Brightness"
,
kk_tsl_report_colorControl_Brightness
},
\
{
"kk_tsl_report_colorControl_RGB"
,
kk_tsl_report_colorControl_RGB
},
\
}
kk_rpc_set_api_s
kk_rpc_set_api
[];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment