forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Telink] Add Mars board overlay and real measurment of sht3xd sensor
- Loading branch information
1 parent
f74e95b
commit bc858f6
Showing
9 changed files
with
345 additions
and
15 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
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
44 changes: 44 additions & 0 deletions
44
examples/air-quality-sensor-app/telink/include/SensorManager.h
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,44 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* 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 "AppEventCommon.h" | ||
|
||
#include <app-common/zap-generated/attributes/Accessors.h> | ||
#include <lib/core/CHIPError.h> | ||
|
||
class SensorManager | ||
{ | ||
public: | ||
CHIP_ERROR Init(); | ||
CHIP_ERROR GetTempAndHumMeasurValue(int16_t *pTempMeasured, uint16_t *pHumMeasured); | ||
|
||
private: | ||
friend SensorManager & SensorMgr(); | ||
|
||
static SensorManager sSensorManager; | ||
}; | ||
|
||
inline SensorManager & SensorMgr() | ||
{ | ||
return SensorManager::sSensorManager; | ||
} |
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
120 changes: 120 additions & 0 deletions
120
examples/air-quality-sensor-app/telink/src/SensorManager.cpp
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,120 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* 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 "SensorManager.h" | ||
#include "AppConfig.h" | ||
#include "AppTask.h" | ||
#include <zephyr/drivers/sensor.h> | ||
|
||
LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); | ||
|
||
using namespace chip; | ||
using namespace ::chip::DeviceLayer; | ||
|
||
constexpr float kMinTempDelta = 0.5; // 0.5 degree Celsius | ||
|
||
#ifdef CONFIG_CHIP_USE_MARS_SENSOR | ||
const struct device *const sht3xd_dev = DEVICE_DT_GET_ONE(sensirion_sht3xd); | ||
#elif | ||
constexpr float kSimulatedHum = 55.5; // percents | ||
constexpr uint16_t kSimulatedReadingFrequency = 5; // change Simulated number | ||
static float mSimulatedTemp[] = { 23.01, 24.02, 28.03, 25.50, 22.05, 21.25, 21.07, 26.08, 18.09, 27.11 }; | ||
#endif // CONFIG_CHIP_USE_MARS_SENSOR | ||
|
||
SensorManager SensorManager::sSensorManager; | ||
|
||
CHIP_ERROR SensorManager::Init() | ||
{ | ||
#ifdef CONFIG_CHIP_USE_MARS_SENSOR | ||
if (!device_is_ready(sht3xd_dev)) | ||
{ | ||
LOG_ERR("Device %s is not ready", sht3xd_dev->name); | ||
return CHIP_ERROR_INCORRECT_STATE; | ||
} | ||
#endif // CONFIG_CHIP_USE_MARS_SENSOR | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR SensorManager::GetTempAndHumMeasurValue(int16_t *pTempMeasured, uint16_t *pHumMeasured) | ||
{ | ||
static float lastTemp = 0.0; | ||
float temp = 0.0; | ||
float hum = 0.0; | ||
|
||
#ifdef CONFIG_CHIP_USE_MARS_SENSOR | ||
struct sensor_value sensorTemp = {0}; | ||
struct sensor_value sensorHum = {0}; | ||
|
||
int status = sensor_sample_fetch(sht3xd_dev); | ||
if (!status) | ||
{ | ||
status = sensor_channel_get(sht3xd_dev, SENSOR_CHAN_AMBIENT_TEMP, &sensorTemp); | ||
} | ||
|
||
if (!status) | ||
{ | ||
status = sensor_channel_get(sht3xd_dev, SENSOR_CHAN_HUMIDITY, &sensorHum); | ||
} | ||
|
||
if (status) | ||
{ | ||
LOG_ERR("Device %s is not ready for temperature and humidity measurement (status: %d)", sht3xd_dev->name, status); | ||
return System::MapErrorZephyr(status); | ||
} | ||
|
||
temp = (float)sensor_value_to_double(&sensorTemp); | ||
hum = (float)sensor_value_to_double(&sensorHum); | ||
#else | ||
/* Temperature simulation is used */ | ||
static uint8_t nbOfRepetition = 0; | ||
static uint8_t simulatedIndex = 0; | ||
if (simulatedIndex >= ArraySize(mSimulatedTemp)) | ||
{ | ||
simulatedIndex = 0; | ||
} | ||
temp = mSimulatedTemp[simulatedIndex]; | ||
|
||
nbOfRepetition++; | ||
|
||
if (nbOfRepetition >= kSimulatedReadingFrequency) | ||
{ | ||
simulatedIndex++; | ||
nbOfRepetition = 0; | ||
} | ||
|
||
/* Humidity simulation is used */ | ||
hum = kSimulatedHum; | ||
|
||
#endif // CONFIG_CHIP_USE_MARS_SENSOR | ||
|
||
if ((temp >= (lastTemp + kMinTempDelta)) || temp <= (lastTemp - kMinTempDelta)) | ||
{ | ||
lastTemp = temp; | ||
} | ||
else | ||
{ | ||
temp = lastTemp; | ||
} | ||
|
||
// Per spec Application Clusters 2.3.4.1. : MeasuredValue = 100 x temperature [°C] | ||
*pTempMeasured = (int16_t) 100 * temp; | ||
*pHumMeasured = (uint16_t) hum; | ||
|
||
return CHIP_NO_ERROR; | ||
} |
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,4 @@ | ||
CONFIG_CHIP_USE_MARS_SENSOR=y | ||
CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE=y | ||
CONFIG_I2C=y | ||
CONFIG_SENSOR=y |
Oops, something went wrong.