Update app.py
Browse files
app.py
CHANGED
@@ -5,15 +5,37 @@ app = Flask(__name__)
|
|
5 |
app.config['SECRET_KEY'] = 'secret!'
|
6 |
socketio = SocketIO(app)
|
7 |
|
|
|
|
|
|
|
8 |
@app.route('/')
|
9 |
def index():
|
10 |
return render_template('index.html')
|
11 |
|
12 |
@socketio.on('control_command')
|
13 |
def handle_control(data):
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
if __name__ == '__main__':
|
19 |
-
socketio.run(app, debug=True)
|
|
|
5 |
app.config['SECRET_KEY'] = 'secret!'
|
6 |
socketio = SocketIO(app)
|
7 |
|
8 |
+
# Global flag to track if manual mode is activated
|
9 |
+
manual_mode_activated = False
|
10 |
+
|
11 |
@app.route('/')
|
12 |
def index():
|
13 |
return render_template('index.html')
|
14 |
|
15 |
@socketio.on('control_command')
|
16 |
def handle_control(data):
|
17 |
+
if manual_mode_activated:
|
18 |
+
print(f"Manual mode is activated. Received command: {data}")
|
19 |
+
# Forward the command to the receiver
|
20 |
+
socketio.emit('rover_control', {'data': data})
|
21 |
+
else:
|
22 |
+
print("Manual mode is not activated. Command ignored.")
|
23 |
+
|
24 |
+
# Route to activate manual mode
|
25 |
+
@app.route('/activate_manual_mode', methods=['POST'])
|
26 |
+
def activate_manual_mode():
|
27 |
+
global manual_mode_activated
|
28 |
+
manual_mode_activated = True
|
29 |
+
print("Manual mode activated.")
|
30 |
+
return "Manual mode activated", 200
|
31 |
+
|
32 |
+
# Route to deactivate manual mode
|
33 |
+
@app.route('/deactivate_manual_mode', methods=['POST'])
|
34 |
+
def deactivate_manual_mode():
|
35 |
+
global manual_mode_activated
|
36 |
+
manual_mode_activated = False
|
37 |
+
print("Manual mode deactivated.")
|
38 |
+
return "Manual mode deactivated", 200
|
39 |
|
40 |
if __name__ == '__main__':
|
41 |
+
socketio.run(app, debug=True)
|