Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Widgets Example Sketch #262

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Add Widgets Example Sketch #262

merged 3 commits into from
Oct 30, 2024

Conversation

forntoh
Copy link
Owner

@forntoh forntoh commented Oct 29, 2024

  • New Features
    • Introduced a menu-driven interface for an LCD display, allowing users to interact with various widget types.
    • Added options for user interaction, including functionalities for "Buy," "Sell," and setting parameters like price and quantity.
    • Implemented a structured approach for managing user inputs through custom widgets and a dynamic menu system.
  • Tests
    • Added a new test configuration to simulate user interactions with the widget interface, ensuring proper functionality and response to inputs.

Showcase

Only 3 buttons used UP, DOWN and ENTER

Screen.Recording.2024-10-30.at.13.50.24.mov

Include various widgets and custom characters for LCD menu. Set up main screen with different item widgets handling input and displaying data.
Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

The pull request introduces a new Arduino sketch file, Widgets.ino, which implements a menu-driven interface for a Liquid Crystal Display (LCD). This file organizes various widget types and user interaction options, such as "Buy" and "Sell," into a modular structure. It defines custom characters for the LCD, initializes menu screens, and handles user input through lambda functions, allowing dynamic interaction with the menu.

Changes

File Change Summary
examples/Widgets/Widgets.ino New file implementing a menu-driven LCD interface with multiple widget types and user interaction options. Includes setup for custom characters and dynamic input handling.
test/Widgets.test.yml New test configuration added to simulate user interactions with the widget interface, covering various functionalities and expected outputs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LCD
    participant Menu
    participant Widget

    User->>LCD: Start interaction
    LCD->>Menu: Display main menu
    Menu->>User: Show options (Buy, Sell, etc.)
    User->>Menu: Select an option
    Menu->>Widget: Trigger corresponding widget
    Widget->>User: Request input
    User->>Widget: Provide input
    Widget->>LCD: Display selected values
Loading

🐇 "In a world of screens and lights,
Widgets dance with user delights.
With buttons pressed and choices made,
A menu blooms, no need for aid.
LCD glows, a joyful sight,
In rabbit's realm, all feels just right!" 🐇

Possibly related PRs

  • Update Examples to use Widgets #260: The changes in this PR involve updating examples to utilize a widget-based approach, which directly relates to the new Widgets.ino file that implements a menu-driven interface using various widget types.

Suggested labels

feature, enhancement


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 9fed69e and 4e12256.

📒 Files selected for processing (1)
  • examples/Widgets/Widgets.ino (1 hunks)
🧰 Additional context used
🪛 GitHub Check: spell-check
examples/Widgets/Widgets.ino

[failure] 36-36:
tollerance ==> tolerance


[failure] 36-36:
tollerance ==> tolerance

🔇 Additional comments (2)
examples/Widgets/Widgets.ino (2)

1-13: LGTM! Well-organized includes and constants.

The code follows best practices with:

  • Logical organization of includes from core to specific components
  • Clear constant definitions for LCD dimensions

65-75: LGTM! Clean setup and loop implementation.

The setup and loop functions are well-organized and focused on their specific responsibilities.

examples/Widgets/Widgets.ino Outdated Show resolved Hide resolved
examples/Widgets/Widgets.ino Outdated Show resolved Hide resolved
examples/Widgets/Widgets.ino Outdated Show resolved Hide resolved
examples/Widgets/Widgets.ino Outdated Show resolved Hide resolved
examples/Widgets/Widgets.ino Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 29, 2024
- Fix tolerance spelling in Quantity widget lambda function
- Change Freq widget ranges to not allow wrapping
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 4e12256 and bbb3347.

📒 Files selected for processing (1)
  • examples/Widgets/Widgets.ino (1 hunks)
🧰 Additional context used
📓 Learnings (1)
examples/Widgets/Widgets.ino (1)
Learnt from: forntoh
PR: forntoh/LcdMenu#262
File: examples/Widgets/Widgets.ino:14-17
Timestamp: 2024-10-29T23:12:27.533Z
Learning: The user prefers not to include ASCII art comments for custom characters in their code.
🔇 Additional comments (5)
examples/Widgets/Widgets.ino (5)

