HDMI-CEC: auto-disable in dev mode + docs/tests synced
README: document dev-mode CEC auto-disable; add testing notes; set CEC_POWER_OFF_WAIT=5 Copilot instructions: add dev-mode CEC behavior and test script guidance test-hdmi-cec.sh: respect ENV=development (skip option 5), explicit .env load, ASCII output, 30s wait display_manager: remove emoji from logs to avoid Unicode errors
This commit is contained in:
261
scripts/test-hdmi-cec.sh
Executable file
261
scripts/test-hdmi-cec.sh
Executable file
@@ -0,0 +1,261 @@
|
||||
#!/bin/bash
|
||||
# Test HDMI-CEC functionality
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${BLUE}==================================${NC}"
|
||||
echo -e "${BLUE}HDMI-CEC Test Script${NC}"
|
||||
echo -e "${BLUE}==================================${NC}"
|
||||
echo ""
|
||||
|
||||
# Check if cec-client is installed
|
||||
echo -e "${YELLOW}1. Checking for cec-client...${NC}"
|
||||
if command -v cec-client &> /dev/null; then
|
||||
echo -e "${GREEN}✓ cec-client found${NC}"
|
||||
CEC_VERSION=$(cec-client --version 2>&1 | head -n1 || echo "unknown")
|
||||
echo " Version: $CEC_VERSION"
|
||||
else
|
||||
echo -e "${RED}✗ cec-client not found${NC}"
|
||||
echo ""
|
||||
echo "Install with:"
|
||||
echo " sudo apt-get install cec-utils"
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Scan for CEC devices
|
||||
echo -e "${YELLOW}2. Scanning for CEC devices...${NC}"
|
||||
echo "This may take a few seconds..."
|
||||
SCAN_OUTPUT=$(echo "scan" | cec-client -s -d 1 2>&1)
|
||||
echo "$SCAN_OUTPUT" | grep -E "device|found" || echo "$SCAN_OUTPUT"
|
||||
echo ""
|
||||
|
||||
# Check for TV
|
||||
if echo "$SCAN_OUTPUT" | grep -q "device #0"; then
|
||||
echo -e "${GREEN}✓ TV detected as device 0${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠ TV not detected on device 0${NC}"
|
||||
echo " Check if HDMI-CEC is enabled on your TV"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Query TV power status
|
||||
echo -e "${YELLOW}3. Checking TV power status...${NC}"
|
||||
POW_OUTPUT=$(echo "pow 0" | cec-client -s -d 1 2>&1)
|
||||
echo "$POW_OUTPUT" | grep -i "power status" || echo "Could not determine power status"
|
||||
echo ""
|
||||
|
||||
# Interactive menu
|
||||
while true; do
|
||||
echo -e "${BLUE}==================================${NC}"
|
||||
echo "Choose an option:"
|
||||
echo " 1) Turn TV ON"
|
||||
echo " 2) Turn TV OFF (standby)"
|
||||
echo " 3) Check TV power status"
|
||||
echo " 4) Scan for devices"
|
||||
echo " 5) Test Display Manager CEC integration"
|
||||
echo " 6) View CEC logs from Display Manager"
|
||||
echo " q) Quit"
|
||||
echo ""
|
||||
read -p "Enter choice: " choice
|
||||
echo ""
|
||||
|
||||
case $choice in
|
||||
1)
|
||||
echo -e "${YELLOW}Sending TV power ON command...${NC}"
|
||||
echo "on 0" | cec-client -s -d 1
|
||||
echo -e "${GREEN}Command sent${NC}"
|
||||
sleep 2
|
||||
;;
|
||||
2)
|
||||
echo -e "${YELLOW}Sending TV standby command...${NC}"
|
||||
echo "standby 0" | cec-client -s -d 1
|
||||
echo -e "${GREEN}Command sent${NC}"
|
||||
sleep 2
|
||||
;;
|
||||
3)
|
||||
echo -e "${YELLOW}Checking TV power status...${NC}"
|
||||
echo "pow 0" | cec-client -s -d 1
|
||||
sleep 1
|
||||
;;
|
||||
4)
|
||||
echo -e "${YELLOW}Scanning for CEC devices...${NC}"
|
||||
echo "scan" | cec-client -s -d 1
|
||||
sleep 1
|
||||
;;
|
||||
5)
|
||||
echo -e "${YELLOW}Testing Display Manager CEC integration...${NC}"
|
||||
echo ""
|
||||
echo "This will run a Python test of the HDMICECController class"
|
||||
echo ""
|
||||
|
||||
# Run Python test inline (no temp file)
|
||||
cd "$PROJECT_ROOT"
|
||||
python3 << 'PYTEST'
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, 'src')
|
||||
|
||||
# Load environment configuration with explicit path
|
||||
from dotenv import load_dotenv
|
||||
env_path = os.path.join(os.getcwd(), '.env')
|
||||
if os.path.exists(env_path):
|
||||
load_dotenv(env_path)
|
||||
else:
|
||||
print(f"Warning: .env file not found at {env_path}")
|
||||
|
||||
from display_manager import HDMICECController
|
||||
|
||||
# Read configuration from environment (SAME LOGIC as display_manager.py)
|
||||
ENV = os.getenv("ENV", "development")
|
||||
CEC_ENABLED = os.getenv("CEC_ENABLED", "true").lower() in ("true", "1", "yes")
|
||||
|
||||
# Apply development mode override (same as display_manager.py does)
|
||||
if ENV == "development":
|
||||
print("=" * 70)
|
||||
print("DEVELOPMENT MODE DETECTED")
|
||||
print("=" * 70)
|
||||
print("")
|
||||
print("HDMI-CEC is automatically DISABLED in development mode")
|
||||
print("to prevent constantly switching the TV on/off during testing.")
|
||||
print("")
|
||||
print("To test CEC functionality:")
|
||||
print(" 1. Change ENV=production in .env")
|
||||
print(" 2. Or use options 1-4 in this menu for manual CEC commands")
|
||||
print("")
|
||||
print("Skipping CEC integration test.")
|
||||
print("=" * 70)
|
||||
sys.exit(0)
|
||||
|
||||
CEC_DEVICE = os.getenv("CEC_DEVICE", "0") # Default to 0
|
||||
CEC_TURN_OFF_DELAY = int(os.getenv("CEC_TURN_OFF_DELAY", "30"))
|
||||
CEC_POWER_ON_WAIT = int(os.getenv("CEC_POWER_ON_WAIT", "5"))
|
||||
CEC_POWER_OFF_WAIT = int(os.getenv("CEC_POWER_OFF_WAIT", "2"))
|
||||
|
||||
print("Initializing HDMI-CEC Controller...")
|
||||
print(f"Environment: {ENV}")
|
||||
print(f"Using configuration from .env file:")
|
||||
print(f" CEC_ENABLED={CEC_ENABLED}")
|
||||
print(f" CEC_DEVICE={CEC_DEVICE}")
|
||||
print(f" CEC_TURN_OFF_DELAY={CEC_TURN_OFF_DELAY}")
|
||||
print(f" CEC_POWER_ON_WAIT={CEC_POWER_ON_WAIT}")
|
||||
print(f" CEC_POWER_OFF_WAIT={CEC_POWER_OFF_WAIT}")
|
||||
print("")
|
||||
|
||||
cec = HDMICECController(
|
||||
enabled=CEC_ENABLED,
|
||||
device=CEC_DEVICE,
|
||||
turn_off_delay=CEC_TURN_OFF_DELAY,
|
||||
power_on_wait=CEC_POWER_ON_WAIT,
|
||||
power_off_wait=CEC_POWER_OFF_WAIT
|
||||
)
|
||||
|
||||
if not cec.enabled:
|
||||
print("ERROR: CEC controller could not initialize (cec-client missing?)")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"\nCEC Controller initialized successfully")
|
||||
print(f" Device: {cec.device}")
|
||||
print(f" Turn-off delay: {cec.turn_off_delay}s")
|
||||
print(f" Power ON wait: {cec.power_on_wait}s")
|
||||
print(f" Power OFF wait: {cec.power_off_wait}s")
|
||||
print(f" Current TV state: {cec.tv_state}")
|
||||
print("")
|
||||
|
||||
print("=" * 70)
|
||||
print("Test 1: Turn TV ON")
|
||||
print("=" * 70)
|
||||
print(f"Command: 'on {cec.device}'")
|
||||
print("Watch your TV screen - it should power ON now...")
|
||||
print("")
|
||||
result = cec.turn_on()
|
||||
print(f"Result: {'[OK] SUCCESS - TV should be ON' if result else '[FAIL] FAILED'}")
|
||||
if result:
|
||||
print(f"(Waited {cec.power_on_wait}s for TV to boot)")
|
||||
print("")
|
||||
|
||||
import time
|
||||
print("Waiting 30 seconds to let TV fully initialize...")
|
||||
for i in range(30, 0, -1):
|
||||
print(f" {i}s remaining...", end='\r')
|
||||
time.sleep(1)
|
||||
print("") # New line after countdown
|
||||
|
||||
print("=" * 70)
|
||||
print("Test 2: Turn TV OFF with delay")
|
||||
print("=" * 70)
|
||||
print(f"Scheduling turn-off in {cec.turn_off_delay}s...")
|
||||
print("")
|
||||
result = cec.turn_off(delayed=True)
|
||||
print(f"Result: Scheduled (timer started)")
|
||||
print("")
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
print("=" * 70)
|
||||
print("Test 3: Cancel turn-off")
|
||||
print("=" * 70)
|
||||
cec.cancel_turn_off()
|
||||
print("Result: [OK] Timer cancelled (TV stays ON)")
|
||||
print("")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
print("=" * 70)
|
||||
print("Test 4: Turn TV OFF immediately")
|
||||
print("=" * 70)
|
||||
print(f"Command: 'standby {cec.device}'")
|
||||
print("Watch your TV screen - it should power OFF now...")
|
||||
print("")
|
||||
result = cec.turn_off(delayed=False)
|
||||
print(f"Result: {'[OK] SUCCESS - TV should be OFF' if result else '[FAIL] FAILED'}")
|
||||
if result:
|
||||
print(f"(Waited {cec.power_off_wait}s for TV to enter standby)")
|
||||
print("")
|
||||
|
||||
print("=" * 70)
|
||||
print("All tests completed!")
|
||||
print("=" * 70)
|
||||
print("")
|
||||
print("Did your TV actually turn ON and OFF?")
|
||||
print("If not, try:")
|
||||
print(f" 1. Increase CEC_POWER_ON_WAIT in .env (currently {cec.power_on_wait}s)")
|
||||
print(" 2. Check TV CEC settings (must be enabled)")
|
||||
print(" 3. Try manual command: echo 'on {cec.device}' | cec-client -s -d 1")
|
||||
PYTEST
|
||||
;;
|
||||
6)
|
||||
echo -e "${YELLOW}Viewing CEC-related logs...${NC}"
|
||||
echo ""
|
||||
LOG_FILE="$PROJECT_ROOT/logs/display_manager.log"
|
||||
if [ -f "$LOG_FILE" ]; then
|
||||
echo "Last 20 CEC-related log entries:"
|
||||
echo "================================"
|
||||
grep -i -E "(cec|tv|turn)" "$LOG_FILE" | tail -n 20 || echo "No CEC logs found"
|
||||
else
|
||||
echo "Log file not found: $LOG_FILE"
|
||||
echo "Display Manager may not have run yet"
|
||||
fi
|
||||
echo ""
|
||||
read -p "Press Enter to continue..."
|
||||
;;
|
||||
q|Q)
|
||||
echo "Exiting..."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Invalid choice${NC}"
|
||||
;;
|
||||
esac
|
||||
echo ""
|
||||
done
|
||||
174
scripts/test-tv-response.sh
Executable file
174
scripts/test-tv-response.sh
Executable file
@@ -0,0 +1,174 @@
|
||||
#!/bin/bash
|
||||
# Test script to diagnose TV physical response to CEC commands
|
||||
|
||||
echo "════════════════════════════════════════════════════════════"
|
||||
echo " TV Physical Response Diagnostic Test"
|
||||
echo "════════════════════════════════════════════════════════════"
|
||||
echo ""
|
||||
|
||||
# Load configuration
|
||||
if [ -f ../.env ]; then
|
||||
export $(grep -v '^#' ../.env | xargs)
|
||||
elif [ -f .env ]; then
|
||||
export $(grep -v '^#' .env | xargs)
|
||||
fi
|
||||
|
||||
CEC_DEVICE=${CEC_DEVICE:-0}
|
||||
|
||||
echo "Using CEC_DEVICE: $CEC_DEVICE"
|
||||
echo ""
|
||||
|
||||
# Test 1: Check current power status
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "📊 Test 1: Current TV Power Status"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "Command: echo \"pow $CEC_DEVICE\" | cec-client -s -d 1"
|
||||
echo ""
|
||||
INITIAL_STATE=$(echo "pow $CEC_DEVICE" | cec-client -s -d 1 2>&1)
|
||||
echo "$INITIAL_STATE"
|
||||
echo ""
|
||||
|
||||
if echo "$INITIAL_STATE" | grep -q "on"; then
|
||||
echo "✅ TV reports: ON"
|
||||
INITIAL_ON=true
|
||||
elif echo "$INITIAL_STATE" | grep -q "standby"; then
|
||||
echo "✅ TV reports: STANDBY/OFF"
|
||||
INITIAL_ON=false
|
||||
else
|
||||
echo "⚠️ TV power state unclear"
|
||||
INITIAL_ON=unknown
|
||||
fi
|
||||
|
||||
echo ""
|
||||
read -p "❓ Does this match the actual TV LED indicator? (y/n): " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "⚠️ CEC status doesn't match physical state - possible CEC communication issue"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "🔌 Test 2: Power ON Command"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "👀 WATCH YOUR TV SCREEN AND LED NOW!"
|
||||
echo ""
|
||||
echo "Sending: echo \"on $CEC_DEVICE\" | cec-client -s -d 1"
|
||||
echo ""
|
||||
|
||||
START_TIME=$(date +%s)
|
||||
TURN_ON_RESULT=$(echo "on $CEC_DEVICE" | cec-client -s -d 1 2>&1)
|
||||
END_TIME=$(date +%s)
|
||||
DURATION=$((END_TIME - START_TIME))
|
||||
|
||||
echo "$TURN_ON_RESULT"
|
||||
echo ""
|
||||
echo "⏱️ Command took: ${DURATION}s"
|
||||
echo ""
|
||||
|
||||
if echo "$TURN_ON_RESULT" | grep -iq "success\|power on"; then
|
||||
echo "✅ CEC command reported success"
|
||||
else
|
||||
echo "❌ CEC command may have failed"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Waiting 5 seconds for TV to respond..."
|
||||
sleep 5
|
||||
|
||||
# Check power status after ON command
|
||||
AFTER_ON_STATE=$(echo "pow $CEC_DEVICE" | cec-client -s -d 1 2>&1)
|
||||
if echo "$AFTER_ON_STATE" | grep -q "on"; then
|
||||
echo "✅ TV now reports: ON"
|
||||
else
|
||||
echo "⚠️ TV still reports: STANDBY/OFF"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
read -p "❓ Did the TV screen actually turn on? (y/n): " -n 1 -r
|
||||
echo ""
|
||||
TV_TURNED_ON=$REPLY
|
||||
|
||||
if [[ ! $TV_TURNED_ON =~ ^[Yy]$ ]]; then
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "🔄 Test 3: Try with Active Source Command"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "Some TVs need explicit input switch. Trying 'active source'..."
|
||||
echo ""
|
||||
echo "Command: echo \"as\" | cec-client -s -d 1"
|
||||
AS_RESULT=$(echo "as" | cec-client -s -d 1 2>&1)
|
||||
echo "$AS_RESULT"
|
||||
echo ""
|
||||
echo "Waiting 3 seconds..."
|
||||
sleep 3
|
||||
echo ""
|
||||
read -p "❓ Did the TV screen turn on now? (y/n): " -n 1 -r
|
||||
echo ""
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "✅ TV responds to 'active source' command!"
|
||||
echo "💡 Solution: Display Manager should send both 'on' and 'as' commands"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "📺 Test 4: Check TV Vendor"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "Command: echo \"ven $CEC_DEVICE\" | cec-client -s -d 1"
|
||||
VENDOR_INFO=$(echo "ven $CEC_DEVICE" | cec-client -s -d 1 2>&1)
|
||||
echo "$VENDOR_INFO"
|
||||
echo ""
|
||||
|
||||
if echo "$VENDOR_INFO" | grep -iq "samsung"; then
|
||||
echo "📌 Samsung TV detected"
|
||||
echo " Known issue: Some Samsung TVs need 'as' (active source) after 'on'"
|
||||
elif echo "$VENDOR_INFO" | grep -iq "lg"; then
|
||||
echo "📌 LG TV detected"
|
||||
echo " Known issue: Some LG TVs have 'Simplink' mode that must be 'Full'"
|
||||
elif echo "$VENDOR_INFO" | grep -iq "sony"; then
|
||||
echo "📌 Sony TV detected"
|
||||
echo " Known issue: Check 'Bravia Sync' settings"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "📊 Test Summary"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
|
||||
if [[ $TV_TURNED_ON =~ ^[Yy]$ ]]; then
|
||||
echo "✅ SUCCESS: TV turns on with CEC commands"
|
||||
echo ""
|
||||
echo "Your configuration is working correctly."
|
||||
else
|
||||
echo "❌ ISSUE: TV doesn't respond physically"
|
||||
echo ""
|
||||
echo "💡 Troubleshooting steps:"
|
||||
echo ""
|
||||
echo "1. Check TV CEC Settings:"
|
||||
echo " • Settings → HDMI-CEC (or Anynet+/Simplink/Bravia Sync)"
|
||||
echo " • Must be 'Enabled' or 'Full' mode (not 'Limited')"
|
||||
echo ""
|
||||
echo "2. Try Different HDMI Port:"
|
||||
echo " • Some TVs only support CEC on HDMI 1"
|
||||
echo " • Move Raspberry Pi to a different port"
|
||||
echo ""
|
||||
echo "3. Check HDMI Cable:"
|
||||
echo " • Must be HDMI 1.4 or newer"
|
||||
echo " • Try a different cable"
|
||||
echo ""
|
||||
echo "4. Update Display Manager:"
|
||||
echo " • If 'active source' worked, add it to turn_on()"
|
||||
echo " • Some TVs need both 'on' and 'as' commands"
|
||||
echo ""
|
||||
echo "5. Increase Wait Time:"
|
||||
echo " • Set CEC_POWER_ON_WAIT=10 in .env"
|
||||
echo " • Some TVs are slow to respond"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "════════════════════════════════════════════════════════════"
|
||||
Reference in New Issue
Block a user