126 lines
4.3 KiB
Bash
126 lines
4.3 KiB
Bash
#!/bin/bash
|
|
# Setup script for IR controller mapping
|
|
|
|
echo "=========================================="
|
|
echo "IR Controller Setup Script"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Check if we're on the Raspberry Pi
|
|
if ! command -v python3 &> /dev/null; then
|
|
echo "Error: Python3 not found. Please install Python3."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if RPi.GPIO is available
|
|
python3 -c "import RPi.GPIO" 2>/dev/null
|
|
if [ $? -ne 0 ]; then
|
|
echo "Error: RPi.GPIO not available. This script requires Raspberry Pi hardware."
|
|
exit 1
|
|
fi
|
|
|
|
echo "This script will help you set up your IR remote controller."
|
|
echo "It will:"
|
|
echo "1. Integrate the custom protocol decoder into your IR system"
|
|
echo "2. Run the controller setup to map your remote buttons"
|
|
echo ""
|
|
|
|
read -p "Do you want to continue? (y/n): " -n 1 -r
|
|
echo ""
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Setup cancelled."
|
|
exit 0
|
|
fi
|
|
|
|
echo ""
|
|
echo "Step 1: Integrating custom protocol decoder..."
|
|
echo "=============================================="
|
|
|
|
# Check if custom protocol files exist
|
|
if [ ! -f "custom_ir_protocol_final.py" ]; then
|
|
echo "Error: custom_ir_protocol_final.py not found!"
|
|
echo "Please make sure the custom protocol decoder is available."
|
|
exit 1
|
|
fi
|
|
|
|
# Backup existing files
|
|
echo "Backing up existing IR system files..."
|
|
mkdir -p backup_ir_system
|
|
cp ir_remote.py backup_ir_system/ 2>/dev/null || echo "ir_remote.py not found, skipping backup"
|
|
cp simple_ir_listener.py backup_ir_system/ 2>/dev/null || echo "simple_ir_listener.py not found, skipping backup"
|
|
cp simple_ir_listener_polling.py backup_ir_system/ 2>/dev/null || echo "simple_ir_listener_polling.py not found, skipping backup"
|
|
|
|
# Update ir_remote.py to include custom protocol
|
|
echo "Updating ir_remote.py..."
|
|
if [ -f "ir_remote.py" ]; then
|
|
# Add import for custom protocol
|
|
if ! grep -q "from custom_ir_protocol_final import CustomIRProtocol" ir_remote.py; then
|
|
# Find the import section and add our import
|
|
sed -i '/^import /a from custom_ir_protocol_final import CustomIRProtocol' ir_remote.py
|
|
fi
|
|
|
|
# Update the protocols initialization
|
|
sed -i 's/protocols or \[NECProtocol(), RC5Protocol()\]/protocols or [NECProtocol(), RC5Protocol(), CustomIRProtocol()]/' ir_remote.py
|
|
echo "✅ Updated ir_remote.py"
|
|
else
|
|
echo "⚠️ ir_remote.py not found, skipping update"
|
|
fi
|
|
|
|
# Update simple listeners
|
|
echo "Updating simple IR listeners..."
|
|
for listener in simple_ir_listener.py simple_ir_listener_polling.py; do
|
|
if [ -f "$listener" ]; then
|
|
# Add import for custom protocol
|
|
if ! grep -q "from custom_ir_protocol_final import CustomIRProtocol" "$listener"; then
|
|
sed -i '/^import /a from custom_ir_protocol_final import CustomIRProtocol' "$listener"
|
|
fi
|
|
|
|
# Update the protocols initialization
|
|
sed -i 's/protocols or \[NECProtocol(), RC5Protocol()\]/protocols or [NECProtocol(), RC5Protocol(), CustomIRProtocol()]/' "$listener"
|
|
sed -i 's/\[NECProtocol(), RC5Protocol()\]/[NECProtocol(), RC5Protocol(), CustomIRProtocol()]/' "$listener"
|
|
echo "✅ Updated $listener"
|
|
else
|
|
echo "⚠️ $listener not found, skipping update"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "Step 2: Running controller setup..."
|
|
echo "=================================="
|
|
|
|
# Check if controller setup script exists
|
|
if [ ! -f "quick_controller_setup.py" ]; then
|
|
echo "Error: quick_controller_setup.py not found!"
|
|
echo "Please make sure the controller setup script is available."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Starting controller setup..."
|
|
echo "This will guide you through mapping your remote buttons."
|
|
echo ""
|
|
|
|
# Run the controller setup
|
|
python3 quick_controller_setup.py
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "SETUP COMPLETE!"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "Your IR controller has been set up successfully."
|
|
echo "The mappings have been saved to ir_mapping.json"
|
|
echo ""
|
|
echo "You can now use your IR remote with the video player system."
|
|
echo ""
|
|
echo "To test the setup, run:"
|
|
echo " python3 simple_ir_listener_polling.py --verbose"
|
|
echo ""
|
|
echo "Backup files are in: backup_ir_system/"
|
|
else
|
|
echo ""
|
|
echo "Setup failed or was interrupted."
|
|
echo "You can restore from backup if needed."
|
|
fi
|