Skip to content

Commit f53612f

Browse files
jmartinez-silabsrerasool
authored andcommitted
Pull request project-chip#246: Update the thermostat app
Merge in WMN_TOOLS/matter from thermostat_rc1 to RC_1.0.0 Squashed commit of the following: commit 3e066e49a2361905ffdafcd460793f5546d4b032 Author: Junior Martinez <junior.martinez@silabs.com> Date: Mon Oct 31 10:05:35 2022 -0400 Fix #else not else{} commit f81ecce0a95d5eab42eacca1c8df03ca0d19185c Author: Junior Martinez <junior.martinez@silabs.com> 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 <rehan.rasool@silabs.com> Date: Sun Oct 30 23:04:32 2022 -0400 Add thermostat example to openthread builds ... and 1 more commit
1 parent 266b8dd commit f53612f

26 files changed

+1479
-154
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
*
3+
* Copyright (c) 2020 Project CHIP Authors
4+
* Copyright (c) 2019 Google LLC.
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
#include "TemperatureSensor.h"
25+
#include "sl_sensor_rht.h"
26+
27+
28+
#define SENSOR_TEMP_OFFSET 800
29+
30+
sl_status_t TemperatureSensor::Init(void)
31+
{
32+
return sl_sensor_rht_init();
33+
}
34+
35+
sl_status_t TemperatureSensor::GetTemp(uint32_t * rh, int16_t * t)
36+
{
37+
// Sensor resolution 0.001 C
38+
// DataModel resolution 0.01 C
39+
int32_t temp;
40+
sl_status_t status = sl_sensor_rht_get(rh, &temp);
41+
*t = static_cast<int16_t>(temp / 10) - SENSOR_TEMP_OFFSET;
42+
return status;
43+
}
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* Copyright (c) 2020 Project CHIP Authors
4+
* Copyright (c) 2019 Google LLC.
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include "sl_status.h"
23+
#include <stdint.h>
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
class TemperatureSensor
30+
{
31+
public:
32+
static sl_status_t Init(void);
33+
static sl_status_t GetTemp(uint32_t * rh, int16_t * t);
34+
};
35+
36+
#ifdef __cplusplus
37+
}
38+
#endif

examples/platform/efr32/display/lcd.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,20 @@ void SilabsLCD::WriteDemoUI(bool state)
135135
void SilabsLCD::WriteDemoUI()
136136
{
137137
Clear();
138-
demoUIClearMainScreen(mName);
139-
demoUIDisplayApp(dState.mainState);
138+
if (customUI != nullptr)
139+
{
140+
customUI(&glibContext);
141+
}
142+
else
143+
{
144+
demoUIClearMainScreen(mName);
145+
demoUIDisplayApp(dState.mainState);
146+
}
147+
}
148+
149+
void SilabsLCD::SetCustomUI(customUICB cb)
150+
{
151+
customUI = cb;
140152
}
141153

142154
#ifdef QR_CODE_ENABLED

examples/platform/efr32/display/lcd.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ class SilabsLCD
3333
{
3434

3535
public:
36+
typedef void (*customUICB)(GLIB_Context_t * context);
3637
CHIP_ERROR Init(uint8_t * name = nullptr, bool initialState = false);
3738
void * Context();
3839
int Clear(void);
3940
int DrawPixel(void * pContext, int32_t x, int32_t y);
4041
int Update(void);
4142
void WriteDemoUI(bool state);
43+
void SetCustomUI(customUICB cb);
44+
4245
#ifdef QR_CODE_ENABLED
4346
void SetQRCode(uint8_t * str, uint32_t size);
4447
void ShowQRCode(bool show, bool forceRefresh = false);
@@ -66,6 +69,6 @@ class SilabsLCD
6669
#else
6770
uint8_t mName[APP_NAME_MAX_LENGTH + 1];
6871
#endif
69-
70-
DemoState_t dState;
72+
customUICB customUI = nullptr;
73+
DemoState_t dState;
7174
};

examples/thermostat/efr32/BUILD.gn

+38
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ assert(current_os == "freertos")
3333

3434
efr32_project_dir = "${chip_root}/examples/thermostat/efr32"
3535
examples_plat_dir = "${chip_root}/examples/platform/efr32"
36+
efr32_sdk_root = "${chip_root}/third_party/silabs/gecko_sdk"
3637

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

6061
# Argument to Disable IPv4 for wifi(rs911)
6162
chip_enable_wifi_ipv4 = false
63+
64+
# Enable the temperature sensor
65+
use_temp_sensor = true
6266
}
6367

6468
declare_args() {
@@ -86,6 +90,11 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" ||
8690
disable_lcd = true
8791
}
8892

93+
# Boards that do not support temperature sensor
94+
if (silabs_board == "BRD2703A" || silabs_board == "BRD4319A") {
95+
use_temp_sensor = false
96+
}
97+
8998
# WiFi settings
9099
if (chip_enable_wifi) {
91100
wifi_sdk_dir = "${chip_root}/src/platform/EFR32/wifi"
@@ -133,6 +142,7 @@ efr32_sdk("sdk") {
133142
"${efr32_project_dir}/include",
134143
"${examples_plat_dir}",
135144
"${chip_root}/src/lib",
145+
"${efr32_sdk_root}/app/common/util/app_assert",
136146
]
137147

138148
defines = [
@@ -172,6 +182,18 @@ efr32_sdk("sdk") {
172182
defines += [ "SL_WFX_CONFIG_SCAN" ]
173183
}
174184
}
185+
if (use_temp_sensor) {
186+
include_dirs += [
187+
"${efr32_sdk_root}/platform/driver/i2cspm/inc",
188+
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht",
189+
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht/config",
190+
"${efr32_sdk_root}/hardware/driver/si70xx/inc",
191+
"${efr32_sdk_root}/app/bluetooth/common/sensor_select",
192+
"${efr32_sdk_root}/platform/common/config",
193+
]
194+
195+
defines += [ "USE_TEMP_SENSOR" ]
196+
}
175197
}
176198

