-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add screen manager and virtual sensors to app (#1453)
- add simple UI framework for tiny screens and few buttons - add README documenting simple UI framework - add screens for list of items, QR code - add demo devices/endpoints/clusters/attributes - add VLEDs (virtual LEDs) - improve display wake behaviour
- Loading branch information
1 parent
92fda7c
commit 6350c46
Showing
15 changed files
with
1,339 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Simple Screen UI Framework | ||
|
||
## Overview | ||
|
||
This is a framework for creating simple user interfaces for devices with tiny | ||
screens and just a few buttons. | ||
|
||
For example, the [M5Stack](http://m5stack.com/) ESP32 Basic Core IoT device has | ||
a 320x240 TFT display and three push buttons. | ||
|
||
This framework enables a UI such as the following, where focus is indicated by | ||
color, the left and middle buttons function as a single axis navpad, the right | ||
button function as an action button, and the back button is provided by the | ||
framework onscreen: | ||
|
||
+--------------------------------------+ | ||
| < SCREEN TITLE | | ||
| ------------ | | ||
| | | ||
| ITEM 1 | | ||
| ITEM 2 | | ||
| ITEM 3 | | ||
| | | ||
| | | ||
| | | ||
| | | ||
| PREVIOUS NEXT ACTION | | ||
+--------------------------------------+ | ||
|
||
## Features | ||
|
||
- stack of screens with system back button | ||
- labeled buttons for navigation and action | ||
- focus handling | ||
- custom screen content | ||
- virtual LEDs (VLEDs) | ||
|
||
## Screen Manager | ||
|
||
The screen manager maintains a stack of screens that are pushed and popped for | ||
interaction. Each is drawn with a title, system back button, three button | ||
labels, and custom screen content. The screen manager dispatches events to the | ||
topmost screen, such as: | ||
|
||
- enter/exit events (including whether the screen was pushed or popped) | ||
- focus events (for navigation) | ||
- action events | ||
- display events (lazily) | ||
|
||
If configured, virtual LEDs (VLEDs) are omnipresent and can be toggled at will. | ||
|
||
## Screen | ||
|
||
Screens provide a title and three button labels to the screen manager. They | ||
handle events from the screen manager, and cooperate to ensure focus behaves | ||
nicely. | ||
|
||
## Focus Handling | ||
|
||
Screens are created without focus, and indicate to the screen manager whether | ||
they can receive focus. If so, the screen manager focuses them when they are | ||
pushed, and subsequently dispatches focus next/previous events which the screen | ||
can use for navigation before any action is performed. | ||
|
||
The screen can request the screen manager to focus the system back button, which | ||
is always available except when there are no covered screens on the stack. In | ||
this way, a list screen can wrap its focus of list items through the system back | ||
button if it is available, while skipping it otherwise. | ||
|
||
Blur and unblur focus events allow a screen's focus state to be preserved when | ||
it is covered by a pushed screen and restored when it is subsequently uncovered. | ||
|
||
In summary, screens collaborate with the screen manager to handle focus via the | ||
following focus event types: | ||
|
||
- NONE: remove focus from screen completely | ||
- BLUR: unfocus screen (but retain focus state) | ||
- UNBLUR: restore focus state (that was retained when blurred) | ||
- NEXT: navigate focus forward in screen (possibly requesting focus back | ||
button) | ||
- PREVIOUS: navigate focus forward (possibly requesting back button focus) | ||
|
||
## Typical Usage | ||
|
||
A list screen can provide multiple options to the user. Each list item can push | ||
another screen on the stack with more items. In this way a hierarchy of screens | ||
can be formed. | ||
|
||
The back button dismisses a screen much as "escape" or "cancel" would. It's | ||
possible to push an informational screen that is not focusable and has no | ||
interaction, such that the only action available is back. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @file ListScreen.cpp | ||
* | ||
* Simple list screen. | ||
* | ||
*/ | ||
|
||
#include "ListScreen.h" | ||
|
||
#if CONFIG_HAVE_DISPLAY | ||
|
||
#include <algorithm> | ||
|
||
namespace { | ||
|
||
const char * buttonText[] = { "Up", "Down", "Action" }; | ||
|
||
}; | ||
|
||
std::string ListScreen::GetButtonText(int id) | ||
{ | ||
return buttonText[id - 1]; | ||
} | ||
|
||
void ListScreen::Display() | ||
{ | ||
int i = 0; | ||
int items = (DisplayHeight - ScreenTitleSafeTop - ScreenTitleSafeBottom) / ScreenFontHeight; | ||
if (items < model->GetItemCount()) | ||
{ | ||
i = std::max(0, focusIndex - items + (focusIndex == model->GetItemCount() - 1 ? 1 : 2)); | ||
} | ||
|
||
for (int count = 0, y = ScreenTitleSafeTop; i < model->GetItemCount() && count < items; ++i, ++count, y += ScreenFontHeight) | ||
{ | ||
tft_fg = focusIndex == i ? ScreenFocusColor : ScreenNormalColor; | ||
TFT_print((char *) model->GetItemText(i).c_str(), ScreenTitleSafeTop, y); | ||
} | ||
} | ||
|
||
void ListScreen::Focus(FocusType focus) | ||
{ | ||
switch (focus) | ||
{ | ||
case FocusType::NONE: | ||
hasFocus = false; | ||
focusIndex = -1; | ||
break; | ||
case FocusType::BLUR: | ||
hasFocus = false; | ||
// leave focus index alone | ||
break; | ||
case FocusType::UNBLUR: | ||
hasFocus = true; | ||
// leave focus index alone | ||
break; | ||
case FocusType::NEXT: | ||
hasFocus = true; | ||
if (focusIndex == -1) | ||
{ | ||
focusIndex = 0; | ||
break; | ||
} | ||
focusIndex = (focusIndex + 1) % model->GetItemCount(); // wraparound | ||
if (focusIndex == 0) | ||
{ | ||
ScreenManager::FocusBack(); // try focus back if it did wrap | ||
} | ||
break; | ||
case FocusType::PREVIOUS: | ||
hasFocus = true; | ||
if (focusIndex == -1) | ||
{ | ||
focusIndex = model->GetItemCount() - 1; | ||
break; | ||
} | ||
focusIndex = (focusIndex + model->GetItemCount() - 1) % model->GetItemCount(); // wraparound | ||
if (focusIndex == model->GetItemCount() - 1) | ||
{ | ||
ScreenManager::FocusBack(); // try focus back if it did wrap | ||
} | ||
break; | ||
} | ||
} | ||
|
||
#endif // CONFIG_HAVE_DISPLAY |
Oops, something went wrong.