from flask import Flask, render_template from flask_socketio import SocketIO, emit app = Flask(__name__) app.config['SECRET_KEY'] = 'secret!' socketio = SocketIO(app) # Global flag to track if manual mode is activated manual_mode_activated = False @app.route('/') def index(): return render_template('index.html') @socketio.on('control_command') def handle_control(data): if manual_mode_activated: print(f"Manual mode is activated. Received command: {data}") # Forward the command to the receiver socketio.emit('rover_control', {'data': data}) else: print("Manual mode is not activated. Command ignored.") # Route to activate manual mode @app.route('/activate_manual_mode', methods=['POST']) def activate_manual_mode(): global manual_mode_activated manual_mode_activated = True print("Manual mode activated.") # Emit the status to all connected clients socketio.emit('manual_mode_status', {'status': 'activated'}) return "Manual mode activated", 200 # Route to deactivate manual mode @app.route('/deactivate_manual_mode', methods=['POST']) def deactivate_manual_mode(): global manual_mode_activated manual_mode_activated = False print("Manual mode deactivated.") # Emit the status to all connected clients socketio.emit('manual_mode_status', {'status': 'deactivated'}) return "Manual mode deactivated", 200 if __name__ == '__main__': socketio.run(app, debug=True)