177199
efr32_executable("thermostat_app") {
@@ -186,6 +208,8 @@ efr32_executable("thermostat_app") {
186208
"${examples_plat_dir}/init_efrPlatform.cpp",
187209
"${examples_plat_dir}/matter_config.cpp",
188210
"src/AppTask.cpp",
211+
"src/SensorManager.cpp",
212+
"src/TemperatureManager.cpp",
189213
"src/ZclCallbacks.cpp",
190214
"src/main.cpp",
191215
]
@@ -194,6 +218,19 @@ efr32_executable("thermostat_app") {
194218
sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
195219
}
196220

221+
if (use_temp_sensor) {
222+
sources += [
223+
"${efr32_sdk_root}/app/bluetooth/common/sensor_rht/sl_sensor_rht.c",
224+
"${efr32_sdk_root}/app/bluetooth/common/sensor_select/sl_sensor_select.c",
225+
"${efr32_sdk_root}/hardware/driver/si70xx/src/sl_si70xx.c",
226+
"${efr32_sdk_root}/platform/common/src/sl_status.c",
227+
"${efr32_sdk_root}/platform/driver/i2cspm/src/sl_i2cspm.c",
228+
"${efr32_sdk_root}/platform/emlib/src/em_i2c.c",
229+
"${sdk_support_root}/matter/efr32/${silabs_family}/${silabs_board}/autogen/sl_i2cspm_init.c",
230+
"${examples_plat_dir}/TemperatureSensor.cpp",
231+
]
232+
}
233+
197234
if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli ||
198235
use_wf200 || use_rs911x) {
199236
sources += [ "${examples_plat_dir}/uart.cpp" ]
@@ -266,6 +303,7 @@ efr32_executable("thermostat_app") {
266303

267304
if (!disable_lcd) {
268305
sources += [
306+
"src/ThermostatUI.cpp",
269307
"${examples_plat_dir}/display/demo-ui.c",
270308
"${examples_plat_dir}/display/lcd.cpp",
271309
]

examples/thermostat/efr32/include/AppEvent.h

-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct AppEvent
2828
{
2929
kEventType_Button = 0,
3030
kEventType_Timer,
31-
kEventType_Light,
3231
kEventType_Install,
3332
};
3433

@@ -44,11 +43,6 @@ struct AppEvent
4443
{
4544
void * Context;
4645
} TimerEvent;
47-
struct
48-
{
49-
uint8_t Action;
50-
int32_t Actor;
51-
} LightEvent;
5246
};
5347

5448
EventHandler Handler;

examples/thermostat/efr32/include/AppTask.h

+13-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@
2626
#include <stdbool.h>
2727
#include <stdint.h>
2828

29+
#ifdef DISPLAY_ENABLED
30+
#include "ThermostatUI.h"
31+
#endif
32+
2933
#include "AppEvent.h"
3034
#include "BaseApplication.h"
3135
#include "FreeRTOS.h"
36+
#include "SensorManager.h"
37+
#include "TemperatureManager.h"
3238
#include "sl_simple_button_instances.h"
3339
#include "timers.h" // provides FreeRTOS timer support
3440
#include <app/clusters/identify-server/identify-server.h>
@@ -69,6 +75,11 @@ class AppTask : public BaseApplication
6975

7076
CHIP_ERROR StartAppTask();
7177

78+
/**
79+
* @brief Request an update of the Thermostat LCD UI
80+
*/
81+
void UpdateThermoStatUI();
82+
7283
/**
7384
* @brief Event handler when a button is pressed
7485
* Function posts an event for button processing
@@ -112,11 +123,7 @@ class AppTask : public BaseApplication
112123
*/
113124
static void ButtonHandler(AppEvent * aEvent);
114125

115-
/**
116-
* @brief PB1 Button event processing function
117-
* Function triggers a thermostat action sent to the CHIP task
118-
*
119-
* @param aEvent button event being processed
120-
*/
126+
121127
static void ThermostatActionEventHandler(AppEvent * aEvent);
128+
122129
};

examples/thermostat/efr32/include/CHIPProjectConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
*
5858
* 0x8005: example lighting app
5959
*/
60-
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8004
60+
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x800E
6161

6262
/**
6363
* CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
*
3+
* Copyright (c) 2019 Google LLC.
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <stdbool.h>
22+
#include <stdint.h>
23+
24+
#include "AppEvent.h"
25+
26+
#include "FreeRTOS.h"
27+
#include "timers.h" // provides FreeRTOS timer support
28+
#include <app-common/zap-generated/attributes/Accessors.h>
29+
#include <lib/core/CHIPError.h>
30+
31+
#define SIMULATED_TEMP 2300, 2400, 2800, 2550, 2200, 2125, 2100, 2600, 1800, 2700
32+
33+
34+
class SensorManager
35+
{
36+
public:
37+
CHIP_ERROR Init();
38+
39+
private:
40+
friend SensorManager & SensorMgr(void);
41+
42+
43+
// Reads new generated sensor value, stores it, and updates local temperature attribute
44+
static void SensorTimerEventHandler(TimerHandle_t xTimer);
45+
46+
static SensorManager sSensorManager;
47+
48+
};
49+
50+
inline SensorManager & SensorMgr(void)
51+
{
52+
return SensorManager::sSensorManager;
53+
}

0 commit comments

Comments
 (0)