Skip to content

Commit

Permalink
Address PR comments, Cleanup rebase and regen
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinez-silabs committed Nov 14, 2022
1 parent e0b55f8 commit 7d27f1f
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 101 deletions.
25 changes: 14 additions & 11 deletions examples/platform/efr32/TemperatureSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@
* limitations under the License.
*/

#include "TemperatureSensor.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "TemperatureSensor.h"
// This is a C implementation. Need the ifdef __cplusplus else we get linking issues
#include "sl_sensor_rht.h"

#define SENSOR_TEMP_OFFSET 800
#ifdef __cplusplus
}
#endif

namespace TemperatureSensor {
constexpr uint16_t kSensorTemperatureOffset = 800;

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

sl_status_t TemperatureSensor::GetTemp(uint32_t * rh, int16_t * t)
sl_status_t GetTemp(uint32_t * relativeHumidity, int16_t * temperature)
{
// 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;
sl_status_t status = sl_sensor_rht_get(relativeHumidity, &temp);
*temperature = static_cast<int16_t>(temp / 10) - kSensorTemperatureOffset;
return status;
}

#ifdef __cplusplus
}
#endif
}; // namespace TemperatureSensor
18 changes: 4 additions & 14 deletions examples/platform/efr32/TemperatureSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@
#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
namespace TemperatureSensor {
sl_status_t Init();
sl_status_t GetTemp(uint32_t * relativeHumidity, int16_t * temperature);
}; // namespace TemperatureSensor
8 changes: 2 additions & 6 deletions examples/thermostat/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ declare_args() {
chip_enable_wifi_ipv4 = false

# Enable the temperature sensor
use_temp_sensor = true
# Some boards do not have a temperature sensor
use_temp_sensor = silabs_board != "BRD2703A" && silabs_board != "BRD4319A"
}

declare_args() {
Expand Down Expand Up @@ -90,11 +91,6 @@ 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
6 changes: 2 additions & 4 deletions examples/thermostat/efr32/include/SensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@
#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);
friend SensorManager & SensorMgr();

// 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)
inline SensorManager & SensorMgr()
{
return SensorManager::sSensorManager;
}
21 changes: 9 additions & 12 deletions examples/thermostat/efr32/include/TemperatureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

#include <lib/core/CHIPError.h>

#define TEMPERATURE_OFFSET 100 // Offset taken into account before switching thermostat states
#define TEMP_INCREMENT 10

using namespace chip;

// AppCluster Spec Table 85.
Expand All @@ -49,24 +46,24 @@ class TemperatureManager
public:
CHIP_ERROR Init();
void AttributeChangeHandler(EndpointId endpointId, AttributeId attributeId, uint8_t * value, uint16_t size);
uint8_t GetMode(void);
int8_t GetCurrentTemp(void);
int8_t GetHeatingSetPoint(void);
int8_t GetCoolingSetPoint(void);
uint8_t GetMode();
int8_t GetCurrentTemp();
int8_t GetHeatingSetPoint();
int8_t GetCoolingSetPoint();

private:
friend TemperatureManager & TempMgr(void);
friend TemperatureManager & TempMgr();

int8_t mCurrentTemp; // in Celsius
int8_t mCoolingSetPoint; // in Celsius
int8_t mHeatingSetPoint; // in Celsius
int8_t mCurrentTempCelsius;
int8_t mCoolingCelsiusSetPoint;
int8_t mHeatingCelsiusSetPoint;
uint8_t mThermMode;

int8_t ConvertToPrintableTemp(int16_t temperature);
static TemperatureManager sTempMgr;
};

inline TemperatureManager & TempMgr(void)
inline TemperatureManager & TempMgr()
{
return TemperatureManager::sTempMgr;
}
20 changes: 9 additions & 11 deletions examples/thermostat/efr32/src/SensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,31 @@
* Defines and Constants
*********************************************************/

#define ENDPOINT_ID 1

#define SENSOR_TIMER_PERIOD_ms 30000 // 5s timer period
#define SIMULATED_READING_REPETITION (60000 / SENSOR_TIMER_PERIOD_ms) // Change Simulated number at each minutes

using namespace chip;
using namespace ::chip::DeviceLayer;

constexpr EndpointId kThermostatEndpoint = 1;
constexpr uint16_t kSensorTImerPeriodMs = 30000; // 30s timer period
constexpr uint16_t kMinTemperatureDelta = 50; // 0.5 degree Celcius

/**********************************************************
* Variable declarations
*********************************************************/

TimerHandle_t sSensorTimer;
StaticTimer_t sStaticSensorTimerStruct;

constexpr uint16_t kMinTemperatureDelta = 50; // 0.5 degree Celcius

SensorManager SensorManager::sSensorManager;

#ifndef USE_TEMP_SENSOR
static int16_t mSimulatedTemp[] = { SIMULATED_TEMP };
constexpr uint16_t kSimulatedReadingFrequency = (60000 / kSensorTImerPeriodMs); // Change Simulated number at each minutes
static int16_t mSimulatedTemp[] = { 2300, 2400, 2800, 2550, 2200, 2125, 2100, 2600, 1800, 2700 };
#endif

