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