![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test
Dependencies: mbed AndroidAccessory
demokit.cpp@1:6bc62b9aa7c4, 2021-03-15 (annotated)
- Committer:
- asemanpayehring
- Date:
- Mon Mar 15 14:19:40 2021 +0000
- Revision:
- 1:6bc62b9aa7c4
- Parent:
- 0:4be11cf8cf0c
test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
p07gbar | 0:4be11cf8cf0c | 1 | /* |
p07gbar | 0:4be11cf8cf0c | 2 | * ADKTerm |
p07gbar | 0:4be11cf8cf0c | 3 | * |
p07gbar | 0:4be11cf8cf0c | 4 | * Written by p07gbar |
p07gbar | 0:4be11cf8cf0c | 5 | * |
p07gbar | 0:4be11cf8cf0c | 6 | * This program is just a simple serial port program for comunication with mbedWrapper |
p07gbar | 0:4be11cf8cf0c | 7 | */ |
p07gbar | 0:4be11cf8cf0c | 8 | #include "mbed.h" |
p07gbar | 0:4be11cf8cf0c | 9 | #include "AndroidAccessory.h" |
p07gbar | 0:4be11cf8cf0c | 10 | |
p07gbar | 0:4be11cf8cf0c | 11 | |
p07gbar | 0:4be11cf8cf0c | 12 | #define OUTL 100 |
p07gbar | 0:4be11cf8cf0c | 13 | #define INBL 100 |
p07gbar | 0:4be11cf8cf0c | 14 | |
p07gbar | 0:4be11cf8cf0c | 15 | |
p07gbar | 0:4be11cf8cf0c | 16 | |
p07gbar | 0:4be11cf8cf0c | 17 | |
p07gbar | 0:4be11cf8cf0c | 18 | |
p07gbar | 0:4be11cf8cf0c | 19 | class AdkTerm :public AndroidAccessory { |
p07gbar | 0:4be11cf8cf0c | 20 | public: |
p07gbar | 0:4be11cf8cf0c | 21 | AdkTerm():AndroidAccessory(INBL,OUTL, |
p07gbar | 0:4be11cf8cf0c | 22 | "ARM", |
p07gbar | 0:4be11cf8cf0c | 23 | "mbed", |
p07gbar | 0:4be11cf8cf0c | 24 | "mbed Terminal", |
p07gbar | 0:4be11cf8cf0c | 25 | "0.1", |
p07gbar | 0:4be11cf8cf0c | 26 | "http://www.mbed.org", |
p07gbar | 0:4be11cf8cf0c | 27 | "0000000012345678"),pc(USBTX,USBRX) {}; |
p07gbar | 0:4be11cf8cf0c | 28 | virtual int callbackRead(u8 *buff, int len); |
p07gbar | 0:4be11cf8cf0c | 29 | virtual void setupDevice(); |
p07gbar | 0:4be11cf8cf0c | 30 | virtual void resetDevice(); |
p07gbar | 0:4be11cf8cf0c | 31 | virtual int callbackWrite(); |
p07gbar | 0:4be11cf8cf0c | 32 | |
p07gbar | 0:4be11cf8cf0c | 33 | private: |
p07gbar | 0:4be11cf8cf0c | 34 | void serialIRQ(); |
p07gbar | 0:4be11cf8cf0c | 35 | char buffer[OUTL]; |
p07gbar | 0:4be11cf8cf0c | 36 | int bcount; |
p07gbar | 0:4be11cf8cf0c | 37 | Serial pc; |
p07gbar | 0:4be11cf8cf0c | 38 | }; |
p07gbar | 0:4be11cf8cf0c | 39 | |
p07gbar | 0:4be11cf8cf0c | 40 | |
p07gbar | 0:4be11cf8cf0c | 41 | |
p07gbar | 0:4be11cf8cf0c | 42 | void AdkTerm::setupDevice() { |
p07gbar | 0:4be11cf8cf0c | 43 | pc.printf("Welcome to adkTerm\n\n\n\n\n\n\r"); |
p07gbar | 0:4be11cf8cf0c | 44 | pc.attach(this, &AdkTerm::serialIRQ, Serial::RxIrq); |
p07gbar | 0:4be11cf8cf0c | 45 | for (int i = 0; i<OUTL; i++) { |
p07gbar | 0:4be11cf8cf0c | 46 | buffer[i] = 0; |
p07gbar | 0:4be11cf8cf0c | 47 | } |
p07gbar | 0:4be11cf8cf0c | 48 | bcount = 0; |
p07gbar | 0:4be11cf8cf0c | 49 | |
p07gbar | 0:4be11cf8cf0c | 50 | } |
p07gbar | 0:4be11cf8cf0c | 51 | |
p07gbar | 0:4be11cf8cf0c | 52 | |
p07gbar | 0:4be11cf8cf0c | 53 | void AdkTerm::resetDevice() { |
p07gbar | 0:4be11cf8cf0c | 54 | pc.printf("adkTerm reset\n\r"); |
p07gbar | 0:4be11cf8cf0c | 55 | for (int i = 0; i<OUTL; i++) { |
p07gbar | 0:4be11cf8cf0c | 56 | buffer[i] = 0; |
p07gbar | 0:4be11cf8cf0c | 57 | } |
p07gbar | 0:4be11cf8cf0c | 58 | bcount = 0; |
p07gbar | 0:4be11cf8cf0c | 59 | } |
p07gbar | 0:4be11cf8cf0c | 60 | |
p07gbar | 0:4be11cf8cf0c | 61 | int AdkTerm::callbackRead(u8 *buf, int len) { |
p07gbar | 0:4be11cf8cf0c | 62 | pc.printf("%i %s\n\r\n\n\n",len,buf); |
p07gbar | 0:4be11cf8cf0c | 63 | for (int i = 0; i<INBL;i++) { |
p07gbar | 0:4be11cf8cf0c | 64 | buf[i] = 0; |
p07gbar | 0:4be11cf8cf0c | 65 | } |
p07gbar | 0:4be11cf8cf0c | 66 | return 0; |
p07gbar | 0:4be11cf8cf0c | 67 | } |
p07gbar | 0:4be11cf8cf0c | 68 | |
p07gbar | 0:4be11cf8cf0c | 69 | int AdkTerm::callbackWrite() { |
p07gbar | 0:4be11cf8cf0c | 70 | pc.printf("DoneWrite\n\r"); |
p07gbar | 0:4be11cf8cf0c | 71 | |
p07gbar | 0:4be11cf8cf0c | 72 | return 0; |
p07gbar | 0:4be11cf8cf0c | 73 | } |
p07gbar | 0:4be11cf8cf0c | 74 | |
p07gbar | 0:4be11cf8cf0c | 75 | |
p07gbar | 0:4be11cf8cf0c | 76 | void AdkTerm::serialIRQ() { |
p07gbar | 0:4be11cf8cf0c | 77 | buffer[bcount] = pc.getc(); |
p07gbar | 0:4be11cf8cf0c | 78 | pc.putc(buffer[bcount]); |
p07gbar | 0:4be11cf8cf0c | 79 | |
p07gbar | 0:4be11cf8cf0c | 80 | if (buffer[bcount] == '\n' || buffer[bcount] == '\r') { |
p07gbar | 0:4be11cf8cf0c | 81 | u8* wbuf = _writebuff; |
p07gbar | 0:4be11cf8cf0c | 82 | for (int i = 0; i<OUTL; i++) { |
p07gbar | 0:4be11cf8cf0c | 83 | wbuf[i] = buffer[i]; |
p07gbar | 0:4be11cf8cf0c | 84 | buffer[i] = 0; |
p07gbar | 0:4be11cf8cf0c | 85 | } |
p07gbar | 0:4be11cf8cf0c | 86 | pc.printf("Sending: %s\n\r",wbuf); |
p07gbar | 0:4be11cf8cf0c | 87 | |
p07gbar | 0:4be11cf8cf0c | 88 | this->write(wbuf,bcount); |
p07gbar | 0:4be11cf8cf0c | 89 | bcount = 0; |
p07gbar | 0:4be11cf8cf0c | 90 | } else { |
p07gbar | 0:4be11cf8cf0c | 91 | if (buffer[bcount] != 0x08 && buffer[bcount] != 0x7F ) { |
p07gbar | 0:4be11cf8cf0c | 92 | bcount++; |
p07gbar | 0:4be11cf8cf0c | 93 | if (bcount == OUTL) { |
p07gbar | 0:4be11cf8cf0c | 94 | bcount = 0; |
p07gbar | 0:4be11cf8cf0c | 95 | } |
p07gbar | 0:4be11cf8cf0c | 96 | } else { |
p07gbar | 0:4be11cf8cf0c | 97 | bcount--; |
p07gbar | 0:4be11cf8cf0c | 98 | |
p07gbar | 0:4be11cf8cf0c | 99 | } |
p07gbar | 0:4be11cf8cf0c | 100 | } |
p07gbar | 0:4be11cf8cf0c | 101 | } |
p07gbar | 0:4be11cf8cf0c | 102 | |
p07gbar | 0:4be11cf8cf0c | 103 | |
p07gbar | 0:4be11cf8cf0c | 104 | |
p07gbar | 0:4be11cf8cf0c | 105 | AdkTerm AdkTerm; |
p07gbar | 0:4be11cf8cf0c | 106 | |
p07gbar | 0:4be11cf8cf0c | 107 | |
p07gbar | 0:4be11cf8cf0c | 108 | |
p07gbar | 0:4be11cf8cf0c | 109 | int main() { |
p07gbar | 0:4be11cf8cf0c | 110 | printf("Android Development Kit: start\r\n"); |
p07gbar | 0:4be11cf8cf0c | 111 | |
p07gbar | 0:4be11cf8cf0c | 112 | AdkTerm.setupDevice(); |
p07gbar | 0:4be11cf8cf0c | 113 | USBInit(); |
p07gbar | 0:4be11cf8cf0c | 114 | while (1) { |
p07gbar | 0:4be11cf8cf0c | 115 | USBLoop(); |
p07gbar | 0:4be11cf8cf0c | 116 | } |
p07gbar | 0:4be11cf8cf0c | 117 | |
p07gbar | 0:4be11cf8cf0c | 118 | } |