Skip to content

Commit

Permalink
Pull request project-chip#246: Update the thermostat app
Browse files Browse the repository at this point in the history
Merge in WMN_TOOLS/matter from thermostat_rc1 to RC_1.0.0

Squashed commit of the following:

commit 3e066e49a2361905ffdafcd460793f5546d4b032
Author: Junior Martinez <[email protected]>
Date:   Mon Oct 31 10:05:35 2022 -0400

    Fix #else not else{}

commit f81ecce0a95d5eab42eacca1c8df03ca0d19185c
Author: Junior Martinez <[email protected]>
Date:   Mon Oct 31 09:58:27 2022 -0400

    Fix thermostat for boards without lcd and/or temp sensor support

commit 6c3127f0b3b5f470d3fe5a3b812c5bfec647eb21
Author: Rehan Rasool <[email protected]>
Date:   Sun Oct 30 23:04:32 2022 -0400

    Add thermostat example to openthread builds

... and 1 more commit
  • Loading branch information
jmartinez-silabs authored and rerasool committed Oct 31, 2022
1 parent 266b8dd commit f53612f
Show file tree
Hide file tree
Showing 26 changed files with 1,479 additions and 154 deletions.
47 changes: 47 additions & 0 deletions examples/platform/efr32/TemperatureSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* 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.
*/

#ifdef __cplusplus
extern "C" {
#endif

#include "TemperatureSensor.h"
#include "sl_sensor_rht.h"


#define SENSOR_TEMP_OFFSET 800

sl_status_t TemperatureSensor::Init(void)
{
return sl_sensor_rht_init();
}

sl_status_t TemperatureSensor::GetTemp(uint32_t * rh, int16_t * t)
{
// Sensor resolution 0.001 C
// DataModel resolution 0.01 C
int32_t temp;
sl_status_t status = sl_sensor_rht_get(rh, &temp);
*t = static_cast<int16_t>(temp / 10) - SENSOR_TEMP_OFFSET;
return status;
}

#ifdef __cplusplus
}
#endif
38 changes: 38 additions & 0 deletions examples/platform/efr32/TemperatureSensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2019 Google LLC.
* 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 "sl_status.h"
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

class TemperatureSensor
{
public:
static sl_status_t Init(void);
static sl_status_t GetTemp(uint32_t * rh, int16_t * t);
};

#ifdef __cplusplus
}
#endif
16 changes: 14 additions & 2 deletions examples/platform/efr32/display/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,20 @@ void SilabsLCD::WriteDemoUI(bool state)
void SilabsLCD::WriteDemoUI()
{
Clear();
demoUIClearMainScreen(mName);
demoUIDisplayApp(dState.mainState);
if (customUI != nullptr)
{
customUI(&glibContext);
}
else
{
demoUIClearMainScreen(mName);
demoUIDisplayApp(dState.mainState);
}
}

void SilabsLCD::SetCustomUI(customUICB cb)
{
customUI = cb;
}

#ifdef QR_CODE_ENABLED
Expand Down
7 changes: 5 additions & 2 deletions examples/platform/efr32/display/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class SilabsLCD
{

public:
typedef void (*customUICB)(GLIB_Context_t * context);
CHIP_ERROR Init(uint8_t * name = nullptr, bool initialState = false);
void * Context();
int Clear(void);
int DrawPixel(void * pContext, int32_t x, int32_t y);
int Update(void);
void WriteDemoUI(bool state);
void SetCustomUI(customUICB cb);

#ifdef QR_CODE_ENABLED
void SetQRCode(uint8_t * str, uint32_t size);
void ShowQRCode(bool show, bool forceRefresh = false);
Expand Down Expand Up @@ -66,6 +69,6 @@ class SilabsLCD
#else
uint8_t mName[APP_NAME_MAX_LENGTH + 1];
#endif

DemoState_t dState;
customUICB customUI = nullptr;
DemoState_t dState;
};
38 changes: 38 additions & 0 deletions examples/thermostat/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ assert(current_os == "freertos")

efr32_project_dir = "${chip_root}/examples/thermostat/efr32"
examples_plat_dir = "${chip_root}/examples/platform/efr32"
efr32_sdk_root = "${chip_root}/third_party/silabs/gecko_sdk"

