Skip to content

changelog New Features#2

Open
vicliu624 wants to merge 18 commits into
Moo93egy:mainfrom
vicliu624:main
Open

changelog New Features#2
vicliu624 wants to merge 18 commits into
Moo93egy:mainfrom
vicliu624:main

Conversation

@vicliu624
Copy link
Copy Markdown

Version 2.0 - Major Feature Additions and Improvements

New Features

  1. Multi-Language Character Support

    • Added UTF-8 encoding support for displaying Chinese, Japanese, and Korean song names
    • Implemented automatic language detection with font selection:
      • Korean: efontKR_12 (Hangul syllables)
      • Japanese: efontJA_12 (Hiragana, Katakana, Kanji)
      • Chinese: efontCN_12 (CJK Unified Ideographs)
      • English/Others: Default system font
    • Font selection priority: Korean > Japanese > Chinese > Default
    • Adjusted line height from 12 to 16 pixels to accommodate CJK characters
  2. Screen Power Management

    • Added screen off/on toggle functionality (S key)
    • Automatically saves current brightness when turning off screen
    • Restores saved brightness when turning screen back on
    • Skips drawing operations when screen is off to save CPU
  3. Song Deletion Feature

    • Added delete confirmation dialog (D key to show, Y to confirm, C to cancel)
    • Smart deletion logic: continues playing current song if deleted song is not playing
    • Automatically switches to next song if currently playing song is deleted
    • Properly adjusts all indices after deletion
  4. Playback Mode System

    • Added three playback modes: Sequential (SEQ), Random (RND), Single Repeat (ONE)
    • Mode toggle via M key (replaces original B key random function)
    • Mode indicator displayed in top-right area (replaces scrolling song title)
    • Automatic next song selection based on selected mode
    • Smart N/P key behavior: In random mode, both N and P keys select random songs (avoiding current playing song)
  5. Fine Volume Control

    • Added - key for decreasing volume (step 1)
    • Added = key for increasing volume (step 1)
    • Improved volume bar calculation for smooth linear mapping (0-21 range mapped to 60 pixels)
    • Original V key still works for step-based volume cycling (step 5)
  6. Smart Scrolling for Selected Songs

    • Selected song names scroll from right to left after 1 second delay
    • Scrolling strictly limited within LIST box boundaries (doesn't overlap scrollbar)
    • Automatically resets scroll position when selection changes
    • Optimized update rate (every 4 frames) to reduce CPU usage
  7. Dual Index System

    • Separated selected index (n) from playing index (currentPlayingIndex)
    • Enables independent navigation and playback tracking
    • Properly handles index adjustments during song deletion

Enhanced Features

  1. File Organization

    • Changed default music directory from /mp3s to /music
    • File names displayed without path and extension for cleaner interface
    • Improved file path extraction and display logic
  2. User Interface Improvements

    • Reduced song list display from 10 lines to 7 lines (better fit with 16px line height)
    • Added color coding: Red for playing song, White for selected song, Green for others
    • Removed top scrolling area (previously showed current playing song title)
    • Replaced with playback mode indicator (SEQ/RND/ONE)
  3. List Navigation

    • Made list navigation circular: pressing up at first song jumps to last, pressing down at last jumps to first
    • Improved navigation logic for better user experience
  4. Performance Optimizations

    • Battery display caching: updates every 30 seconds (was real-time)
    • Time display caching: updates every 1 second (was real-time)
    • Spectrum graph throttling: updates every 200ms (was every frame)
    • Text scrolling optimization: updates every 4 frames
    • Screen refresh rate: optimized to 20fps (50ms delay, was 25fps/40ms)
    • Main loop delay: increased to 200ms (was 100ms) to reduce CPU usage
  5. Volume Control Enhancement

    • Improved volume bar calculation: linear mapping 155 + (volume * 60 / 21) instead of step-based (volume / 5) * 17
    • Ensures smooth movement for each volume unit change
  6. Code Quality

    • All comments translated to English
    • Improved code organization and structure
    • Better variable naming and documentation

Removed Features

  • Removed top scrolling song title area (replaced with playback mode display)
  • Removed B key random playback function (replaced with M key mode toggle)

Technical Changes

  • Added multiple global state variables for new features (screenOff, showDeleteDialog, playMode, etc.)
  • Implemented caching mechanisms for battery, time, and graph updates
  • Added scroll position tracking for selected songs
  • Enhanced deleteCurrentFile() function with smart index management
  • Modified audio_eof_mp3() to support different playback modes
  • Updated draw() function with Chinese font support and improved rendering logic

Notes

  • Ensure SD card is formatted as FAT32
  • Audio files are recommended to be placed in /music directory
  • Deleting songs permanently removes files from SD card, use with caution
  • In single repeat mode, the song automatically repeats after finishing

This commit represents a comprehensive refactoring effort to improve code
organization, maintainability, and performance. The monolithic M5mp3.cpp has
been broken down into well-organized modules with clear responsibilities.

## Module Structure

### Core Modules Created:
- **config.hpp/cpp**: Centralized configuration constants (UI layout, hardware pins, timing intervals)
- **app_state.hpp**: Centralized application state structure (AppState) aggregating all global variables
- **input_handler.hpp/cpp**: Keyboard input handling abstraction
- **ui_renderer.hpp/cpp**: UI rendering logic (main view and ID3 page)
- **audio_manager.hpp/cpp**: Audio playback control and callback management
- **board_init.hpp/cpp**: Hardware initialization and variant detection
- **file_manager.hpp/cpp**: File operations (list, delete, screenshot)
- **image_utils.hpp/cpp**: Image scanning and dimension parsing utilities

## Key Improvements

### Code Organization:
- Reduced M5mp3.cpp from ~1800 lines to ~420 lines (76% reduction)
- Separated concerns: UI, audio, file operations, hardware init
- Clear module boundaries with well-defined interfaces
- Eliminated code duplication

### Performance Optimizations:
- Replaced String concatenation with snprintf for better performance
- Optimized screenshot capture with row-by-row pixel reading/writing
- Removed unused functions and variables
- Centralized constants to reduce magic numbers

### Code Quality:
- Unified logging system with compile-time switches (LOG, DEBUG_PRINTF)
- Consistent error handling and resource management
- Better type safety (proper includes instead of forward declarations)
- Improved code documentation and comments

### Memory Management:
- Stream-only album cover handling (no RAM caching)
- Optimized screenshot memory usage
- Better resource cleanup

## Technical Details

- All hardware constants moved to config.hpp
- All application state consolidated in AppState struct
- Audio operations unified through AudioManager interface
- File operations abstracted via FileManager module
- UI rendering separated into UiRenderer module
- Input handling centralized in InputHandler module

## Files Changed

- M5mp3.cpp: Reduced from ~1800 to ~420 lines
- Added 8 new module files (headers + implementations)
- Removed history/main.cpp (no longer needed)

## Testing

All functionality verified and tested. The refactored code maintains 100%
feature parity with the original implementation while significantly improving
code maintainability and organization.
- Add VERSION file for version tracking
- Add CHANGELOG.md following Keep a Changelog format
- Add version macros to config.hpp
- Add release scripts (release.sh and release.ps1)
- Add GitHub Actions workflow for automated releases
- Update .gitignore for build artifacts
- Remove Changelog section from README (moved to CHANGELOG.md)
- Expand Features section with comprehensive feature descriptions
- Add Version History section with link to CHANGELOG.md
- Update release scripts with correct GitHub username (vicliu624)
- Update CHANGELOG.md with actual release dates
…nced

- Use M5Cardputer.Power.getBatteryLevel() API (uses AXP2101 PMIC internal gauge)
- Add fallback to ADC reading for compatibility with Standard version
- Add detailed comments explaining:
  - AXP2101 PMIC provides accurate battery level via internal gauge
  - Battery capacity (1750mAh) is handled by PMIC, not voltage mapping
  - Voltage-to-percentage mapping is a linear approximation
  - Voltage range (3.3V-4.2V) is determined by battery chemistry, not capacity
Main fixes:
1. Fix cover image scaling issue
   - Properly calculate image dimensions and compute appropriate scale ratio
   - Pass scaleX/scaleY parameters to M5GFX drawJpg/drawPng functions
   - Use fit-to-size mode (scale=0) when dimensions cannot be determined

2. Fix crash when switching tracks in ID3 page
   - Save local copies at start of drawId3Page to avoid accessing shared state
     that may be modified during rendering
   - Add double-check to verify buffer validity (pointer and size)
   - Add index validation to prevent accessing invalid audioFiles array indices
   - Early return when stale data is detected to avoid accessing freed memory

3. Improve error handling in streaming read branch
   - Check getImageSize return value
   - Use scaleX=0.0f (fit-to-size) instead of fixed 0.5f scaling

These fixes resolve LoadProhibited crashes that could occur when switching
tracks while viewing the ID3 information page.
…2.2.0)

- Added current playback time display (MM:SS format, smaller font)
- Added minimalist progress bar (1-pixel high, green, at bottom)
- Added control icons (Previous: |◀, Play/Pause: ▶/⏸, Next: ▶|) with rounded square backgrounds
- Added ContentType metadata display (conditional)
- Improved ID3 page layout with dynamic text positioning to prevent overlap
- Fixed screenshot color conversion issue (removed redundant byte swap)
- Fixed album name text clipping when scrolling
- Fixed scroll trigger logic (only scrolls when text exceeds width)
- Added interface screenshots to README.md
- Updated version to 2.2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant