فهرست منبع

Add option to turn off wled when in Still Sands

tuanchris 4 ماه پیش
والد
کامیت
75bf303dbe
6فایلهای تغییر یافته به همراه62 افزوده شده و 4 حذف شده
  1. 4 1
      docker-compose.yml
  2. 5 1
      main.py
  3. 15 2
      modules/core/pattern_manager.py
  4. 3 0
      modules/core/state.py
  5. 16 0
      static/js/settings.js
  6. 19 0
      templates/settings.html

+ 4 - 1
docker-compose.yml

@@ -1,12 +1,15 @@
 services:
   dune-weaver:
-    build: . # Uncomment this if you need to build 
+    build: . # Uncomment this if you need to build
     image: ghcr.io/tuanchris/dune-weaver:main # Use latest production image
     restart: always
     ports:
       - "8080:8080" # Map port 8080 of the container to 8080 of the host (access via http://localhost:8080)
     volumes:
       - .:/app
+      # Automatically inherit timezone from host system (works on Linux/Pi)
+      - /etc/localtime:/etc/localtime:ro
+      - /etc/timezone:/etc/timezone:ro
     devices:
       - "/dev/ttyACM0:/dev/ttyACM0"
     privileged: true

+ 5 - 1
main.py

@@ -162,6 +162,7 @@ class TimeSlot(BaseModel):
 
 class ScheduledPauseRequest(BaseModel):
     enabled: bool
+    control_wled: Optional[bool] = False
     time_slots: List[TimeSlot] = []
 
 class CoordinateRequest(BaseModel):
@@ -320,6 +321,7 @@ async def get_scheduled_pause():
     """Get current Still Sands settings."""
     return {
         "enabled": state.scheduled_pause_enabled,
+        "control_wled": state.scheduled_pause_control_wled,
         "time_slots": state.scheduled_pause_time_slots
     }
 
@@ -364,10 +366,12 @@ async def set_scheduled_pause(request: ScheduledPauseRequest):
 
         # Update state
         state.scheduled_pause_enabled = request.enabled
+        state.scheduled_pause_control_wled = request.control_wled
         state.scheduled_pause_time_slots = [slot.model_dump() for slot in request.time_slots]
         state.save()
 
-        logger.info(f"Still Sands {'enabled' if request.enabled else 'disabled'} with {len(request.time_slots)} time slots")
+        wled_msg = " (with WLED control)" if request.control_wled else ""
+        logger.info(f"Still Sands {'enabled' if request.enabled else 'disabled'} with {len(request.time_slots)} time slots{wled_msg}")
         return {"success": True, "message": "Still Sands settings updated"}
 
     except HTTPException:

+ 15 - 2
modules/core/pattern_manager.py

@@ -588,10 +588,19 @@ async def run_theta_rho_file(file_path, is_playlist=False):
                         logger.info("Execution paused (manual)...")
                     else:
                         logger.info("Execution paused (scheduled pause period)...")
-
-                    if state.led_controller:
+                        # Turn off WLED if scheduled pause and control_wled is enabled
+                        if state.scheduled_pause_control_wled and state.led_controller:
+                            logger.info("Turning off WLED lights during Still Sands period")
+                            state.led_controller.set_power(0)
+
+                    # Only show idle effect if NOT in scheduled pause with WLED control
+                    # (manual pause always shows idle effect)
+                    if state.led_controller and not (scheduled_pause and state.scheduled_pause_control_wled):
                         effect_idle(state.led_controller)
 
+                    # Remember if we turned off WLED for scheduled pause
+                    wled_was_off_for_scheduled = scheduled_pause and state.scheduled_pause_control_wled and not manual_pause
+
                     # Wait until both manual pause is released AND we're outside scheduled pause period
                     while state.pause_requested or is_in_scheduled_pause_period():
                         await asyncio.sleep(1)  # Check every second
@@ -601,6 +610,10 @@ async def run_theta_rho_file(file_path, is_playlist=False):
 
                     logger.info("Execution resumed...")
                     if state.led_controller:
+                        # Turn WLED back on if it was turned off for scheduled pause
+                        if wled_was_off_for_scheduled:
+                            logger.info("Turning WLED lights back on as Still Sands period ended")
+                            state.led_controller.set_power(1)
                         effect_playing(state.led_controller)
 
                 # Dynamically determine the speed for each movement

+ 3 - 0
modules/core/state.py

@@ -64,6 +64,7 @@ class AppState:
         # Still Sands settings
         self.scheduled_pause_enabled = False
         self.scheduled_pause_time_slots = []  # List of time slot dictionaries
+        self.scheduled_pause_control_wled = False  # Turn off WLED during pause periods
         
         self.load()
 
@@ -198,6 +199,7 @@ class AppState:
             "auto_play_shuffle": self.auto_play_shuffle,
             "scheduled_pause_enabled": self.scheduled_pause_enabled,
             "scheduled_pause_time_slots": self.scheduled_pause_time_slots,
+            "scheduled_pause_control_wled": self.scheduled_pause_control_wled,
         }
 
     def from_dict(self, data):
@@ -236,6 +238,7 @@ class AppState:
         self.auto_play_shuffle = data.get("auto_play_shuffle", False)
         self.scheduled_pause_enabled = data.get("scheduled_pause_enabled", False)
         self.scheduled_pause_time_slots = data.get("scheduled_pause_time_slots", [])
+        self.scheduled_pause_control_wled = data.get("scheduled_pause_control_wled", False)
 
     def save(self):
         """Save the current state to a JSON file."""

+ 16 - 0
static/js/settings.js

@@ -1038,6 +1038,7 @@ async function initializeStillSandsMode() {
     const addTimeSlotButton = document.getElementById('addTimeSlotButton');
     const saveStillSandsButton = document.getElementById('savePauseSettings');
     const timeSlotsContainer = document.getElementById('timeSlotsContainer');
+    const wledControlToggle = document.getElementById('stillSandsWledControl');
 
     // Check if elements exist
     if (!stillSandsToggle || !stillSandsSettings || !addTimeSlotButton || !saveStillSandsButton || !timeSlotsContainer) {
@@ -1071,6 +1072,11 @@ async function initializeStillSandsMode() {
             stillSandsSettings.style.display = 'block';
         }
 
+        // Load WLED control setting
+        if (wledControlToggle) {
+            wledControlToggle.checked = data.control_wled || false;
+        }
+
         // Load existing time slots
         timeSlots = data.time_slots || [];
         renderTimeSlots();
@@ -1280,6 +1286,7 @@ async function initializeStillSandsMode() {
                 headers: { 'Content-Type': 'application/json' },
                 body: JSON.stringify({
                     enabled: stillSandsToggle.checked,
+                    control_wled: wledControlToggle ? wledControlToggle.checked : false,
                     time_slots: timeSlots.map(slot => ({
                         start_time: slot.start_time,
                         end_time: slot.end_time,
@@ -1332,4 +1339,13 @@ async function initializeStillSandsMode() {
 
     addTimeSlotButton.addEventListener('click', addTimeSlot);
     saveStillSandsButton.addEventListener('click', saveStillSandsSettings);
+
+    // Add listener for WLED control toggle
+    if (wledControlToggle) {
+        wledControlToggle.addEventListener('change', async () => {
+            logMessage(`WLED control toggle changed: ${wledControlToggle.checked}`, LOG_TYPE.INFO);
+            // Auto-save when WLED control changes
+            await saveStillSandsSettings();
+        });
+    }
 }

+ 19 - 0
templates/settings.html

@@ -617,6 +617,25 @@ input:checked + .slider:before {
       </div>
 
       <div id="scheduledPauseSettings" class="space-y-4" style="display: none;">
+        <!-- WLED Control Option -->
+        <div class="bg-amber-50 rounded-lg p-4 border border-amber-200">
+          <div class="flex items-center justify-between">
+            <div class="flex-1">
+              <h4 class="text-slate-800 text-sm font-medium flex items-center gap-2">
+                <span class="material-icons text-amber-600 text-base">lightbulb</span>
+                Control WLED Lights
+              </h4>
+              <p class="text-xs text-slate-600 mt-1">
+                Turn off WLED lights during still periods for complete rest
+              </p>
+            </div>
+            <label class="switch">
+              <input type="checkbox" id="stillSandsWledControl">
+              <span class="slider round"></span>
+            </label>
+          </div>
+        </div>
+
         <div class="bg-slate-50 rounded-lg p-4 space-y-4">
           <div class="flex items-center justify-between">
             <h4 class="text-slate-800 text-base font-semibold">Still Periods</h4>