Skip to content

Commit

Permalink
Update the efr32 Thermostat app, Use the temperature sensor when avai…
Browse files Browse the repository at this point in the history
…lable, add a LCD UI for thermostat
  • Loading branch information
jmartinez-silabs committed Nov 14, 2022
1 parent e072098 commit e0b55f8
Show file tree
Hide file tree
Showing 22 changed files with 1,445 additions and 150 deletions.
46 changes: 46 additions & 0 deletions examples/platform/efr32/TemperatureSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* 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",
"${examples_plat_dir}/TemperatureSensor.cpp",
"${sdk_support_root}/matter/efr32/${silabs_family}/${silabs_board}/autogen/sl_i2cspm_init.c",
]
}

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 @@ -268,6 +305,7 @@ efr32_executable("thermostat_app") {
sources += [
"${examples_plat_dir}/display/demo-ui.c",
"${examples_plat_dir}/display/lcd.cpp",
"src/ThermostatUI.cpp",
]
include_dirs += [ "${examples_plat_dir}/display" ]
defines += [
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
17 changes: 11 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,5 @@ 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);
};
10 changes: 9 additions & 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 Expand Up @@ -97,6 +97,14 @@
*/
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1

/**
* CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC
*
* Enables synchronizing the device's real time clock with a remote Chip Time service
* using the Chip Time Sync protocol.
*/
#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0

/**
* CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER
*
Expand Down
50 changes: 50 additions & 0 deletions examples/thermostat/efr32/include/SensorManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
*
* 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 e0b55f8

Please sign in to comment.