Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ameba] Add examples/lighting-app #12092

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/lighting-app/ameba/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.vscode

/build/
/sdkconfig
/sdkconfig.old
108 changes: 108 additions & 0 deletions examples/lighting-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
cmake_minimum_required(VERSION 3.6)

project(chip_main)

set(chip_dir "${ameba_matter_root}")
set(chip_dir_output "${matter_output_path}/chip")
set(dir "${sdk_root}/component/common/api")
set(chip_main chip_main)
set(list_chip_main_sources chip_main_sources)

include(${prj_root}/GCC-RELEASE/project_hp/asdk/includepath.cmake)

list(
APPEND ${list_chip_main_sources}

#chip app
${chip_dir}/src/app/Command.cpp
${chip_dir}/src/app/CommandHandler.cpp
${chip_dir}/src/app/InteractionModelEngine.cpp
${chip_dir}/src/app/CommandSender.cpp
${chip_dir}/src/app/decoder.cpp
${chip_dir}/src/app/encoder-common.cpp
${chip_dir}/src/app/EventManagement.cpp
${chip_dir}/src/app/ReadClient.cpp
${chip_dir}/src/app/ReadHandler.cpp
${chip_dir}/src/app/WriteClient.cpp
${chip_dir}/src/app/WriteHandler.cpp
${chip_dir}/src/app/util/CHIPDeviceCallbacksMgr.cpp
${chip_dir}/src/app/util/esi-management.cpp
${chip_dir}/src/app/reporting/Engine.cpp

${chip_dir}/zzz_generated/lighting-app/zap-generated/attribute-size.cpp
${chip_dir}/zzz_generated/lighting-app/zap-generated/CHIPClientCallbacks.cpp
${chip_dir}/zzz_generated/lighting-app/zap-generated/callback-stub.cpp
${chip_dir}/zzz_generated/lighting-app/zap-generated/IMClusterCommandHandler.cpp
${chip_dir}/zzz_generated/lighting-app/zap-generated/CHIPClusters.cpp

${chip_dir}/examples/lighting-app/lighting-common/color_format/color_format.cpp

${chip_dir}/examples/lighting-app/ameba/main/chipinterface.cpp
${chip_dir}/examples/lighting-app/ameba/main/DeviceCallbacks.cpp
${chip_dir}/examples/lighting-app/ameba/main/CHIPDeviceManager.cpp
${chip_dir}/examples/lighting-app/ameba/main/Globals.cpp
${chip_dir}/examples/lighting-app/ameba/main/LEDWidget.cpp
)

add_library(
${chip_main}
STATIC
${chip_main_sources}
)

chip_configure_data_model(chip_main
INCLUDE_SERVER
ZAP_FILE ${matter_example_path}/../lighting-common/lighting-app.zap
)

target_include_directories(
${chip_main}
PUBLIC
${inc_path}
${chip_dir}/zzz_generated/lighting-app
${chip_dir}/zzz_generated/lighting-app/zap-generated
${chip_dir}/zzz_generated/app-common
${chip_dir}/examples/lighting-app/lighting-common
${chip_dir}/examples/lighting-app/lighting-common/color_format
${chip_dir}/examples/lighting-app/ameba/main/include
${chip_dir_output}/gen/include
${chip_dir}/src/include/
${chip_dir}/src/lib/
${chip_dir}/src/
${chip_dir}/third_party/nlassert/repo/include/
${chip_dir}/src/app/
${chip_dir}/src/app/util/
${chip_dir}/src/app/server/
${chip_dir}/src/controller/data_model
${chip_dir}/third_party/nlio/repo/include/
${chip_dir}/third_party/nlunit-test/repo/src
)

list(
APPEND chip_main_flags

-DINET_CONFIG_ENABLE_IPV4=1
-DCHIP_PROJECT=1
-DCHIP_DEVICE_LAYER_TARGET=Ameba
-DUSE_ZAP_CONFIG
-DCHIP_HAVE_CONFIG_H
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
)

list(
APPEND chip_main_cpp_flags

-Wno-unused-parameter
-std=gnu++11
-std=c++14
-fno-rtti
)
target_compile_definitions(${chip_main} PRIVATE ${chip_main_flags} )
target_compile_options(${chip_main} PRIVATE ${chip_main_cpp_flags})

