Psi Swarm Robot / PsiSwarmV8_CPP

Dependents:   PsiSwarm_V8_Blank_CPP Autonomia_RndmWlk

Fork of PsiSwarmV7_CPP by Psi Swarm Robot

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sound.cpp Source File

sound.cpp

00001 /* University of York Robotics Laboratory PsiSwarm Library: Audio Driver using PIC coprocessor Source File
00002  *
00003  * Copyright 2016 University of York
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
00007  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS
00008  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00009  * See the License for the specific language governing permissions and limitations under the License.
00010  *
00011  * File: sound.cpp [formerly pic.cpp]
00012  *
00013  * (C) Dept. Electronics & Computer Science, University of York
00014  * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis
00015  *
00016  * PsiSwarm Library Version: 0.8
00017  *
00018  * October 2016
00019  *
00020  *
00021  */
00022 
00023 
00024 #include "psiswarm.h"
00025 
00026 
00027 void Sound::play_audio_string(char * tune)
00028 {
00029     char length = strlen(tune);
00030     play_tune(tune,length);
00031 }
00032 
00033 void Sound::play_tune(char * tune, char length)
00034 {
00035     char to_send [length+3];
00036     char start_array[2];
00037     start_array [0] = 'S';
00038     start_array [1] = length;
00039     strcpy(to_send,start_array);
00040     strncat(to_send,tune,length);
00041     psi.debug(to_send);
00042     primary_i2c.write(PIC_ADDRESS,to_send,length+2,false);
00043 }
00044 
00045 
00046 char Sound::IF_check_pic_firmware()
00047 {
00048     char buffer[6];
00049     buffer[0] = 0;
00050     primary_i2c.write(PIC_ADDRESS,"I",1,false);
00051     wait(0.1);
00052     primary_i2c.read(PIC_ADDRESS,buffer,6);
00053     psi.debug(buffer);
00054     if(buffer[0] != 'F' || buffer[1] != 'W') {
00055         psi.debug("WARNING:  Cannot read information from PIC microcontroller");
00056         return 1;
00057     }
00058     psi.debug(buffer);
00059     return 0;
00060 }