Imports System.Speech
Imports System.Drawing


' This is the top level interface to the Bot.  Commands are parsed, interpreted and sent to the specific Bot IF.
' COMMAND SYNTAX
'    Move 10 i
'    Move 90 degrees
'    battery
'    position
'    input analog 1
'    input digital
'    play 
'    bumper
'    set
'    stop


Module modIF_BotTop
    Dim strRecv As String

    Public Function ftnSendCommand(ByRef strCommand As String) As String
        ftnSendCommand = ""
        Try
            Dim strParsedText As String() = strCommand.Split(" "c)
            If (Not boolSimulatedMovement) Or (strParsedText(0) = "play") Then ' 
                If boolER1Selected Then
                    ftnSendCommand = ftnER1_Command(strCommand)
                ElseIf boolHeroSelected Then
                    ftnSendCommand = ftnHeroCommand(strCommand)
                End If
            End If
            If boolSimulatedMovement Then subWait(1000)
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in ftnSendCommand :  " & ex.ToString)
        End Try
    End Function

    ' Public synth As Synthesis.SpeechSynthesizer
    Public Sub subSpeak(ByVal strCommand As String)
        Try
            If Not boolMute Then
                If (strCommand = "play phrase Beep") Then
                    Beep()
                ElseIf (strCommand = "play phrase fail") Then
                    'subPlaySoundFile("KLAXON2.wav")
                    subPlaySoundFile("C:\Windows\Media\Windows Hardware Fail.wav")
                ElseIf (strCommand = "play phrase tada") Then
                    subPlaySoundFile("C:\Windows\Media\tada.wav")
                ElseIf (strCommand = "play phrase prompt") Then
                    subPlaySoundFile("C:\Windows\Media\Windows Ding.wav")
                ElseIf (strCommand = "play phrase alert") Then
                    subPlaySoundFile("C:\Windows\Media\Windows Hardware Fail.wav")
                ElseIf (strCommand = "play phrase notify") Then
                    subPlaySoundFile("C:\Windows\Media\Windows Notify.wav")
                ElseIf (strCommand = "play phrase error") Then
                    subPlaySoundFile("C:\Windows\Media\Windows Critical Stop.wav")
                ElseIf (strCommand = "play phrase click") Then
                    subPlaySoundFile("C:\Windows\Media\Windows Recycle.wav")
                ElseIf (strCommand = "play phrase doh") Then
                    subPlaySoundFile("doh.wav")
                Else
                    Dim synth As New Synthesis.SpeechSynthesizer
                    If CBool(InStr(strCommand, "phraseA")) Then
                        strCommand = strCommand.Replace("play phraseA", "")
                        strCommand = strCommand.Replace("'", "")
                        synth.SpeakAsync(strCommand)
                    Else
                        strCommand = strCommand.Replace("play phrase", "")
                        strCommand = strCommand.Replace("'", "")
                        synth.Speak(strCommand)
                    End If
                End If
            End If
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in subSpeak :  " & ex.ToString)
        End Try
    End Sub

    Private Sub subPlaySoundFile(ByRef strSoundFile As String)
        Try
            If (Dir(strSoundFile) <> "") Then
                If (Dir(strSoundFile) <> "") Then My.Computer.Audio.Play(strSoundFile, AudioPlayMode.WaitToComplete)
            Else
                Beep()
            End If
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in subPlaySoundFile :  " & ex.ToString)
        End Try
    End Sub

End Module
