Fix extra button to only work when OFF-hook and add greeting delay

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 <noreply@anthropic.com>
This commit is contained in:
2025-10-24 15:15:05 +07:00
parent 4205b5d09d
commit 38eff5c2c8
3 changed files with 27 additions and 8 deletions

View File

@@ -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)
}
}

View File

@@ -26,6 +26,7 @@
"system": {
"active_greeting": "dialtone.wav",
"extra_button_sound": "button_sound.wav",
"greeting_delay_seconds": 0,
"volume": 70
}
}

View File

@@ -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)