PAT9125 - sampled only Y value, new debug code D9125.

FSensor - synchronous sampling and new algorithm
build number = 103
This commit is contained in:
Robert Pelnar 2017-10-24 19:45:15 +02:00
parent 8734961e0e
commit cddb0eafb8
11 changed files with 14668 additions and 128 deletions
Firmware

View file

@ -17,9 +17,12 @@
unsigned char pat9125_PID1 = 0;
unsigned char pat9125_PID2 = 0;
unsigned char pat9125_xres = 0;
unsigned char pat9125_yres = 0;
int pat9125_x = 0;
int pat9125_y = 0;
int pat9125_b = 0;
unsigned char pat9125_b = 0;
unsigned char pat9125_s = 0;
int pat9125_init(unsigned char xres, unsigned char yres)
{
@ -32,14 +35,17 @@ int pat9125_init(unsigned char xres, unsigned char yres)
#ifdef PAT9125_HWI2C
Wire.begin();
#endif //PAT9125_HWI2C
pat9125_xres = xres;
pat9125_yres = yres;
pat9125_PID1 = pat9125_rd_reg(PAT9125_PID1);
pat9125_PID2 = pat9125_rd_reg(PAT9125_PID2);
if ((pat9125_PID1 != 0x31) || (pat9125_PID2 != 0x91))
{
return 0;
}
pat9125_wr_reg(PAT9125_RES_X, xres);
pat9125_wr_reg(PAT9125_RES_Y, yres);
pat9125_wr_reg(PAT9125_RES_X, pat9125_xres);
pat9125_wr_reg(PAT9125_RES_Y, pat9125_yres);
// pat9125_wr_reg(PAT9125_ORIENTATION, 0x04 | (xinv?0x08:0) | (yinv?0x10:0)); //!? direction switching does not work
return 1;
}
@ -49,6 +55,7 @@ int pat9125_update()
{
unsigned char ucMotion = pat9125_rd_reg(PAT9125_MOTION);
pat9125_b = pat9125_rd_reg(PAT9125_FRAME);
pat9125_s = pat9125_rd_reg(PAT9125_SHUTTER);
if (ucMotion & 0x80)
{
unsigned char ucXL = pat9125_rd_reg(PAT9125_DELTA_XL);
@ -59,7 +66,25 @@ int pat9125_update()
if (iDX & 0x800) iDX -= 4096;
if (iDY & 0x800) iDY -= 4096;
pat9125_x += iDX;
pat9125_y += iDY;
pat9125_y -= iDY; //negative number, because direction switching does not work
return 1;
}
}
return 0;
}
int pat9125_update_y()
{
if ((pat9125_PID1 == 0x31) && (pat9125_PID2 == 0x91))
{
unsigned char ucMotion = pat9125_rd_reg(PAT9125_MOTION);
if (ucMotion & 0x80)
{
unsigned char ucYL = pat9125_rd_reg(PAT9125_DELTA_YL);
unsigned char ucXYH = pat9125_rd_reg(PAT9125_DELTA_XYH);
int iDY = ucYL | ((ucXYH << 8) & 0xf00);
if (iDY & 0x800) iDY -= 4096;
pat9125_y -= iDY; //negative number, because direction switching does not work
return 1;
}
}