1-14: LGTM! Well-organized includes and constants.

The code follows good practices by:

  • Including all necessary headers
  • Using constants for LCD configuration
  • Making the I2C address configurable via LCD_ADDR constant

15-18: LGTM! Clean custom character definitions.

The bit patterns for plusMinus (±) and euro (€) characters are correctly defined.


19-22: LGTM! Well-structured constant arrays.

The arrays are appropriately defined and initialized.


60-64: LGTM! Proper hardware initialization sequence.

The components are initialized in the correct order using the defined constants.


66-76: ⚠️ Potential issue

Add error handling in setup function.

The setup function should include error handling for Serial and custom character initialization.

Consider adding error handling:

 void setup() {
     Serial.begin(9600);
+    // Wait for Serial to be ready (optional, remove if not debugging)
+    while (!Serial && millis() < 3000);  // Wait up to 3 seconds
+    
     renderer.begin();
     menu.setScreen(mainScreen);
-    lcd.createChar(2, plusMinus);
-    lcd.createChar(3, euro);
+    // Verify custom character creation
+    if (!lcd.createChar(2, plusMinus) || !lcd.createChar(3, euro)) {
+        Serial.println(F("Failed to create custom characters"));
+    }
 }

Likely invalid or redundant comment.

examples/Widgets/Widgets.ino Show resolved Hide resolved
examples/Widgets/Widgets.ino Show resolved Hide resolved
Copy link
Contributor

Memory usage change @ bbb3347

Board flash % RAM for global variables %
STMicroelectronics:stm32:GenF1 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:uno 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
esp32:esp32:esp32 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
esp8266:esp8266:huzzah N/A N/A N/A N/A
Click for full report table
Board examples/Basic
flash
% examples/Basic
RAM for global variables
% examples/ButtonAdapter
flash
% examples/ButtonAdapter
RAM for global variables
% examples/Callbacks
flash
% examples/Callbacks
RAM for global variables
% examples/InputRotary
flash
% examples/InputRotary
RAM for global variables
% examples/IntFloatValues
flash
% examples/IntFloatValues
RAM for global variables
% examples/KeyboardAdapter
flash
% examples/KeyboardAdapter
RAM for global variables
% examples/List
flash
% examples/List
RAM for global variables
% examples/SimpleRotary
flash
% examples/SimpleRotary
RAM for global variables
% examples/SSD1803A_I2C
flash
% examples/SSD1803A_I2C
RAM for global variables
% examples/RTOS
flash
% examples/RTOS
RAM for global variables
%
STMicroelectronics:stm32:GenF1 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:avr:uno 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:samd:mkr1000 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
esp32:esp32:esp32 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
esp8266:esp8266:huzzah N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/Basic<br>flash,%,examples/Basic<br>RAM for global variables,%,examples/ButtonAdapter<br>flash,%,examples/ButtonAdapter<br>RAM for global variables,%,examples/Callbacks<br>flash,%,examples/Callbacks<br>RAM for global variables,%,examples/InputRotary<br>flash,%,examples/InputRotary<br>RAM for global variables,%,examples/IntFloatValues<br>flash,%,examples/IntFloatValues<br>RAM for global variables,%,examples/KeyboardAdapter<br>flash,%,examples/KeyboardAdapter<br>RAM for global variables,%,examples/List<br>flash,%,examples/List<br>RAM for global variables,%,examples/SimpleRotary<br>flash,%,examples/SimpleRotary<br>RAM for global variables,%,examples/SSD1803A_I2C<br>flash,%,examples/SSD1803A_I2C<br>RAM for global variables,%,examples/RTOS<br>flash,%,examples/RTOS<br>RAM for global variables,%
STMicroelectronics:stm32:GenF1,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:avr:uno,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:samd:mkr1000,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,,,,
esp32:esp32:esp32,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
esp8266:esp8266:huzzah,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,,,,

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 29, 2024
Added a new test file with detailed steps for simulating various widget interactions and edits.
@forntoh forntoh force-pushed the feat/widgets-example branch from 27c4d46 to b33b2a8 Compare October 29, 2024 23:56
@forntoh forntoh marked this pull request as ready for review October 30, 2024 00:05
@forntoh forntoh enabled auto-merge October 30, 2024 00:09
@forntoh forntoh disabled auto-merge October 30, 2024 00:44
@forntoh forntoh marked this pull request as draft October 30, 2024 00:45
@forntoh forntoh marked this pull request as ready for review October 30, 2024 00:45
@forntoh forntoh enabled auto-merge October 30, 2024 00:45
@forntoh forntoh added the feature New feature label Oct 30, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between bbb3347 and b33b2a8.

