![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ft. button press reset
Fork of BeaconDemo_RobotCode by
PsiSwarm/pic.cpp@6:ff3c66f7372b, 2015-10-22 (annotated)
- Committer:
- jah128
- Date:
- Thu Oct 22 00:46:14 2015 +0000
- Revision:
- 6:ff3c66f7372b
- Parent:
- 4:25039ea5eb09
Initial version: beacon detection and sync. code, bearing estimation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 4:25039ea5eb09 | 1 | /* University of York Robotics Laboratory PsiSwarm Library: PIC and Audio Driver Source File |
jah128 | 4:25039ea5eb09 | 2 | * |
jah128 | 4:25039ea5eb09 | 3 | * File: pic.cpp |
jah128 | 4:25039ea5eb09 | 4 | * |
jah128 | 6:ff3c66f7372b | 5 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 6:ff3c66f7372b | 6 | * James Hilder, Alan Millard, Homero Elizondo, Jon Timmis |
jah128 | 4:25039ea5eb09 | 7 | * |
jah128 | 6:ff3c66f7372b | 8 | * PsiSwarm Library Version: 0.3 |
jah128 | 4:25039ea5eb09 | 9 | * |
jah128 | 4:25039ea5eb09 | 10 | * October 2015 |
jah128 | 4:25039ea5eb09 | 11 | * |
jah128 | 4:25039ea5eb09 | 12 | */ |
jah128 | 4:25039ea5eb09 | 13 | |
jah128 | 4:25039ea5eb09 | 14 | |
jah128 | 4:25039ea5eb09 | 15 | #include "psiswarm.h" |
jah128 | 4:25039ea5eb09 | 16 | |
jah128 | 4:25039ea5eb09 | 17 | |
jah128 | 4:25039ea5eb09 | 18 | void play_audio_string(char * tune){ |
jah128 | 4:25039ea5eb09 | 19 | char length = strlen(tune); |
jah128 | 4:25039ea5eb09 | 20 | play_tune(tune,length); |
jah128 | 4:25039ea5eb09 | 21 | } |
jah128 | 4:25039ea5eb09 | 22 | |
jah128 | 4:25039ea5eb09 | 23 | void play_tune(char * tune, char length){ |
jah128 | 4:25039ea5eb09 | 24 | char to_send [length+3]; |
jah128 | 4:25039ea5eb09 | 25 | char start_array[2]; |
jah128 | 4:25039ea5eb09 | 26 | start_array [0] = 'S'; |
jah128 | 4:25039ea5eb09 | 27 | start_array [1] = length; |
jah128 | 4:25039ea5eb09 | 28 | strcpy(to_send,start_array); |
jah128 | 4:25039ea5eb09 | 29 | strncat(to_send,tune,length); |
jah128 | 4:25039ea5eb09 | 30 | debug(to_send); |
jah128 | 4:25039ea5eb09 | 31 | primary_i2c.write(PIC_ADDRESS,to_send,length+2,false); |
jah128 | 4:25039ea5eb09 | 32 | } |
jah128 | 4:25039ea5eb09 | 33 | |
jah128 | 4:25039ea5eb09 | 34 | |
jah128 | 4:25039ea5eb09 | 35 | char IF_check_pic_firmware(){ |
jah128 | 4:25039ea5eb09 | 36 | char buffer[6]; |
jah128 | 4:25039ea5eb09 | 37 | buffer[0] = 0; |
jah128 | 4:25039ea5eb09 | 38 | primary_i2c.write(PIC_ADDRESS,"I",1,false); |
jah128 | 4:25039ea5eb09 | 39 | wait(0.1); |
jah128 | 4:25039ea5eb09 | 40 | primary_i2c.read(PIC_ADDRESS,buffer,6); |
jah128 | 4:25039ea5eb09 | 41 | debug(buffer); |
jah128 | 4:25039ea5eb09 | 42 | if(buffer[0] != 'F' || buffer[1] != 'W'){ |
jah128 | 4:25039ea5eb09 | 43 | debug("WARNING: Cannot read information from PIC microcontroller"); |
jah128 | 4:25039ea5eb09 | 44 | return 1; |
jah128 | 4:25039ea5eb09 | 45 | } |
jah128 | 4:25039ea5eb09 | 46 | debug(buffer); |
jah128 | 4:25039ea5eb09 | 47 | return 0; |
jah128 | 4:25039ea5eb09 | 48 | } |