CHIP_ERROR SensorManager::Init()
{
// Create FreeRTOS sw timer for temp sensor timer.
sSensorTimer = xTimerCreateStatic("sensorTmr", pdMS_TO_TICKS(SENSOR_TIMER_PERIOD_ms), true, nullptr, SensorTimerEventHandler,
sSensorTimer = xTimerCreateStatic("sensorTmr", pdMS_TO_TICKS(kSensorTImerPeriodMs), true, nullptr, SensorTimerEventHandler,
&sStaticSensorTimerStruct);

if (sSensorTimer == NULL)
Expand Down Expand Up @@ -113,7 +111,7 @@ void SensorManager::SensorTimerEventHandler(TimerHandle_t xTimer)
temperature = mSimulatedTemp[simulatedIndex];

nbOfRepetition++;
if (nbOfRepetition >= SIMULATED_READING_REPETITION)
if (nbOfRepetition >= kSimulatedReadingFrequency)
{
simulatedIndex++;
nbOfRepetition = 0;
Expand All @@ -129,7 +127,7 @@ void SensorManager::SensorTimerEventHandler(TimerHandle_t xTimer)
// The SensorMagager shouldn't be aware of the Endpoint ID TODO Fix this.
// TODO Per Spec we should also apply the Offset stored in the same cluster before saving the temp

app::Clusters::Thermostat::Attributes::LocalTemperature::Set(ENDPOINT_ID, temperature);
app::Clusters::Thermostat::Attributes::LocalTemperature::Set(kThermostatEndpoint, temperature);
PlatformMgr().UnlockChipStack();
}
}
42 changes: 21 additions & 21 deletions examples/thermostat/efr32/src/TemperatureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
* Defines and Constants
*********************************************************/

#define TEMP_TIMER_ms 3000
#define ENDPOINT_ID 1

using namespace chip;
using namespace ::chip::DeviceLayer;

constexpr EndpointId kThermostatEndpoint = 1;

namespace ThermAttr = chip::app::Clusters::Thermostat::Attributes;
/**********************************************************
* Variable declarations
Expand All @@ -50,16 +50,16 @@ CHIP_ERROR TemperatureManager::Init()
uint8_t systemMode;

PlatformMgr().LockChipStack();
ThermAttr::LocalTemperature::Get(ENDPOINT_ID, temp);
ThermAttr::OccupiedCoolingSetpoint::Get(ENDPOINT_ID, &coolingSetpoint);
ThermAttr::OccupiedHeatingSetpoint::Get(ENDPOINT_ID, &heatingSetpoint);
ThermAttr::SystemMode::Get(ENDPOINT_ID, &systemMode);
ThermAttr::LocalTemperature::Get(kThermostatEndpoint, temp);
ThermAttr::OccupiedCoolingSetpoint::Get(kThermostatEndpoint, &coolingSetpoint);
ThermAttr::OccupiedHeatingSetpoint::Get(kThermostatEndpoint, &heatingSetpoint);
ThermAttr::SystemMode::Get(kThermostatEndpoint, &systemMode);
PlatformMgr().UnlockChipStack();

mCurrentTemp = ConvertToPrintableTemp(temp.Value());
mHeatingSetPoint = ConvertToPrintableTemp(coolingSetpoint);
mCoolingSetPoint = ConvertToPrintableTemp(heatingSetpoint);
mThermMode = systemMode;
mCurrentTempCelsius = ConvertToPrintableTemp(temp.Value());
mHeatingCelsiusSetPoint = ConvertToPrintableTemp(coolingSetpoint);
mCoolingCelsiusSetPoint = ConvertToPrintableTemp(heatingSetpoint);
mThermMode = systemMode;

AppTask::GetAppTask().UpdateThermoStatUI();

Expand Down Expand Up @@ -91,21 +91,21 @@ void TemperatureManager::AttributeChangeHandler(EndpointId endpointId, Attribute
case ThermAttr::LocalTemperature::Id: {
int8_t Temp = ConvertToPrintableTemp(*((int16_t *) value));
EFR32_LOG("Local temp %d", Temp);
mCurrentTemp = Temp;
mCurrentTempCelsius = Temp;
}
break;

case ThermAttr::OccupiedCoolingSetpoint::Id: {
int8_t coolingTemp = ConvertToPrintableTemp(*((int16_t *) value));
EFR32_LOG("CoolingSetpoint %d", coolingTemp);
mCoolingSetPoint = coolingTemp;
mCoolingCelsiusSetPoint = coolingTemp;
}
break;

case ThermAttr::OccupiedHeatingSetpoint::Id: {
int8_t heatingTemp = ConvertToPrintableTemp(*((int16_t *) value));
EFR32_LOG("HeatingSetpoint %d", heatingTemp);
mHeatingSetPoint = heatingTemp;
mHeatingCelsiusSetPoint = heatingTemp;
}
break;

Expand All @@ -129,21 +129,21 @@ void TemperatureManager::AttributeChangeHandler(EndpointId endpointId, Attribute
AppTask::GetAppTask().UpdateThermoStatUI();
}

uint8_t TemperatureManager::GetMode(void)
uint8_t TemperatureManager::GetMode()
{
return mThermMode;
}

int8_t TemperatureManager::GetCurrentTemp(void)
int8_t TemperatureManager::GetCurrentTemp()
{
return mCurrentTemp;
return mCurrentTempCelsius;
}
int8_t TemperatureManager::GetHeatingSetPoint(void)
int8_t TemperatureManager::GetHeatingSetPoint()
{
return mHeatingSetPoint;
return mHeatingCelsiusSetPoint;
}

int8_t TemperatureManager::GetCoolingSetPoint(void)
int8_t TemperatureManager::GetCoolingSetPoint()
{
return mCoolingSetPoint;
return mCoolingCelsiusSetPoint;
}
Loading

0 comments on commit 7d27f1f

Please sign in to comment.