diff --git a/adhan-webapp/app.py b/adhan-webapp/app.py index 1654a54..f34a504 100644 --- a/adhan-webapp/app.py +++ b/adhan-webapp/app.py @@ -328,6 +328,20 @@ def instellingen(): # Hadith instellingen settings['hadith_interval_seconds'] = int(request.form.get('hadith_interval_seconds', 30)) + + # Pi HDMI volume instelling + if 'pi_hdmi_volume' in request.form: + pi_volume = int(request.form.get('pi_hdmi_volume', 70)) + settings['pi_hdmi_volume'] = pi_volume + + # Stel Pi volume direct in via amixer + import subprocess + try: + subprocess.run(['amixer', 'set', 'PCM', f'{pi_volume}%'], + check=True, capture_output=True, text=True) + print(f"🔊 Pi HDMI volume ingesteld op {pi_volume}%") + except subprocess.CalledProcessError as e: + print(f"❌ Kon Pi volume niet instellen: {e}") settings['zones'] = request.form.getlist('zones') settings['audio_clip'] = request.form['audio_clip'] @@ -727,5 +741,49 @@ def debug_time(): 'real_time': datetime.now().strftime('%H:%M:%S') }) +@app.route('/api/set-pi-volume', methods=['POST']) +def set_pi_volume(): + """API endpoint om Pi HDMI volume in te stellen""" + try: + data = flask_request.get_json() + volume = data.get('volume', 70) + + # Valideer volume (0-100) + if not isinstance(volume, int) or volume < 0 or volume > 100: + return jsonify({'success': False, 'error': 'Volume moet tussen 0 en 100 zijn'}), 400 + + # Stel Pi volume in via amixer + import subprocess + try: + # Stel PCM volume in (HDMI audio) + subprocess.run(['amixer', 'set', 'PCM', f'{volume}%'], + check=True, capture_output=True, text=True) + + # Sla volume op in settings voor persistentie + settings = load_settings() + settings['pi_hdmi_volume'] = volume + + with open(SETTINGS_PATH, 'w') as f: + json.dump(settings, f, indent=2) + + print(f"🔊 Pi HDMI volume ingesteld op {volume}%") + + return jsonify({ + 'success': True, + 'message': f'Pi HDMI volume ingesteld op {volume}%', + 'volume': volume + }) + + except subprocess.CalledProcessError as e: + print(f"❌ Amixer fout: {e}") + return jsonify({ + 'success': False, + 'error': f'Kon volume niet instellen: {e.stderr if e.stderr else str(e)}' + }), 500 + + except Exception as e: + print(f"❌ Volume API fout: {e}") + return jsonify({'success': False, 'error': str(e)}), 500 + if __name__ == '__main__': app.run(host='0.0.0.0', port=80) \ No newline at end of file diff --git a/adhan-webapp/templates/settings.html b/adhan-webapp/templates/settings.html index adccb1d..e03039d 100644 --- a/adhan-webapp/templates/settings.html +++ b/adhan-webapp/templates/settings.html @@ -73,6 +73,30 @@ +
+ +

+ Stel het HDMI audio volume van de Raspberry Pi in (0-100%). Dit beïnvloedt het volume van de browser audio via HDMI. +

+
+
+ + {{ settings.pi_hdmi_volume or 70 }}% +
+
+ +
+
+
+