From 38eff5c2c86b50c08764871b81860f71cf25cd4e Mon Sep 17 00:00:00 2001 From: grabowski Date: Fri, 24 Oct 2025 15:15:05 +0700 Subject: [PATCH] Fix extra button to only work when OFF-hook and add greeting delay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Breaking Behavior Change: - Extra button NOW only works when handset is OFF-hook (during call) - Previous: worked when on-hook (idle) - REVERSED - Reason: Button is for guests to trigger during their call/recording New Feature - Greeting Delay: - Add greeting_delay_seconds to config.json (0-10 seconds) - Delays greeting playback after handset pickup - Gives guests time to position phone comfortably - Default: 0 (plays immediately, backward compatible) Extra Button Logic: - Only responds when phone_status == "off_hook" - Ignored when phone is on-hook (idle) - Can be pressed during greeting or recording - Plays entire sound without interruption - Useful for: "Press button to hear special message" Greeting Delay Use Cases: - Wedding: Give guests moment to settle in - Events: Time to position phone comfortably - Accessibility: Extra time for elderly guests - Professional: Pause before message delivery Configuration: { "system": { "greeting_delay_seconds": 2, // 2 second pause "extra_button_sound": "surprise.wav" } } Console Output: - "Extra button ignored - phone is on hook" (when idle) - "Waiting X seconds before greeting..." (delay active) - "=== Extra button pressed ===" (during call) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- README.md | 20 ++++++++++++++++---- config.example.json | 1 + rotary_phone_web.py | 14 ++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 37ccbc1..cf4e303 100644 --- a/README.md +++ b/README.md @@ -189,10 +189,21 @@ The web interface provides four main sections: ### Extra Button Operation (Optional) If enabled in `config.json`: -1. **Guest presses button**: System detects GPIO signal -2. **Sound plays**: Configured button sound plays through speaker -3. **Non-blocking**: Button can be pressed anytime, even during recording -4. **Debounced**: 0.5s delay prevents accidental double-presses +1. **Guest picks up phone**: Phone goes off-hook +2. **Guest presses button**: System detects GPIO signal (only works when off-hook) +3. **Sound plays**: Configured button sound plays through speaker +4. **Can be pressed multiple times**: Works during greeting or recording +5. **Debounced**: 0.5s delay prevents accidental double-presses + +**Note:** Button only responds when handset is off-hook (during active call) + +### Greeting Delay (Optional) + +Configure a delay before the greeting plays: +- Set `greeting_delay_seconds` in `config.json` (0-10 seconds) +- Useful for giving guests a moment after picking up +- Example: 2 second delay gives time to position the phone +- Default: 0 (greeting plays immediately) ## File Structure @@ -256,6 +267,7 @@ The `config.json` file contains all system settings: "system": { "active_greeting": "dialtone.wav", // Default greeting "extra_button_sound": "button_sound.wav", // Default button sound + "greeting_delay_seconds": 0, // Delay before greeting plays (0-10) "volume": 70 // Default volume (0-100) } } diff --git a/config.example.json b/config.example.json index 0a65dfc..e9125ff 100644 --- a/config.example.json +++ b/config.example.json @@ -26,6 +26,7 @@ "system": { "active_greeting": "dialtone.wav", "extra_button_sound": "button_sound.wav", + "greeting_delay_seconds": 0, "volume": 70 } } diff --git a/rotary_phone_web.py b/rotary_phone_web.py index 89b1cea..9ff2465 100644 --- a/rotary_phone_web.py +++ b/rotary_phone_web.py @@ -305,13 +305,13 @@ class RotaryPhone: } def play_extra_button_sound(self): - """Play sound when extra button is pressed (only when on-hook)""" + """Play sound when extra button is pressed (only when off-hook/in call)""" if not EXTRA_BUTTON_ENABLED: return - # Only play if phone is on hook (not in use) - if self.phone_status != "on_hook": - print("Extra button ignored - phone is off hook") + # Only play if phone is OFF hook (during a call) + if self.phone_status != "off_hook": + print("Extra button ignored - phone is on hook") return button_sound = self.get_extra_button_sound_path() @@ -348,6 +348,12 @@ class RotaryPhone: self.phone_status = "off_hook" print("\n=== Handset picked up ===") + # Apply greeting delay if configured + greeting_delay = SYS_CONFIG['system'].get('greeting_delay_seconds', 0) + if greeting_delay > 0: + print(f"Waiting {greeting_delay} seconds before greeting...") + time.sleep(greeting_delay) + # Play active greeting message greeting_file = self.get_active_greeting_path() self.play_sound_file(greeting_file)