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