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.
Android.cpp@0:9b41a36d03d9, 2018-01-07 (annotated)
- Committer:
- maskas
- Date:
- Sun Jan 07 11:59:16 2018 +0000
- Revision:
- 0:9b41a36d03d9
- Child:
- 1:6d9353593c3c
communication with android;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maskas | 0:9b41a36d03d9 | 1 | |
maskas | 0:9b41a36d03d9 | 2 | |
maskas | 0:9b41a36d03d9 | 3 | #include "mbed.h" |
maskas | 0:9b41a36d03d9 | 4 | #include "Android.h" |
maskas | 0:9b41a36d03d9 | 5 | |
maskas | 0:9b41a36d03d9 | 6 | Android::Android(PinName txPin, PinName rxPin): serial(txPin, rxPin), myled(LED1) { |
maskas | 0:9b41a36d03d9 | 7 | //Serial pc(USBTX, USBRX); // tx, rx |
maskas | 0:9b41a36d03d9 | 8 | |
maskas | 0:9b41a36d03d9 | 9 | this->serial.baud(115200); |
maskas | 0:9b41a36d03d9 | 10 | this->serial.attach(callback(this, &Android::onData)); |
maskas | 0:9b41a36d03d9 | 11 | |
maskas | 0:9b41a36d03d9 | 12 | this->ticker.attach(callback(this, &Android::hearthBeat), 2.0); |
maskas | 0:9b41a36d03d9 | 13 | } |
maskas | 0:9b41a36d03d9 | 14 | |
maskas | 0:9b41a36d03d9 | 15 | void Android::hearthBeat(void) |
maskas | 0:9b41a36d03d9 | 16 | { |
maskas | 0:9b41a36d03d9 | 17 | this->myled = !this->myled; |
maskas | 0:9b41a36d03d9 | 18 | printf("HEARTH BEAT SENT\n"); |
maskas | 0:9b41a36d03d9 | 19 | this->serial.printf("ARD_HB"); |
maskas | 0:9b41a36d03d9 | 20 | this->serial.putc(-91); |
maskas | 0:9b41a36d03d9 | 21 | this->serial.printf("OK"); |
maskas | 0:9b41a36d03d9 | 22 | this->serial.putc(-91); |
maskas | 0:9b41a36d03d9 | 23 | |
maskas | 0:9b41a36d03d9 | 24 | } |
maskas | 0:9b41a36d03d9 | 25 | |
maskas | 0:9b41a36d03d9 | 26 | void Android::onData(void) |
maskas | 0:9b41a36d03d9 | 27 | { |
maskas | 0:9b41a36d03d9 | 28 | char command[50]; |
maskas | 0:9b41a36d03d9 | 29 | int product; |
maskas | 0:9b41a36d03d9 | 30 | if (this->serial.readable()) { |
maskas | 0:9b41a36d03d9 | 31 | this->serial.scanf("%s", &command); |
maskas | 0:9b41a36d03d9 | 32 | this->serial.scanf("%d", &product); |
maskas | 0:9b41a36d03d9 | 33 | printf(command); |
maskas | 0:9b41a36d03d9 | 34 | printf("%d", product); |
maskas | 0:9b41a36d03d9 | 35 | |
maskas | 0:9b41a36d03d9 | 36 | printf("Command Received: \r\n"); |
maskas | 0:9b41a36d03d9 | 37 | } |
maskas | 0:9b41a36d03d9 | 38 | } |