📒 Files selected for processing (1)
  • test/Widgets.test.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
test/Widgets.test.yml

[error] 166-166: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (2)
test/Widgets.test.yml (2)

1-3: LGTM: Test metadata is well-defined.

The test configuration includes essential metadata fields.


49-90: Verify decimal precision handling in Quantity widget.

The test should explicitly verify:

  1. Decimal precision limits
  2. Cursor wraparound behavior when moving left/right
✅ Verification successful

Let me search for more specific implementation details about the Quantity widget and float handling.


Let me check the specific implementation of WidgetRange to understand the decimal precision and cursor behavior better.


Let me check one final thing about the Quantity widget's specific implementation.


Based on the code analysis from the test file and WidgetRange implementation, I can now provide a final response:

Decimal precision and cursor behavior are correctly implemented

The test adequately verifies the decimal precision handling:

  • It tests decimal increments (0.10 steps) in the first decimal place
  • It verifies cursor movement between integer and decimal parts
  • The implementation in WidgetRange template class properly handles:
    • Value constraints through min/max bounds
    • Precise stepping through the templated step parameter
    • Cursor movement between positions

The test case demonstrates proper decimal precision by:

  1. Incrementing decimals (1.10 -> 1.20 -> 1.30 -> 1.40 -> 1.50)
  2. Moving cursor between decimal/integer parts (right/left)
  3. Verifying both increment/decrement operations maintain precision
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for decimal precision configuration in the codebase
rg -A 2 "decimal.*precision|float.*format" --type cpp

Length of output: 265


Script:

#!/bin/bash
# Search for Quantity widget implementation and float handling
ast-grep --pattern 'class $_ {
  $$$
  float $$$
  $$$
}'

# Also search for relevant method implementations
rg -l "Quantity.*Widget|WidgetRange" --type cpp

# Look for cursor movement implementation
rg -A 3 "right|left.*cursor" --type cpp

Length of output: 5445


Script:

#!/bin/bash
# Check WidgetRange implementation
cat src/widget/WidgetRange.h

# Look for increment/decrement implementations that handle decimal precision
rg -A 5 "increment|decrement" src/widget/WidgetRange.h

# Search for any float formatting or precision handling
rg -A 3 "format.*float|sprintf|dtostrf" --type cpp

Length of output: 7184


Script:

#!/bin/bash
# Look for Quantity widget format string and initialization
rg -A 5 "Quantity.*Widget.*format|WIDGET_RANGE.*float" --type cpp

# Check BaseWidgetValue implementation for cursor handling
cat src/BaseWidgetValue.h

Length of output: 149

test/Widgets.test.yml Show resolved Hide resolved
test/Widgets.test.yml Show resolved Hide resolved
test/Widgets.test.yml Show resolved Hide resolved
test/Widgets.test.yml Show resolved Hide resolved
test/Widgets.test.yml Show resolved Hide resolved
@forntoh forntoh disabled auto-merge October 30, 2024 01:27
@forntoh forntoh merged commit 940bfbc into master Oct 30, 2024
21 checks passed
@forntoh forntoh deleted the feat/widgets-example branch October 30, 2024 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant