Przeglądaj źródła

add feature flag

tuanchris 3 miesięcy temu
rodzic
commit
965b60f671
4 zmienionych plików z 50 dodań i 3 usunięć
  1. 21 1
      main.py
  2. 4 0
      modules/core/state.py
  3. 23 1
      static/js/settings.js
  4. 2 1
      templates/settings.html

+ 21 - 1
main.py

@@ -94,6 +94,13 @@ def normalize_file_path(file_path: str) -> str:
 async def lifespan(app: FastAPI):
     # Startup
     logger.info("Starting Dune Weaver application...")
+
+    # Check for advanced calibration feature flag (Desert Compass)
+    advanced_cal_env = os.getenv('ADVANCED_CALIBRATION', 'false').lower()
+    state.advanced_calibration_enabled = advanced_cal_env in ('true', '1', 'yes')
+    if state.advanced_calibration_enabled:
+        logger.info("Advanced calibration features enabled (Desert Compass)")
+
     # Register signal handlers
     signal.signal(signal.SIGINT, signal_handler)
     signal.signal(signal.SIGTERM, signal_handler)
@@ -102,7 +109,7 @@ async def lifespan(app: FastAPI):
     global process_pool
     process_pool = ProcessPoolExecutor(max_workers=process_pool_size)
     logger.info(f"Initialized process pool with {process_pool_size} workers (detected {cpu_count} cores total)")
-    
+
     try:
         connection_manager.connect_device()
     except Exception as e:
@@ -493,9 +500,19 @@ async def set_scheduled_pause(request: ScheduledPauseRequest):
         logger.error(f"Error updating Still Sands settings: {str(e)}")
         raise HTTPException(status_code=500, detail=f"Failed to update Still Sands settings: {str(e)}")
 
+@app.get("/api/advanced-calibration-status")
+async def get_advanced_calibration_status():
+    """Check if advanced calibration features (Desert Compass) are enabled."""
+    return {
+        "enabled": state.advanced_calibration_enabled
+    }
+
 @app.get("/api/angular-homing")
 async def get_angular_homing():
     """Get current Desert Compass settings."""
+    if not state.advanced_calibration_enabled:
+        raise HTTPException(status_code=403, detail="Advanced calibration features not enabled")
+
     return {
         "angular_homing_enabled": state.angular_homing_enabled,
         "angular_homing_gpio_pin": state.angular_homing_gpio_pin,
@@ -512,6 +529,9 @@ class AngularHomingRequest(BaseModel):
 @app.post("/api/angular-homing")
 async def set_angular_homing(request: AngularHomingRequest):
     """Update Desert Compass settings."""
+    if not state.advanced_calibration_enabled:
+        raise HTTPException(status_code=403, detail="Advanced calibration features not enabled")
+
     try:
         # Validate GPIO pin
         if request.angular_homing_gpio_pin < 2 or request.angular_homing_gpio_pin > 27:

+ 4 - 0
modules/core/state.py

@@ -34,6 +34,10 @@ class AppState:
         self.gear_ratio = 10
         # 0 for crash homing, 1 for auto homing
         self.homing = 0
+        # Advanced calibration feature flag (Desert Compass)
+        # Set via environment variable ADVANCED_CALIBRATION=true
+        self.advanced_calibration_enabled = False
+
         # Angular homing with reed switch (Raspberry Pi only)
         self.angular_homing_enabled = False
         # GPIO pin number (BCM numbering) for reed switch

+ 23 - 1
static/js/settings.js

@@ -1494,7 +1494,29 @@ async function initializeStillSandsMode() {
 
 // Desert Compass Configuration Functions
 async function initializeAngularHomingConfig() {
-    logMessage('Initializing Desert Compass configuration', LOG_TYPE.INFO);
+    logMessage('Checking Desert Compass feature availability', LOG_TYPE.INFO);
+
+    // Check if advanced calibration features are enabled
+    try {
+        const statusResponse = await fetch('/api/advanced-calibration-status');
+        const statusData = await statusResponse.json();
+
+        if (!statusData.enabled) {
+            logMessage('Advanced calibration features not enabled, skipping Desert Compass', LOG_TYPE.INFO);
+            return;
+        }
+
+        logMessage('Advanced calibration enabled, initializing Desert Compass', LOG_TYPE.INFO);
+
+        // Show the Desert Compass section
+        const desertCompassSection = document.getElementById('desertCompassSection');
+        if (desertCompassSection) {
+            desertCompassSection.style.display = 'block';
+        }
+    } catch (error) {
+        logMessage(`Failed to check advanced calibration status: ${error.message}`, LOG_TYPE.ERROR);
+        return;
+    }
 
     const angularHomingToggle = document.getElementById('angularHomingToggle');
     const angularHomingInfo = document.getElementById('angularHomingInfo');

+ 2 - 1
templates/settings.html

@@ -328,7 +328,8 @@ input:checked + .slider:before {
       </div>
     </div>
   </section>
-  <section class="bg-white rounded-xl shadow-sm overflow-hidden">
+  <!-- Desert Compass Section (hidden unless advanced calibration enabled) -->
+  <section id="desertCompassSection" class="bg-white rounded-xl shadow-sm overflow-hidden" style="display: none;">
     <h2
       class="text-slate-800 text-xl sm:text-2xl font-semibold leading-tight tracking-[-0.01em] px-6 py-4 border-b border-slate-200"
     >