diff --git a/examples/weather_station/src/app_task.cpp b/examples/weather_station/src/app_task.cpp index 1d3fa92e1b0b00..c28955068cb267 100644 --- a/examples/weather_station/src/app_task.cpp +++ b/examples/weather_station/src/app_task.cpp @@ -76,8 +76,7 @@ constexpr uint32_t kBatteryCapacityUaH = 1350000; /* Average device current consumption in uA */ constexpr uint32_t kDeviceAverageCurrentConsumptionUa = CONFIG_AVERAGE_CURRENT_CONSUMPTION; /* Fully charged battery operation time in seconds */ -constexpr uint32_t kFullBatteryOperationTime = - kBatteryCapacityUaH / kDeviceAverageCurrentConsumptionUa * 3600; +constexpr uint32_t kFullBatteryOperationTime = kBatteryCapacityUaH / kDeviceAverageCurrentConsumptionUa * 3600; /* It is recommended to toggle the signalled state with 0.5 s interval. */ constexpr size_t kIdentifyTimerIntervalMs = 500; @@ -99,12 +98,12 @@ bool sHaveBLEConnections; LedState sLedState = LedState::kAlive; /* Add identify for all endpoints */ -Identify sIdentifyTemperature = { chip::EndpointId{ kTemperatureMeasurementEndpointId }, AppTask::OnIdentifyStart, AppTask::OnIdentifyStop, - EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_AUDIBLE_BEEP }; -Identify sIdentifyHumidity = { chip::EndpointId{ kHumidityMeasurementEndpointId }, AppTask::OnIdentifyStart, AppTask::OnIdentifyStop, - EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_AUDIBLE_BEEP }; -Identify sIdentifyPressure = { chip::EndpointId{ kPressureMeasurementEndpointId }, AppTask::OnIdentifyStart, AppTask::OnIdentifyStop, - EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_AUDIBLE_BEEP }; +Identify sIdentifyTemperature = { chip::EndpointId{ kTemperatureMeasurementEndpointId }, AppTask::OnIdentifyStart, + AppTask::OnIdentifyStop, EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_AUDIBLE_BEEP }; +Identify sIdentifyHumidity = { chip::EndpointId{ kHumidityMeasurementEndpointId }, AppTask::OnIdentifyStart, + AppTask::OnIdentifyStop, EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_AUDIBLE_BEEP }; +Identify sIdentifyPressure = { chip::EndpointId{ kPressureMeasurementEndpointId }, AppTask::OnIdentifyStart, + AppTask::OnIdentifyStop, EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_AUDIBLE_BEEP }; const device *sBme688SensorDev = DEVICE_DT_GET_ONE(bosch_bme680); } /* namespace */ @@ -135,11 +134,9 @@ CHIP_ERROR AppTask::Init() } #ifdef CONFIG_OPENTHREAD_MTD_SED - err = ConnectivityMgr().SetThreadDeviceType( - ConnectivityManager::kThreadDeviceType_SleepyEndDevice); + err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice); #else - err = ConnectivityMgr().SetThreadDeviceType( - ConnectivityManager::kThreadDeviceType_MinimalEndDevice); + err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); #endif if (err != CHIP_NO_ERROR) { LOG_ERR("ConnectivityMgr().SetThreadDeviceType() failed"); @@ -204,19 +201,13 @@ CHIP_ERROR AppTask::Init() /* Initialize timers */ k_timer_init( - &sFunctionTimer, - [](k_timer *) { sAppTask.PostEvent(AppEvent{ AppEvent::FunctionTimer }); }, - nullptr); + &sFunctionTimer, [](k_timer *) { sAppTask.PostEvent(AppEvent{ AppEvent::FunctionTimer }); }, nullptr); k_timer_init( - &sMeasurementsTimer, - [](k_timer *) { sAppTask.PostEvent(AppEvent{ AppEvent::MeasurementsTimer }); }, + &sMeasurementsTimer, [](k_timer *) { sAppTask.PostEvent(AppEvent{ AppEvent::MeasurementsTimer }); }, nullptr); - k_timer_start(&sMeasurementsTimer, K_MSEC(kMeasurementsIntervalMs), - K_MSEC(kMeasurementsIntervalMs)); + k_timer_start(&sMeasurementsTimer, K_MSEC(kMeasurementsIntervalMs), K_MSEC(kMeasurementsIntervalMs)); k_timer_init( - &sIdentifyTimer, - [](k_timer *) { sAppTask.PostEvent(AppEvent{ AppEvent::IdentifyTimer }); }, - nullptr); + &sIdentifyTimer, [](k_timer *) { sAppTask.PostEvent(AppEvent{ AppEvent::IdentifyTimer }); }, nullptr); /* Initialize CHIP server */ SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); @@ -228,8 +219,7 @@ CHIP_ERROR AppTask::Init() InitBasicOTARequestor(); #endif ConfigurationMgr().LogDeviceConfig(); - PrintOnboardingCodes( - chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); + PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); /* * Add CHIP event handler and start CHIP thread. @@ -259,9 +249,8 @@ void AppTask::OpenPairingWindow() return; } - if (chip::Server::GetInstance() - .GetCommissioningWindowManager() - .OpenBasicCommissioningWindow() != CHIP_NO_ERROR) { + if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != + CHIP_NO_ERROR) { LOG_ERR("OpenBasicCommissioningWindow() failed"); } } @@ -275,7 +264,7 @@ CHIP_ERROR AppTask::StartApp() while (true) { k_msgq_get(&sAppEventQueue, &event, K_FOREVER); DispatchEvent(event); - } + } return CHIP_NO_ERROR; } @@ -378,8 +367,7 @@ void AppTask::MeasurementsTimerHandler() void AppTask::OnIdentifyStart(Identify *) { - k_timer_start(&sIdentifyTimer, K_MSEC(kIdentifyTimerIntervalMs), - K_MSEC(kIdentifyTimerIntervalMs)); + k_timer_start(&sIdentifyTimer, K_MSEC(kIdentifyTimerIntervalMs), K_MSEC(kIdentifyTimerIntervalMs)); } void AppTask::OnIdentifyStop(Identify *) @@ -402,8 +390,7 @@ void AppTask::UpdateTemperatureClusterState() /* Defined by cluster temperature measured value = 100 x temperature in degC with resolution of * 0.01 degC. val1 is an integer part of the value and val2 is fractional part in one-millionth * parts. To achieve resolution of 0.01 degC val2 needs to be divided by 10000. */ - int16_t newValue = - static_cast(sTemperature.val1 * 100 + sTemperature.val2 / 10000); + int16_t newValue = static_cast(sTemperature.val1 * 100 + sTemperature.val2 / 10000); if (newValue > kTemperatureMeasurementAttributeMaxValue || newValue < kTemperatureMeasurementAttributeMinValue) { @@ -430,8 +417,7 @@ void AppTask::UpdatePressureClusterState() /* Defined by cluster pressure measured value = 10 x pressure in kPa with resolution of 0.1 kPa. * val1 is an integer part of the value and val2 is fractional part in one-millionth parts. * To achieve resolution of 0.1 kPa val2 needs to be divided by 100000. */ - int16_t newValue = - static_cast(sPressure.val1 * 10 + sPressure.val2 / 100000); + int16_t newValue = static_cast(sPressure.val1 * 10 + sPressure.val2 / 100000); if (newValue > kPressureMeasurementAttributeMaxValue || newValue < kPressureMeasurementAttributeMinValue) { @@ -439,8 +425,8 @@ void AppTask::UpdatePressureClusterState() newValue = kPressureMeasurementAttributeInvalidValue; } - status = Clusters::PressureMeasurement::Attributes::MeasuredValue::Set( - kPressureMeasurementEndpointId, newValue); + status = Clusters::PressureMeasurement::Attributes::MeasuredValue::Set(kPressureMeasurementEndpointId, + newValue); if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating pressure measurement %x", status); } @@ -458,8 +444,7 @@ void AppTask::UpdateRelativeHumidityClusterState() /* Defined by cluster humidity measured value = 100 x humidity in %RH with resolution of 0.01 %. * val1 is an integer part of the value and val2 is fractional part in one-millionth parts. * To achieve resolution of 0.01 % val2 needs to be divided by 10000. */ - uint16_t newValue = - static_cast(sHumidity.val1 * 100 + sHumidity.val2 / 10000); + uint16_t newValue = static_cast(sHumidity.val1 * 100 + sHumidity.val2 / 10000); if (newValue > kHumidityMeasurementAttributeMaxValue || newValue < kHumidityMeasurementAttributeMinValue) { @@ -510,8 +495,7 @@ void AppTask::UpdatePowerSourceClusterState() (kMaximalOperatingVoltageMv - kMinimalOperatingVoltageMv); } - batteryTimeRemaining = - kFullBatteryOperationTime * batteryPercentage / kMaxBatteryPercentage; + batteryTimeRemaining = kFullBatteryOperationTime * batteryPercentage / kMaxBatteryPercentage; if (voltage < kCriticalThresholdVoltageMv) { batteryChargeLevel = Clusters::PowerSource::BatChargeLevel::kCritical; @@ -527,44 +511,37 @@ void AppTask::UpdatePowerSourceClusterState() batteryCharged = Clusters::PowerSource::BatChargeState::kIsNotCharging; } - status = Clusters::PowerSource::Attributes::BatteryVoltage::Set(kPowerSourceEndpointId, - voltage); + status = Clusters::PowerSource::Attributes::BatVoltage::Set(kPowerSourceEndpointId, voltage); if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating battery voltage failed %x", status); } - status = Clusters::PowerSource::Attributes::BatteryPercentRemaining::Set( - kPowerSourceEndpointId, batteryPercentage); + status = Clusters::PowerSource::Attributes::BatPercentRemaining::Set(kPowerSourceEndpointId, batteryPercentage); if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating battery percentage failed %x", status); } - status = Clusters::PowerSource::Attributes::BatteryTimeRemaining::Set( - kPowerSourceEndpointId, batteryTimeRemaining); + status = Clusters::PowerSource::Attributes::BatTimeRemaining::Set(kPowerSourceEndpointId, batteryTimeRemaining); if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating battery time remaining failed %x", status); } - status = Clusters::PowerSource::Attributes::BatteryChargeLevel::Set( - kPowerSourceEndpointId, chip::to_underlying(batteryChargeLevel)); + status = Clusters::PowerSource::Attributes::BatChargeLevel::Set(kPowerSourceEndpointId, batteryChargeLevel); if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating battery charge level failed %x", status); } - status = Clusters::PowerSource::Attributes::Status::Set(kPowerSourceEndpointId, - chip::to_underlying(batteryStatus)); + status = Clusters::PowerSource::Attributes::Status::Set(kPowerSourceEndpointId, batteryStatus); if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating battery status failed %x", status); } - status = Clusters::PowerSource::Attributes::BatteryPresent::Set(kPowerSourceEndpointId, - batteryPresent); + status = Clusters::PowerSource::Attributes::BatPresent::Set(kPowerSourceEndpointId, batteryPresent); if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating battery present failed %x", status); } - status = Clusters::PowerSource::Attributes::BatteryChargeState::Set( - kPowerSourceEndpointId, chip::to_underlying(batteryCharged)); + status = Clusters::PowerSource::Attributes::BatChargeState::Set(kPowerSourceEndpointId, batteryCharged); if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating battery charge failed %x", status); } @@ -624,7 +601,7 @@ void AppTask::UpdateStatusLED() default: break; } - } +} void AppTask::LEDStateUpdateHandler(LEDWidget &ledWidget) { @@ -640,8 +617,8 @@ void AppTask::ChipEventHandler(const ChipDeviceEvent *event, intptr_t /* arg */) if (NFCMgr().IsTagEmulationStarted()) { LOG_INF("NFC Tag emulation is already started"); } else { - ShareQRCodeOverNFC(chip::RendezvousInformationFlags( - chip::RendezvousInformationFlag::kBLE)); + ShareQRCodeOverNFC( + chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); } } else if (event->CHIPoBLEAdvertisingChange.Result == kActivity_Stopped) { NFCMgr().StopTagEmulation();