Ai
1 Star 0 Fork 0

DFRobot/DFRobotIRPosition

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DFRobotIRPosition.cpp 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
jimaobian 提交于 2016-02-19 16:57 +08:00 . init
/*!
* @file DFRobotIRPosition.cpp
* @brief DFRobot's Positioning ir camera
* @n CPP file for DFRobot's Positioning ir camera
*
* @copyright [DFRobot](http://www.dfrobot.com), 2016
* @copyright GNU Lesser General Public License
*
* @author [Angelo](Angelo.qiao@dfrobot.com)
* @version V1.0
* @date 2016-02-17
*/
#include "DFRobotIRPosition.h"
DFRobotIRPosition::DFRobotIRPosition()
{
}
DFRobotIRPosition::~DFRobotIRPosition()
{
}
void DFRobotIRPosition::writeTwoIICByte(uint8_t first, uint8_t second)
{
Wire.beginTransmission(IRAddress);
Wire.write(first);
Wire.write(second);
Wire.endTransmission();
}
void DFRobotIRPosition::begin()
{
Wire.begin();
writeTwoIICByte(0x30,0x01);
delay(10);
writeTwoIICByte(0x30,0x08);
delay(10);
writeTwoIICByte(0x06,0x90);
delay(10);
writeTwoIICByte(0x08,0xC0);
delay(10);
writeTwoIICByte(0x1A,0x40);
delay(10);
writeTwoIICByte(0x33,0x33);
delay(10);
delay(100);
}
void DFRobotIRPosition::requestPosition()
{
Wire.beginTransmission(IRAddress);
Wire.write(0x36);
Wire.endTransmission();
Wire.requestFrom(IRAddress, 16);
}
bool DFRobotIRPosition::available()
{
if (Wire.available() == 16) { //read only the data lenth fits.
for (int i=0; i<16; i++) {
positionData.receivedBuffer[i]=Wire.read();
}
for (int i=0; i<4; i++) {
positionX[i] = (uint16_t)(positionData.positionFrame.rawPosition[i].xLowByte)
+ ((uint16_t)(positionData.positionFrame.rawPosition[i].xyHighByte & 0x30U) << 4);
positionY[i] = (uint16_t)(positionData.positionFrame.rawPosition[i].yLowByte)
+ ((uint16_t)(positionData.positionFrame.rawPosition[i].xyHighByte & 0xC0U) << 2);
}
return true;
}
else{ //otherwise skip them.
while (Wire.available()) {
Wire.read();
}
return false;
}
}
int DFRobotIRPosition::readX(int index)
{
return positionX[index];
}
int DFRobotIRPosition::readY(int index)
{
return positionY[index];
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/dfrobot/DFRobotIRPosition.git
git@gitee.com:dfrobot/DFRobotIRPosition.git
dfrobot
DFRobotIRPosition
DFRobotIRPosition
master

搜索帮助