DIY Scene Editing Feature
Applicable: Wi-Fi + BLE Panel
🖼️ Preview:
The DIY scene editing feature module allows users to create and edit custom lighting scenes, supporting two editing modes: dynamic scene editing (based on colors and motion parameters) and static scene editing (based on LED bead painting). This module provides complete scene creation, editing, preview, saving, and management functionality, making it a core tool for users to personalize lighting effects.
Feature List
- Dynamic DIY Scene Editing: Create dynamic scenes through color lists and motion parameters
- Static DIY Scene Editing: Precisely control each LED bead color through painting
- Scene Preview: Real-time preview of scene effects
- Scene Saving: Save scenes to cloud storage
- Scene Loading: Load existing scenes from cloud storage for editing
- Scene Deletion: Delete unwanted scenes
- Scene List Management: View and manage all DIY scenes
Feature Implementation Details
Dynamic DIY Scene Editing
Dynamic DIY scene editing uses SceneData data structure, containing color lists and motion parameters. The editing page provides color management and parameter adjustment functionality, and scene data is sent through the rgbic_linerlight_scene DP point.
Core Components
src/pages/diyEdit/index.tsx: Dynamic DIY scene editing pagesrc/components/colors/index.tsx: Color list componentsrc/components/motion-config/index.tsx: Motion parameter configuration componentsrc/hooks/useSceneSet.ts: Scene setting Hook
Data Flow
flowchart TD
A[Enter editing page] --> B[Load scene data]
B --> C{Is edit mode}
C -->|Yes| D[Load from cloud storage]
C -->|No| E[Use default data]
D --> F[Display color list]
E --> F
F --> G[User adds/removes colors]
G --> H[Select motion type]
H --> I[Adjust motion parameters]
I --> J[Preview scene]
J --> K[Save scene]
K --> L[Encode scene data]
L --> M[Save to cloud storage]
M --> N[Send DP to device]Key Code Snippets
Scene Save Implementation:
Data Structures
Scene Data Format:
Static DIY Scene Editing
Static DIY scene editing uses DiySceneData data structure, containing color information for each LED bead. Control each LED bead through painting, and scene data is sent through the diy_scene DP point.
Core Components
src/pages/staticDiyEdit/index.tsx: Static DIY scene editing pagesrc/components/light-strip/index.tsx: Light strip visualization componentsrc/hooks/useDrawToolDataList.ts: Painting tool data management Hooksrc/hooks/useCutDrawDiyScene.ts: Painting scene setting Hook
Data Flow
sequenceDiagram
participant User as User
participant Page as Editing Page
participant Strip as Light Strip Component
participant Hook as Data Hook
participant Protocol as Protocol Parser
participant Device as Device
User->>Page: Select color and painting mode
User->>Strip: Select LED beads
Strip->>Page: Update selection state
Page->>Hook: Call update function
Hook->>Hook: Update light strip data
Hook->>Protocol: Encode scene data
Protocol->>Device: Send DP
Device-->>User: Display effect
User->>Page: Save scene
Page->>Hook: Save to cloud storageKey Code Snippets
Scene Save Implementation:
Painting Scene Setting:
Data Structures
DIY Scene Data Format:
Scene Preview
Scene preview is implemented through the preview method of useSceneSet Hook, encoding scene data and sending to device without saving to cloud storage.
Core Components
src/hooks/useSceneSet.ts: Scene setting Hook
Data Flow
flowchart TD
A[User clicks preview] --> B[Build scene data]
B --> C[useSceneSet.preview]
C --> D[Encode scene data]
D --> E[Send DP to device]
E --> F[Device executes scene]
F --> G[User observes effect]
G --> H{Continue editing?}
H -->|Yes| I[Return to editing]
H -->|No| J[Save scene]Key Code Snippets
Preview Implementation:
Scene Saving
Scene saving includes three steps: data encoding, cloud storage saving, and DP sending. It supports both add and update modes, and triggers scene creation event after successful save.
Core Components
src/pages/diyEdit/index.tsx: Dynamic scene savesrc/pages/staticDiyEdit/index.tsx: Static scene savesrc/hooks/useCloudStorageCombinedList.ts: Cloud storage list managementsrc/hooks/useCloudDrawToolList.ts: Scene data encoding/decoding
Data Flow
Already detailed in Feature 1 and Feature 2.
Scene Loading
Scene loading reads scene data from cloud storage, decodes and fills into editing page. Load to corresponding editing page based on scene type (dynamic or static).
Core Components
src/pages/diyEdit/index.tsx: Dynamic scene loadingsrc/pages/staticDiyEdit/index.tsx: Static scene loadingsrc/hooks/useCloudDrawToolList.ts: Scene data decoding
Data Flow
flowchart TD
A[User selects edit] --> B[Get scene ID]
B --> C[Read from cloud storage]
C --> D[Decode scene data]
D --> E{Scene type}
E -->|Dynamic| F[Load to dynamic edit page]
E -->|Static| G[Load to static edit page]
F --> H[Fill color list]
G --> I[Fill LED bead data]
H --> J[Fill motion parameters]
I --> K[Display light strip state]Scene Deletion
Scene deletion removes scene data from cloud storage and updates scene list. User confirmation is required before deletion.
Core Components
src/pages/diyEdit/index.tsx: Delete functionalitysrc/pages/staticDiyEdit/index.tsx: Delete functionalitysrc/hooks/useCloudStorageCombinedList.ts: Cloud storage deletion
Key Code Snippets
Delete Implementation (using dynamic scene as example):
Scene List Management
Scene list management is implemented through useDiySceneInit Hook, reading all scenes from cloud storage, categorizing by type, and supporting scene selection and switching.
Core Components
src/components/tab-diy/index.tsx: DIY scene list componentsrc/hooks/useDiySceneInit.ts: DIY scene initialization Hook
Data Flow
flowchart TD
A[Enter DIY tab] --> B[useDiySceneInit initialization]
B --> C[Read scene list from cloud storage]
C --> D[Decode scene data]
D --> E[Categorize by type]
E --> F[Display scene cards]
F --> G[User selects scene]
G --> H{Scene type}
H -->|Dynamic| I[Apply dynamic scene]
H -->|Static| J[Apply static scene]
I --> K[Send scene DP]
J --> K
K --> L[Update current scene ID]Key Code Snippets
Scene Initialization:
Scene List Generation:
Notes
Implementation Challenges
-
Scene Data Encoding/Decoding:
- Challenge: Dynamic scenes and static scenes use different data formats and DP points
- Solution: Use
encodeCloudSceneDataanddecodeCloudSceneDatafor unified encoding/decoding, distinguish scene type throughtypefield
-
LED Bead Data Alignment:
- Challenge: Static scene LED bead data needs to align with device LED bead count
- Solution: Check data length in
useCutDrawDiySceneSet, pad with default colors when insufficient, truncate when exceeded
-
Scene Type Differentiation:
- Challenge: Need to distinguish dynamic scenes (scene) and static scenes (draw)
- Solution: Use
typefield in cloud storage data for identification, select corresponding processing logic based on type when loading
-
Scene Name Deduplication:
- Challenge: Prevent duplicate scene names
- Solution: Use
dedupfunction to check names, prompt user to modify when saving
Common Issues
-
Issue: Data incorrect after scene loading
- Cause: Data decoding failed or format mismatch
- Solution: Check data format, add error handling, use default values as fallback
-
Issue: Preview has no effect
- Cause: Device not connected or DP sending failed
- Solution: Check device connection status, view DP sending logs
-
Issue: Static scene LED bead count mismatch
- Cause: Device LED bead count changed or data corrupted
- Solution: Automatically align LED bead count, pad or truncate data
Performance Optimization
-
Scene List Caching:
- Use
useMemoto cache scene list, avoid repeated calculations - Scene list sorted by ID in descending order, newest scenes first
- Use
-
Data Encoding Optimization:
- Scene data encoding uses efficient string concatenation
- Avoid unnecessary deep copies
-
Lazy Loading:
- Scene list paginated display, avoid loading all scenes at once
- Scene data decoded on demand
-
Debounce Processing:
- Scene saving uses debounce, avoid repeated saves
- Scene preview uses throttle, avoid frequent DP sending
Edge Cases
-
Empty Scene List:
- Handling: Display empty state prompt, guide user to create scene
- Provide default scene options
-
Scene Data Corrupted:
- Handling: Use default data when decoding fails
- Prompt user about scene data anomaly
-
Device LED Bead Count Changes:
- Handling: Automatically align LED bead count
- Truncate exceeded parts, pad insufficient parts with default colors
-
Scene Name Too Long:
- Handling: Limit scene name length
- Truncate exceeded parts or prompt user
-
Editing Multiple Scenes Simultaneously:
- Handling: Only one scene can be edited at a time
- Save current scene when switching edits