declare_args() {
# Dump memory usage at link time.
Expand All @@ -59,6 +60,9 @@ declare_args() {

# Argument to Disable IPv4 for wifi(rs911)
chip_enable_wifi_ipv4 = false

# Enable the temperature sensor
use_temp_sensor = true
}

declare_args() {
Expand Down Expand Up @@ -86,6 +90,11 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" ||
disable_lcd = true
}

# Boards that do not support temperature sensor
if (silabs_board == "BRD2703A" || silabs_board == "BRD4319A") {
use_temp_sensor = false
}

# WiFi settings
if (chip_enable_wifi) {
wifi_sdk_dir = "${chip_root}/src/platform/EFR32/wifi"
Expand Down Expand Up @@ -133,6 +142,7 @@ efr32_sdk("sdk") {
"${efr32_project_dir}/include",
"${examples_plat_dir}",
"${chip_root}/src/lib",
"${efr32_sdk_root}/app/common/util/app_assert",
]

defines = [
Expand Down Expand Up @@ -172,6 +182,18 @@ efr32_sdk("sdk") {
defines += [ "SL_WFX_CONFIG_SCAN" ]
}
}
if (use_temp_sensor) {
include_dirs += [
"${efr32_sdk_root}/platform/driver/i2cspm/inc",
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht",
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht/config",
"${efr32_sdk_root}/hardware/driver/si70xx/inc",
"${efr32_sdk_root}/app/bluetooth/common/sensor_select",
"${efr32_sdk_root}/platform/common/config",
]

defines += [ "USE_TEMP_SENSOR" ]
}
}

efr32_executable("thermostat_app") {
Expand All @@ -186,6 +208,8 @@ efr32_executable("thermostat_app") {
"${examples_plat_dir}/init_efrPlatform.cpp",
"${examples_plat_dir}/matter_config.cpp",
"src/AppTask.cpp",
"src/SensorManager.cpp",
"src/TemperatureManager.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]
Expand All @@ -194,6 +218,19 @@ efr32_executable("thermostat_app") {
sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
}

if (use_temp_sensor) {
sources += [
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht/sl_sensor_rht.c",
"${efr32_sdk_root}/app/bluetooth/common/sensor_select/sl_sensor_select.c",
"${efr32_sdk_root}/hardware/driver/si70xx/src/sl_si70xx.c",
"${efr32_sdk_root}/platform/common/src/sl_status.c",
"${efr32_sdk_root}/platform/driver/i2cspm/src/sl_i2cspm.c",
"${efr32_sdk_root}/platform/emlib/src/em_i2c.c",
"${sdk_support_root}/matter/efr32/${silabs_family}/${silabs_board}/autogen/sl_i2cspm_init.c",
"${examples_plat_dir}/TemperatureSensor.cpp",
]
}

if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli ||
use_wf200 || use_rs911x) {
sources += [ "${examples_plat_dir}/uart.cpp" ]
Expand Down Expand Up @@ -266,6 +303,7 @@ efr32_executable("thermostat_app") {

if (!disable_lcd) {
sources += [
"src/ThermostatUI.cpp",
"${examples_plat_dir}/display/demo-ui.c",
"${examples_plat_dir}/display/lcd.cpp",
]
Expand Down
6 changes: 0 additions & 6 deletions examples/thermostat/efr32/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct AppEvent
{
kEventType_Button = 0,
kEventType_Timer,
kEventType_Light,
kEventType_Install,
};

Expand All @@ -44,11 +43,6 @@ struct AppEvent
{
void * Context;
} TimerEvent;
struct
{
uint8_t Action;
int32_t Actor;
} LightEvent;
};

EventHandler Handler;
Expand Down
19 changes: 13 additions & 6 deletions examples/thermostat/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
#include <stdbool.h>
#include <stdint.h>

#ifdef DISPLAY_ENABLED
#include "ThermostatUI.h"
#endif

#include "AppEvent.h"
#include "BaseApplication.h"
#include "FreeRTOS.h"
#include "SensorManager.h"
#include "TemperatureManager.h"
#include "sl_simple_button_instances.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/identify-server/identify-server.h>
Expand Down Expand Up @@ -69,6 +75,11 @@ class AppTask : public BaseApplication

CHIP_ERROR StartAppTask();

/**
* @brief Request an update of the Thermostat LCD UI
*/
void UpdateThermoStatUI();

/**
* @brief Event handler when a button is pressed
* Function posts an event for button processing
Expand Down Expand Up @@ -112,11 +123,7 @@ class AppTask : public BaseApplication
*/
static void ButtonHandler(AppEvent * aEvent);

/**
* @brief PB1 Button event processing function
* Function triggers a thermostat action sent to the CHIP task
*
* @param aEvent button event being processed
*/

static void ThermostatActionEventHandler(AppEvent * aEvent);

};
2 changes: 1 addition & 1 deletion examples/thermostat/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*
* 0x8005: example lighting app
*/
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8004
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x800E

/**
* CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION
Expand Down
53 changes: 53 additions & 0 deletions examples/thermostat/efr32/include/SensorManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
*
* Copyright (c) 2019 Google LLC.
* 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 <stdbool.h>
#include <stdint.h>

#include "AppEvent.h"

#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app-common/zap-generated/attributes/Accessors.h>
#include <lib/core/CHIPError.h>

#define SIMULATED_TEMP 2300, 2400, 2800, 2550, 2200, 2125, 2100, 2600, 1800, 2700


class SensorManager
{
public:
CHIP_ERROR Init();

private:
friend SensorManager & SensorMgr(void);


// Reads new generated sensor value, stores it, and updates local temperature attribute
static void SensorTimerEventHandler(TimerHandle_t xTimer);

static SensorManager sSensorManager;

};

inline SensorManager & SensorMgr(void)
{
return SensorManager::sSensorManager;
}
Loading

0 comments on commit f53612f

Please sign in to comment.