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.
Diff: UM12.cpp
- Revision:
- 0:18297993986b
- Child:
- 1:84430ccc5662
diff -r 000000000000 -r 18297993986b UM12.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UM12.cpp Tue Jul 19 17:09:58 2011 +0000 @@ -0,0 +1,91 @@ +#include "UM12.h" +#include "mbed.h" + +UM12::UM12( PinName tx, PinName rx, PinName slp, PinName rst) : Serial::Serial(tx, rx) +{ + if(slp != LED1) sleepPin = new DigitalOut(slp); + else sleepPin = 0; + if(rst != LED2) resetPin = new DigitalOut(rst); + else resetPin = 0; + baud(1200); +} + +UM12::~UM12() +{ + if(sleepPin) delete sleepPin; + if(resetPin) delete resetPin; +} + +void UM12::sleep() +{ + if(sleepPin) *sleepPin = 1; +} + +void UM12::wake() +{ + if(sleepPin) *sleepPin = 0; +} + +void UM12::reset() +{ + if(resetPin) + { + *resetPin = 0; + wait(0.15); + *resetPin = 1; + } +} + +void UM12::send(char msg) +{ + putc(msg); +} + +void UM12::send(int msg) +{ + char *ch; + ch = (char*) &msg; + for (int i=0; i<sizeof(float);i++) putc(ch[i]); +} + +void UM12::send(float msg) +{ + char *ch; + ch = (char*) &msg; + for (int i=0; i<sizeof(float);i++) putc(ch[i]); +} + +char UM12::receive(char &msg) +{ + msg = getc(); + return msg; +} + +int UM12::receive(int &msg) +{ + int i, intsize = sizeof(int); + char bytes[intsize]; + + for(i=0; i<intsize; i++) bytes[i] = getc(); + + int *rec; + rec = (int*) bytes; + msg = *rec; + + return msg; +} + + +float UM12::receive(float &msg) +{ + int i, flsize = sizeof(float); + char bytes[flsize]; + + for(i=0; i<flsize; i++) bytes[i] = getc(); + + float *rec; + rec = (float*) bytes; + msg = *rec; + + return msg; +} \ No newline at end of file