From 5fc4394b5db47be27c298a16f3d5b39414469bf2 Mon Sep 17 00:00:00 2001 From: Markus Becker Date: Wed, 19 May 2021 15:52:42 +0200 Subject: [PATCH] Include occupancy sensor from SiLabs (#5731) * Add Occupancy sensor from SimplicityStudio v5 * Move to cpp * Adapt Occupancy Sensor Server Cluster to CHIP * Add Occupancy Sensor Server Cluster to all-clusters-app * Add Occupancy Sensing to the list of objects with init function * Add weak implementation of Occupancy Sensor Type * Add occupancy-sensor-server to ESP32 build * Restyled by whitespace * Restyled by clang-format * Apply review suggestions from Lukas Duda. * Remove commented code. * Enable OCCUPANCY_SENSING_CLUSTER/occupancy-sensor-server in zap_cluster_list.py * Add generated modified files Co-authored-by: Restyled.io --- .../all-clusters-common/all-clusters-app.zap | 97 ++++++++++++++ .../gen/call-command-handler.cpp | 5 + .../all-clusters-common/gen/callback-stub.cpp | 8 ++ .../all-clusters-common/gen/callback.h | 79 +++++++++++ .../all-clusters-common/gen/endpoint_config.h | 32 ++++- .../all-clusters-common/gen/gen_config.h | 6 + .../all-clusters-app/esp32/main/component.mk | 1 + .../occupancy-sensor-server/occupancy-hal.h | 63 +++++++++ .../occupancy-sensor-server.cpp | 126 ++++++++++++++++++ .../occupancy-sensor-server.h | 31 +++++ src/app/zap-templates/templates/app/helper.js | 3 +- src/app/zap_cluster_list.py | 4 +- 12 files changed, 446 insertions(+), 9 deletions(-) create mode 100644 src/app/clusters/occupancy-sensor-server/occupancy-hal.h create mode 100644 src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp create mode 100644 src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index 23a72f9b0d60ef..4566461a4677dd 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -13020,6 +13020,103 @@ } ] }, + { + "name": "Occupancy Sensing", + "code": 1030, + "mfgCode": null, + "define": "OCCUPANCY_SENSING_CLUSTER", + "side": "client", + "enabled": 0, + "commands": [], + "attributes": [ + { + "name": "cluster revision", + "code": 65533, + "mfgCode": null, + "side": "client", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "2", + "reportable": 0, + "minInterval": 0, + "maxInterval": 65344, + "reportableChange": 0 + } + ] + }, + { + "name": "Occupancy Sensing", + "code": 1030, + "mfgCode": null, + "define": "OCCUPANCY_SENSING_CLUSTER", + "side": "server", + "enabled": 1, + "commands": [], + "attributes": [ + { + "name": "cluster revision", + "code": 65533, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "2", + "reportable": 0, + "minInterval": 0, + "maxInterval": 65344, + "reportableChange": 0 + }, + { + "name": "occupancy", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 0, + "maxInterval": 65344, + "reportableChange": 0 + }, + { + "name": "occupancy sensor type", + "code": 1, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 0, + "maxInterval": 65344, + "reportableChange": 0 + }, + { + "name": "occupancy sensor type bitmap", + "code": 2, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 0, + "minInterval": 0, + "maxInterval": 65344, + "reportableChange": 0 + } + ] + }, { "name": "Temperature Measurement", "code": 1026, diff --git a/examples/all-clusters-app/all-clusters-common/gen/call-command-handler.cpp b/examples/all-clusters-app/all-clusters-common/gen/call-command-handler.cpp index 3bd9de82e6fd87..80edb083678ec4 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/call-command-handler.cpp +++ b/examples/all-clusters-app/all-clusters-common/gen/call-command-handler.cpp @@ -47,6 +47,7 @@ EmberAfStatus emberAfLowPowerClusterServerCommandParse(EmberAfClusterCommand * c EmberAfStatus emberAfNetworkCommissioningClusterServerCommandParse(EmberAfClusterCommand * cmd); EmberAfStatus emberAfOtaSoftwareUpdateClientClusterServerCommandParse(EmberAfClusterCommand * cmd); EmberAfStatus emberAfOtaSoftwareUpdateServerClusterServerCommandParse(EmberAfClusterCommand * cmd); +EmberAfStatus emberAfOccupancySensingClusterServerCommandParse(EmberAfClusterCommand * cmd); EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand * cmd); EmberAfStatus emberAfOperationalCredentialsClusterServerCommandParse(EmberAfClusterCommand * cmd); EmberAfStatus emberAfPumpConfigurationAndControlClusterServerCommandParse(EmberAfClusterCommand * cmd); @@ -161,6 +162,10 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd) case ZCL_OTA_SERVER_CLUSTER_ID: result = emberAfOtaSoftwareUpdateServerClusterServerCommandParse(cmd); break; + case ZCL_OCCUPANCY_SENSING_CLUSTER_ID: + // No commands are enabled for cluster Occupancy Sensing + result = status(false, true, cmd->mfgSpecific); + break; case ZCL_ON_OFF_CLUSTER_ID: result = emberAfOnOffClusterServerCommandParse(cmd); break; diff --git a/examples/all-clusters-app/all-clusters-common/gen/callback-stub.cpp b/examples/all-clusters-app/all-clusters-common/gen/callback-stub.cpp index aba6e42e22b945..b58383c0902168 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/callback-stub.cpp +++ b/examples/all-clusters-app/all-clusters-common/gen/callback-stub.cpp @@ -86,6 +86,9 @@ void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId) case ZCL_OTA_SERVER_CLUSTER_ID: emberAfOtaSoftwareUpdateServerClusterInitCallback(endpoint); break; + case ZCL_OCCUPANCY_SENSING_CLUSTER_ID: + emberAfOccupancySensingClusterInitCallback(endpoint); + break; case ZCL_ON_OFF_CLUSTER_ID: emberAfOnOffClusterInitCallback(endpoint); break; @@ -220,6 +223,11 @@ void __attribute__((weak)) emberAfOtaSoftwareUpdateServerClusterInitCallback(End // To prevent warning (void) endpoint; } +void __attribute__((weak)) emberAfOccupancySensingClusterInitCallback(EndpointId endpoint) +{ + // To prevent warning + (void) endpoint; +} void __attribute__((weak)) emberAfOnOffClusterInitCallback(EndpointId endpoint) { // To prevent warning diff --git a/examples/all-clusters-app/all-clusters-common/gen/callback.h b/examples/all-clusters-app/all-clusters-common/gen/callback.h index 2b6ae92c27e07d..3dbae3f35b85c6 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/callback.h +++ b/examples/all-clusters-app/all-clusters-common/gen/callback.h @@ -192,6 +192,14 @@ void emberAfOtaSoftwareUpdateClientClusterInitCallback(chip::EndpointId endpoint */ void emberAfOtaSoftwareUpdateServerClusterInitCallback(chip::EndpointId endpoint); +/** @brief Occupancy Sensing Cluster Init + * + * Cluster Init + * + * @param endpoint Endpoint that is being initialized + */ +void emberAfOccupancySensingClusterInitCallback(chip::EndpointId endpoint); + /** @brief On/off Cluster Init * * Cluster Init @@ -1623,6 +1631,77 @@ EmberAfStatus emberAfOtaSoftwareUpdateServerClusterServerPreAttributeChangedCall */ void emberAfOtaSoftwareUpdateServerClusterServerTickCallback(chip::EndpointId endpoint); +// +// Occupancy Sensing Cluster server +// + +/** @brief Occupancy Sensing Cluster Server Init + * + * Server Init + * + * @param endpoint Endpoint that is being initialized + */ +void emberAfOccupancySensingClusterServerInitCallback(chip::EndpointId endpoint); + +/** @brief Occupancy Sensing Cluster Server Attribute Changed + * + * Server Attribute Changed + * + * @param endpoint Endpoint that is being initialized + * @param attributeId Attribute that changed + */ +void emberAfOccupancySensingClusterServerAttributeChangedCallback(chip::EndpointId endpoint, chip::AttributeId attributeId); + +/** @brief Occupancy Sensing Cluster Server Manufacturer Specific Attribute Changed + * + * Server Manufacturer Specific Attribute Changed + * + * @param endpoint Endpoint that is being initialized + * @param attributeId Attribute that changed + * @param manufacturerCode Manufacturer Code of the attribute that changed + */ +void emberAfOccupancySensingClusterServerManufacturerSpecificAttributeChangedCallback(chip::EndpointId endpoint, + chip::AttributeId attributeId, + uint16_t manufacturerCode); + +/** @brief Occupancy Sensing Cluster Server Message Sent + * + * Server Message Sent + * + * @param type The type of message sent + * @param destination The destination to which the message was sent + * @param apsFrame The APS frame for the message + * @param msgLen The length of the message + * @param message The message that was sent + * @param status The status of the sent message + */ +void emberAfOccupancySensingClusterServerMessageSentCallback(EmberOutgoingMessageType type, + chip::MessageSendDestination destination, EmberApsFrame * apsFrame, + uint16_t msgLen, uint8_t * message, EmberStatus status); + +/** @brief Occupancy Sensing Cluster Server Pre Attribute Changed + * + * server Pre Attribute Changed + * + * @param endpoint Endpoint that is being initialized + * @param attributeId Attribute to be changed + * @param attributeType Attribute type + * @param size Attribute size + * @param value Attribute value + */ +EmberAfStatus emberAfOccupancySensingClusterServerPreAttributeChangedCallback(chip::EndpointId endpoint, + chip::AttributeId attributeId, + EmberAfAttributeType attributeType, uint16_t size, + uint8_t * value); + +/** @brief Occupancy Sensing Cluster Server Tick + * + * server Tick + * + * @param endpoint Endpoint that is being served + */ +void emberAfOccupancySensingClusterServerTickCallback(chip::EndpointId endpoint); + // // On/off Cluster server // diff --git a/examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h b/examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h index 61a61f39a79be0..8ab197abe41858 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h +++ b/examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h @@ -1179,7 +1179,7 @@ #define ZAP_ATTRIBUTE_MASK(mask) ATTRIBUTE_MASK_##mask // This is an array of EmberAfAttributeMetadata structures. -#define GENERATED_ATTRIBUTE_COUNT 250 +#define GENERATED_ATTRIBUTE_COUNT 254 #define GENERATED_ATTRIBUTES \ { \ \ @@ -1512,6 +1512,12 @@ /* Endpoint: 2, Cluster: On/off (server) */ \ { 0x0000, ZAP_TYPE(BOOLEAN), 1, 0, ZAP_SIMPLE_DEFAULT(0x00) }, /* on/off */ \ { 0xFFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(2) }, /* cluster revision */ \ + \ + /* Endpoint: 2, Cluster: Occupancy Sensing (server) */ \ + { 0x0000, ZAP_TYPE(BITMAP8), 1, 0, ZAP_EMPTY_DEFAULT() }, /* occupancy */ \ + { 0x0001, ZAP_TYPE(ENUM8), 1, 0, ZAP_EMPTY_DEFAULT() }, /* occupancy sensor type */ \ + { 0x0002, ZAP_TYPE(BITMAP8), 1, 0, ZAP_EMPTY_DEFAULT() }, /* occupancy sensor type bitmap */ \ + { 0xFFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(2) }, /* cluster revision */ \ } // This is an array of EmberAfCluster structures. @@ -1548,10 +1554,13 @@ (EmberAfGenericClusterFunction) emberAfIasZoneClusterServerInitCallback, \ (EmberAfGenericClusterFunction) emberAfIasZoneClusterServerMessageSentCallback, \ (EmberAfGenericClusterFunction) emberAfIasZoneClusterServerPreAttributeChangedCallback, \ + }; \ + const EmberAfGenericClusterFunction chipFuncArrayOccupancySensingServer[] = { \ + (EmberAfGenericClusterFunction) emberAfOccupancySensingClusterServerInitCallback, \ }; #define ZAP_CLUSTER_MASK(mask) CLUSTER_MASK_##mask -#define GENERATED_CLUSTER_COUNT 33 +#define GENERATED_CLUSTER_COUNT 34 #define GENERATED_CLUSTERS \ { \ { \ @@ -1684,6 +1693,12 @@ 3, \ ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \ chipFuncArrayOnOffServer }, /* Endpoint: 2, Cluster: On/off (server) */ \ + { 0x0406, \ + ZAP_ATTRIBUTE_INDEX(250), \ + 4, \ + 5, \ + ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(INIT_FUNCTION), \ + chipFuncArrayOccupancySensingServer }, /* Endpoint: 2, Cluster: Occupancy Sensing (server) */ \ } #define ZAP_CLUSTER_INDEX(index) ((EmberAfCluster *) (&generatedClusters[index])) @@ -1691,7 +1706,7 @@ // This is an array of EmberAfEndpointType structures. #define GENERATED_ENDPOINT_TYPES \ { \ - { ZAP_CLUSTER_INDEX(0), 12, 3726 }, { ZAP_CLUSTER_INDEX(12), 20, 2130 }, { ZAP_CLUSTER_INDEX(32), 1, 3 }, \ + { ZAP_CLUSTER_INDEX(0), 12, 3726 }, { ZAP_CLUSTER_INDEX(12), 20, 2130 }, { ZAP_CLUSTER_INDEX(32), 2, 8 }, \ } // Largest attribute size is needed for various buffers @@ -1701,7 +1716,7 @@ #define ATTRIBUTE_SINGLETONS_SIZE (875) // Total size of attribute storage -#define ATTRIBUTE_MAX_SIZE (5859) +#define ATTRIBUTE_MAX_SIZE (5864) // Number of fixed endpoints #define FIXED_ENDPOINT_COUNT (3) @@ -1971,10 +1986,10 @@ #define ZAP_REPORT_DIRECTION(x) ZRD(x) // User options for plugin Reporting -#define EMBER_AF_PLUGIN_REPORTING_TABLE_SIZE (13) +#define EMBER_AF_PLUGIN_REPORTING_TABLE_SIZE (14) #define EMBER_AF_PLUGIN_REPORTING_ENABLE_GROUP_BOUND_REPORTS -#define EMBER_AF_GENERATED_REPORTING_CONFIG_DEFAULTS_TABLE_SIZE (13) +#define EMBER_AF_GENERATED_REPORTING_CONFIG_DEFAULTS_TABLE_SIZE (14) #define EMBER_AF_GENERATED_REPORTING_CONFIG_DEFAULTS \ { \ \ @@ -2034,4 +2049,9 @@ { \ ZAP_REPORT_DIRECTION(REPORTED), 0x0002, 0x0006, 0x0000, ZAP_CLUSTER_MASK(SERVER), 0x0000, { { 0, 65344, 0 } } \ }, /* on/off */ \ + \ + /* Endpoint: 2, Cluster: Occupancy Sensing (server) */ \ + { \ + ZAP_REPORT_DIRECTION(REPORTED), 0x0002, 0x0406, 0x0000, ZAP_CLUSTER_MASK(SERVER), 0x0000, { { 0, 65344, 0 } } \ + }, /* occupancy */ \ } diff --git a/examples/all-clusters-app/all-clusters-common/gen/gen_config.h b/examples/all-clusters-app/all-clusters-common/gen/gen_config.h index b485a36bebf8df..264dd3962c0f07 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/gen_config.h +++ b/examples/all-clusters-app/all-clusters-common/gen/gen_config.h @@ -48,6 +48,7 @@ #define EMBER_AF_NETWORK_COMMISSIONING_CLUSTER_SERVER_ENDPOINT_COUNT (1) #define EMBER_AF_OTA_CLIENT_CLUSTER_SERVER_ENDPOINT_COUNT (1) #define EMBER_AF_OTA_SERVER_CLUSTER_SERVER_ENDPOINT_COUNT (1) +#define EMBER_AF_OCCUPANCY_SENSING_CLUSTER_SERVER_ENDPOINT_COUNT (1) #define EMBER_AF_ON_OFF_CLUSTER_SERVER_ENDPOINT_COUNT (2) #define EMBER_AF_OPERATIONAL_CREDENTIALS_CLUSTER_SERVER_ENDPOINT_COUNT (1) #define EMBER_AF_PUMP_CONFIG_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT (1) @@ -167,6 +168,11 @@ #define EMBER_AF_PLUGIN_OTA_SOFTWARE_UPDATE_SERVER_SERVER #define EMBER_AF_PLUGIN_OTA_SOFTWARE_UPDATE_SERVER +// Use this macro to check if the server side of the Occupancy Sensing cluster is included +#define ZCL_USING_OCCUPANCY_SENSING_CLUSTER_SERVER +#define EMBER_AF_PLUGIN_OCCUPANCY_SENSING_SERVER +#define EMBER_AF_PLUGIN_OCCUPANCY_SENSING + // Use this macro to check if the server side of the On/off cluster is included #define ZCL_USING_ON_OFF_CLUSTER_SERVER #define EMBER_AF_PLUGIN_ON_OFF_SERVER diff --git a/examples/all-clusters-app/esp32/main/component.mk b/examples/all-clusters-app/esp32/main/component.mk index e8c22cb7db5fba..bacfb33784819b 100644 --- a/examples/all-clusters-app/esp32/main/component.mk +++ b/examples/all-clusters-app/esp32/main/component.mk @@ -56,6 +56,7 @@ COMPONENT_SRCDIRS := ../third_party/connectedhomeip/src/app/clusters/bindings \ ../third_party/connectedhomeip/src/app/reporting \ ../third_party/connectedhomeip/src/app/clusters/door-lock-server \ + ../third_party/connectedhomeip/src/app/clusters/occupancy-sensor-server \ ../third_party/connectedhomeip/src/app/clusters/ias-zone-server \ # ../third_party/connectedhomeip/src/app/clusters/ias-zone-client \ diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-hal.h b/src/app/clusters/occupancy-sensor-server/occupancy-hal.h new file mode 100644 index 00000000000000..1943a790e75af1 --- /dev/null +++ b/src/app/clusters/occupancy-sensor-server/occupancy-hal.h @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +// enum used to track the type of occupancy sensor being implemented +typedef enum +{ + HAL_OCCUPANCY_SENSOR_TYPE_PIR = 0x00, + HAL_OCCUPANCY_SENSOR_TYPE_ULTRASONIC = 0x01, + HAL_OCCUPANCY_SENSOR_TYPE_PIR_AND_ULTRASONIC = 0x02, + HAL_OCCUPANCY_SENSOR_TYPE_PHYSICAL = 0x03, +} HalOccupancySensorType; + +typedef enum +{ + HAL_OCCUPANCY_STATE_UNOCCUPIED = 0x00, + HAL_OCCUPANCY_STATE_OCCUPIED = 0x01, +} HalOccupancyState; + +/** @brief Initializes the occupancy sensor, along with any hardware + * peripherals necessary to interface with the hardware. The application + * framework will generally initialize this plugin automatically. Customers who + * do not use the framework must ensure the plugin is initialized by calling + * this function. + */ +void halOccupancyInit(chip::EndpointId endpoint); + +/** @brief Get the hardware mechanism used to detect occupancy + * + * This function should be used to determine what kind of hardware mechanism + * is driving the occupancy functionality. + * + * @return HAL_OCCUPANCY_SENSOR_TYPE_PIR, HAL_OCCUPANCY_SENSOR_TYPE_ULTRASONIC, + * or HAL_OCCUPANCY_SENSOR_TYPE_PIR_AND_ULTRASONIC, which are defined to match + * the values used by the ZCL defined SensorType attribute + */ +HalOccupancySensorType halOccupancyGetSensorType(chip::EndpointId endpoint); + +/** @brief Notify the system of a change in occupancy state + * + * This function will be called whenever the occupancy state of the system + * changes. + * + * @param occupancyState The new occupancy state + */ +void halOccupancyStateChangedCallback(chip::EndpointId endpoint, HalOccupancyState occupancyState); diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp new file mode 100644 index 00000000000000..a5f9d2c5bacd5d --- /dev/null +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp @@ -0,0 +1,126 @@ +/** + * + * Copyright (c) 2020 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * + * Copyright (c) 2020 Silicon Labs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/***************************************************************************/ +/** + * @file + * @brief Routines for the Occupancy plugin, which + *implements the Occupancy server cluster. + ******************************************************************************* + ******************************************************************************/ +#include "occupancy-sensor-server.h" + +#include + +#include +#include + +#include "gen/att-storage.h" +#include "gen/attribute-id.h" +#include "gen/attribute-type.h" +#include "gen/cluster-id.h" +#include "gen/command-id.h" +#include "gen/enums.h" + +#include "occupancy-hal.h" + +#ifdef EMBER_AF_PLUGIN_REPORTING +#include +#endif + +using namespace chip; + +//****************************************************************************** +// Plugin init function +//****************************************************************************** +void emberAfOccupancySensingClusterServerInitCallback(chip::EndpointId endpoint) +{ + HalOccupancySensorType deviceType; + + deviceType = halOccupancyGetSensorType(endpoint); + + emberAfWriteAttribute(endpoint, ZCL_OCCUPANCY_SENSING_CLUSTER_ID, ZCL_OCCUPANCY_SENSOR_TYPE_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, + (uint8_t *) &deviceType, ZCL_ENUM8_ATTRIBUTE_TYPE); + + uint8_t deviceTypeBitmap = 0; + switch (deviceType) + { + case HAL_OCCUPANCY_SENSOR_TYPE_PIR: + deviceTypeBitmap = EMBER_AF_OCCUPANCY_SENSOR_TYPE_BITMAP_PIR; + break; + + case HAL_OCCUPANCY_SENSOR_TYPE_ULTRASONIC: + deviceTypeBitmap = EMBER_AF_OCCUPANCY_SENSOR_TYPE_BITMAP_ULTRASONIC; + break; + + case HAL_OCCUPANCY_SENSOR_TYPE_PIR_AND_ULTRASONIC: + deviceTypeBitmap = (EMBER_AF_OCCUPANCY_SENSOR_TYPE_BITMAP_PIR | EMBER_AF_OCCUPANCY_SENSOR_TYPE_BITMAP_ULTRASONIC); + break; + + case HAL_OCCUPANCY_SENSOR_TYPE_PHYSICAL: + deviceTypeBitmap = EMBER_AF_OCCUPANCY_SENSOR_TYPE_BITMAP_PHYSICAL_CONTACT; + break; + + default: + break; + } + emberAfWriteAttribute(endpoint, ZCL_OCCUPANCY_SENSING_CLUSTER_ID, ZCL_OCCUPANCY_SENSOR_TYPE_BITMAP_ATTRIBUTE_ID, + CLUSTER_MASK_SERVER, &deviceTypeBitmap, ZCL_BITMAP8_ATTRIBUTE_TYPE); + + emberAfPluginOccupancyClusterServerPostInitCallback(endpoint); +} + +//****************************************************************************** +// Notification callback from the HAL plugin +//****************************************************************************** +void halOccupancyStateChangedCallback(EndpointId endpoint, HalOccupancyState occupancyState) +{ + if (occupancyState == HAL_OCCUPANCY_STATE_OCCUPIED) + { + emberAfOccupancySensingClusterPrintln("Occupancy detected"); + } + else + { + emberAfOccupancySensingClusterPrintln("Occupancy no longer detected"); + } + + emberAfWriteAttribute(endpoint, ZCL_OCCUPANCY_SENSING_CLUSTER_ID, ZCL_OCCUPANCY_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, + (uint8_t *) &occupancyState, ZCL_BITMAP8_ATTRIBUTE_TYPE); +} + +void emberAfPluginOccupancyClusterServerPostInitCallback(EndpointId endpoint) {} + +HalOccupancySensorType __attribute__((weak)) halOccupancyGetSensorType(chip::EndpointId endpoint) +{ + return HAL_OCCUPANCY_SENSOR_TYPE_PIR; +} diff --git a/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h new file mode 100644 index 00000000000000..3ed762cbfb4013 --- /dev/null +++ b/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.h @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +/** @brief Occupancy Cluster Server Post Init + * + * Following resolution of the Occupancy state at startup for this endpoint, + * perform any additional initialization needed; e.g., synchronize hardware + * state. + * + * @param endpoint Endpoint that is being initialized Ver.: always + */ +void emberAfPluginOccupancyClusterServerPostInitCallback(chip::EndpointId endpoint); diff --git a/src/app/zap-templates/templates/app/helper.js b/src/app/zap-templates/templates/app/helper.js index 7a9a6e4bf67066..2cc69780681bf6 100644 --- a/src/app/zap-templates/templates/app/helper.js +++ b/src/app/zap-templates/templates/app/helper.js @@ -195,7 +195,8 @@ function asChipUnderlyingType(label, type) // These helpers only works within the endpoint_config iterator // List of all cluster with generated functions -var endpointClusterWithInit = [ 'Basic', 'Identify', 'Groups', 'Scenes', 'On/off', 'Level Control', 'Color Control', 'IAS Zone' ]; +var endpointClusterWithInit = + [ 'Basic', 'Identify', 'Groups', 'Scenes', 'Occupancy Sensing', 'On/off', 'Level Control', 'Color Control', 'IAS Zone' ]; var endpointClusterWithAttributeChanged = [ 'Identify', 'Door Lock' ]; var endpointClusterWithPreAttribute = [ 'IAS Zone' ]; var endpointClusterWithMessageSent = [ 'IAS Zone' ]; diff --git a/src/app/zap_cluster_list.py b/src/app/zap_cluster_list.py index f54cbaf6424aa3..57fe013cc90123 100755 --- a/src/app/zap_cluster_list.py +++ b/src/app/zap_cluster_list.py @@ -36,7 +36,7 @@ 'MEDIA_INPUT_CLUSTER': ['media-input-server'], 'MEDIA_PLAYBACK_CLUSTER': ['media-playback-server'], 'NETWORK_COMMISSIONING_CLUSTER': ['network-commissioning'], - 'OCCUPANCY_SENSING_CLUSTER': [], + 'OCCUPANCY_SENSING_CLUSTER': ['occupancy-sensor-server'], 'ON_OFF_CLUSTER': ['on-off-server'], 'OPERATIONAL_CREDENTIALS_CLUSTER': ['operational-credentials-server'], 'OTA_BOOTLOAD_CLUSTER': [], @@ -88,7 +88,7 @@ 'MEDIA_INPUT_CLUSTER': [], 'MEDIA_PLAYBACK_CLUSTER': [], 'NETWORK_COMMISSIONING_CLUSTER': [], - 'OCCUPANCY_SENSING_CLUSTER': [], + 'OCCUPANCY_SENSING_CLUSTER': ['occupancy-sensor-server'], 'ON_OFF_CLUSTER': [], 'OPERATIONAL_CREDENTIALS_CLUSTER': [], 'OTA_BOOTLOAD_CLUSTER': [],