Toggle input monitoring for a pin
()
| 458 | |
| 459 | @app.route('/api/monitor', methods=['POST']) |
| 460 | def toggle_monitor(): |
| 461 | """Toggle input monitoring for a pin""" |
| 462 | try: |
| 463 | data = request.get_json() |
| 464 | pin = int(data['pin']) |
| 465 | enable = data.get('enable', True) |
| 466 | |
| 467 | if pin not in pin_states or pin_states[pin]['mode'] != 'input': |
| 468 | return jsonify({'error': f'Pin {pin} is not configured as input'}), 400 |
| 469 | |
| 470 | if enable: |
| 471 | input_monitors.add(pin) |
| 472 | log_event(f"Started monitoring pin {pin}") |
| 473 | else: |
| 474 | input_monitors.discard(pin) |
| 475 | log_event(f"Stopped monitoring pin {pin}") |
| 476 | |
| 477 | return jsonify({'success': True, 'monitoring': pin in input_monitors}) |
| 478 | |
| 479 | except Exception as e: |
| 480 | error_msg = f"Error toggling monitor: {str(e)}" |
| 481 | log_event(error_msg, 'error') |
| 482 | return jsonify({'error': error_msg}), 500 |
| 483 | |
| 484 | @app.route('/api/reset', methods=['POST']) |
| 485 | def reset_all_pins(): |
nothing calls this directly
no test coverage detected