2323#include " LEDWidget.h"
2424
2525#ifdef DISPLAY_ENABLED
26+ #include " ClosureUI.h"
27+ #include " ClosureUIStrings.h"
2628#include " lcd.h"
2729#ifdef QR_CODE_ENABLED
2830#include " qrcodegen.h"
4850#include < setup_payload/OnboardingCodesUtil.h>
4951#include < setup_payload/QRCodeSetupPayloadGenerator.h>
5052#include < setup_payload/SetupPayload.h>
53+ #include < stdio.h>
5154
5255#define APP_FUNCTION_BUTTON 0
5356#define APP_CLOSURE_BUTTON 1
@@ -81,14 +84,15 @@ CHIP_ERROR AppTask::AppInit()
8184
8285#ifdef DISPLAY_ENABLED
8386 GetLCD ().Init ((uint8_t *) " Closure-App" );
87+ GetLCD ().SetCustomUI (ClosureUI::DrawUI);
8488#endif
8589
8690 // Initialization of Closure Manager and endpoints of closure and closurepanel.
8791 ClosureManager::GetInstance ().Init ();
8892
8993// Update the LCD with the Stored value. Show QR Code if not provisioned
9094#ifdef DISPLAY_ENABLED
91- GetLCD (). WriteDemoUI ( false );
95+ UpdateClosureUI ( );
9296#ifdef QR_CODE_ENABLED
9397#ifdef SL_WIFI
9498 if (!ConnectivityMgr ().IsWiFiStationProvisioned ())
@@ -99,7 +103,7 @@ CHIP_ERROR AppTask::AppInit()
99103 GetLCD ().ShowQRCode (true );
100104 }
101105#endif // QR_CODE_ENABLED
102- #endif
106+ #endif // DISPLAY_ENABLED
103107
104108 return err;
105109}
@@ -228,3 +232,103 @@ void AppTask::ClosureButtonActionEventHandler(AppEvent * aEvent)
228232 ChipLogError (AppServer, " Unhandled event type in ClosureButtonActionEventHandler" );
229233 }
230234}
235+
236+ #ifdef DISPLAY_ENABLED
237+ void AppTask::UpdateClosureUIHandler (AppEvent * aEvent)
238+ {
239+ if (aEvent->Type == AppEvent::kEventType_UpdateUI )
240+ {
241+ UpdateClosureUI ();
242+ }
243+ }
244+
245+ void AppTask::UpdateClosureUI ()
246+ {
247+ ClosureManager & closureManager = ClosureManager::GetInstance ();
248+
249+ // Lock chip stack when accessing CHIP attributes from app task context
250+ DeviceLayer::PlatformMgr ().LockChipStack ();
251+ auto uiData = closureManager.GetClosureUIData ();
252+ DeviceLayer::PlatformMgr ().UnlockChipStack ();
253+
254+ ClosureUI::SetMainState (uiData.mainState );
255+
256+ const char * positionSuffix = ClosureUIStrings::SUFFIX_UNKNOWN;
257+ if (!uiData.overallCurrentState .IsNull () && uiData.overallCurrentState .Value ().position .HasValue () &&
258+ !uiData.overallCurrentState .Value ().position .Value ().IsNull ())
259+ {
260+ switch (uiData.overallCurrentState .Value ().position .Value ().Value ())
261+ {
262+ case chip::app::Clusters::ClosureControl::CurrentPositionEnum::kFullyClosed :
263+ positionSuffix = ClosureUIStrings::POSITION_SUFFIX_CLOSED;
264+ break ;
265+ case chip::app::Clusters::ClosureControl::CurrentPositionEnum::kFullyOpened :
266+ positionSuffix = ClosureUIStrings::POSITION_SUFFIX_OPEN;
267+ break ;
268+ case chip::app::Clusters::ClosureControl::CurrentPositionEnum::kPartiallyOpened :
269+ positionSuffix = ClosureUIStrings::POSITION_SUFFIX_PARTIAL;
270+ break ;
271+ case chip::app::Clusters::ClosureControl::CurrentPositionEnum::kOpenedForPedestrian :
272+ positionSuffix = ClosureUIStrings::POSITION_SUFFIX_PEDESTRIAN;
273+ break ;
274+ case chip::app::Clusters::ClosureControl::CurrentPositionEnum::kOpenedForVentilation :
275+ positionSuffix = ClosureUIStrings::POSITION_SUFFIX_VENTILATION;
276+ break ;
277+ default :
278+ positionSuffix = ClosureUIStrings::SUFFIX_UNKNOWN;
279+ break ;
280+ }
281+ }
282+ ClosureUI::FormatAndSetPosition (positionSuffix);
283+
284+ const char * latchSuffix = ClosureUIStrings::SUFFIX_UNKNOWN;
285+ if (!uiData.overallCurrentState .IsNull () && uiData.overallCurrentState .Value ().latch .HasValue () &&
286+ !uiData.overallCurrentState .Value ().latch .Value ().IsNull ())
287+ {
288+ latchSuffix = uiData.overallCurrentState .Value ().latch .Value ().Value () ? ClosureUIStrings::LATCH_SUFFIX_ENGAGED
289+ : ClosureUIStrings::LATCH_SUFFIX_RELEASED;
290+ }
291+ ClosureUI::FormatAndSetLatch (latchSuffix);
292+
293+ const char * secureSuffix = ClosureUIStrings::SUFFIX_UNKNOWN;
294+ if (!uiData.overallCurrentState .IsNull () && !uiData.overallCurrentState .Value ().secureState .IsNull ())
295+ {
296+ secureSuffix = uiData.overallCurrentState .Value ().secureState .Value () ? ClosureUIStrings::SECURE_SUFFIX_YES
297+ : ClosureUIStrings::SECURE_SUFFIX_NO;
298+ }
299+ ClosureUI::FormatAndSetSecure (secureSuffix);
300+
301+ const char * speedSuffix = ClosureUIStrings::SUFFIX_UNKNOWN;
302+ if (!uiData.overallCurrentState .IsNull () && uiData.overallCurrentState .Value ().speed .HasValue ())
303+ {
304+ switch (uiData.overallCurrentState .Value ().speed .Value ())
305+ {
306+ case chip::app::Clusters::Globals::ThreeLevelAutoEnum::kLow :
307+ speedSuffix = ClosureUIStrings::SPEED_SUFFIX_LOW;
308+ break ;
309+ case chip::app::Clusters::Globals::ThreeLevelAutoEnum::kMedium :
310+ speedSuffix = ClosureUIStrings::SPEED_SUFFIX_MEDIUM;
311+ break ;
312+ case chip::app::Clusters::Globals::ThreeLevelAutoEnum::kHigh :
313+ speedSuffix = ClosureUIStrings::SPEED_SUFFIX_HIGH;
314+ break ;
315+ case chip::app::Clusters::Globals::ThreeLevelAutoEnum::kAuto :
316+ speedSuffix = ClosureUIStrings::SPEED_SUFFIX_AUTO;
317+ break ;
318+ default :
319+ speedSuffix = ClosureUIStrings::SUFFIX_UNKNOWN;
320+ break ;
321+ }
322+ }
323+ ClosureUI::FormatAndSetSpeed (speedSuffix);
324+
325+ #ifdef SL_WIFI
326+ if (ConnectivityMgr ().IsWiFiStationProvisioned ())
327+ #else
328+ if (ConnectivityMgr ().IsThreadProvisioned ())
329+ #endif /* !SL_WIFI */
330+ {
331+ AppTask::GetAppTask ().GetLCD ().WriteDemoUI (false ); // State doesn't matter for custom UI
332+ }
333+ }
334+ #endif // DISPLAY_ENABLED
0 commit comments