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

Align joiner functionality on ncs example with other platforms #2261

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
1 change: 1 addition & 0 deletions config/nrfconnect/nrfconnect-app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ chip_configure(ChipConfig
ARCH arm-none-eabi
CFLAGS ${CHIP_COMMON_FLAGS} --specs=nosys.specs
CXXFLAGS ${CHIP_COMMON_FLAGS}
PROJECT_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/main/include/CHIPProjectConfig.h
)

chip_build(ChipLib ChipConfig
Expand Down
5 changes: 4 additions & 1 deletion examples/lock-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ position to another.
used to mimick a user manually operating the lock. The button behaves as a
toggle, swapping the state every time it is pressed.

The remaining two LEDs and buttons (#3 and #4) are unused.
**Button #3** can be used to trigger a thread joiner. It should be use to
commission to the thread network. Credentials will be presented in log messages.

The remaining two LEDs (#3 and #4) and button #4 are unused.

<a name="building"></a>

Expand Down
22 changes: 22 additions & 0 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ void AppTask::ButtonEventHandler(uint32_t button_state, uint32_t has_changed)
button_event.Handler = FunctionHandler;
sAppTask.PostEvent(&button_event);
}

if (JOINER_BUTTON_MASK & button_state & has_changed)
{
button_event.ButtonEvent.PinNo = JOINER_BUTTON;
button_event.ButtonEvent.Action = BUTTON_PUSH_EVENT;
button_event.Handler = JoinerHandler;
sAppTask.PostEvent(&button_event);
}
}

void AppTask::TimerEventHandler(k_timer * timer)
Expand Down Expand Up @@ -299,6 +307,20 @@ void AppTask::FunctionHandler(AppEvent * aEvent)
}
}

void AppTask::JoinerHandler(AppEvent * aEvent)
{
if (aEvent->ButtonEvent.PinNo != JOINER_BUTTON)
return;

CHIP_ERROR error = CHIP_ERROR_NOT_IMPLEMENTED;

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
error = ThreadStackMgr().JoinerStart();
#endif

LOG_INF("Thread joiner triggering result: %s", chip::ErrorStr(error));
}

void AppTask::CancelTimer()
{
k_timer_stop(&sFunctionTimer);
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AppTask

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void FunctionHandler(AppEvent * aEvent);
static void JoinerHandler(AppEvent * aEvent);
static void LockActionEventHandler(AppEvent * aEvent);

static void ButtonEventHandler(uint32_t buttons_state, uint32_t has_changed);
Expand Down
35 changes: 35 additions & 0 deletions examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* Copyright (c) 2020 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.
*
*/

#ifndef CHIP_PROJECT_CONFIG_H
#define CHIP_PROJECT_CONFIG_H

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 12345678
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00

#endif // CHIP_PROJECT_CONFIG_H
2 changes: 2 additions & 0 deletions examples/lock-app/nrfconnect/main/include/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define LOCK_BUTTON_MASK DK_BTN2_MSK
#define FUNCTION_BUTTON DK_BTN1
#define FUNCTION_BUTTON_MASK DK_BTN1_MSK
#define JOINER_BUTTON DK_BTN3
#define JOINER_BUTTON_MASK DK_BTN3_MSK

#define SYSTEM_STATE_LED DK_LED1
#define LOCK_STATE_LED DK_LED2
Expand Down
2 changes: 2 additions & 0 deletions examples/lock-app/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ CONFIG_OPENTHREAD_BORDER_AGENT=y
CONFIG_OPENTHREAD_BORDER_ROUTER=y
CONFIG_OPENTHREAD_UDP_FORWARD=y
CONFIG_OPENTHREAD_ENABLE_SERVICE=y
CONFIG_OPENTHREAD_JOINER=y
CONFIG_OPENTHREAD_MANUAL_START=y

# Enable OpenThread shell
CONFIG_OPENTHREAD_SHELL=y
Expand Down