#! /usr/bin/python

import atexit, pickle, socket, time, subprocess
import os, sys, digitalio, busio, adafruit_ssd1306, board
import keypad
from board import SCL, SDA
from pygame                import mixer

## Load the sounds:
mixer.init()
sound_applause = mixer.Sound('/home/pi/pianobar/wav_files/applause-1.wav')

sound_play       = mixer.Sound('/home/pi/pianobar/wav_files/play.wav')
sound_potty      = mixer.Sound('/home/pi/pianobar/wav_files/potty.wav')
sound_water      = mixer.Sound('/home/pi/pianobar/wav_files/water.wav')
sound_walk       = mixer.Sound('/home/pi/pianobar/wav_files/walk.wav')
sound_later      = mixer.Sound('/home/pi/pianobar/wav_files/later.wav')
sound_anabelle   = mixer.Sound('/home/pi/pianobar/wav_files/anabelle.wav')
sound_outside    = mixer.Sound('/home/pi/pianobar/wav_files/outside.wav')
sound_hmmm       = mixer.Sound('/home/pi/pianobar/wav_files/hmmm.wav')
sound_daddy      = mixer.Sound('/home/pi/pianobar/wav_files/daddy.wav')
sound_mommy      = mixer.Sound('/home/pi/pianobar/wav_files/mommy.wav')

sound_all_done   = mixer.Sound('/home/pi/pianobar/wav_files/all-done-happy-v2.wav')
sound_ball       = mixer.Sound('/home/pi/pianobar/wav_files/ball.wav')
sound_bed_time   = mixer.Sound('/home/pi/pianobar/wav_files/bed-time.wav')
sound_cuddles    = mixer.Sound('/home/pi/pianobar/wav_files/cuddles.wav')
sound_downstairs = mixer.Sound('/home/pi/pianobar/wav_files/downstairs.wav')
sound_hard       = mixer.Sound('/home/pi/pianobar/wav_files/hard-best-v4.wav')
sound_lazer      = mixer.Sound('/home/pi/pianobar/wav_files/lazer.wav')
sound_lila       = mixer.Sound('/home/pi/pianobar/wav_files/lila.wav')
sound_love_you   = mixer.Sound('/home/pi/pianobar/wav_files/love-you.wav')
sound_nap_time   = mixer.Sound('/home/pi/pianobar/wav_files/nap-time.wav')
sound_noise      = mixer.Sound('/home/pi/pianobar/wav_files/noise.wav')
sound_pets       = mixer.Sound('/home/pi/pianobar/wav_files/pets.wav')
sound_soft       = mixer.Sound('/home/pi/pianobar/wav_files/soft.wav')
sound_thea       = mixer.Sound('/home/pi/pianobar/wav_files/thea.wav')
sound_tug        = mixer.Sound('/home/pi/pianobar/wav_files/tug.wav')
sound_upstairs   = mixer.Sound('/home/pi/pianobar/wav_files/upstairs.wav')
sound_want       = mixer.Sound('/home/pi/pianobar/wav_files/want.wav')
sound_yard       = mixer.Sound('/home/pi/pianobar/wav_files/yard.wav')

km = keypad.KeyMatrix(
    row_pins=(board.D4, board.D7, board.D8, board.D11, board.D9, board.D10),
    column_pins=(board.D17, board.D18, board.D27, board.D22, board.D23, board.D24, board.D25),
    columns_to_anodes=True,
)

while True:
    event = km.events.get()
    if event:
        print(event)
        if event.pressed == True and event.key_number == 26: sound_later.play()
        if event.pressed == True and event.key_number == 25: sound_water.play()
        if event.pressed == True and event.key_number == 27: sound_walk.play()
        if event.pressed == True and event.key_number == 24: sound_potty.play()
        if event.pressed == True and event.key_number == 23: sound_outside.play()
        if event.pressed == True and event.key_number == 22: sound_play.play()
        if event.pressed == True and event.key_number == 21: sound_hmmm.play()
        if event.pressed == True and event.key_number ==  5: sound_daddy.play()
        if event.pressed == True and event.key_number ==  1: sound_mommy.play()

        if event.pressed == True and event.key_number ==  0:
            break

os.system('sudo shutdown now -h')
exit(0)