k4be
đã đẩy đến master tại k4be/GPStracker
80c8a01353 Add comprehensive error tracking and browsing system
This commit implements a new global error tracking mechanism that
complements the existing System.status error handling. Errors are now
logged persistently in System.global_error and can be browsed and
manually reset by the user.
## Architecture Changes
### Dual Error Recording
- File access errors now set BOTH System.status (for control flow)
and System.global_error (for persistent logging)
- System.status continues to trigger loop breaks and reinitializations
- System.global_error accumulates errors via bitwise OR for user review
- This hybrid approach maintains existing critical error behavior while
adding error history tracking
### New Error Types Added to System.global_error
- ERROR_TEMPERATURE (4): Temperature sensor failure
- ERROR_DISK (8): SD card mount/access errors
- ERROR_FILE_WRITE (16): File write failures
- ERROR_FILE_SYNC (32): FAT sync errors
- ERROR_FILE_CLOSE (64): File close failures
- ERROR_FILE_OPEN (128): File open failures
- Existing: ERROR_I2C, ERROR_I2C_TIMEOUT
## Menu System Enhancements
### New Menu Type: MENU_TYPE_FUNCTION_WITH_KEY
- Extends menu system to handle arbitrary key presses
- Function receives key code as parameter: func_key(unsigned char k)
- Uses anonymous union with existing func pointer (no RAM overhead)
- Enables custom key handling within menu items
### Error Browser Interface
- Added as last item in default_menu (main screen rotation)
- LEFT/RIGHT arrows: Navigate between multiple errors
- UP+DOWN simultaneously: Reset all errors
- Display format: "<1/3> Error name" when multiple errors present
- Shows "Brak" (None) when no errors
## Implementation Details
### Auto-Jump to Error Screen
- check_error_and_jump(): Monitors for new errors in main loop
- Automatically jumps to error display when error transitions from
ERROR_NO to any error state
- Only activates when viewing default_menu (main screens)
- Preserves user context when in submenus
### Temperature Sensor Monitoring
- Checks System.temperature_ok after GPS initialization
- Waits for F_GPSOK flag to avoid false positives at startup
- Sets ERROR_TEMPERATURE flag when sensor fails after warmup
### Error Browser State Machine
- Maintains current error index and total error count
- Dynamically counts active errors from bitfield
- Wraps navigation at boundaries
- Resets state when all errors cleared
### Time Display Improvements
- Added format_time() helper for human-readable time formatting
- Converts seconds to XhXXmXXs format with automatic scaling:
* <1 min: "XXs"
* <1 hour: "XXmXXs"
* <10 hours: "XhXXmXXs"
* ≥10 hours: "XXhXXm" (seconds dropped to fit display)
- Uses unsigned char for mins/secs (8-bit optimization)
- Applied to track time (display.c:242) and pause time (display.c:250)
## Memory Optimization
- Anonymous union in struct menu_pos saves 2 bytes per menu item
- Static error_browser struct: 2 bytes total
- Error list table stored in flash memory (__flash const)
## User Interface
Navigation in error screen:
← → : Browse multiple errors
↑ + ↓ : Reset all errors (press simultaneously)
Single ↑/↓ : Navigate out of error screen (standard menu behavior)
The simultaneous UP+DOWN press works because the combined key value
(K_UP | K_DOWN) doesn't match individual case statements in menu
navigation, allowing it to pass through to the custom handler.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
4 tuần trước cách đây