![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ft. button press reset
Fork of BeaconDemo_RobotCode by
PsiSwarm/pic.cpp@4:25039ea5eb09, 2015-10-12 (annotated)
- Committer:
- jah128
- Date:
- Mon Oct 12 12:39:35 2015 +0000
- Revision:
- 4:25039ea5eb09
- Child:
- 6:ff3c66f7372b
Removed code to make 'blank' example
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 | 4:25039ea5eb09 | 5 | * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York |
jah128 | 4:25039ea5eb09 | 6 | * |
jah128 | 4:25039ea5eb09 | 7 | * PsiSwarm Library Version: 0.2 |
jah128 | 4:25039ea5eb09 | 8 | * |
jah128 | 4:25039ea5eb09 | 9 | * October 2015 |
jah128 | 4:25039ea5eb09 | 10 | * |
jah128 | 4:25039ea5eb09 | 11 | */ |
jah128 | 4:25039ea5eb09 | 12 | |
jah128 | 4:25039ea5eb09 | 13 | |
jah128 | 4:25039ea5eb09 | 14 | #include "psiswarm.h" |
jah128 | 4:25039ea5eb09 | 15 | |
jah128 | 4:25039ea5eb09 | 16 | |
jah128 | 4:25039ea5eb09 | 17 | void play_audio_string(char * tune){ |
jah128 | 4:25039ea5eb09 | 18 | char length = strlen(tune); |
jah128 | 4:25039ea5eb09 | 19 | play_tune(tune,length); |
jah128 | 4:25039ea5eb09 | 20 | } |
jah128 | 4:25039ea5eb09 | 21 | |
jah128 | 4:25039ea5eb09 | 22 | void play_tune(char * tune, char length){ |
jah128 | 4:25039ea5eb09 | 23 | char to_send [length+3]; |
jah128 | 4:25039ea5eb09 | 24 | char start_array[2]; |
jah128 | 4:25039ea5eb09 | 25 | start_array [0] = 'S'; |
jah128 | 4:25039ea5eb09 | 26 | start_array [1] = length; |
jah128 | 4:25039ea5eb09 | 27 | strcpy(to_send,start_array); |
jah128 | 4:25039ea5eb09 | 28 | strncat(to_send,tune,length); |
jah128 | 4:25039ea5eb09 | 29 | debug(to_send); |
jah128 | 4:25039ea5eb09 | 30 | primary_i2c.write(PIC_ADDRESS,to_send,length+2,false); |
jah128 | 4:25039ea5eb09 | 31 | } |
jah128 | 4:25039ea5eb09 | 32 | |
jah128 | 4:25039ea5eb09 | 33 | |
jah128 | 4:25039ea5eb09 | 34 | char IF_check_pic_firmware(){ |
jah128 | 4:25039ea5eb09 | 35 | char buffer[6]; |
jah128 | 4:25039ea5eb09 | 36 | buffer[0] = 0; |
jah128 | 4:25039ea5eb09 | 37 | primary_i2c.write(PIC_ADDRESS,"I",1,false); |
jah128 | 4:25039ea5eb09 | 38 | wait(0.1); |
jah128 | 4:25039ea5eb09 | 39 | primary_i2c.read(PIC_ADDRESS,buffer,6); |
jah128 | 4:25039ea5eb09 | 40 | debug(buffer); |
jah128 | 4:25039ea5eb09 | 41 | if(buffer[0] != 'F' || buffer[1] != 'W'){ |
jah128 | 4:25039ea5eb09 | 42 | debug("WARNING: Cannot read information from PIC microcontroller"); |
jah128 | 4:25039ea5eb09 | 43 | return 1; |
jah128 | 4:25039ea5eb09 | 44 | } |
jah128 | 4:25039ea5eb09 | 45 | debug(buffer); |
jah128 | 4:25039ea5eb09 | 46 | return 0; |
jah128 | 4:25039ea5eb09 | 47 | } |