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.
Dependents: 2018NHK_gakugaku_robo 2018NHK_gaku_ver2 2019NHK_A_sensor
TFmini.cpp
- Committer:
- UCHITAKE
- Date:
- 2018-08-27
- Revision:
- 4:7622beb45675
- Parent:
- 3:04330e82af20
- Child:
- 5:eeb0e5bdd8b9
File content as of revision 4:7622beb45675:
#include "TFmini.h" TFmini::TFmini(PinName serialTX, PinName serialRX) : RawSerial(serialTX, serialRX, TF_DEFAULT_BAUD) { attach(callback(this, &TFmini::receiveByte)); thread.start(callback(this, &TFmini::assembleLoop)); } void TFmini::receiveByte() { buf.push_back(getc()); } void TFmini::assemble() { distance = ((buf[3]<<8)|buf[2]); strength = ((buf[5]<<8)|buf[4]); } void TFmini::assembleLoop() { while(true) { if(buf.size() > TF_SERIAL_BUFFER_SIZE) { if(buf[0] == TF_HEADER_FIRST_BYTE && buf[1] == TF_HEADER_SECOND_BYTE) { assemble(); buf.erase(buf.begin(), buf.begin() + (TF_SERIAL_BUFFER_SIZE - 1)); } else { buf.erase(buf.begin()); } } } } int TFmini::getDistance() { return distance; } int TFmini::getStrength() { return strength; }