PsiSwarm Library  0.8
All Classes Files Functions Macros Pages
sound.cpp
1 /* University of York Robotics Laboratory PsiSwarm Library: Audio Driver using PIC coprocessor Source File
2  *
3  * Copyright 2016 University of York
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS
8  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9  * See the License for the specific language governing permissions and limitations under the License.
10  *
11  * File: sound.cpp [formerly pic.cpp]
12  *
13  * (C) Dept. Electronics & Computer Science, University of York
14  * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis
15  *
16  * PsiSwarm Library Version: 0.8
17  *
18  * October 2016
19  *
20  *
21  */
22 
23 
24 #include "psiswarm.h"
25 
26 
27 void Sound::play_audio_string(char * tune)
28 {
29  char length = strlen(tune);
30  play_tune(tune,length);
31 }
32 
33 void Sound::play_tune(char * tune, char length)
34 {
35  char to_send [length+3];
36  char start_array[2];
37  start_array [0] = 'S';
38  start_array [1] = length;
39  strcpy(to_send,start_array);
40  strncat(to_send,tune,length);
41  psi.debug(to_send);
42  primary_i2c.write(PIC_ADDRESS,to_send,length+2,false);
43 }
44 
45 
46 char Sound::IF_check_pic_firmware()
47 {
48  char buffer[6];
49  buffer[0] = 0;
50  primary_i2c.write(PIC_ADDRESS,"I",1,false);
51  wait(0.1);
52  primary_i2c.read(PIC_ADDRESS,buffer,6);
53  psi.debug(buffer);
54  if(buffer[0] != 'F' || buffer[1] != 'W') {
55  psi.debug("WARNING: Cannot read information from PIC microcontroller");
56  return 1;
57  }
58  psi.debug(buffer);
59  return 0;
60 }
void play_audio_string(char *tune)
Definition: sound.cpp:27
void play_tune(char *tune, char length)
Definition: sound.cpp:33
void debug(const char *format,...)
Definition: psiswarm.cpp:325