Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 2015robot_main by
communicate.h@13:87794ce49b50, 2015-09-16 (annotated)
- Committer:
- DeguNaoto
- Date:
- Wed Sep 16 00:47:46 2015 +0000
- Revision:
- 13:87794ce49b50
- Parent:
- 8:1638e8c8ca93
- Child:
- 14:a99f81878336
??? class ??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DeguNaoto | 0:bd4719e15f7e | 1 | /***RS485 Communication.***/ |
DeguNaoto | 4:51d87d2b698c | 2 | |
DeguNaoto | 0:bd4719e15f7e | 3 | Serial RS485(RS485_TX, RS485_RX); |
DeguNaoto | 4:51d87d2b698c | 4 | inline void sendData(int address, int data5) { |
DeguNaoto | 4:51d87d2b698c | 5 | unsigned int data; |
DeguNaoto | 4:51d87d2b698c | 6 | if (data5 <= 31) { |
DeguNaoto | 4:51d87d2b698c | 7 | data = ((address << 5) | data5); |
DeguNaoto | 4:51d87d2b698c | 8 | RS485.putc(data); |
DeguNaoto | 4:51d87d2b698c | 9 | } |
DeguNaoto | 4:51d87d2b698c | 10 | } |
DeguNaoto | 0:bd4719e15f7e | 11 | |
DeguNaoto | 0:bd4719e15f7e | 12 | /***Get state ps3con.***/ |
DeguNaoto | 13:87794ce49b50 | 13 | inline void SBDBT_interrupt(); |
DeguNaoto | 13:87794ce49b50 | 14 | inline void initializeSBDBT(); |
DeguNaoto | 0:bd4719e15f7e | 15 | Serial SBDBT(SBDBT_TX, SBDBT_RX); |
DeguNaoto | 0:bd4719e15f7e | 16 | #define ps3_start 0x80 |
DeguNaoto | 13:87794ce49b50 | 17 | extern short toggle = 0; |
DeguNaoto | 13:87794ce49b50 | 18 | extern short edge_circle = 0; |
DeguNaoto | 13:87794ce49b50 | 19 | extern short edge_triangle = 0; |
DeguNaoto | 13:87794ce49b50 | 20 | extern short edge_r1 = 0; |
DeguNaoto | 13:87794ce49b50 | 21 | extern short edge_l1 = 0; |
DeguNaoto | 13:87794ce49b50 | 22 | extern short edge_l_up = 0; |
DeguNaoto | 13:87794ce49b50 | 23 | extern short edge_l_down = 0; |
DeguNaoto | 13:87794ce49b50 | 24 | extern short edge_r_up = 0; |
DeguNaoto | 13:87794ce49b50 | 25 | extern short edge_r_down = 0; |
DeguNaoto | 13:87794ce49b50 | 26 | extern short edge_right = 0; |
DeguNaoto | 13:87794ce49b50 | 27 | extern short edge_left = 0; |
DeguNaoto | 13:87794ce49b50 | 28 | extern short edge_up = 0; |
DeguNaoto | 0:bd4719e15f7e | 29 | short square=0,triangle=0,circle=0,cross=0,up=0,down=0,right=0,left=0,l1=0,l2=0,r1=0,r2=0; |
DeguNaoto | 8:1638e8c8ca93 | 30 | signed int analog_lx=0,analog_ly=0,analog_rx=0,analog_ry=0; |
DeguNaoto | 0:bd4719e15f7e | 31 | int ps3_data[7]; |
DeguNaoto | 0:bd4719e15f7e | 32 | int count=0; |
DeguNaoto | 0:bd4719e15f7e | 33 | int sample=0; |
DeguNaoto | 2:cf8ca6742db9 | 34 | inline void data_clear() |
DeguNaoto | 2:cf8ca6742db9 | 35 | { |
DeguNaoto | 2:cf8ca6742db9 | 36 | for(int i=0; i<7; i++) ps3_data[i]=0; |
DeguNaoto | 0:bd4719e15f7e | 37 | } |
DeguNaoto | 2:cf8ca6742db9 | 38 | inline void data_check() |
DeguNaoto | 2:cf8ca6742db9 | 39 | { |
DeguNaoto | 0:bd4719e15f7e | 40 | square=0,triangle=0,circle=0,cross=0,up=0,down=0,right=0,left=0,l1=0,l2=0,r1=0,r2=0; |
DeguNaoto | 0:bd4719e15f7e | 41 | analog_lx=0,analog_ly=0,analog_rx=0,analog_ry=0; |
DeguNaoto | 0:bd4719e15f7e | 42 | if((ps3_data[0]==0x00)&&(ps3_data[1]==0x01)) up=1; |
DeguNaoto | 0:bd4719e15f7e | 43 | else if((ps3_data[0]==0x00)&&(ps3_data[1]==0x02)) down=1; |
DeguNaoto | 0:bd4719e15f7e | 44 | else if((ps3_data[0]==0x00)&&(ps3_data[1]==0x04)) right=1; |
DeguNaoto | 0:bd4719e15f7e | 45 | else if((ps3_data[0]==0x00)&&(ps3_data[1]==0x08)) left=1; |
DeguNaoto | 0:bd4719e15f7e | 46 | else if((ps3_data[0]==0x00)&&(ps3_data[1]==0x10)) triangle=1; |
DeguNaoto | 0:bd4719e15f7e | 47 | else if((ps3_data[0]==0x00)&&(ps3_data[1]==0x20)) cross=1; |
DeguNaoto | 0:bd4719e15f7e | 48 | else if((ps3_data[0]==0x00)&&(ps3_data[1]==0x40)) circle=1; |
DeguNaoto | 0:bd4719e15f7e | 49 | else if((ps3_data[0]==0x01)&&(ps3_data[1]==0x00)) square=1; |
DeguNaoto | 0:bd4719e15f7e | 50 | else if((ps3_data[0]==0x02)&&(ps3_data[1]==0x00)) l1=1; |
DeguNaoto | 0:bd4719e15f7e | 51 | else if((ps3_data[0]==0x04)&&(ps3_data[1]==0x00)) l2=1; |
DeguNaoto | 0:bd4719e15f7e | 52 | else if((ps3_data[0]==0x08)&&(ps3_data[1]==0x00)) r1=1; |
DeguNaoto | 0:bd4719e15f7e | 53 | else if((ps3_data[0]==0x10)&&(ps3_data[1]==0x00)) r2=1; |
DeguNaoto | 8:1638e8c8ca93 | 54 | analog_lx=64-(signed int)ps3_data[2]; |
DeguNaoto | 8:1638e8c8ca93 | 55 | analog_ly=64-(signed int)ps3_data[3]; |
DeguNaoto | 8:1638e8c8ca93 | 56 | analog_rx=64-(signed int)ps3_data[4]; |
DeguNaoto | 8:1638e8c8ca93 | 57 | analog_ry=64-(signed int)ps3_data[5]; |
DeguNaoto | 4:51d87d2b698c | 58 | if(!circle) edge_circle=1; |
DeguNaoto | 4:51d87d2b698c | 59 | if(!triangle) edge_triangle=1; |
DeguNaoto | 4:51d87d2b698c | 60 | if(!r1) edge_r1=1; |
DeguNaoto | 4:51d87d2b698c | 61 | if(!l1) edge_l1=1; |
DeguNaoto | 4:51d87d2b698c | 62 | /*if(!(analog_ry<40)) edge_r_up=1; |
DeguNaoto | 4:51d87d2b698c | 63 | if(!(analog_ry>90)) edge_r_down=1; |
DeguNaoto | 4:51d87d2b698c | 64 | if(!(analog_ly<40)) edge_l_up=1; |
DeguNaoto | 4:51d87d2b698c | 65 | if(!(analog_ly>90)) edge_l_down=1;*/ |
DeguNaoto | 4:51d87d2b698c | 66 | if(!edge_right) edge_right=1; |
DeguNaoto | 4:51d87d2b698c | 67 | if(!edge_left) edge_left=1; |
DeguNaoto | 4:51d87d2b698c | 68 | if(!edge_up) edge_up=1; |
DeguNaoto | 0:bd4719e15f7e | 69 | } |
DeguNaoto | 0:bd4719e15f7e | 70 | ///interrupt SBDBT RX. |
DeguNaoto | 2:cf8ca6742db9 | 71 | inline void SBDBT_interrupt() |
DeguNaoto | 2:cf8ca6742db9 | 72 | { |
DeguNaoto | 0:bd4719e15f7e | 73 | sample=SBDBT.getc(); |
DeguNaoto | 0:bd4719e15f7e | 74 | if(count==7) data_clear(); |
DeguNaoto | 0:bd4719e15f7e | 75 | if(sample==ps3_start) count=0; |
DeguNaoto | 2:cf8ca6742db9 | 76 | else { |
DeguNaoto | 0:bd4719e15f7e | 77 | ps3_data[count]=sample; |
DeguNaoto | 0:bd4719e15f7e | 78 | count++; |
DeguNaoto | 0:bd4719e15f7e | 79 | } |
DeguNaoto | 0:bd4719e15f7e | 80 | if(count==6) data_check(); |
DeguNaoto | 0:bd4719e15f7e | 81 | } |
DeguNaoto | 2:cf8ca6742db9 | 82 | inline void initializeSBDBT() |
DeguNaoto | 2:cf8ca6742db9 | 83 | { |
DeguNaoto | 2:cf8ca6742db9 | 84 | for(int i=0; i<7; i++) ps3_data[i]=0; |
DeguNaoto | 0:bd4719e15f7e | 85 | SBDBT.baud(2400); |
DeguNaoto | 0:bd4719e15f7e | 86 | SBDBT.format(8, Serial::None, 1); |
DeguNaoto | 0:bd4719e15f7e | 87 | SBDBT.attach(SBDBT_interrupt, Serial::RxIrq); |
DeguNaoto | 0:bd4719e15f7e | 88 | } |