| /* |
| * |
| * Copyright (c) 2020 Project CHIP Authors |
| * Copyright (c) 2019 Google LLC. |
| * All rights reserved. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #include "AppTask.h" |
| #include "AppConfig.h" |
| #include "AppEvent.h" |
| |
| #include "WindowManager.h" |
| |
| #include "LEDWidget.h" |
| |
| #include <app/clusters/on-off-server/on-off-server.h> |
| #include <app/server/OnboardingCodesUtil.h> |
| #include <app/server/Server.h> |
| #include <app/util/attribute-storage.h> |
| |
| #include <assert.h> |
| |
| #include <platform/silabs/platformAbstraction/SilabsPlatform.h> |
| |
| #include <setup_payload/QRCodeSetupPayloadGenerator.h> |
| #include <setup_payload/SetupPayload.h> |
| |
| #include <lib/support/CodeUtils.h> |
| |
| #if !defined(BRD2704A) |
| #define LIGHT_LED 1 |
| #else |
| #define LIGHT_LED 0 |
| #endif |
| |
| using namespace chip; |
| using namespace ::chip::DeviceLayer; |
| using namespace ::chip::DeviceLayer::Silabs; |
| |
| namespace { |
| LEDWidget sLightLED; |
| } |
| |
| using namespace chip::TLV; |
| using namespace ::chip::DeviceLayer; |
| |
| AppTask AppTask::sAppTask; |
| |
| CHIP_ERROR AppTask::Init() |
| { |
| CHIP_ERROR err = CHIP_NO_ERROR; |
| chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(WindowManager::ButtonEventHandler); |
| |
| #ifdef DISPLAY_ENABLED |
| GetLCD().Init((uint8_t *) "Window-App"); |
| #endif |
| |
| err = BaseApplication::Init(); |
| if (err != CHIP_NO_ERROR) |
| { |
| SILABS_LOG("BaseApplication::Init() failed"); |
| appError(err); |
| } |
| |
| err = WindowManager::sWindow.Init(); |
| |
| if (err != CHIP_NO_ERROR) |
| { |
| SILABS_LOG("WindowMgr::Init() failed"); |
| appError(err); |
| } |
| |
| sLightLED.Init(LIGHT_LED); |
| |
| // Update the LCD with the Stored value. Show QR Code if not provisioned |
| #ifdef DISPLAY_ENABLED |
| |
| #ifdef QR_CODE_ENABLED |
| #ifdef SL_WIFI |
| if (!ConnectivityMgr().IsWiFiStationProvisioned()) |
| #else |
| if (!ConnectivityMgr().IsThreadProvisioned()) |
| #endif /* !SL_WIFI */ |
| { |
| GetLCD().ShowQRCode(true, true); |
| } |
| #endif // QR_CODE_ENABLED |
| #endif |
| |
| return err; |
| } |
| |
| CHIP_ERROR AppTask::StartAppTask() |
| { |
| return BaseApplication::StartAppTask(AppTaskMain); |
| } |
| |
| void AppTask::AppTaskMain(void * pvParameter) |
| { |
| |
| AppEvent event; |
| QueueHandle_t sAppEventQueue = *(static_cast<QueueHandle_t *>(pvParameter)); |
| |
| CHIP_ERROR err = sAppTask.Init(); |
| if (err != CHIP_NO_ERROR) |
| { |
| SILABS_LOG("AppTask.Init() failed"); |
| appError(err); |
| } |
| |
| #if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED) |
| sAppTask.StartStatusLEDTimer(); |
| #endif |
| |
| SILABS_LOG("App Task started"); |
| |
| WindowManager::sWindow.UpdateLEDs(); |
| WindowManager::sWindow.UpdateLCD(); |
| |
| while (true) |
| { |
| BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, portMAX_DELAY); |
| while (eventReceived == pdTRUE) |
| { |
| sAppTask.DispatchEvent(&event); |
| eventReceived = xQueueReceive(sAppEventQueue, &event, 0); |
| } |
| } |
| } |