Skip to content

Commit

Permalink
Added an RVC app example containg the RvcRunMode and RvcClean clusters.
Browse files Browse the repository at this point in the history
  • Loading branch information
hicklin committed Sep 1, 2023
1 parent 3e6fec6 commit 1079264
Show file tree
Hide file tree
Showing 12 changed files with 12,842 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/rvc-app/linux/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

import("//build_overrides/build.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
import("//args.gni")
}
51 changes: 51 additions & 0 deletions examples/rvc-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

config("includes") {
include_dirs = [
".",
"include",
]
}

executable("chip-rvc-app") {
sources = [
"${chip_root}/examples/rvc-app/rvc-common/src/rvc-mode-delegates.cpp",
"include/CHIPProjectAppConfig.h",
"main.cpp",
]

deps = [
"${chip_root}/examples/rvc-app/rvc-common",
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/src/lib",
]

include_dirs = [
"include",
"${chip_root}/examples/rvc-app/rvc-common/include",
]
output_dir = root_out_dir
}

group("linux") {
deps = [ ":chip-rvc-app" ]
}

group("default") {
deps = [ ":linux" ]
}
25 changes: 25 additions & 0 deletions examples/rvc-app/linux/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

import("//build_overrides/chip.gni")

import("${chip_root}/config/standalone/args.gni")

chip_device_project_config_include = "<CHIPProjectAppConfig.h>"
chip_project_config_include = "<CHIPProjectAppConfig.h>"
chip_system_project_config_include = "<SystemProjectConfig.h>"

chip_project_config_include_dirs =
[ "${chip_root}/examples/rvc-app/linux/include" ]
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]
1 change: 1 addition & 0 deletions examples/rvc-app/linux/build_overrides
35 changes: 35 additions & 0 deletions examples/rvc-app/linux/include/CHIPProjectAppConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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
* Example project configuration file for CHIP.
*
* This is a place to put application or project-specific overrides
* to the default configuration values for general CHIP features.
*
*/

#pragma once

// include the CHIPProjectConfig from config/standalone
#include <CHIPProjectConfig.h>

#define CHIP_DEVICE_CONFIG_DEVICE_TYPE 116 // 0x0074 = 117 = Matter Robotic Vacuum Cleaner
#define CHIP_DEVICE_CONFIG_DEVICE_NAME "Test RVC"

42 changes: 42 additions & 0 deletions examples/rvc-app/linux/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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.
*/
#include "rvc-mode-delegates.h"
#include <AppMain.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;

void ApplicationInit() {}

void ApplicationShutdown()
{
Clusters::RvcCleanMode::Shutdown();
Clusters::RvcRunMode::Shutdown();
}

int main(int argc, char * argv[])
{
if (ChipLinuxAppInit(argc, argv) != 0)
{
return -1;
}

ChipLinuxAppMainLoop();
return 0;
}
1 change: 1 addition & 0 deletions examples/rvc-app/linux/third_party/connectedhomeip
28 changes: 28 additions & 0 deletions examples/rvc-app/rvc-common/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

import("//build_overrides/chip.gni")
import("${chip_root}/src/app/chip_data_model.gni")

config("config") {
include_dirs = [ "include" ]
}

chip_data_model("rvc-common") {
zap_file = "rvc-app.zap"

zap_pregenerated_dir =
"${chip_root}/zzz_generated/rvc-app/zap-generated"
is_server = true
}
118 changes: 118 additions & 0 deletions examples/rvc-app/rvc-common/include/rvc-mode-delegates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 <app/clusters/mode-base-server/mode-base-server.h>
#include <app/util/af.h>
#include <app/util/config.h>
#include <cstring>
#include <utility>

namespace chip {
namespace app {
namespace Clusters {

namespace RvcRunMode {

const uint8_t ModeIdle = 0;
const uint8_t ModeCleaning = 1;
const uint8_t ModeMapping = 2;

/// This is an application level delegate to handle RvcRun commands according to the specific business logic.
class RvcRunModeDelegate : public ModeBase::Delegate
{
private:
using ModeTagStructType = detail::Structs::ModeTagStruct::Type;
ModeTagStructType ModeTagsIdle[1] = { { .value = to_underlying(ModeTag::kIdle) } };
ModeTagStructType ModeTagsCleaning[1] = { { .value = to_underlying(ModeTag::kCleaning) } };

const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = {
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Idle"),
.mode = ModeIdle,
.modeTags = DataModel::List<const ModeTagStructType>(ModeTagsIdle) },
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Cleaning"),
.mode = ModeCleaning,
.modeTags = DataModel::List<const ModeTagStructType>(ModeTagsCleaning) },
detail::Structs::ModeOptionStruct::Type{
.label = CharSpan::fromCharString("Mapping"),
.mode = ModeMapping,
.modeTags = DataModel::List<const ModeTagStructType>(ModeTagsIdle) }, // todo set to no mode tags
};

CHIP_ERROR Init() override;
void HandleChangeToMode(uint8_t mode, ModeBase::Commands::ChangeToModeResponse::Type & response) override;

CHIP_ERROR GetModeLabelByIndex(uint8_t modeIndex, MutableCharSpan & label) override;
CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override;
CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<ModeTagStructType> & tags) override;

public:
~RvcRunModeDelegate() override = default;
};

void Shutdown();

} // namespace RvcRunMode

namespace RvcCleanMode {

const uint8_t ModeVacuum = 0;
const uint8_t ModeWash = 1;
const uint8_t ModeDeepClean = 2;

/// This is an application level delegate to handle RvcClean commands according to the specific business logic.
class RvcCleanModeDelegate : public ModeBase::Delegate
{
private:
using ModeTagStructType = detail::Structs::ModeTagStruct::Type;
ModeTagStructType modeTagsVac[1] = { { .value = to_underlying(ModeTag::kVacuum) } };
ModeTagStructType modeTagsMop[1] = { { .value = to_underlying(ModeTag::kMop) } };
ModeTagStructType modeTagsBoost[2] = { { .value = to_underlying(ModeBase::ModeTag::kMax) },
{ .value = to_underlying(ModeTag::kDeepClean) } };

const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = {
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Vacuum"),
.mode = ModeVacuum,
.modeTags = DataModel::List<const ModeTagStructType>(modeTagsVac) },
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Wash"),
.mode = ModeWash,
.modeTags = DataModel::List<const ModeTagStructType>(modeTagsMop) },
detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Deep clean"),
.mode = ModeDeepClean,
.modeTags = DataModel::List<const ModeTagStructType>(modeTagsBoost) },
};

CHIP_ERROR Init() override;
void HandleChangeToMode(uint8_t mode, ModeBase::Commands::ChangeToModeResponse::Type & response) override;

CHIP_ERROR GetModeLabelByIndex(uint8_t modeIndex, MutableCharSpan & label) override;
CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override;
CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<ModeTagStructType> & tags) override;

public:
~RvcCleanModeDelegate() override = default;
};

void Shutdown();

} // namespace RvcCleanMode

} // namespace Clusters
} // namespace app
} // namespace chip
Loading

0 comments on commit 1079264

Please sign in to comment.