-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Silabs] Refactor Sensor code (#35979)
* Refactor Sensor and LCD code * Address review comments
- Loading branch information
1 parent
e02f0f2
commit 5224cec
Showing
13 changed files
with
196 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "sl_board_control.h" | ||
#include "sl_i2cspm_instances.h" | ||
#include "sl_si70xx.h" | ||
#include <Si70xxSensor.h> | ||
#include <lib/support/CodeUtils.h> | ||
|
||
namespace { | ||
|
||
constexpr uint16_t kSensorTemperatureOffset = 475; | ||
bool initialized = false; | ||
|
||
} // namespace | ||
|
||
namespace Si70xxSensor { | ||
|
||
sl_status_t Init() | ||
{ | ||
sl_status_t status = SL_STATUS_OK; | ||
|
||
status = sl_board_enable_sensor(SL_BOARD_SENSOR_RHT); | ||
VerifyOrReturnError(status == SL_STATUS_OK, status); | ||
|
||
status = sl_si70xx_init(sl_i2cspm_sensor, SI7021_ADDR); | ||
VerifyOrReturnError(status == SL_STATUS_OK, status); | ||
|
||
initialized = true; | ||
return status; | ||
} | ||
|
||
sl_status_t GetSensorData(uint16_t & relativeHumidity, int16_t & temperature) | ||
{ | ||
VerifyOrReturnError(initialized, SL_STATUS_NOT_INITIALIZED); | ||
|
||
sl_status_t status = SL_STATUS_OK; | ||
int32_t tempTemperature = 0; | ||
uint32_t tempHumidity = 0; | ||
|
||
status = sl_si70xx_measure_rh_and_temp(sl_i2cspm_sensor, SI7021_ADDR, &tempHumidity, &tempTemperature); | ||
VerifyOrReturnError(status == SL_STATUS_OK, status); | ||
|
||
// Sensor precision is milliX. We need to reduce to change the precision to centiX to fit with the cluster attributes presicion. | ||
temperature = static_cast<int16_t>(tempTemperature / 10) - kSensorTemperatureOffset; | ||
relativeHumidity = static_cast<uint16_t>(tempHumidity / 10); | ||
|
||
return status; | ||
} | ||
|
||
}; // namespace Si70xxSensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* | ||
* 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> | ||
|
||
namespace Si70xxSensor { | ||
|
||
/** | ||
* @brief Initialises the Si70xx Sensor. | ||
* | ||
* @return sl_status_t SL_STATUS_OK if there were no errors occured during initialisation. | ||
* Error if an underlying platform error occured | ||
*/ | ||
sl_status_t Init(); | ||
|
||
/** | ||
* @brief Reads Humidity and temperature values from the Si70xx sensor. | ||
* The init function must be called before calling the GetSensorData. | ||
* | ||
* @param[out] relativeHumidity Relative humidity percentage in centi-pourcentage (1000 == 10.00%) | ||
* @param[out] temperature Ambiant temperature in centi-celsium (1000 == 10.00C) | ||
* | ||
* @return sl_status_t SL_STATUS_OK if there were no errors occured during initialisation. | ||
* SL_STATUS_NOT_INITIALIZED if the sensor was not initialised | ||
* Error if an underlying platform error occured | ||
*/ | ||
sl_status_t GetSensorData(uint16_t & relativeHumidity, int16_t & temperature); | ||
|
||
}; // namespace Si70xxSensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.