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.
PositionModule.cpp
- Committer:
- erikkallen
- Date:
- 2010-10-19
- Revision:
- 0:886002922b6a
File content as of revision 0:886002922b6a:
#include "PositionModule.h" #include "Point.h" PositionModule::PositionModule(PinName tx, PinName rx):_mouse(tx,rx) { _mouse.frequency(100000); } long PositionModule::getX() { updatePosition(); return -_ypos; } long PositionModule::getY() { updatePosition(); return -_xpos; } void PositionModule::setZero() { char cmd[1] = {2}; _mouse.write(4,cmd,1); } long PositionModule::getDistance() { updatePosition(); return sqrt((long double)(getX()*getX())+(getY()*getY())); } float PositionModule::getHeading() { return Point::XYToDegrees(Point(0,0),Point(getX(),getY())); } void PositionModule::updatePosition() { char * buf = new char[8]; char cmd[1] = {3}; _mouse.read(5,buf,8); _mouse.write(4,cmd,1); _xpos = (long)((buf[0] << 24) + (buf[1] << 16) + ( buf[2] << 8) + buf[3]); _ypos = (long)((buf[4] << 24) + (buf[5] << 16) + ( buf[6] << 8) + buf[7]); wait(0.1); }