|
from flask import Flask, render_template |
|
from flask_socketio import SocketIO, emit |
|
|
|
app = Flask(__name__) |
|
app.config['SECRET_KEY'] = 'secret!' |
|
socketio = SocketIO(app) |
|
|
|
|
|
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}") |
|
|
|
socketio.emit('rover_control', {'data': data}) |
|
else: |
|
print("Manual mode is not activated. Command ignored.") |
|
|
|
|
|
@app.route('/activate_manual_mode', methods=['POST']) |
|
def activate_manual_mode(): |
|
global manual_mode_activated |
|
manual_mode_activated = True |
|
print("Manual mode activated.") |
|
|
|
|
|
socketio.emit('manual_mode_status', {'status': 'activated'}) |
|
|
|
return "Manual mode activated", 200 |
|
|
|
|
|
@app.route('/deactivate_manual_mode', methods=['POST']) |
|
def deactivate_manual_mode(): |
|
global manual_mode_activated |
|
manual_mode_activated = False |
|
print("Manual mode deactivated.") |
|
|
|
|
|
socketio.emit('manual_mode_status', {'status': 'deactivated'}) |
|
|
|
return "Manual mode deactivated", 200 |
|
|
|
if __name__ == '__main__': |
|
socketio.run(app, debug=True) |
|
|