C++ Library for the PsiSwarm Robot - Version 0.7
Fork of PsiSwarmV7 by
pic.cpp@2:c6986ee3c7c5, 2016-03-11 (annotated)
- Committer:
- jah128
- Date:
- Fri Mar 11 13:51:24 2016 +0000
- Revision:
- 2:c6986ee3c7c5
- Parent:
- 0:d6269d17c8cf
- Child:
- 5:3cdd1a37cdd7
Added Alex' IR functions
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 | 0:d6269d17c8cf | 3 | * File: pic.cpp |
jah128 | 0:d6269d17c8cf | 4 | * |
jah128 | 0:d6269d17c8cf | 5 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:d6269d17c8cf | 6 | * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:d6269d17c8cf | 7 | * |
jah128 | 2:c6986ee3c7c5 | 8 | * PsiSwarm Library Version: 0.41 |
jah128 | 0:d6269d17c8cf | 9 | * |
jah128 | 2:c6986ee3c7c5 | 10 | * March 2016 |
jah128 | 0:d6269d17c8cf | 11 | * |
jah128 | 0:d6269d17c8cf | 12 | * |
jah128 | 0:d6269d17c8cf | 13 | */ |
jah128 | 0:d6269d17c8cf | 14 | |
jah128 | 0:d6269d17c8cf | 15 | |
jah128 | 0:d6269d17c8cf | 16 | #include "psiswarm.h" |
jah128 | 0:d6269d17c8cf | 17 | |
jah128 | 0:d6269d17c8cf | 18 | |
jah128 | 0:d6269d17c8cf | 19 | void play_audio_string(char * tune){ |
jah128 | 0:d6269d17c8cf | 20 | char length = strlen(tune); |
jah128 | 0:d6269d17c8cf | 21 | play_tune(tune,length); |
jah128 | 0:d6269d17c8cf | 22 | } |
jah128 | 0:d6269d17c8cf | 23 | |
jah128 | 0:d6269d17c8cf | 24 | void play_tune(char * tune, char length){ |
jah128 | 0:d6269d17c8cf | 25 | char to_send [length+3]; |
jah128 | 0:d6269d17c8cf | 26 | char start_array[2]; |
jah128 | 0:d6269d17c8cf | 27 | start_array [0] = 'S'; |
jah128 | 0:d6269d17c8cf | 28 | start_array [1] = length; |
jah128 | 0:d6269d17c8cf | 29 | strcpy(to_send,start_array); |
jah128 | 0:d6269d17c8cf | 30 | strncat(to_send,tune,length); |
jah128 | 0:d6269d17c8cf | 31 | debug(to_send); |
jah128 | 0:d6269d17c8cf | 32 | primary_i2c.write(PIC_ADDRESS,to_send,length+2,false); |
jah128 | 0:d6269d17c8cf | 33 | } |
jah128 | 0:d6269d17c8cf | 34 | |
jah128 | 0:d6269d17c8cf | 35 | |
jah128 | 0:d6269d17c8cf | 36 | char IF_check_pic_firmware(){ |
jah128 | 0:d6269d17c8cf | 37 | char buffer[6]; |
jah128 | 0:d6269d17c8cf | 38 | buffer[0] = 0; |
jah128 | 0:d6269d17c8cf | 39 | primary_i2c.write(PIC_ADDRESS,"I",1,false); |
jah128 | 0:d6269d17c8cf | 40 | wait(0.1); |
jah128 | 0:d6269d17c8cf | 41 | primary_i2c.read(PIC_ADDRESS,buffer,6); |
jah128 | 0:d6269d17c8cf | 42 | debug(buffer); |
jah128 | 0:d6269d17c8cf | 43 | if(buffer[0] != 'F' || buffer[1] != 'W'){ |
jah128 | 0:d6269d17c8cf | 44 | debug("WARNING: Cannot read information from PIC microcontroller"); |
jah128 | 0:d6269d17c8cf | 45 | return 1; |
jah128 | 0:d6269d17c8cf | 46 | } |
jah128 | 0:d6269d17c8cf | 47 | debug(buffer); |
jah128 | 0:d6269d17c8cf | 48 | return 0; |
jah128 | 0:d6269d17c8cf | 49 | } |