# move static library post build command
add_custom_command(
TARGET ${chip_main}
POST_BUILD
COMMAND cp lib${chip_main}.a ${CMAKE_CURRENT_SOURCE_DIR}/lib/application
)
173 changes: 173 additions & 0 deletions examples/lighting-app/ameba/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
*
* 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.
*/

/**
* @file
* This file implements the CHIP Device Interface that is used by
* applications to interact with the CHIP stack
*
*/

#include <stdlib.h>

#include "CHIPDeviceManager.h"
#include <app/util/basic-types.h>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>

#include "Globals.h"
#include "LEDWidget.h"

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/command-id.h>
#include <app/util/af-types.h>
#include <app/util/attribute-storage.h>
#include <app/util/util.h>

using namespace ::chip;

namespace chip {

namespace DeviceManager {

using namespace ::chip::DeviceLayer;

void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg)
{
CHIPDeviceManagerCallbacks * cb = reinterpret_cast<CHIPDeviceManagerCallbacks *>(arg);
if (cb != nullptr)
{
cb->DeviceEventCallback(event, reinterpret_cast<intptr_t>(cb));
}
}

CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
{
CHIP_ERROR err;
mCB = cb;

err = PlatformMgr().InitChipStack();
SuccessOrExit(err);

if (CONFIG_NETWORK_LAYER_BLE)
{
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
}

err = Platform::MemoryInit();
SuccessOrExit(err);

PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb));

// // Start a task to run the CHIP Device event loop.
err = PlatformMgr().StartEventLoopTask();
if (err != CHIP_NO_ERROR)
{
printf("StartEventLoopTask() - ERROR!\r\n");
}
else
{
printf("StartEventLoopTask() - OK\r\n");
}

exit:
return err;
}
} // namespace DeviceManager
} // namespace chip

void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type,
uint16_t size, uint8_t * value)
{
chip::DeviceManager::CHIPDeviceManagerCallbacks * cb =
chip::DeviceManager::CHIPDeviceManager::GetInstance().GetCHIPDeviceManagerCallbacks();

EndpointId endpointId = attributePath.mEndpointId;
ClusterId clusterId = attributePath.mClusterId;
AttributeId attributeId = attributePath.mAttributeId;

if (clusterId == ZCL_ON_OFF_CLUSTER_ID)
{
if (attributeId != ZCL_ON_OFF_ATTRIBUTE_ID)
{
ChipLogProgress(Zcl, "Unknown attribute ID: %" PRIx32, attributeId);
return;
}

statusLED1.Set(*value);
}
else if (clusterId == ZCL_LEVEL_CONTROL_CLUSTER_ID)
{
if (attributeId != ZCL_CURRENT_LEVEL_ATTRIBUTE_ID)
{
ChipLogProgress(Zcl, "Unknown attribute ID: %" PRIx32, attributeId);
return;
}
if (size == 1)
{
// ChipLogProgress(Zcl, "New level: %u ", *value);
}
else
{
ChipLogError(Zcl, "wrong length for level: %d\n", size);
}
}
else if (clusterId == ZCL_COLOR_CONTROL_CLUSTER_ID)
{
uint8_t hue, saturation;

if ((attributeId != ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) &&
(attributeId != ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID))
{
ChipLogProgress(Zcl, "Unknown attribute ID: %" PRIx32, attributeId);
return;
}

if (attributeId == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID)
{
hue = *value;
emberAfReadServerAttribute(endpointId, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID,
&saturation, sizeof(uint8_t));
}
if (attributeId == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID)
{
saturation = *value;
emberAfReadServerAttribute(endpointId, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID, &hue,
sizeof(uint8_t));
}
ChipLogProgress(Zcl, "New hue: %d, New saturation: %d ", hue, saturation);
}
else if (clusterId == ZCL_IDENTIFY_CLUSTER_ID)
{
if (attributeId == ZCL_IDENTIFY_TIME_ATTRIBUTE_ID)
{
if (cb != nullptr)
{
cb->PostAttributeChangeCallback(endpointId, clusterId, attributeId, mask, type, size, value);
}
ChipLogProgress(Zcl, "ZCL_IDENTIFY_TIME_ATTRIBUTE_ID value: %u ", *value);
}
}
else
{
// ChipLogProgress(Zcl, "Unknown cluster ID: %" PRIx32, clusterId);
return;
}
}
Loading