diff --git a/examples/lighting-app/bouffalolab/bl702l/BUILD.gn b/examples/lighting-app/bouffalolab/bl702l/BUILD.gn index a3f4e3120e8092..26c470f7e96780 100644 --- a/examples/lighting-app/bouffalolab/bl702l/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702l/BUILD.gn @@ -128,9 +128,7 @@ bouffalolab_executable("lighting_app") { defines += [ "BOOT_PIN_RESET=16" ] } - if ("BL704LDK" == board) { - defines += [ "XT_ZB6_DevKit" ] - } + defines += [ "BL706_NIGHT_LIGHT" ] sources = [ "${example_dir}/common/AppTask.cpp", diff --git a/examples/lighting-app/bouffalolab/bl702l/mboard.h b/examples/lighting-app/bouffalolab/bl702l/mboard.h index 62ee3648eede00..c589be5ae48189 100644 --- a/examples/lighting-app/bouffalolab/bl702l/mboard.h +++ b/examples/lighting-app/bouffalolab/bl702l/mboard.h @@ -39,16 +39,22 @@ #ifdef BL706_NIGHT_LIGHT -#define LED_B_PIN_PORT 2 -#define LED_B_PIN 12 +#define LED_B_PIN_PORT 0 +#define LED_B_PIN 0 -#define LED_R_PIN_PORT 0 -#define LED_R_PIN 10 +#define LED_R_PIN_PORT 3 +#define LED_R_PIN 3 -#define LED_G_PIN_PORT 1 -#define LED_G_PIN 16 +#define LED_G_PIN_PORT 4 +#define LED_G_PIN 9 -#define MAX_PWM_CHANNEL 3 +#define LED_C_PIN_PORT 1 +#define LED_C_PIN 21 + +#define LED_W_PIN_PORT 2 +#define LED_W_PIN 22 + +#define MAX_PWM_CHANNEL 5 #elif defined(XT_ZB6_DevKit) @@ -75,6 +81,10 @@ #endif +#if defined(BOARD_BTN_BOOT_PIN) +#define LED_BTN_RESET 16 +#endif + #define SPI_WIFI_MISO_PIN 4 #define SPI_WIFI_MOSI_PIN 5 #define SPI_WIFI_CLK_PIN 3 @@ -82,4 +92,4 @@ #define SPI_WIFI_IRQ_PIN 10 #define CHIP_UART_PIN_RX 15 -#define CHIP_UART_PIN_TX 14 +#define CHIP_UART_PIN_TX 14 \ No newline at end of file diff --git a/examples/lighting-app/bouffalolab/common/AppTask.cpp b/examples/lighting-app/bouffalolab/common/AppTask.cpp index a0eb17fd747eec..9ebc6800b8f835 100644 --- a/examples/lighting-app/bouffalolab/common/AppTask.cpp +++ b/examples/lighting-app/bouffalolab/common/AppTask.cpp @@ -1,6 +1,7 @@ /* * * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2019 Google LLC. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,24 +17,39 @@ * limitations under the License. */ +#include +#include + #include +#include #include +#include #include #include #include #include #include +#include +#include #include +#ifdef OTA_ENABLED +#include "OTAConfig.h" +#endif // OTA_ENABLED + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#include +#include +#endif #if HEAP_MONITORING #include "MemMonitoring.h" #endif #if CHIP_ENABLE_OPENTHREAD +#include #include #include -#include #include #endif @@ -42,28 +58,16 @@ #include #endif -#include -#include - -#include - extern "C" { +#include "mboard.h" +#include "demo_pwm.h" #include +#include #include #include } #include "AppTask.h" -#include "mboard.h" - -using namespace ::chip; -using namespace ::chip::app; -using namespace ::chip::Credentials; -using namespace ::chip::DeviceLayer; - -#if CONFIG_ENABLE_CHIP_SHELL -using namespace chip::Shell; -#endif namespace { @@ -73,15 +77,17 @@ ColorLEDWidget sLightLED; DimmableLEDWidget sLightLED; #endif -Identify sIdentify = { - APP_LIGHT_ENDPOINT_ID, - AppTask::IdentifyStartHandler, - AppTask::IdentifyStopHandler, - Clusters::Identify::IdentifyTypeEnum::kLightOutput, -}; - } // namespace +using namespace ::chip; +using namespace ::chip::app; +using namespace ::chip::Credentials; +using namespace ::chip::DeviceLayer; + +#if CONFIG_ENABLE_CHIP_SHELL +using namespace chip::Shell; +#endif + AppTask AppTask::sAppTask; StackType_t AppTask::appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; StaticTask_t AppTask::appTaskStruct; @@ -133,42 +139,33 @@ void AppTask::PostEvent(app_event_t event) void AppTask::AppTaskMain(void * pvParameter) { app_event_t appEvent; - bool onoff = false; + bool isStateReady = false; -#if !(CHIP_DEVICE_LAYER_TARGET_BL702 && CHIP_DEVICE_CONFIG_ENABLE_ETHERNET) sLightLED.Init(); -#endif - -#ifdef BOOT_PIN_RESET + size_t saved_value_len = 0; +#ifdef LED_BTN_RESET ButtonInit(); #else - /** Without RESET PIN defined, factory reset will be executed if power cycle count(resetCnt) >= APP_REBOOT_RESET_COUNT */ + uint32_t resetCnt = 0; - size_t saved_value_len = 0; + ef_get_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt), &saved_value_len); - - if (resetCnt > APP_REBOOT_RESET_COUNT) - { - resetCnt = 0; - /** To share with RESET PIN logic, mButtonPressedTime is used to recorded resetCnt increased. - * +1 makes sure mButtonPressedTime is not zero; - * a power cycle during factory reset confirm time APP_BUTTON_PRESS_LONG will cancel factoryreset */ - GetAppTask().mButtonPressedTime = System::SystemClock().GetMonotonicMilliseconds64().count() + 1; - } - else - { - resetCnt++; - GetAppTask().mButtonPressedTime = 0; - } + resetCnt++; ef_set_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt)); + ChipLogProgress(NotSpecified, "resetCnt %ld \r\n", resetCnt); #endif - - GetAppTask().sTimer = - xTimerCreate("lightTmr", pdMS_TO_TICKS(APP_TIMER_EVENT_DEFAULT_ITVL), false, NULL, AppTask::TimerCallback); - if (GetAppTask().sTimer == NULL) + saved_value_len = 0; + GetAppTask().isProvisioned=false; + ef_get_env_blob(APP_LIGHT_PROVISION, &GetAppTask().isProvisioned, sizeof(GetAppTask().isProvisioned), &saved_value_len); + if(GetAppTask().isProvisioned==true) { - ChipLogError(NotSpecified, "Failed to create timer task"); - appError(APP_ERROR_EVENT_QUEUE_FAILED); + uint8_t level; + uint16_t temperature; + saved_value_len = 0; + ef_get_env_blob(APP_LIGHT_TEMP, &temperature, sizeof(temperature), &saved_value_len); + saved_value_len = 0; + ef_get_env_blob(APP_LIGHT_LEVEL, &level, sizeof(level), &saved_value_len); + sLightLED.SetTemperature(level, temperature); } ChipLogProgress(NotSpecified, "Starting Platform Manager Event Loop"); @@ -179,48 +176,71 @@ void AppTask::AppTaskMain(void * pvParameter) appError(ret); } - GetAppTask().PostEvent(APP_EVENT_TIMER); - GetAppTask().PostEvent(APP_EVENT_LIGHTING_MASK); - + GetAppTask().PostEvent(AppTask::APP_EVENT_TIMER); vTaskSuspend(NULL); - ChipLogProgress(NotSpecified, "App Task started, with SRAM heap %d left\r\n", xPortGetFreeHeapSize()); +#ifndef LED_BTN_RESET + GetAppTask().mButtonPressedTime = chip::System::SystemClock().GetMonotonicMilliseconds64().count() + 1; + if (ConnectivityMgr().IsThreadProvisioned()) + { + GetAppTask().PostEvent(APP_EVENT_SYS_PROVISIONED); + } +#endif + + GetAppTask().mIsConnected = false; + + GetAppTask().sTimer = xTimerCreate("lightTmr", pdMS_TO_TICKS(1000), false, NULL, AppTask::TimerCallback); + GetAppTask().ProvisionLight_Timer_Init(); + if (GetAppTask().sTimer == NULL) + { + ChipLogError(NotSpecified, "Failed to create timer task"); + appError(APP_ERROR_EVENT_QUEUE_FAILED); + } + + ChipLogProgress(NotSpecified, "App Task started, with heap %d left\r\n", xPortGetFreeHeapSize()); + + StartTimer(); while (true) { appEvent = APP_EVENT_NONE; BaseType_t eventReceived = xTaskNotifyWait(0, APP_EVENT_ALL_MASK, (uint32_t *) &appEvent, portMAX_DELAY); - + if (GetAppTask().mIsConnected == true) + { + if (Server::GetInstance().GetFabricTable().FabricCount() == 0) + { + DeviceLayer::ConfigurationMgr().InitiateFactoryReset(); + } + } if (eventReceived) { PlatformMgr().LockChipStack(); + if (APP_EVENT_SYS_BLE_ADV & appEvent) + { + LightingSetStatus(APP_EVENT_SYS_BLE_ADV); + LightingUpdate(APP_EVENT_LIGHTING_GO_THROUGH); - if (APP_EVENT_LIGHTING_MASK & appEvent) + isStateReady = false; + } + + if (APP_EVENT_SYS_PROVISIONED & appEvent) { - LightingUpdate(appEvent); + LightingSetStatus(APP_EVENT_SYS_PROVISIONED); + LightingUpdate(APP_EVENT_LIGHTING_GO_THROUGH); + + isStateReady = true; } if (APP_EVENT_BTN_SHORT & appEvent) { - if (Server::GetInstance().GetFabricTable().FabricCount()) - { - Clusters::OnOff::Attributes::OnOff::Get(GetAppTask().GetEndpointId(), &onoff); - onoff = !onoff; - Clusters::OnOff::Attributes::OnOff::Set(GetAppTask().GetEndpointId(), onoff); - } - else - { - sLightLED.Toggle(); - } + LightingSetStatus(APP_EVENT_SYS_LIGHT_TOGGLE); + LightingUpdate(APP_EVENT_LIGHTING_GO_THROUGH); } - -#ifdef BOOT_PIN_RESET - if (APP_EVENT_BTN_LONG & appEvent) + if ((APP_EVENT_LIGHTING_MASK & appEvent) && isStateReady) { - /** Turn off light to indicate button long press for factory reset is confirmed */ - sLightLED.SetOnoff(false); + LightingUpdate((app_event_t) (APP_EVENT_LIGHTING_MASK & appEvent)); } -#endif + if (APP_EVENT_IDENTIFY_MASK & appEvent) { IdentifyHandleOp(appEvent); @@ -238,67 +258,238 @@ void AppTask::AppTaskMain(void * pvParameter) } } -void AppTask::LightingUpdate(app_event_t status) +void AppTask::ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg) +{ + switch (event->Type) + { + case DeviceEventType::kCHIPoBLEAdvertisingChange: + +#ifndef LED_BTN_RESET + if (ConnectivityMgr().IsThreadProvisioned()) + { + GetAppTask().PostEvent(APP_EVENT_SYS_PROVISIONED); + break; + } +#endif + + if (ConnectivityMgr().NumBLEConnections()) + { + GetAppTask().PostEvent(APP_EVENT_SYS_BLE_CONN); + } + else + { + if (event->CHIPoBLEAdvertisingChange.Result == kActivity_Started) + { + GetAppTask().PostEvent(APP_EVENT_SYS_BLE_ADV); + } + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + GetAppTask().mIsConnected = ConnectivityMgr().IsWiFiStationConnected(); +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + GetAppTask().mIsConnected = ConnectivityMgr().IsThreadAttached(); +#endif + } + ChipLogProgress(NotSpecified, "BLE adv changed, connection number: %d\r\n", ConnectivityMgr().NumBLEConnections()); + break; +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + case DeviceEventType::kThreadStateChange: + + ChipLogProgress(NotSpecified, "Thread state changed, IsThreadAttached: %d\r\n", ConnectivityMgr().IsThreadAttached()); + if (!GetAppTask().mIsConnected && ConnectivityMgr().IsThreadAttached()) + { + GetAppTask().PostEvent(APP_EVENT_SYS_PROVISIONED); + GetAppTask().mIsConnected = true; + } + break; +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + case DeviceEventType::kWiFiConnectivityChange: + + ChipLogProgress(NotSpecified, "Wi-Fi state changed to %s.\r\n", + ConnectivityMgr().IsWiFiStationConnected() ? "connected" : "disconnected"); + + chip::app::DnssdServer::Instance().StartServer(); + NetworkCommissioning::BLWiFiDriver::GetInstance().SaveConfiguration(); + if (!GetAppTask().mIsConnected && ConnectivityMgr().IsWiFiStationConnected()) + { + GetAppTask().PostEvent(APP_EVENT_SYS_PROVISIONED); + GetAppTask().mIsConnected = true; + } + break; + + case DeviceEventType::kInterfaceIpAddressChanged: + if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || + (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) + { + // MDNS server restart on any ip assignment: if link local ipv6 is configured, that + // will not trigger a 'internet connectivity change' as there is no internet + // connectivity. MDNS still wants to refresh its listening interfaces to include the + // newly selected address. + chip::app::DnssdServer::Instance().StartServer(); + } + + if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned) + { + ChipLogProgress(NotSpecified, "Initializing route hook..."); + bl_route_hook_init(); + } + break; +#endif + case DeviceEventType::kFailSafeTimerExpired: + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + GetAppTask().mIsConnected = ConnectivityMgr().IsWiFiStationConnected(); +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + GetAppTask().mIsConnected = ConnectivityMgr().IsThreadAttached(); +#endif + + break; + default: + break; + } +} + +void AppTask::LightingUpdate(app_event_t event) { uint8_t hue, sat; bool onoff; - DataModel::Nullable v(0); + uint16_t temperature; + uint8_t colormode; + DataModel::Nullable v; EndpointId endpoint = GetAppTask().GetEndpointId(); - if (APP_EVENT_LIGHTING_MASK & status) + do { + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::OnOff::Attributes::OnOff::Get(endpoint, &onoff)) + { + break; + } - if (Server::GetInstance().GetFabricTable().FabricCount()) + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::LevelControl::Attributes::CurrentLevel::Get(endpoint, v)) { - do - { - if (EMBER_ZCL_STATUS_SUCCESS != Clusters::OnOff::Attributes::OnOff::Get(endpoint, &onoff)) - { - break; - } + break; + } +#if 0 + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::CurrentHue::Get(endpoint, &hue)) + { + break; + } - if (EMBER_ZCL_STATUS_SUCCESS != Clusters::LevelControl::Attributes::CurrentLevel::Get(endpoint, v)) - { - break; - } + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::CurrentSaturation::Get(endpoint, &sat)) + { + break; + } +#endif + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::ColorTemperatureMireds::Get(endpoint, &temperature)) + { + break; + } + if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::ColorMode::Get(endpoint, &colormode)) + { + break; + } + if (!onoff) + { + if (GetAppTask().mIsConnected == true) + { + sLightLED.SetLevel(0, colormode); + } + } + else + { + if (v.IsNull()) + { + // Just pick something. + v.SetNonNull(254); + } +#if defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT) - if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::CurrentHue::Get(endpoint, &hue)) - { - break; - } + if (colormode == 0) + { + sLightLED.SetColor(v.Value(), hue, sat); + } + else + { - if (EMBER_ZCL_STATUS_SUCCESS != Clusters::ColorControl::Attributes::CurrentSaturation::Get(endpoint, &sat)) + if (GetAppTask().mIsConnected == true) { - break; + sLightLED.SetTemperature(v.Value(), temperature); } + } - if (!onoff) - { - sLightLED.SetLevel(0); - } - else - { - if (v.IsNull()) - { - v.SetNonNull(254); - } -#if defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT) - sLightLED.SetColor(v.Value(), hue, sat); #else - sLightLED.SetLevel(v.Value()); + sLightLED.SetLevel(v.Value()); #endif - } - } while (0); + if (GetAppTask().mIsConnected == true) + { + // vTaskDelay(50); + ef_set_env_blob(APP_LIGHT_TEMP, &temperature, sizeof(temperature)); + ef_set_env_blob(APP_LIGHT_LEVEL, &v.Value(), sizeof(v.Value())); + } + + } + + } while (0); +} + +void AppTask::LightingSetOnoff(uint8_t bonoff) +{ + uint8_t newValue = bonoff; + EndpointId endpoint = GetAppTask().GetEndpointId(); + + // write the new on/off value + Clusters::OnOff::Attributes::OnOff::Set(endpoint, newValue); + newValue = 254; + Clusters::LevelControl::Attributes::CurrentLevel::Set(endpoint, newValue); +} + +void AppTask::LightingSetStatus(app_event_t status) +{ + uint8_t level, hue, sat; + uint16_t temperature; + bool onoff = true; + EndpointId endpoint = GetAppTask().GetEndpointId(); + + + if (APP_EVENT_SYS_LIGHT_TOGGLE == status) + { + + Clusters::OnOff::Attributes::OnOff::Get(endpoint, &onoff); + onoff = !onoff; + } + else if (APP_EVENT_SYS_BLE_ADV == status) + { + GetAppTask().ProvisionLightTimerStart(); + GetAppTask().isProvisioned = false; + ef_set_env_blob(APP_LIGHT_PROVISION, &GetAppTask().isProvisioned, sizeof( GetAppTask().isProvisioned)); + } + else if (APP_EVENT_SYS_PROVISIONED == status) + { + + if (GetAppTask().isProvisioned == false) + { + set_warm_cold_off(); + vTaskDelay(100); + set_cold_temperature(); + temperature = 370; + onoff = true; + level = 254; + Clusters::ColorControl::Attributes::ColorTemperatureMireds::Set(endpoint, temperature); + Clusters::LevelControl::Attributes::CurrentLevel::Set(endpoint, level); + Clusters::OnOff::Attributes::OnOff::Set(endpoint, onoff); + GetAppTask().isProvisioned = true; + ef_set_env_blob(APP_LIGHT_PROVISION, & GetAppTask().isProvisioned, sizeof( GetAppTask().isProvisioned)); + return; } else { -#if defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT) - /** show yellow to indicate not-provision state for extended color light */ - sLightLED.SetColor(254, 35, 254); -#else - /** show 30% brightness to indicate not-provision state */ - sLightLED.SetLevel(25); -#endif + GetAppTask().isProvisioned = true; + ef_set_env_blob(APP_LIGHT_PROVISION, & GetAppTask().isProvisioned, sizeof( GetAppTask().isProvisioned)); + onoff = true; + Clusters::OnOff::Attributes::OnOff::Set(endpoint, onoff); } } } @@ -312,7 +503,7 @@ bool AppTask::StartTimer(void) if (GetAppTask().mTimerIntvl == 0) { - GetAppTask().mTimerIntvl = APP_TIMER_EVENT_DEFAULT_ITVL; + GetAppTask().mTimerIntvl = 1000; } if (xTimerChangePeriod(GetAppTask().sTimer, pdMS_TO_TICKS(GetAppTask().mTimerIntvl), pdMS_TO_TICKS(100)) != pdPASS) @@ -335,78 +526,117 @@ void AppTask::TimerCallback(TimerHandle_t xTimer) void AppTask::TimerEventHandler(app_event_t event) { - uint32_t pressedTime = 0; - - if (GetAppTask().mButtonPressedTime) + if (event & APP_EVENT_BTN_FACTORY_RESET_PRESS) { - pressedTime = System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime; -#ifdef BOOT_PIN_RESET - if (ButtonPressed()) - { - if (pressedTime > APP_BUTTON_PRESS_LONG) - { - GetAppTask().PostEvent(APP_EVENT_BTN_LONG); - } - else if (pressedTime >= APP_BUTTON_PRESS_SHORT) - { -#if defined(BL602_NIGHT_LIGHT) || defined(BL706_NIGHT_LIGHT) - /** change color to indicate to wait factory reset confirm */ - sLightLED.SetColor(254, 0, 210); -#else - /** toggle led to indicate to wait factory reset confirm */ - sLightLED.Toggle(); -#endif - } - } - else - { - if (pressedTime >= APP_BUTTON_PRESS_LONG) - { - GetAppTask().PostEvent(APP_EVENT_FACTORY_RESET); - } - else if (APP_BUTTON_PRESS_SHORT >= pressedTime && pressedTime >= APP_BUTTON_PRESS_JITTER) - { - GetAppTask().PostEvent(APP_EVENT_BTN_SHORT); - } - else - { - GetAppTask().PostEvent(APP_EVENT_LIGHTING_MASK); - } - - GetAppTask().mTimerIntvl = APP_BUTTON_PRESSED_ITVL; - GetAppTask().mButtonPressedTime = 0; - } -#else - if (pressedTime > APP_BUTTON_PRESS_LONG) + GetAppTask().mTimerIntvl = APP_BUTTON_PRESS_JITTER; + StartTimer(); + } + else if (event & APP_EVENT_BTN_FACTORY_RESET_IND) + { + if (GetAppTask().mButtonPressedTime) { - /** factory reset confirm timeout */ + GetAppTask().mIsFactoryResetIndicat = true; +#if defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT) + // sLightLED.SetColor(254, 0, 210); +#ifndef LED_BTN_RESET + uint32_t resetCnt = 0; GetAppTask().mButtonPressedTime = 0; + ef_set_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt)); + + vTaskDelay(APP_BUTTON_PRESS_LONG); GetAppTask().PostEvent(APP_EVENT_FACTORY_RESET); - } - else - { -#if defined(BL602_NIGHT_LIGHT) || defined(BL706_NIGHT_LIGHT) - /** change color to indicate to wait factory reset confirm */ - sLightLED.SetColor(254, 0, 210); +#endif #else - /** toggle led to indicate to wait factory reset confirm */ sLightLED.Toggle(); + GetAppTask().mTimerIntvl = 100; + StartTimer(); #endif } -#endif } -#ifdef BOOT_PIN_RESET - else + + if (event & APP_EVENT_BTN_FACTORY_RESET_CANCEL) { - if (ButtonPressed()) + GetAppTask().mTimerIntvl = 1000; + StartTimer(); + if (GetAppTask().mIsFactoryResetIndicat) { - GetAppTask().mTimerIntvl = APP_BUTTON_PRESSED_ITVL; - GetAppTask().mButtonPressedTime = System::SystemClock().GetMonotonicMilliseconds64().count(); + LightingUpdate(APP_EVENT_LIGHTING_GO_THROUGH); } + GetAppTask().mIsFactoryResetIndicat = false; + GetAppTask().mButtonPressedTime = 0; } + + if (APP_EVENT_TIMER & event) + { + if (GetAppTask().mButtonPressedTime) + { + if (GetAppTask().mIsFactoryResetIndicat) + { + if (chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime >= + APP_BUTTON_PRESS_LONG) + { + /** factory reset indicat done. */ + sLightLED.SetOnoff(false); + GetAppTask().mTimerIntvl = 1000; + } + else + { +#if !(defined(BL706_NIGHT_LIGHT) || defined(BL602_NIGHT_LIGHT)) + sLightLED.Toggle(); #endif + } + } + else + { - StartTimer(); +#if defined(BL706_NIGHT_LIGHT) && !defined(LED_BTN_RESET) + + if (GetAppTask().mButtonPressedTime) + { + uint32_t resetCnt = 0; + + if (chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime > + APP_BUTTON_PRESS_LONG * 2) + { + GetAppTask().mButtonPressedTime = 0; + } + else if (chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime > + APP_BUTTON_PRESS_LONG) + { + + size_t saved_value_len = 0; + + ef_get_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt), &saved_value_len); + if (resetCnt >= APP_REBOOT_RESET_COUNT) + { + GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_IND); + } + + /** a power cycle during factory reset indication state will quit factory reset operation */ + resetCnt = 0; + ef_set_env_blob(APP_REBOOT_RESET_COUNT_KEY, &resetCnt, sizeof(resetCnt)); + } + } +#else + if (ButtonPressed()) + { + if (!GetAppTask().mIsFactoryResetIndicat && + chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime >= + APP_BUTTON_PRESS_SHORT) + { + GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_IND); + } + } + else + { + GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_CANCEL); + } +#endif + } + } + + StartTimer(); + } } void AppTask::IdentifyStartHandler(Identify *) @@ -438,22 +668,84 @@ void AppTask::IdentifyHandleOp(app_event_t event) if (APP_EVENT_IDENTIFY_STOP & event) { identifyState = 0; - GetAppTask().PostEvent(APP_EVENT_LIGHTING_MASK); + LightingUpdate(APP_EVENT_LIGHTING_GO_THROUGH); ChipLogProgress(NotSpecified, "identify stop"); } } +void AppTask::ProvisionLight_Timer_Init(void) +{ + GetAppTask().ProvisionLightTimer = + xTimerCreate("ProvisionLightTmr", pdMS_TO_TICKS(100), pdTRUE, NULL, AppTask::ProvisionLightTimerCallback); + if (GetAppTask().ProvisionLightTimer == NULL) + { + ChipLogError(NotSpecified, "Failed to create timer task"); + } +} +void AppTask::ProvisionLightTimerCallback(TimerHandle_t xTimer) +{ + + if (GetAppTask().mIsConnected == false) + { + if (GetAppTask().ProvisionLightTimer_Count == 0) + { + set_cold_temperature(); + ChipLogError(NotSpecified, "set_cold_temperature"); + } + else if (GetAppTask().ProvisionLightTimer_Count == 10) + { + set_warm_cold_off(); + ChipLogError(NotSpecified, "set_coldwarm off"); + } + else if (GetAppTask().ProvisionLightTimer_Count == 11) + { + set_warm_temperature(); + ChipLogError(NotSpecified, "set_warm_temperature"); + } + else if (GetAppTask().ProvisionLightTimer_Count == 12) + { + set_warm_cold_off(); + ChipLogError(NotSpecified, "set_coldwarm off"); + } + else if (GetAppTask().ProvisionLightTimer_Count == 13) + { + set_cold_temperature(); + ChipLogError(NotSpecified, "set_cold_temperature"); + ProvisionLightTimerStop(); + } + } + GetAppTask().ProvisionLightTimer_Count++; +} +void AppTask::ProvisionLightTimerStart(void) +{ + if (xTimerIsTimerActive(GetAppTask().ProvisionLightTimer) && GetAppTask().ProvisionLightTimer != NULL) + { + ProvisionLightTimerStop(); + } + + if (xTimerChangePeriod(GetAppTask().ProvisionLightTimer, pdMS_TO_TICKS(100), 0) != pdPASS) + { + ChipLogProgress(NotSpecified, "Failed to access timer with 100 ms delay."); + } +} +void AppTask::ProvisionLightTimerStop(void) +{ + xTimerStop(GetAppTask().ProvisionLightTimer, 0); + GetAppTask().ProvisionLightTimer_Count = 0; +} + void AppTask::ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction) { GetAppTask().PostEvent(APP_EVENT_FACTORY_RESET); } -#ifdef BOOT_PIN_RESET -static hosal_gpio_dev_t gpio_key = { .port = BOOT_PIN_RESET, .config = INPUT_HIGH_IMPEDANCE, .priv = NULL }; +#ifdef LED_BTN_RESET +hosal_gpio_dev_t gpio_key = { .port = LED_BTN_RESET, .config = INPUT_HIGH_IMPEDANCE, .priv = NULL }; void AppTask::ButtonInit(void) { - GetAppTask().mButtonPressedTime = 0; + GetAppTask().mButtonPressedTime = 0; + GetAppTask().mIsFactoryResetIndicat = false; hosal_gpio_init(&gpio_key); hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_POS_PULSE, GetAppTask().ButtonEventHandler, NULL); @@ -462,17 +754,43 @@ void AppTask::ButtonInit(void) bool AppTask::ButtonPressed(void) { uint8_t val = 1; - hosal_gpio_input_get(&gpio_key, &val); - return val == 1; } void AppTask::ButtonEventHandler(void * arg) { + uint32_t presstime; if (ButtonPressed()) { - GetAppTask().PostEvent(APP_EVENT_BTN_ISR); + hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_NEG_LEVEL, GetAppTask().ButtonEventHandler, NULL); + + GetAppTask().mButtonPressedTime = chip::System::SystemClock().GetMonotonicMilliseconds64().count(); + GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_PRESS); + } + else + { + hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_POS_PULSE, GetAppTask().ButtonEventHandler, NULL); + + if (GetAppTask().mButtonPressedTime) + { + + presstime = chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime; + if (presstime >= APP_BUTTON_PRESS_LONG) + { + GetAppTask().PostEvent(APP_EVENT_FACTORY_RESET); + } + else if (presstime <= APP_BUTTON_PRESS_SHORT && presstime >= APP_BUTTON_PRESS_JITTER) + { + GetAppTask().PostEvent(APP_EVENT_BTN_SHORT); + } + else + { + GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_CANCEL); + } + } + + GetAppTask().mButtonPressedTime = 0; } } #endif diff --git a/examples/lighting-app/bouffalolab/common/AppTask.h b/examples/lighting-app/bouffalolab/common/AppTask.h index bcc9dbaec7a4b5..225b521629f679 100644 --- a/examples/lighting-app/bouffalolab/common/AppTask.h +++ b/examples/lighting-app/bouffalolab/common/AppTask.h @@ -21,24 +21,27 @@ #include #include +// #include "AppEvent.h" + #include "FreeRTOS.h" #include "timers.h" - #include using namespace ::chip; using namespace ::chip::DeviceLayer; -#define APP_BUTTON_PRESSED_ITVL 50 -#define APP_BUTTON_PRESS_JITTER 100 +#define APP_BUTTON_PRESS_JITTER 50 #define APP_BUTTON_PRESS_SHORT 1000 -#define APP_BUTTON_PRESS_LONG 4000 -#define APP_TIMER_EVENT_DEFAULT_ITVL 1000 +#define APP_BUTTON_PRESS_LONG 2000 #define APP_LIGHT_ENDPOINT_ID 1 -#define APP_REBOOT_RESET_COUNT 3 +#define APP_REBOOT_RESET_COUNT 6 #define APP_REBOOT_RESET_COUNT_KEY "app_reset_cnt" +#define APP_LIGHT_TEMP "app_light_temp" +#define APP_LIGHT_LEVEL "app_light_level" + +#define APP_LIGHT_PROVISION "app_light_provision" // Application-defined error codes in the CHIP_ERROR space. #define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) #define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) @@ -52,30 +55,41 @@ struct Identify; class AppTask { public: - friend AppTask & GetAppTask(void); - enum app_event_t { APP_EVENT_NONE = 0x00000000, - APP_EVENT_TIMER = 0x00000010, - APP_EVENT_BTN_SHORT = 0x00000020, - APP_EVENT_FACTORY_RESET = 0x00000040, - APP_EVENT_BTN_LONG = 0x00000080, - APP_EVENT_BTN_ISR = 0x00000100, + APP_EVENT_BTN_FACTORY_RESET_CANCEL = 0x00000002, + APP_EVENT_BTN_FACTORY_RESET_IND = 0x00000004, + APP_EVENT_BTN_FACTORY_RESET_PRESS = 0x00000008, + + APP_EVENT_BTN_ALL_MASK = + APP_EVENT_BTN_FACTORY_RESET_CANCEL | APP_EVENT_BTN_FACTORY_RESET_IND | APP_EVENT_BTN_FACTORY_RESET_PRESS, + APP_EVENT_TIMER = 0x00000010, + APP_EVENT_BTN_SHORT = 0x00000020, + + APP_EVENT_SYS_BLE_ADV = 0x00000100, + APP_EVENT_SYS_BLE_CONN = 0x00000200, + APP_EVENT_SYS_PROVISIONED = 0x00000400, + APP_EVENT_SYS_LIGHT_TOGGLE = 0x00000800, + APP_EVENT_FACTORY_RESET = 0x00001000, - APP_EVENT_LIGHTING_ONOFF = 0x00010000, - APP_EVENT_LIGHTING_LEVEL = 0x00020000, - APP_EVENT_LIGHTING_COLOR = 0x00040000, - APP_EVENT_LIGHTING_MASK = APP_EVENT_LIGHTING_ONOFF | APP_EVENT_LIGHTING_LEVEL | APP_EVENT_LIGHTING_COLOR, + APP_EVENT_SYS_ALL_MASK = + APP_EVENT_SYS_BLE_ADV | APP_EVENT_SYS_BLE_CONN | APP_EVENT_SYS_PROVISIONED | APP_EVENT_FACTORY_RESET, + + APP_EVENT_LIGHTING_ONOFF = 0x00010000, + APP_EVENT_LIGHTING_LEVEL = 0x00020000, + APP_EVENT_LIGHTING_COLOR = 0x00040000, + APP_EVENT_LIGHTING_GO_THROUGH = 0x00100000, + APP_EVENT_LIGHTING_MASK = APP_EVENT_LIGHTING_ONOFF | APP_EVENT_LIGHTING_LEVEL | APP_EVENT_LIGHTING_COLOR, APP_EVENT_IDENTIFY_START = 0x01000000, APP_EVENT_IDENTIFY_IDENTIFY = 0x02000000, APP_EVENT_IDENTIFY_STOP = 0x04000000, APP_EVENT_IDENTIFY_MASK = APP_EVENT_IDENTIFY_START | APP_EVENT_IDENTIFY_IDENTIFY | APP_EVENT_IDENTIFY_STOP, - APP_EVENT_ALL_MASK = APP_EVENT_LIGHTING_MASK | APP_EVENT_TIMER | APP_EVENT_BTN_SHORT | APP_EVENT_BTN_LONG | - APP_EVENT_BTN_ISR | APP_EVENT_IDENTIFY_MASK, + APP_EVENT_ALL_MASK = APP_EVENT_LIGHTING_MASK | APP_EVENT_BTN_ALL_MASK | APP_EVENT_SYS_ALL_MASK | APP_EVENT_TIMER | + APP_EVENT_BTN_SHORT | APP_EVENT_IDENTIFY_MASK, }; void SetEndpointId(EndpointId endpointId) @@ -87,20 +101,22 @@ class AppTask EndpointId GetEndpointId(void) { return mEndpointId; } void PostEvent(app_event_t event); void ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction); -#ifdef BOOT_PIN_RESET - static void ButtonEventHandler(void * arg); -#endif static void IdentifyStartHandler(Identify *); static void IdentifyStopHandler(Identify *); static void IdentifyHandleOp(app_event_t event); private: + friend AppTask & GetAppTask(void); friend void StartAppTask(void); friend PlatformManagerImpl; + static void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg); static uint32_t AppRebootCheck(uint32_t time = 0); + static void LightingSetOnoff(uint8_t bonoff); + static void LightingSetStatus(app_event_t status); + static void LightingSetBleAdv(void); static void LightingSetProvisioned(void); static void LightingSetFactoryReset(void); @@ -112,9 +128,15 @@ class AppTask static void TimerEventHandler(app_event_t event); static void TimerCallback(TimerHandle_t xTimer); -#ifdef BOOT_PIN_RESET + static void ProvisionLight_Timer_Init(void); + static void ProvisionLightTimerCallback(TimerHandle_t xTimer); + static void ProvisionLightTimerStart(void); + static void ProvisionLightTimerStop(void); + +#ifdef LED_BTN_RESET static void ButtonInit(void); static bool ButtonPressed(void); + static void ButtonEventHandler(void * arg); #endif static void ScheduleInit(intptr_t arg); @@ -129,6 +151,11 @@ class AppTask TimerHandle_t sTimer; uint32_t mTimerIntvl; uint64_t mButtonPressedTime; + bool mIsFactoryResetIndicat; + bool mIsConnected; + bool isProvisioned = true; + TimerHandle_t ProvisionLightTimer; + uint8_t ProvisionLightTimer_Count; static StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; static StaticTask_t appTaskStruct; diff --git a/examples/lighting-app/bouffalolab/data_model/BUILD.gn b/examples/lighting-app/bouffalolab/data_model/BUILD.gn new file mode 100644 index 00000000000000..c8176fd1163a92 --- /dev/null +++ b/examples/lighting-app/bouffalolab/data_model/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("//build_overrides/chip.gni") +import("${chip_root}/src/app/chip_data_model.gni") +import("${chip_root}/src/platform/device.gni") + +chip_data_model("bouffalolab-lighting") { + if (chip_enable_wifi) { + zap_file = "lighting-app-wifi.zap" + } else { + zap_file = "lighting-app-thread.zap" + } + + zap_pregenerated_dir = "${chip_root}/zzz_generated/lighting-app/zap-generated" + is_server = true +} diff --git a/examples/platform/bouffalolab/common/iot_sdk/demo_pwm.c b/examples/platform/bouffalolab/common/iot_sdk/demo_pwm.c index b2343b63e079fa..81cb2f524604a4 100644 --- a/examples/platform/bouffalolab/common/iot_sdk/demo_pwm.c +++ b/examples/platform/bouffalolab/common/iot_sdk/demo_pwm.c @@ -4,124 +4,312 @@ * Contact information: * web site: https://www.bouffalolab.com/ */ -#include - -#include #include "demo_pwm.h" #include "mboard.h" +#include +#include +#include +#include +#include +#include -#define PWM_FREQ 1000 +#define PWM_FREQ 600 #define PWM_DUTY_CYCLE 10000 -hosal_pwm_dev_t rgb_pwm[] = { +static TimerHandle_t Light_TimerHdl = NULL; +volatile static char Light_Timer_Status = 0; +static void demo_hosal_pwm_task_init(void); +static void Light_TimerHandler(TimerHandle_t p_timerhdl); +static void hard_set_color(uint8_t currLevel, uint8_t currHue, uint8_t currSat); +static uint32_t new_Rduty = 0; +static uint32_t new_Gduty = 0; +static uint32_t new_Bduty = 0; +static uint32_t new_Cduty = 0; +static uint32_t new_Wduty = 0; -#if MAX_PWM_CHANNEL == 3 - { - .port = LED_B_PIN_PORT, - /* pwm config */ - .config.pin = LED_B_PIN, - .config.duty_cycle = 0, // duty_cycle range is 0~10000 correspond to 0~100% - .config.freq = PWM_FREQ, // freq range is between 0~40MHZ - }, - { - .port = LED_R_PIN_PORT, - /* pwm config */ - .config.pin = LED_R_PIN, - .config.duty_cycle = 0, // duty_cycle range is 0~10000 correspond to 0~100% - .config.freq = PWM_FREQ, // freq range is between 0~40MHZ - }, - { - .port = LED_G_PIN_PORT, - /* pwm config */ - .config.pin = LED_G_PIN, - .config.duty_cycle = 0, // duty_cycle range is 0~10000 correspond to 0~100% - .config.freq = PWM_FREQ, // freq range is between 0~40MHZ - } -#else - { - .port = LED_PIN_PORT, - /* pwm config */ - .config.pin = LED_PIN, - .config.duty_cycle = 0, // duty_cycle range is 0~10000 correspond to 0~100% - .config.freq = PWM_FREQ, // freq range is between 0~40MHZ - }, -#endif +static uint32_t Rduty = 0; +static uint32_t Gduty = 0; +static uint32_t Bduty = 0; +static uint32_t Cduty = 0; +static uint32_t Wduty = 0; +static uint16_t targettemp; +static uint8_t targetlevel; +const float pwm_curve[] = { + 0, 1.0, 1.002, 1.003, 1.005, 1.006, 1.008, 1.009, 1.011, 1.012, 1.014, 1.015, 1.017, 1.018, 1.02, 1.021, + 1.023, 1.024, 1.026, 1.028, 1.029, 1.031, 1.032, 1.034, 1.035, 1.037, 1.039, 1.04, 1.042, 1.043, 1.045, 1.046, + 1.048, 1.05, 1.051, 1.053, 1.054, 1.056, 1.058, 1.059, 1.061, 1.062, 1.064, 1.066, 1.067, 1.069, 1.07, 1.072, + 1.074, 1.075, 1.077, 1.078, 1.08, 1.082, 1.083, 1.085, 1.087, 1.088, 1.09, 1.092, 1.093, 1.095, 1.097, 1.098, + 1.1, 1.102, 1.103, 1.105, 1.107, 1.108, 1.11, 1.112, 1.113, 1.115, 1.117, 1.118, 1.12, 1.122, 1.123, 1.125, + 1.127, 1.129, 1.13, 1.132, 1.134, 1.135, 1.137, 1.139, 1.141, 1.142, 1.144, 1.146, 1.147, 1.149, 1.151, 1.153, + 1.154, 1.156, 1.158, 1.16, 1.161, 1.163, 1.165, 1.167, 1.168, 1.17, 1.172, 1.174, 1.176, 1.177, 1.179, 1.181, + 1.183, 1.184, 1.186, 1.188, 1.19, 1.192, 1.193, 1.195, 1.197, 1.199, 1.201, 1.202, 1.204, 1.206, 1.208, 1.21, + 1.212, 1.213, 1.215, 1.217, 1.219, 1.221, 1.223, 1.224, 1.226, 1.228, 1.23, 1.232, 1.234, 1.236, 1.238, 1.239, + 1.241, 1.243, 1.245, 1.247, 1.249, 1.251, 1.253, 1.254, 1.256, 1.258, 1.26, 1.262, 1.264, 1.266, 1.268, 1.27, + 1.272, 1.274, 1.275, 1.277, 1.279, 1.281, 1.283, 1.285, 1.287, 1.289, 1.291, 1.293, 1.295, 1.297, 1.299, 1.301, + 1.303, 1.305, 1.307, 1.309, 1.311, 1.313, 1.315, 1.317, 1.319, 1.321, 1.323, 1.325, 1.327, 1.329, 1.331, 1.333, + 1.335, 1.337, 1.339, 1.341, 1.343, 1.345, 1.347, 1.349, 1.351, 1.353, 1.355, 1.357, 1.359, 1.361, 1.363, 1.365, + 1.367, 1.369, 1.371, 1.374, 1.376, 1.378, 1.38, 1.382, 1.384, 1.386, 1.388, 1.39, 1.392, 1.394, 1.397, 1.399, + 1.401, 1.403, 1.405, 1.407, 1.409, 1.411, 1.414, 1.416, 1.418, 1.42, 1.422, 1.424, 1.426, 1.429, 1.431, 1.433, + 1.435, 1.437, 1.439, 1.442, 1.444, 1.446, 1.448, 1.45, 1.453, 1.455, 1.457, 1.459, 1.461, 1.464, 1.466, 1.468, + 1.47, 1.472, 1.475, 1.477, 1.479, 1.481, 1.484, 1.486, 1.488, 1.49, 1.493, 1.495, 1.497, 1.499, 1.502, 1.504, + 1.506, 1.508, 1.511, 1.513, 1.515, 1.518, 1.52, 1.522, 1.525, 1.527, 1.529, 1.531, 1.534, 1.536, 1.538, 1.541, + 1.543, 1.545, 1.548, 1.55, 1.552, 1.555, 1.557, 1.559, 1.562, 1.564, 1.567, 1.569, 1.571, 1.574, 1.576, 1.578, + 1.581, 1.583, 1.586, 1.588, 1.59, 1.593, 1.595, 1.598, 1.6, 1.602, 1.605, 1.607, 1.61, 1.612, 1.615, 1.617, + 1.62, 1.622, 1.624, 1.627, 1.629, 1.632, 1.634, 1.637, 1.639, 1.642, 1.644, 1.647, 1.649, 1.652, 1.654, 1.657, + 1.659, 1.662, 1.664, 1.667, 1.669, 1.672, 1.674, 1.677, 1.679, 1.682, 1.684, 1.687, 1.69, 1.692, 1.695, 1.697, + 1.7, 1.702, 1.705, 1.707, 1.71, 1.713, 1.715, 1.718, 1.72, 1.723, 1.726, 1.728, 1.731, 1.733, 1.736, 1.739, + 1.741, 1.744, 1.747, 1.749, 1.752, 1.755, 1.757, 1.76, 1.763, 1.765, 1.768, 1.771, 1.773, 1.776, 1.779, 1.781, + 1.784, 1.787, 1.789, 1.792, 1.795, 1.798, 1.8, 1.803, 1.806, 1.808, 1.811, 1.814, 1.817, 1.819, 1.822, 1.825, + 1.828, 1.83, 1.833, 1.836, 1.839, 1.842, 1.844, 1.847, 1.85, 1.853, 1.855, 1.858, 1.861, 1.864, 1.867, 1.87, + 1.872, 1.875, 1.878, 1.881, 1.884, 1.887, 1.889, 1.892, 1.895, 1.898, 1.901, 1.904, 1.907, 1.91, 1.912, 1.915, + 1.918, 1.921, 1.924, 1.927, 1.93, 1.933, 1.936, 1.939, 1.942, 1.945, 1.947, 1.95, 1.953, 1.956, 1.959, 1.962, + 1.965, 1.968, 1.971, 1.974, 1.977, 1.98, 1.983, 1.986, 1.989, 1.992, 1.995, 1.998, 2.001, 2.004, 2.007, 2.01, + 2.013, 2.016, 2.019, 2.022, 2.025, 2.029, 2.032, 2.035, 2.038, 2.041, 2.044, 2.047, 2.05, 2.053, 2.056, 2.059, + 2.063, 2.066, 2.069, 2.072, 2.075, 2.078, 2.081, 2.085, 2.088, 2.091, 2.094, 2.097, 2.1, 2.103, 2.107, 2.11, + 2.113, 2.116, 2.119, 2.123, 2.126, 2.129, 2.132, 2.136, 2.139, 2.142, 2.145, 2.148, 2.152, 2.155, 2.158, 2.162, + 2.165, 2.168, 2.171, 2.175, 2.178, 2.181, 2.184, 2.188, 2.191, 2.194, 2.198, 2.201, 2.204, 2.208, 2.211, 2.214, + 2.218, 2.221, 2.224, 2.228, 2.231, 2.235, 2.238, 2.241, 2.245, 2.248, 2.252, 2.255, 2.258, 2.262, 2.265, 2.269, + 2.272, 2.275, 2.279, 2.282, 2.286, 2.289, 2.293, 2.296, 2.3, 2.303, 2.307, 2.31, 2.314, 2.317, 2.321, 2.324, + 2.328, 2.331, 2.335, 2.338, 2.342, 2.345, 2.349, 2.352, 2.356, 2.36, 2.363, 2.367, 2.37, 2.374, 2.377, 2.381, + 2.385, 2.388, 2.392, 2.395, 2.399, 2.403, 2.406, 2.41, 2.414, 2.417, 2.421, 2.425, 2.428, 2.432, 2.436, 2.439, + 2.443, 2.447, 2.45, 2.454, 2.458, 2.462, 2.465, 2.469, 2.473, 2.476, 2.48, 2.484, 2.488, 2.491, 2.495, 2.499, + 2.503, 2.507, 2.51, 2.514, 2.518, 2.522, 2.526, 2.529, 2.533, 2.537, 2.541, 2.545, 2.549, 2.552, 2.556, 2.56, + 2.564, 2.568, 2.572, 2.576, 2.58, 2.584, 2.587, 2.591, 2.595, 2.599, 2.603, 2.607, 2.611, 2.615, 2.619, 2.623, + 2.627, 2.631, 2.635, 2.639, 2.643, 2.647, 2.651, 2.655, 2.659, 2.663, 2.667, 2.671, 2.675, 2.679, 2.683, 2.687, + 2.691, 2.695, 2.699, 2.703, 2.707, 2.712, 2.716, 2.72, 2.724, 2.728, 2.732, 2.736, 2.74, 2.745, 2.749, 2.753, + 2.757, 2.761, 2.765, 2.77, 2.774, 2.778, 2.782, 2.786, 2.791, 2.795, 2.799, 2.803, 2.807, 2.812, 2.816, 2.82, + 2.824, 2.829, 2.833, 2.837, 2.842, 2.846, 2.85, 2.854, 2.859, 2.863, 2.867, 2.872, 2.876, 2.881, 2.885, 2.889, + 2.894, 2.898, 2.902, 2.907, 2.911, 2.916, 2.92, 2.924, 2.929, 2.933, 2.938, 2.942, 2.947, 2.951, 2.955, 2.96, + 2.964, 2.969, 2.973, 2.978, 2.982, 2.987, 2.991, 2.996, 3.0, 3.005, 3.01, 3.014, 3.019, 3.023, 3.028, 3.032, + 3.037, 3.042, 3.046, 3.051, 3.055, 3.06, 3.065, 3.069, 3.074, 3.079, 3.083, 3.088, 3.093, 3.097, 3.102, 3.107, + 3.111, 3.116, 3.121, 3.125, 3.13, 3.135, 3.14, 3.144, 3.149, 3.154, 3.159, 3.163, 3.168, 3.173, 3.178, 3.183, + 3.187, 3.192, 3.197, 3.202, 3.207, 3.212, 3.217, 3.221, 3.226, 3.231, 3.236, 3.241, 3.246, 3.251, 3.256, 3.261, + 3.265, 3.27, 3.275, 3.28, 3.285, 3.29, 3.295, 3.3, 3.305, 3.31, 3.315, 3.32, 3.325, 3.33, 3.335, 3.34, + 3.345, 3.35, 3.356, 3.361, 3.366, 3.371, 3.376, 3.381, 3.386, 3.391, 3.396, 3.402, 3.407, 3.412, 3.417, 3.422, + 3.427, 3.432, 3.438, 3.443, 3.448, 3.453, 3.459, 3.464, 3.469, 3.474, 3.479, 3.485, 3.49, 3.495, 3.501, 3.506, + 3.511, 3.517, 3.522, 3.527, 3.532, 3.538, 3.543, 3.549, 3.554, 3.559, 3.565, 3.57, 3.575, 3.581, 3.586, 3.592, + 3.597, 3.603, 3.608, 3.613, 3.619, 3.624, 3.63, 3.635, 3.641, 3.646, 3.652, 3.657, 3.663, 3.669, 3.674, 3.68, + 3.685, 3.691, 3.696, 3.702, 3.708, 3.713, 3.719, 3.724, 3.73, 3.736, 3.741, 3.747, 3.753, 3.758, 3.764, 3.77, + 3.775, 3.781, 3.787, 3.793, 3.798, 3.804, 3.81, 3.816, 3.821, 3.827, 3.833, 3.839, 3.844, 3.85, 3.856, 3.862, + 3.868, 3.874, 3.88, 3.885, 3.891, 3.897, 3.903, 3.909, 3.915, 3.921, 3.927, 3.933, 3.939, 3.945, 3.951, 3.956, + 3.962, 3.968, 3.974, 3.98, 3.986, 3.993, 3.999, 4.005, 4.011, 4.017, 4.023, 4.029, 4.035, 4.041, 4.047, 4.053, + 4.059, 4.066, 4.072, 4.078, 4.084, 4.09, 4.096, 4.103, 4.109, 4.115, 4.121, 4.128, 4.134, 4.14, 4.146, 4.153, + 4.159, 4.165, 4.171, 4.178, 4.184, 4.19, 4.197, 4.203, 4.209, 4.216, 4.222, 4.229, 4.235, 4.241, 4.248, 4.254, + 4.261, 4.267, 4.274, 4.28, 4.286, 4.293, 4.299, 4.306, 4.312, 4.319, 4.325, 4.332, 4.339, 4.345, 4.352, 4.358, + 4.365, 4.371, 4.378, 4.385, 4.391, 4.398, 4.405, 4.411, 4.418, 4.425, 4.431, 4.438, 4.445, 4.452, 4.458, 4.465, + 4.472, 4.478, 4.485, 4.492, 4.499, 4.506, 4.512, 4.519, 4.526, 4.533, 4.54, 4.547, 4.554, 4.56, 4.567, 4.574, + 4.581, 4.588, 4.595, 4.602, 4.609, 4.616, 4.623, 4.63, 4.637, 4.644, 4.651, 4.658, 4.665, 4.672, 4.679, 4.686, + 4.693, 4.7, 4.708, 4.715, 4.722, 4.729, 4.736, 4.743, 4.75, 4.758, 4.765, 4.772, 4.779, 4.786, 4.794, 4.801, + 4.808, 4.815, 4.823, 4.83, 4.837, 4.845, 4.852, 4.859, 4.867, 4.874, 4.881, 4.889, 4.896, 4.904, 4.911, 4.918, + 4.926, 4.933, 4.941, 4.948, 4.956, 4.963, 4.971, 4.978, 4.986, 4.993, 5.001, 5.008, 5.016, 5.024, 5.031, 5.039, + 5.046, 5.054, 5.062, 5.069, 5.077, 5.085, 5.092, 5.1, 5.108, 5.116, 5.123, 5.131, 5.139, 5.147, 5.154, 5.162, + 5.17, 5.178, 5.186, 5.193, 5.201, 5.209, 5.217, 5.225, 5.233, 5.241, 5.249, 5.257, 5.265, 5.273, 5.281, 5.289, + 5.297, 5.305, 5.313, 5.321, 5.329, 5.337, 5.345, 5.353, 5.361, 5.369, 5.377, 5.385, 5.393, 5.402, 5.41, 5.418, + 5.426, 5.434, 5.443, 5.451, 5.459, 5.467, 5.476, 5.484, 5.492, 5.5, 5.509, 5.517, 5.525, 5.534, 5.542, 5.551, + 5.559, 5.567, 5.576, 5.584, 5.593, 5.601, 5.61, 5.618, 5.627, 5.635, 5.644, 5.652, 5.661, 5.669, 5.678, 5.686, + 5.695, 5.704, 5.712, 5.721, 5.73, 5.738, 5.747, 5.756, 5.764, 5.773, 5.782, 5.791, 5.799, 5.808, 5.817, 5.826, + 5.834, 5.843, 5.852, 5.861, 5.87, 5.879, 5.888, 5.896, 5.905, 5.914, 5.923, 5.932, 5.941, 5.95, 5.959, 5.968, + 5.977, 5.986, 5.995, 6.004, 6.013, 6.023, 6.032, 6.041, 6.05, 6.059, 6.068, 6.077, 6.087, 6.096, 6.105, 6.114, + 6.124, 6.133, 6.142, 6.151, 6.161, 6.17, 6.179, 6.189, 6.198, 6.207, 6.217, 6.226, 6.236, 6.245, 6.255, 6.264, + 6.273, 6.283, 6.292, 6.302, 6.311, 6.321, 6.331, 6.34, 6.35, 6.359, 6.369, 6.379, 6.388, 6.398, 6.408, 6.417, + 6.427, 6.437, 6.446, 6.456, 6.466, 6.476, 6.486, 6.495, 6.505, 6.515, 6.525, 6.535, 6.545, 6.555, 6.564, 6.574, + 6.584, 6.594, 6.604, 6.614, 6.624, 6.634, 6.644, 6.654, 6.664, 6.674, 6.685, 6.695, 6.705, 6.715, 6.725, 6.735, + 6.745, 6.756, 6.766, 6.776, 6.786, 6.797, 6.807, 6.817, 6.828, 6.838, 6.848, 6.859, 6.869, 6.879, 6.89, 6.9, + 6.911, 6.921, 6.931, 6.942, 6.952, 6.963, 6.974, 6.984, 6.995, 7.005, 7.016, 7.026, 7.037, 7.048, 7.058, 7.069, + 7.08, 7.09, 7.101, 7.112, 7.123, 7.133, 7.144, 7.155, 7.166, 7.177, 7.188, 7.198, 7.209, 7.22, 7.231, 7.242, + 7.253, 7.264, 7.275, 7.286, 7.297, 7.308, 7.319, 7.33, 7.341, 7.352, 7.363, 7.375, 7.386, 7.397, 7.408, 7.419, + 7.431, 7.442, 7.453, 7.464, 7.476, 7.487, 7.498, 7.51, 7.521, 7.532, 7.544, 7.555, 7.567, 7.578, 7.589, 7.601, + 7.612, 7.624, 7.635, 7.647, 7.659, 7.67, 7.682, 7.693, 7.705, 7.717, 7.728, 7.74, 7.752, 7.763, 7.775, 7.787, + 7.799, 7.811, 7.822, 7.834, 7.846, 7.858, 7.87, 7.882, 7.894, 7.906, 7.918, 7.929, 7.941, 7.953, 7.966, 7.978, + 7.99, 8.002, 8.014, 8.026, 8.038, 8.05, 8.062, 8.075, 8.087, 8.099, 8.111, 8.124, 8.136, 8.148, 8.16, 8.173, + 8.185, 8.198, 8.21, 8.222, 8.235, 8.247, 8.26, 8.272, 8.285, 8.297, 8.31, 8.322, 8.335, 8.348, 8.36, 8.373, + 8.386, 8.398, 8.411, 8.424, 8.436, 8.449, 8.462, 8.475, 8.488, 8.5, 8.513, 8.526, 8.539, 8.552, 8.565, 8.578, + 8.591, 8.604, 8.617, 8.63, 8.643, 8.656, 8.669, 8.682, 8.695, 8.708, 8.722, 8.735, 8.748, 8.761, 8.775, 8.788, + 8.801, 8.814, 8.828, 8.841, 8.854, 8.868, 8.881, 8.895, 8.908, 8.922, 8.935, 8.949, 8.962, 8.976, 8.989, 9.003, + 9.016, 9.03, 9.044, 9.057, 9.071, 9.085, 9.099, 9.112, 9.126, 9.14, 9.154, 9.168, 9.182, 9.195, 9.209, 9.223, + 9.237, 9.251, 9.265, 9.279, 9.293, 9.307, 9.321, 9.335, 9.35, 9.364, 9.378, 9.392, 9.406, 9.42, 9.435, 9.449, + 9.463, 9.478, 9.492, 9.506, 9.521, 9.535, 9.549, 9.564, 9.578, 9.593, 9.607, 9.622, 9.636, 9.651, 9.666, 9.68, + 9.695, 9.71, 9.724, 9.739, 9.754, 9.768, 9.783, 9.798, 9.813, 9.828, 9.843, 9.857, 9.872, 9.887, 9.902, 9.917, + 9.932, 9.947, 9.962, 9.977, 9.992, 10.008, 10.023, 10.038, 10.053, 10.068, 10.083, 10.099, 10.114, 10.129, 10.145, 10.16, + 10.175, 10.191, 10.206, 10.222, 10.237, 10.253, 10.268, 10.284, 10.299, 10.315, 10.33, 10.346, 10.362, 10.377, 10.393, 10.409, + 10.424, 10.44, 10.456, 10.472, 10.488, 10.503, 10.519, 10.535, 10.551, 10.567, 10.583, 10.599, 10.615, 10.631, 10.647, 10.663, + 10.68, 10.696, 10.712, 10.728, 10.744, 10.761, 10.777, 10.793, 10.809, 10.826, 10.842, 10.859, 10.875, 10.891, 10.908, 10.924, + 10.941, 10.957, 10.974, 10.991, 11.007, 11.024, 11.041, 11.057, 11.074, 11.091, 11.108, 11.124, 11.141, 11.158, 11.175, 11.192, + 11.209, 11.226, 11.243, 11.26, 11.277, 11.294, 11.311, 11.328, 11.345, 11.362, 11.379, 11.397, 11.414, 11.431, 11.448, 11.466, + 11.483, 11.5, 11.518, 11.535, 11.553, 11.57, 11.588, 11.605, 11.623, 11.64, 11.658, 11.676, 11.693, 11.711, 11.729, 11.746, + 11.764, 11.782, 11.8, 11.818, 11.836, 11.853, 11.871, 11.889, 11.907, 11.925, 11.943, 11.961, 11.979, 11.998, 12.016, 12.034, + 12.052, 12.07, 12.089, 12.107, 12.125, 12.144, 12.162, 12.18, 12.199, 12.217, 12.236, 12.254, 12.273, 12.291, 12.31, 12.328, + 12.347, 12.366, 12.384, 12.403, 12.422, 12.441, 12.46, 12.478, 12.497, 12.516, 12.535, 12.554, 12.573, 12.592, 12.611, 12.63, + 12.649, 12.668, 12.688, 12.707, 12.726, 12.745, 12.765, 12.784, 12.803, 12.823, 12.842, 12.861, 12.881, 12.9, 12.92, 12.939, + 12.959, 12.979, 12.998, 13.018, 13.038, 13.057, 13.077, 13.097, 13.117, 13.136, 13.156, 13.176, 13.196, 13.216, 13.236, 13.256, + 13.276, 13.296, 13.316, 13.336, 13.357, 13.377, 13.397, 13.417, 13.438, 13.458, 13.478, 13.499, 13.519, 13.54, 13.56, 13.581, + 13.601, 13.622, 13.642, 13.663, 13.684, 13.704, 13.725, 13.746, 13.767, 13.787, 13.808, 13.829, 13.85, 13.871, 13.892, 13.913, + 13.934, 13.955, 13.976, 13.997, 14.019, 14.04, 14.061, 14.082, 14.104, 14.125, 14.146, 14.168, 14.189, 14.21, 14.232, 14.254, + 14.275, 14.297, 14.318, 14.34, 14.362, 14.383, 14.405, 14.427, 14.449, 14.471, 14.492, 14.514, 14.536, 14.558, 14.58, 14.602, + 14.624, 14.647, 14.669, 14.691, 14.713, 14.735, 14.758, 14.78, 14.802, 14.825, 14.847, 14.87, 14.892, 14.915, 14.937, 14.96, + 14.982, 15.005, 15.028, 15.051, 15.073, 15.096, 15.119, 15.142, 15.165, 15.188, 15.211, 15.234, 15.257, 15.28, 15.303, 15.326, + 15.349, 15.372, 15.396, 15.419, 15.442, 15.466, 15.489, 15.512, 15.536, 15.559, 15.583, 15.606, 15.63, 15.654, 15.677, 15.701, + 15.725, 15.749, 15.772, 15.796, 15.82, 15.844, 15.868, 15.892, 15.916, 15.94, 15.964, 15.988, 16.013, 16.037, 16.061, 16.085, + 16.11, 16.134, 16.159, 16.183, 16.207, 16.232, 16.257, 16.281, 16.306, 16.33, 16.355, 16.38, 16.405, 16.429, 16.454, 16.479, + 16.504, 16.529, 16.554, 16.579, 16.604, 16.629, 16.654, 16.68, 16.705, 16.73, 16.755, 16.781, 16.806, 16.832, 16.857, 16.883, + 16.908, 16.934, 16.959, 16.985, 17.011, 17.036, 17.062, 17.088, 17.114, 17.14, 17.166, 17.191, 17.217, 17.244, 17.27, 17.296, + 17.322, 17.348, 17.374, 17.401, 17.427, 17.453, 17.48, 17.506, 17.533, 17.559, 17.586, 17.612, 17.639, 17.666, 17.692, 17.719, + 17.746, 17.773, 17.8, 17.827, 17.853, 17.88, 17.908, 17.935, 17.962, 17.989, 18.016, 18.043, 18.071, 18.098, 18.125, 18.153, + 18.18, 18.208, 18.235, 18.263, 18.29, 18.318, 18.346, 18.374, 18.401, 18.429, 18.457, 18.485, 18.513, 18.541, 18.569, 18.597, + 18.625, 18.653, 18.682, 18.71, 18.738, 18.767, 18.795, 18.823, 18.852, 18.88, 18.909, 18.937, 18.966, 18.995, 19.024, 19.052, + 19.081, 19.11, 19.139, 19.168, 19.197, 19.226, 19.255, 19.284, 19.313, 19.342, 19.372, 19.401, 19.43, 19.46, 19.489, 19.519, + 19.548, 19.578, 19.607, 19.637, 19.667, 19.696, 19.726, 19.756, 19.786, 19.816, 19.846, 19.876, 19.906, 19.936, 19.966, 19.996, + 20.027, 20.057, 20.087, 20.118, 20.148, 20.179, 20.209, 20.24, 20.27, 20.301, 20.332, 20.362, 20.393, 20.424, 20.455, 20.486, + 20.517, 20.548, 20.579, 20.61, 20.641, 20.672, 20.704, 20.735, 20.766, 20.798, 20.829, 20.861, 20.892, 20.924, 20.956, 20.987, + 21.019, 21.051, 21.083, 21.115, 21.146, 21.178, 21.21, 21.243, 21.275, 21.307, 21.339, 21.371, 21.404, 21.436, 21.469, 21.501, + 21.533, 21.566, 21.599, 21.631, 21.664, 21.697, 21.73, 21.763, 21.795, 21.828, 21.861, 21.894, 21.928, 21.961, 21.994, 22.027, + 22.061, 22.094, 22.127, 22.161, 22.194, 22.228, 22.262, 22.295, 22.329, 22.363, 22.397, 22.43, 22.464, 22.498, 22.532, 22.566, + 22.601, 22.635, 22.669, 22.703, 22.738, 22.772, 22.806, 22.841, 22.875, 22.91, 22.945, 22.979, 23.014, 23.049, 23.084, 23.119, + 23.154, 23.189, 23.224, 23.259, 23.294, 23.329, 23.365, 23.4, 23.435, 23.471, 23.506, 23.542, 23.577, 23.613, 23.649, 23.685, + 23.72, 23.756, 23.792, 23.828, 23.864, 23.9, 23.937, 23.973, 24.009, 24.045, 24.082, 24.118, 24.155, 24.191, 24.228, 24.264, + 24.301, 24.338, 24.375, 24.411, 24.448, 24.485, 24.522, 24.56, 24.597, 24.634, 24.671, 24.708, 24.746, 24.783, 24.821, 24.858, + 24.896, 24.934, 24.971, 25.009, 25.047, 25.085, 25.123, 25.161, 25.199, 25.237, 25.275, 25.313, 25.352, 25.39, 25.428, 25.467, + 25.505, 25.544, 25.582, 25.621, 25.66, 25.699, 25.738, 25.777, 25.815, 25.855, 25.894, 25.933, 25.972, 26.011, 26.051, 26.09, + 26.13, 26.169, 26.209, 26.248, 26.288, 26.328, 26.368, 26.407, 26.447, 26.487, 26.527, 26.568, 26.608, 26.648, 26.688, 26.729, + 26.769, 26.81, 26.85, 26.891, 26.931, 26.972, 27.013, 27.054, 27.095, 27.136, 27.177, 27.218, 27.259, 27.3, 27.342, 27.383, + 27.424, 27.466, 27.507, 27.549, 27.591, 27.632, 27.674, 27.716, 27.758, 27.8, 27.842, 27.884, 27.926, 27.968, 28.011, 28.053, + 28.096, 28.138, 28.181, 28.223, 28.266, 28.309, 28.352, 28.394, 28.437, 28.48, 28.523, 28.567, 28.61, 28.653, 28.696, 28.74, + 28.783, 28.827, 28.87, 28.914, 28.958, 29.002, 29.045, 29.089, 29.133, 29.177, 29.222, 29.266, 29.31, 29.354, 29.399, 29.443, + 29.488, 29.532, 29.577, 29.622, 29.667, 29.711, 29.756, 29.801, 29.846, 29.892, 29.937, 29.982, 30.027, 30.073, 30.118, 30.164, + 30.21, 30.255, 30.301, 30.347, 30.393, 30.439, 30.485, 30.531, 30.577, 30.623, 30.67, 30.716, 30.762, 30.809, 30.856, 30.902, + 30.949, 30.996, 31.043, 31.09, 31.137, 31.184, 31.231, 31.278, 31.325, 31.373, 31.42, 31.468, 31.515, 31.563, 31.611, 31.659, + 31.707, 31.754, 31.803, 31.851, 31.899, 31.947, 31.995, 32.044, 32.092, 32.141, 32.189, 32.238, 32.287, 32.336, 32.385, 32.434, + 32.483, 32.532, 32.581, 32.63, 32.68, 32.729, 32.779, 32.828, 32.878, 32.927, 32.977, 33.027, 33.077, 33.127, 33.177, 33.227, + 33.278, 33.328, 33.378, 33.429, 33.479, 33.53, 33.581, 33.632, 33.682, 33.733, 33.784, 33.836, 33.887, 33.938, 33.989, 34.041, + 34.092, 34.144, 34.195, 34.247, 34.299, 34.351, 34.403, 34.455, 34.507, 34.559, 34.611, 34.664, 34.716, 34.769, 34.821, 34.874, + 34.927, 34.979, 35.032, 35.085, 35.138, 35.192, 35.245, 35.298, 35.352, 35.405, 35.459, 35.512, 35.566, 35.62, 35.674, 35.728, + 35.782, 35.836, 35.89, 35.944, 35.999, 36.053, 36.108, 36.162, 36.217, 36.272, 36.326, 36.381, 36.436, 36.492, 36.547, 36.602, + 36.657, 36.713, 36.768, 36.824, 36.88, 36.935, 36.991, 37.047, 37.103, 37.159, 37.216, 37.272, 37.328, 37.385, 37.441, 37.498, + 37.555, 37.611, 37.668, 37.725, 37.782, 37.84, 37.897, 37.954, 38.011, 38.069, 38.127, 38.184, 38.242, 38.3, 38.358, 38.416, + 38.474, 38.532, 38.59, 38.649, 38.707, 38.766, 38.824, 38.883, 38.942, 39.001, 39.06, 39.119, 39.178, 39.237, 39.297, 39.356, + 39.416, 39.475, 39.535, 39.595, 39.655, 39.715, 39.775, 39.835, 39.895, 39.955, 40.016, 40.076, 40.137, 40.198, 40.258, 40.319, + 40.38, 40.441, 40.503, 40.564, 40.625, 40.687, 40.748, 40.81, 40.872, 40.933, 40.995, 41.057, 41.119, 41.182, 41.244, 41.306, + 41.369, 41.431, 41.494, 41.557, 41.62, 41.683, 41.746, 41.809, 41.872, 41.935, 41.999, 42.062, 42.126, 42.19, 42.253, 42.317, + 42.381, 42.445, 42.51, 42.574, 42.638, 42.703, 42.767, 42.832, 42.897, 42.962, 43.027, 43.092, 43.157, 43.222, 43.288, 43.353, + 43.419, 43.484, 43.55, 43.616, 43.682, 43.748, 43.814, 43.88, 43.947, 44.013, 44.08, 44.147, 44.213, 44.28, 44.347, 44.414, + 44.481, 44.549, 44.616, 44.684, 44.751, 44.819, 44.887, 44.955, 45.022, 45.091, 45.159, 45.227, 45.296, 45.364, 45.433, 45.501, + 45.57, 45.639, 45.708, 45.777, 45.847, 45.916, 45.985, 46.055, 46.125, 46.194, 46.264, 46.334, 46.404, 46.474, 46.545, 46.615, + 46.686, 46.756, 46.827, 46.898, 46.969, 47.04, 47.111, 47.182, 47.253, 47.325, 47.397, 47.468, 47.54, 47.612, 47.684, 47.756, + 47.828, 47.901, 47.973, 48.046, 48.118, 48.191, 48.264, 48.337, 48.41, 48.483, 48.557, 48.63, 48.704, 48.777, 48.851, 48.925, + 48.999, 49.073, 49.147, 49.222, 49.296, 49.371, 49.445, 49.52, 49.595, 49.67, 49.745, 49.82, 49.896, 49.971, 50.047, 50.123, + 50.198, 50.274, 50.35, 50.426, 50.503, 50.579, 50.656, 50.732, 50.809, 50.886, 50.963, 51.04, 51.117, 51.194, 51.272, 51.349, + 51.427, 51.505, 51.583, 51.661, 51.739, 51.817, 51.895, 51.974, 52.053, 52.131, 52.21, 52.289, 52.368, 52.447, 52.527, 52.606, + 52.686, 52.765, 52.845, 52.925, 53.005, 53.085, 53.166, 53.246, 53.327, 53.407, 53.488, 53.569, 53.65, 53.731, 53.812, 53.894, + 53.975, 54.057, 54.139, 54.221, 54.303, 54.385, 54.467, 54.549, 54.632, 54.715, 54.797, 54.88, 54.963, 55.046, 55.13, 55.213, + 55.297, 55.38, 55.464, 55.548, 55.632, 55.716, 55.8, 55.885, 55.969, 56.054, 56.139, 56.224, 56.309, 56.394, 56.479, 56.564, + 56.65, 56.736, 56.821, 56.907, 56.994, 57.08, 57.166, 57.253, 57.339, 57.426, 57.513, 57.6, 57.687, 57.774, 57.861, 57.949, + 58.037, 58.124, 58.212, 58.3, 58.389, 58.477, 58.565, 58.654, 58.743, 58.831, 58.92, 59.01, 59.099, 59.188, 59.278, 59.367, + 59.457, 59.547, 59.637, 59.727, 59.818, 59.908, 59.999, 60.09, 60.18, 60.271, 60.363, 60.454, 60.545, 60.637, 60.729, 60.82, + 60.912, 61.005, 61.097, 61.189, 61.282, 61.375, 61.467, 61.56, 61.653, 61.747, 61.84, 61.934, 62.027, 62.121, 62.215, 62.309, + 62.403, 62.498, 62.592, 62.687, 62.782, 62.877, 62.972, 63.067, 63.163, 63.258, 63.354, 63.45, 63.546, 63.642, 63.738, 63.834, + 63.931, 64.028, 64.124, 64.221, 64.319, 64.416, 64.513, 64.611, 64.709, 64.806, 64.904, 65.003, 65.101, 65.199, 65.298, 65.397, + 65.496, 65.595, 65.694, 65.793, 65.893, 65.993, 66.092, 66.192, 66.292, 66.393, 66.493, 66.594, 66.694, 66.795, 66.896, 66.997, + 67.099, 67.2, 67.302, 67.404, 67.506, 67.608, 67.71, 67.812, 67.915, 68.018, 68.121, 68.224, 68.327, 68.43, 68.534, 68.637, + 68.741, 68.845, 68.949, 69.054, 69.158, 69.263, 69.367, 69.472, 69.577, 69.683, 69.788, 69.894, 69.999, 70.105, 70.211, 70.317, + 70.424, 70.53, 70.637, 70.744, 70.851, 70.958, 71.065, 71.173, 71.28, 71.388, 71.496, 71.604, 71.713, 71.821, 71.93, 72.039, + 72.147, 72.257, 72.366, 72.475, 72.585, 72.695, 72.805, 72.915, 73.025, 73.136, 73.246, 73.357, 73.468, 73.579, 73.69, 73.802, + 73.913, 74.025, 74.137, 74.249, 74.362, 74.474, 74.587, 74.7, 74.813, 74.926, 75.039, 75.153, 75.266, 75.38, 75.494, 75.608, + 75.723, 75.837, 75.952, 76.067, 76.182, 76.297, 76.412, 76.528, 76.644, 76.76, 76.876, 76.992, 77.108, 77.225, 77.342, 77.459, + 77.576, 77.693, 77.811, 77.929, 78.046, 78.164, 78.283, 78.401, 78.52, 78.638, 78.757, 78.877, 78.996, 79.115, 79.235, 79.355, + 79.475, 79.595, 79.715, 79.836, 79.957, 80.078, 80.199, 80.32, 80.442, 80.563, 80.685, 80.807, 80.929, 81.052, 81.174, 81.297, + 81.42, 81.543, 81.667, 81.79, 81.914, 82.038, 82.162, 82.286, 82.411, 82.535, 82.66, 82.785, 82.91, 83.036, 83.161, 83.287, + 83.413, 83.539, 83.666, 83.792, 83.919, 84.046, 84.173, 84.3, 84.428, 84.555, 84.683, 84.811, 84.94, 85.068, 85.197, 85.326, + 85.455, 85.584, 85.713, 85.843, 85.973, 86.103, 86.233, 86.364, 86.494, 86.625, 86.756, 86.887, 87.019, 87.15, 87.282, 87.414, + 87.546, 87.679, 87.811, 87.944, 88.077, 88.21, 88.344, 88.478, 88.611, 88.745, 88.88, 89.014, 89.149, 89.284, 89.419, 89.554, + 89.689, 89.825, 89.961, 90.097, 90.233, 90.37, 90.506, 90.643, 90.78, 90.918, 91.055, 91.193, 91.331, 91.469, 91.607, 91.746, + 91.885, 92.024, 92.163, 92.302, 92.442, 92.582, 92.722, 92.862, 93.002, 93.143, 93.284, 93.425, 93.566, 93.708, 93.849, 93.991, + 94.134, 94.276, 94.419, 94.561, 94.704, 94.848, 94.991, 95.135, 95.279, 95.423, 95.567, 95.712, 95.856, 96.001, 96.147, 96.292, + 96.438, 96.584, 96.73, 96.876, 97.022, 97.169, 97.316, 97.463, 97.611, 97.758, 97.906, 98.054, 98.203, 98.351, 98.5, 98.649, + 98.798, 98.948, 99.097, 99.247, 99.397, 99.548, 99.698, 99.849, 100.0 }; -void demo_pwm_init(void) +void demo_hosal_pwm_init(void) { - /* init pwm with given settings */ - for (uint32_t i = 0; i < MAX_PWM_CHANNEL; i++) - { - hosal_pwm_init(rgb_pwm + i); - } + + bl_pwm_port_init(LED_R_PIN_PORT, PWM_FREQ); + bl_pwm_port_init(LED_B_PIN_PORT, PWM_FREQ); + bl_pwm_port_init(LED_G_PIN_PORT, PWM_FREQ); + bl_pwm_port_init(LED_C_PIN_PORT, PWM_FREQ); + bl_pwm_port_init(LED_W_PIN_PORT, PWM_FREQ); + + bl_pwm_channel_init(LED_R_PIN_PORT, LED_R_PIN); + bl_pwm_channel_init(LED_B_PIN_PORT, LED_B_PIN); + bl_pwm_channel_init(LED_G_PIN_PORT, LED_G_PIN); + bl_pwm_channel_init(LED_C_PIN_PORT, LED_C_PIN); + bl_pwm_channel_init(LED_W_PIN_PORT, LED_W_PIN); + demo_hosal_pwm_task_init(); } -void demo_pwm_start(void) +void demo_hosal_pwm_start(void) { /* start pwm */ for (uint32_t i = 0; i < MAX_PWM_CHANNEL; i++) { - hosal_pwm_start(rgb_pwm + i); + bl_pwm_start(i); } } -void demo_pwm_change_param(hosal_pwm_config_t * para) +void demo_hosal_pwm_set_param(uint32_t p_Rduty, uint32_t p_Gduty, uint32_t p_Bduty, uint32_t p_Cduty, uint32_t p_Wduty) { - /* change pwm param */ - for (uint32_t i = 0; i < MAX_PWM_CHANNEL; i++) + + uint16_t threshold1, threshold2; + threshold1 = 0; + + bl_pwm_set_duty(LED_R_PIN_PORT, pwm_curve[p_Rduty]); + bl_pwm_set_duty(LED_G_PIN_PORT, pwm_curve[p_Gduty]); + bl_pwm_set_duty(LED_B_PIN_PORT, pwm_curve[p_Bduty]); +#if 0 + if((pwm_curve[p_Cduty]+pwm_curve[p_Wduty])>100) { - if (para[i].duty_cycle > PWM_DUTY_CYCLE) - { - para[i].duty_cycle = PWM_DUTY_CYCLE; - } - hosal_pwm_para_chg(rgb_pwm + i, para[i]); + printf("%s >100",__func__); } + else + { + + } +#endif + bl_pwm_set_duty_ex(LED_C_PIN_PORT, pwm_curve[p_Cduty], &threshold1, &threshold2); + threshold1 = threshold2; + bl_pwm_set_duty_ex(LED_W_PIN_PORT, pwm_curve[p_Wduty], &threshold1, &threshold2); } -void demo_pwm_stop(void) +void demo_hosal_pwm_stop(void) { for (uint32_t i = 0; i < MAX_PWM_CHANNEL; i++) { - hosal_pwm_stop(rgb_pwm + i); - hosal_pwm_finalize(rgb_pwm + i); + bl_pwm_stop(i); } } void set_level(uint8_t currLevel) { - hosal_pwm_config_t para; - - if (currLevel <= 5 && currLevel >= 1) - { - currLevel = 5; // avoid demo off - } - - para.duty_cycle = currLevel * PWM_DUTY_CYCLE / 254; - para.freq = PWM_FREQ; - - demo_pwm_change_param(¶); + printf("%s\r\n", __func__); } void set_color_red(uint8_t currLevel) { - set_color(currLevel, 0, 254); + hard_set_color(currLevel, 0, 254); } void set_color_green(uint8_t currLevel) { - set_color(currLevel, 84, 254); + hard_set_color(currLevel, 84, 254); } void set_color_yellow(uint8_t currLevel) { - set_color(currLevel, 42, 254); + hard_set_color(currLevel, 42, 254); } -void set_color(uint8_t currLevel, uint8_t currHue, uint8_t currSat) +static void hard_set_color(uint8_t currLevel, uint8_t currHue, uint8_t currSat) { -#if MAX_PWM_CHANNEL == 3 +#if MAX_PWM_CHANNEL uint16_t hue = (uint16_t) currHue * 360 / 254; uint8_t sat = (uint16_t) currSat * 100 / 254; @@ -176,18 +364,356 @@ void set_color(uint8_t currLevel, uint8_t currHue, uint8_t currSat) break; } - // change level to pwm duty_cycle - // 0-254 to 0-10000 - hosal_pwm_config_t para[3]; - para[0].duty_cycle = blue * PWM_DUTY_CYCLE / 254; - para[0].freq = PWM_FREQ; - para[1].duty_cycle = red * PWM_DUTY_CYCLE / 254; - para[1].freq = PWM_FREQ; - para[2].duty_cycle = green * PWM_DUTY_CYCLE / 254; - para[2].freq = PWM_FREQ; - - demo_pwm_change_param(para); + Rduty = (red * 12); + Gduty = (green * 12); + Bduty = (blue * 12); + printf("Rduty=%lx,Gduty=%lx,Bduty=%lx\r\n", Rduty, Gduty, Bduty); + demo_hosal_pwm_set_param(Rduty, Gduty, Bduty, 0, 0); #else set_level(currLevel); #endif } +int get_curve_value(uint32_t temp) +{ + int value = 0; + float temp1 = (float) (temp) / 254.000; + temp1 = temp1 * 100; + + printf("temp1 %f\r\n", temp1); + + while (1) + { + if ((pwm_curve[value] <= temp1) && (pwm_curve[value + 1] >= temp1)) + { + break; + } + value++; + } + return value; +} +void set_color(uint8_t currLevel, uint8_t currHue, uint8_t currSat) +{ + printf("%s\r\n", __func__); + uint16_t hue = (uint16_t) currHue * 360 / 254; + uint8_t sat = (uint16_t) currSat * 100 / 254; + + if (sat > 100) + { + sat = 100; + } + + uint16_t i = hue / 60; + uint16_t rgb_max = currLevel; + uint16_t rgb_min = rgb_max * (100 - sat) / 100; + uint16_t diff = hue % 60; + uint16_t rgb_adj = (rgb_max - rgb_min) * diff / 60; + uint32_t red, green, blue; + + switch (i) + { + case 0: + red = rgb_max; + green = rgb_min + rgb_adj; + blue = rgb_min; + break; + case 1: + red = rgb_max - rgb_adj; + green = rgb_max; + blue = rgb_min; + break; + case 2: + red = rgb_min; + green = rgb_max; + blue = rgb_min + rgb_adj; + break; + case 3: + red = rgb_min; + green = rgb_max - rgb_adj; + blue = rgb_max; + break; + case 4: + red = rgb_min + rgb_adj; + green = rgb_min; + blue = rgb_max; + break; + default: + red = rgb_max; + green = rgb_min; + blue = rgb_max - rgb_adj; + break; + } + + new_Rduty = (red * 12); + new_Gduty = (green * 12); + new_Bduty = (blue * 12); + printf("now_Rduty update=%lx,now_Gduty update =%lx,now_Bduty update =%lx\r\n", new_Rduty, new_Gduty, new_Bduty); + if (Light_TimerHdl != NULL) + { + if (xTimerIsTimerActive(Light_TimerHdl) != pdFALSE) + { + if (Light_TimerHdl) + xTimerStop(Light_TimerHdl, 0); + } + if (xTimerChangePeriod(Light_TimerHdl, pdMS_TO_TICKS(1), 0) == pdPASS) + { + + Light_Timer_Status = 1; + if (Light_TimerHdl) + xTimerStart(Light_TimerHdl, 0); + } + } +} +void set_temperature(uint8_t currLevel, uint16_t temperature) +{ + + if ((targettemp != temperature) || (targetlevel != currLevel)) + { + targettemp = temperature; + targetlevel = currLevel; + printf("%s\r\n", __func__); + uint32_t hw_temp_delta = LAM_MAX_MIREDS_DEFAULT - LAM_MIN_MIREDS_DEFAULT; + uint32_t soft_temp_delta; + + if (temperature > LAM_MAX_MIREDS_DEFAULT) + { + temperature = LAM_MAX_MIREDS_DEFAULT; + } + else if (temperature < LAM_MIN_MIREDS_DEFAULT) + { + temperature = LAM_MIN_MIREDS_DEFAULT; + } + + soft_temp_delta = temperature - LAM_MIN_MIREDS_DEFAULT; + soft_temp_delta *= 100; + + uint32_t warm = (254 * (soft_temp_delta / hw_temp_delta)) / 100; + uint32_t clod = 254 - warm; + + warm = warm * currLevel / 254; + clod = clod * currLevel / 254; + new_Wduty = get_curve_value(warm); + new_Cduty = get_curve_value(clod); + printf("now_Cduty update=%lx,now_Wduty update =%lx\r\n", new_Cduty, new_Wduty); + if (Light_TimerHdl != NULL) + { + if (xTimerIsTimerActive(Light_TimerHdl) != pdFALSE) + { + if (Light_TimerHdl) + xTimerStop(Light_TimerHdl, 0); + } + if (xTimerChangePeriod(Light_TimerHdl, pdMS_TO_TICKS(1), 0) == pdPASS) + { + + Light_Timer_Status = 2; + if (Light_TimerHdl) + xTimerStart(Light_TimerHdl, 0); + } + } + } +} +void set_warm_temperature() +{ + uint16_t threshold1, threshold2; + targetlevel = 254; + targettemp = 454; + uint32_t hw_temp_delta = LAM_MAX_MIREDS_DEFAULT - LAM_MIN_MIREDS_DEFAULT; + uint32_t soft_temp_delta; + + if (targettemp > LAM_MAX_MIREDS_DEFAULT) + { + targettemp = LAM_MAX_MIREDS_DEFAULT; + } + else if (targettemp < LAM_MIN_MIREDS_DEFAULT) + { + targettemp = LAM_MIN_MIREDS_DEFAULT; + } + + soft_temp_delta = targettemp - LAM_MIN_MIREDS_DEFAULT; + soft_temp_delta *= 100; + + uint32_t warm = (254 * (soft_temp_delta / hw_temp_delta)) / 100; + uint32_t clod = 254 - warm; + Cduty = 0; + Wduty = 0xbe7; + // Cduty = get_curve_value(clod); + // Wduty = get_curve_value(warm); + Rduty = 0; + Gduty = 0; + Bduty = 0; + printf("now_Cduty update=%lx,now_Wduty update =%lx\r\n", Cduty, Wduty); + bl_pwm_set_duty(LED_R_PIN_PORT, pwm_curve[Rduty]); + bl_pwm_set_duty(LED_G_PIN_PORT, pwm_curve[Gduty]); + bl_pwm_set_duty(LED_B_PIN_PORT, pwm_curve[Bduty]); + bl_pwm_set_duty_ex(LED_C_PIN_PORT, pwm_curve[Cduty], &threshold1, &threshold2); + threshold1 = threshold2; + bl_pwm_set_duty_ex(LED_W_PIN_PORT, pwm_curve[Wduty], &threshold1, &threshold2); +} + +void set_cold_temperature(void) +{ + uint16_t threshold1, threshold2; + targetlevel = 254; + targettemp = 370; + uint32_t hw_temp_delta = LAM_MAX_MIREDS_DEFAULT - LAM_MIN_MIREDS_DEFAULT; + uint32_t soft_temp_delta; + + if (targettemp > LAM_MAX_MIREDS_DEFAULT) + { + targettemp = LAM_MAX_MIREDS_DEFAULT; + } + else if (targettemp < LAM_MIN_MIREDS_DEFAULT) + { + targettemp = LAM_MIN_MIREDS_DEFAULT; + } + + soft_temp_delta = targettemp - LAM_MIN_MIREDS_DEFAULT; + soft_temp_delta *= 100; + + uint32_t warm = (254 * (soft_temp_delta / hw_temp_delta)) / 100; + uint32_t clod = 254 - warm; + Cduty = 0x8a5; + Wduty = 0xB0B; + // Cduty = get_curve_value(clod); + // Wduty = get_curve_value(warm); + threshold1 = 0; + Rduty = 0; + Gduty = 0; + Bduty = 0; + printf("now_Cduty update=%lx,now_Wduty update =%lx\r\n", Cduty, Wduty); + bl_pwm_set_duty(LED_R_PIN_PORT, pwm_curve[Rduty]); + bl_pwm_set_duty(LED_G_PIN_PORT, pwm_curve[Gduty]); + bl_pwm_set_duty(LED_B_PIN_PORT, pwm_curve[Bduty]); + bl_pwm_set_duty_ex(LED_C_PIN_PORT, pwm_curve[Cduty], &threshold1, &threshold2); + threshold1 = threshold2; + bl_pwm_set_duty_ex(LED_W_PIN_PORT, pwm_curve[Wduty], &threshold1, &threshold2); +} +void set_warm_cold_off(void) +{ + uint16_t threshold1, threshold2; + threshold1 = 0; + Rduty = 0; + Gduty = 0; + Bduty = 0; + Wduty = 0; + Cduty = 0; + + bl_pwm_set_duty(LED_R_PIN_PORT, pwm_curve[Rduty]); + bl_pwm_set_duty(LED_G_PIN_PORT, pwm_curve[Gduty]); + bl_pwm_set_duty(LED_B_PIN_PORT, pwm_curve[Bduty]); + + bl_pwm_set_duty_ex(LED_C_PIN_PORT, pwm_curve[Cduty], &threshold1, &threshold2); + threshold1 = threshold2; + bl_pwm_set_duty_ex(LED_W_PIN_PORT, pwm_curve[Wduty], &threshold1, &threshold2); + targetlevel = 0; +} +static void Light_TimerHandler(TimerHandle_t p_timerhdl) +{ + + if (Light_Timer_Status == 1) + { + if ((new_Rduty != Rduty) || (new_Gduty != Gduty) || (new_Bduty != Bduty)) + { + if (new_Rduty > Rduty) + { + Rduty++; + } + else if (new_Rduty < Rduty) + { + Rduty--; + } + + if (new_Gduty > Gduty) + { + Gduty++; + } + else if (new_Gduty < Gduty) + { + Gduty--; + } + + if (new_Bduty > Bduty) + { + Bduty++; + } + else if (new_Bduty < Bduty) + { + Bduty--; + } + demo_hosal_pwm_set_param(Rduty, Gduty, Bduty, 0, 0); + } + else + { + if (Light_TimerHdl) + { + xTimerStop(Light_TimerHdl, 0); + } + Light_Timer_Status = 0; + } + } + else if (Light_Timer_Status == 2) + { + if ((new_Cduty != Cduty) || (new_Wduty != Wduty)) + { + if ((Cduty == 0) && (Wduty == 0)) + { + if (new_Wduty >= 0x5f4) + { + Wduty = 0x5f4; + } + else + { + Wduty = new_Wduty; + } + + if (new_Cduty >= 0x5f4) + { + Cduty = 0x5f4; + } + else + { + Cduty = new_Cduty; + } + } + if (new_Cduty > Cduty) + { + Cduty++; + } + else if (new_Cduty < Cduty) + { + Cduty--; + } + + if (new_Wduty > Wduty) + { + Wduty++; + } + else if (new_Wduty < Wduty) + { + Wduty--; + } + if (targetlevel == 0) + { + if ((Cduty <= 0x5f4) && (Wduty <= 0x5f4)) + { + Cduty = 0; + Wduty = 0; + } + } + + demo_hosal_pwm_set_param(0, 0, 0, Cduty, Wduty); + } + else + { + if (Light_TimerHdl) + { + xTimerStop(Light_TimerHdl, 0); + } + Light_Timer_Status = 0; + } + } +} +static void demo_hosal_pwm_task_init(void) +{ + + Light_TimerHdl = xTimerCreate("zb_Light_TimerHandler", pdMS_TO_TICKS(2), pdTRUE, NULL, Light_TimerHandler); +} \ No newline at end of file diff --git a/examples/platform/bouffalolab/common/plat/LEDWidget.cpp b/examples/platform/bouffalolab/common/plat/LEDWidget.cpp index bf6159befb97f1..349f8b46e022b0 100644 --- a/examples/platform/bouffalolab/common/plat/LEDWidget.cpp +++ b/examples/platform/bouffalolab/common/plat/LEDWidget.cpp @@ -15,13 +15,51 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include +#include +#include #include +#include +#include #include "LEDWidget.h" +void LEDWidget::Init() +{ +#ifdef LED1_PIN + mPin = LED1_PIN; + + hosal_gpio_dev_t gpio_led = { .config = OUTPUT_OPEN_DRAIN_NO_PULL, .priv = NULL }; + gpio_led.port = mPin; + + hosal_gpio_init(&gpio_led); +#endif + SetOnoff(false); +} + +void LEDWidget::Toggle(void) +{ + SetOnoff(1 - mOnoff); +} + +void LEDWidget::SetOnoff(bool state) +{ +#ifdef LED1_PIN + hosal_gpio_dev_t gpio_led = { .port = mPin, .config = OUTPUT_OPEN_DRAIN_NO_PULL, .priv = NULL }; + + mOnoff = state; + + if (state) + { + hosal_gpio_output_set(&gpio_led, 1); + } + else + { + hosal_gpio_output_set(&gpio_led, 0); + } +#endif +} + bool LEDWidget::GetOnoff(void) { return mOnoff ? true : false; @@ -32,8 +70,8 @@ void DimmableLEDWidget::Init() mOnoff = light_v = 0; #ifdef MAX_PWM_CHANNEL - demo_pwm_init(); - demo_pwm_start(); + demo_hosal_pwm_init(); + demo_hosal_pwm_start(); #endif } @@ -77,8 +115,8 @@ void ColorLEDWidget::Init() { mOnoff = light_v = light_s = light_h = 0; #ifdef MAX_PWM_CHANNEL - demo_pwm_init(); - demo_pwm_start(); + demo_hosal_pwm_init(); + demo_hosal_pwm_start(); #endif } @@ -95,23 +133,52 @@ void ColorLEDWidget::SetOnoff(bool state) { if (0 == light_v) { - set_color(254, light_h, light_s); + if (mColor_Mode == 2) + { + set_temperature(254, light_t); + } + else + { + set_color(254, light_h, light_s); + } } else { - set_color(light_v, light_h, light_s); + if (mColor_Mode == 2) + { + set_temperature(light_v, light_t); + } + else + { + set_color(light_v, light_h, light_s); + } } } else { - set_color(0, light_h, light_s); + if (mColor_Mode == 2) + { + set_temperature(0, light_t); + } + else + { + set_color(0, light_h, light_s); + } } #endif } -void ColorLEDWidget::SetLevel(uint8_t level) +void ColorLEDWidget::SetLevel(uint8_t level, uint8_t color_mode) { - SetColor(level, light_h, light_s); + if (color_mode == 2) + { + SetTemperature(level, light_t); + } + else + { + SetColor(level, light_h, light_s); + } + mColor_Mode = color_mode; } void ColorLEDWidget::SetColor(uint8_t level, uint8_t hue, uint8_t sat) @@ -119,8 +186,19 @@ void ColorLEDWidget::SetColor(uint8_t level, uint8_t hue, uint8_t sat) #ifdef MAX_PWM_CHANNEL set_color(level, hue, sat); #endif - light_v = level; - light_h = hue; - light_s = sat; - mOnoff = light_v > 0; + light_v = level; + light_h = hue; + light_s = sat; + mOnoff = light_v > 0; + mColor_Mode = 0; +} +void ColorLEDWidget::SetTemperature(uint8_t level, uint16_t temperature) +{ +#ifdef MAX_PWM_CHANNEL + set_temperature(level, temperature); +#endif + light_v = level; + light_t = temperature; + mOnoff = light_v > 0; + mColor_Mode = 2; } diff --git a/examples/platform/bouffalolab/common/plat/LEDWidget.h b/examples/platform/bouffalolab/common/plat/LEDWidget.h index af1877d1089f3a..c90734a4fd83cc 100644 --- a/examples/platform/bouffalolab/common/plat/LEDWidget.h +++ b/examples/platform/bouffalolab/common/plat/LEDWidget.h @@ -23,11 +23,10 @@ class LEDWidget { public: - virtual void Init(void) = 0; - virtual void SetOnoff(bool state) = 0; + void Init(void); + void SetOnoff(bool state); bool GetOnoff(void); - virtual void Toggle(void) = 0; - virtual ~LEDWidget(void){}; + void Toggle(void); uint8_t mOnoff; uint8_t mPin; @@ -36,11 +35,10 @@ class LEDWidget class DimmableLEDWidget : public LEDWidget { public: - void Init(void) override; - void Toggle(void) override; - void SetOnoff(bool state) override; + void Init(void); + void Toggle(void); + void SetOnoff(bool state); void SetLevel(uint8_t level); - ~DimmableLEDWidget(void) {} uint8_t light_v; }; @@ -48,13 +46,14 @@ class DimmableLEDWidget : public LEDWidget class ColorLEDWidget : public DimmableLEDWidget { public: - void Init(void) override; - void Toggle(void) override; - void SetOnoff(bool state) override; - void SetLevel(uint8_t level); + void Init(void); + void Toggle(void); + void SetOnoff(bool state); + void SetLevel(uint8_t level, uint8_t color_mode); void SetColor(uint8_t level, uint8_t hue, uint8_t sat); - ~ColorLEDWidget(void) {} - + void SetTemperature(uint8_t level, uint16_t temperature); uint8_t light_h; uint8_t light_s; + uint8_t light_t; + uint8_t mColor_Mode; }; diff --git a/examples/platform/bouffalolab/common/plat/demo_pwm.h b/examples/platform/bouffalolab/common/plat/demo_pwm.h index d434ee9addec2b..47f7adb5912d18 100644 --- a/examples/platform/bouffalolab/common/plat/demo_pwm.h +++ b/examples/platform/bouffalolab/common/plat/demo_pwm.h @@ -1,19 +1,29 @@ #ifndef __DEMO_PWM__ #define __DEMO_PWM__ +#include +#include +#include + #ifdef __cplusplus extern "C" { #endif -void demo_pwm_init(void); -void demo_pwm_start(void); +void demo_hosal_pwm_init(void); +void demo_hosal_pwm_start(void); +void demo_hosal_pwm_change_param(hosal_pwm_config_t * para); void set_color_red(uint8_t currLevel); void set_color_green(uint8_t currLevel); void set_color_yellow(uint8_t currLevel); void set_color(uint8_t currLevel, uint8_t currHue, uint8_t currSat); void set_level(uint8_t currLevel); - +void set_temperature(uint8_t currLevel, uint16_t temperature); +void set_warm_temperature(void); +void set_cold_temperature(void); +void set_warm_cold_off(void); +#define LAM_MAX_MIREDS_DEFAULT 454 +#define LAM_MIN_MIREDS_DEFAULT 154 #ifdef __cplusplus } #endif diff --git a/examples/platform/bouffalolab/common/plat/platform.cpp b/examples/platform/bouffalolab/common/plat/platform.cpp index ea6548327847b1..9188024c6e0438 100644 --- a/examples/platform/bouffalolab/common/plat/platform.cpp +++ b/examples/platform/bouffalolab/common/plat/platform.cpp @@ -95,76 +95,6 @@ FactoryDataProvider sFactoryDataProvider; static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; -void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg) -{ - switch (event->Type) - { - case DeviceEventType::kCHIPoBLEAdvertisingChange: - ChipLogProgress(NotSpecified, "BLE adv changed, connection number: %d", ConnectivityMgr().NumBLEConnections()); - break; -#if CHIP_DEVICE_CONFIG_ENABLE_THREAD - case DeviceEventType::kThreadStateChange: - - if (ConnectivityMgr().IsThreadAttached()) - { - chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), - OTAConfig::InitOTARequestorHandler, nullptr); - } - break; -#endif - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET - case DeviceEventType::kInterfaceIpAddressChanged: - if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || - (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) - { - // MDNS server restart on any ip assignment: if link local ipv6 is configured, that - // will not trigger a 'internet connectivity change' as there is no internet - // connectivity. MDNS still wants to refresh its listening interfaces to include the - // newly selected address. - - chip::app::DnssdServer::Instance().StartServer(); - - bl_route_hook_init(); - - chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), - OTAConfig::InitOTARequestorHandler, nullptr); - } - break; -#endif - case DeviceEventType::kInternetConnectivityChange: - if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) - { - ChipLogProgress(NotSpecified, "IPv4 connectivity ready..."); - } - else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost) - { - ChipLogProgress(NotSpecified, "Lost IPv4 connectivity..."); - } - if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established) - { - ChipLogProgress(NotSpecified, "IPv6 connectivity ready..."); - } - else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) - { - ChipLogProgress(NotSpecified, "Lost IPv6 connectivity..."); - } - break; - case DeviceEventType::kCHIPoBLEConnectionEstablished: - ChipLogProgress(NotSpecified, "BLE connection established"); - break; - case DeviceEventType::kCHIPoBLEConnectionClosed: - ChipLogProgress(NotSpecified, "BLE disconnected"); - break; - case DeviceEventType::kCommissioningComplete: - ChipLogProgress(NotSpecified, "Commissioning complete"); - GetAppTask().PostEvent(AppTask::APP_EVENT_LIGHTING_MASK); - break; - default: - break; - } -} - CHIP_ERROR PlatformManagerImpl::PlatformInit(void) { chip::RendezvousInformationFlags rendezvousMode(chip::RendezvousInformationFlag::kOnNetwork); @@ -254,7 +184,7 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) #endif PrintOnboardingCodes(rendezvousMode); - PlatformMgr().AddEventHandler(ChipEventHandler, 0); + PlatformMgr().AddEventHandler(AppTask::ChipEventHandler, 0); #if PW_RPC_ENABLED chip::rpc::Init();