28 #define EPSON_STALL 134 // Microseconds 40 unsigned int length = 0;
127 void registerWriteByte(
unsigned char winNumber,
unsigned char regAddr,
unsigned char regByte,
unsigned int verbose)
129 unsigned char txData[3];
131 #if !(defined G350 || defined V340) 133 txData[1] = winNumber;
139 txData[0] = regAddr | 0x80;
147 printf(
"\r\nREG[0x%02X(W%01X)] < 0x%02X\t", regAddr, winNumber, regByte);
159 unsigned short registerRead16(
unsigned char winNumber,
unsigned char regAddr,
unsigned int verbose)
161 unsigned char response[4] = {0};
163 unsigned char txData[3];
165 #if !(defined G350 || defined V340) 167 txData[1] = winNumber;
173 txData[0] = regAddr & 0x7E;
184 if ((size<4) || (response[0] != txData[0]) || (response[3] !=
UART_DELIMITER))
185 printf(
"Returned less data or unexpected data from previous command.\n");
190 printf(
"REG[0x%02X(W%01X)] > 0x%02X%02X\t", regAddr, winNumber, response[1], response[2]);
192 return (
unsigned short)response[1]<<8|(
unsigned short)response[2];
196 static unsigned char data[256];
253 int gx1, gx2, gx3, gx4;
254 int gy1, gy2, gy3, gy4;
255 int gz1, gz2, gz3, gz4;
256 int ax1, ax2, ax3, ax4;
257 int ay1, ay2, ay3, ay4;
258 int az1, az2, az3, az4;
259 int gdx1, gdx2, gdx3, gdx4;
260 int gdy1, gdy2, gdy3, gdy4;
261 int gdz1, gdz2, gdz3, gdz4;
262 int adx1, adx2, adx3, adx4;
263 int ady1, ady2, ady3, ady4;
264 int adz1, adz2, adz3, adz4;
274 t1 = f2 + 1, t2 = t1 + 1, t3 = t2 + 1, t4 = t3 + 1;
276 t1 = t2 = t3 = t4 = f2;
281 gx1 = t4 + 1, gx2 = gx1 + 1, gx3 = gx2 + 1, gx4 = gx3 + 1;
283 gx1 = gx2 = gx3 = gx4 = t4;
288 gy1 = gx4 + 1, gy2 = gy1 + 1, gy3 = gy2 + 1, gy4 = gy3 + 1;
290 gy1 = gy2 = gy3 = gy4 = t4;
295 gz1 = gy4 + 1, gz2 = gz1 + 1, gz3 = gz2 + 1, gz4 = gz3 + 1;
297 gz1 = gz2 = gz3 = gz4 = t4;
302 ax1 = gz4 + 1, ax2 = ax1 + 1, ax3 = ax2 + 1, ax4 = ax3 + 1;
304 ax1 = ax2 = ax3 = ax4 = gz4;
309 ay1 = ax4 + 1, ay2 = ay1 + 1, ay3 = ay2 + 1, ay4 = ay3 + 1;
311 ay1 = ay2 = ay3 = ay4 = gz4;
316 az1 = ay4 + 1, az2 = az1 + 1, az3 = az2 + 1, az4 = az3 + 1;
318 az1 = az2 = az3 = az4 = gz4;
323 adx1 = az4 + 1, adx2 = adx1 + 1, adx3 = adx2 + 1, adx4 = adx3 + 1;
325 adx1 = adx2 = adx3 = adx4 = az4;
330 ady1 = adx4 + 1, ady2 = ady1 + 1, ady3 = ady2 + 1, ady4 = ady3 + 1;
332 ady1 = ady2 = ady3 = ady4 = az4;
337 adz1 = ady4 + 1, adz2 = adz1 + 1, adz3 = adz2 + 1, adz4 = adz3 + 1;
339 adz1 = adz2 = adz3 = adz4 = az4;
344 gdx1 = adz4 + 1, gdx2 = gdx1 + 1, gdx3 = gdx2 + 1, gdx4 = gdx3 + 1;
346 gdx1 = gdx2 = gdx3 = gdx4 = adz4;
351 gdy1 = adx4 + 1, gdy2 = gdy1 + 1, gdy3 = gdy2 + 1, gdy4 = gdy3 + 1;
353 gdy1 = gdy2 = gdy3 = gdy4 = adz4;
358 gdz1 = ady4 + 1, gdz2 = gdz1 + 1, gdz3 = gdz2 + 1, gdz4 = gdz3 + 1;
360 gdz1 = gdz2 = gdz3 = gdz4 = adz4;
365 gp1 = gdz4 + 1, gp2 = gp1 + 1;
370 c1 = gp2 + 1, c2 = c1 + 1;
375 int temp = (
data[t1] << 8*3) + (
data[t2] << 8*2) + (
data[t3] << 8) +
data[t4];
379 short temp = (
data[t1] << 8) +
data[t2];
384 int gyro_x = (
data[gx1] << 8*3) + (
data[gx2] << 8*2) + (
data[gx3] << 8)+
data[gx4];
385 int gyro_y = (
data[gy1] << 8*3) + (
data[gy2] << 8*2) + (
data[gy3] << 8)+
data[gy4];
386 int gyro_z = (
data[gz1] << 8*3) + (
data[gz2] << 8*2) + (
data[gz3] << 8)+
data[gz4];
392 short gyro_x = (
data[gx1] << 8) +
data[gx2];
393 short gyro_y = (
data[gy1] << 8) +
data[gy2];
394 short gyro_z = (
data[gz1] << 8) +
data[gz2];
401 int accel_x = (
data[ax1] << 8*3) + (
data[ax2] << 8*2) +
403 int accel_y = (
data[ay1] << 8*3) + (
data[ay2] << 8*2) +
405 int accel_z = (
data[az1] << 8*3) + (
data[az2] << 8*2) +
412 short accel_x = (
data[ax1] << 8) + (
data[ax2]);
413 short accel_y = (
data[ay1] << 8) + (
data[ay2]);
414 short accel_z = (
data[az1] << 8) + (
data[az2]);
421 int gyro_delta_x = (
data[gdx1] << 8*3) + (
data[gdx2] << 8*2) +
423 int gyro_delta_y = (
data[gdy1] << 8*3) + (
data[gdy2] << 8*2) +
425 int gyro_delta_z = (
data[gdz1] << 8*3) + (
data[gdz2] << 8*2) +
433 short gyro_delta_x = (
data[gdx1] << 8) +
data[gdx2];
434 short gyro_delta_y = (
data[gdy1] << 8) +
data[gdy2];
435 short gyro_delta_z = (
data[gdz1] << 8) +
data[gdz2];
443 int accel_delta_x = (
data[adx1] << 8*3) + (
data[adx2] << 8*2) +
445 int accel_delta_y = (
data[ady1] << 8*3) + (
data[ady2] << 8*2) +
447 int accel_delta_z = (
data[adz1] << 8*3) + (
data[adz2] << 8*2) +
455 short accel_delta_x = (
data[adx1] << 8) +
data[adx2];
456 short accel_delta_y = (
data[ady1] << 8) +
data[ady2];
457 short accel_delta_z = (
data[adz1] << 8) +
data[adz2];
464 int count = (
data[c1] << 8) +
data[c2];
470 int data_length = byte_length - 2;
491 unsigned short checksum = 0;
495 for(i = 0; i < data_length-2; i += 2)
496 checksum += (
data[i] << 8) +
data[i+1];
497 unsigned short epson_checksum = (
data[data_length - 2] << 8) +
498 data[data_length - 1];
502 if(checksum == epson_checksum){
507 printf(
"checksum failed\n");
538 int byteLength = (readLen*2) + 2;
543 if(size<=0) printf(
"!");
549 for (i = 1; i < (byteLength-1); i=i+2)
553 sensorReadData[j] = (tmp << 8) +
rxBuffer[i+1];
559 for(k = 0; k < byteLength-1; k++)
560 printf(
"%d: 0x%02x, ", k,
rxBuffer[k]);
564 #if !(defined G350 || defined V340) 565 unsigned short chksum16_calc = 0;
566 for (i = 0; i < readLen-1; i++)
567 chksum16_calc += (
unsigned short)sensorReadData[i];
574 if (chksum16_calc != (
unsigned short)sensorReadData[readLen-1])
575 printf(
" Checksum error detected!");
unsigned int sensorDataByteLength(struct EpsonOptions options)
unsigned char rxBuffer[256]
static double da_scale_factors[16]
static double dv_scale_factors[16]
static int scale_factors_initialized
void sensorDataReadBurstN(signed short sensorReadData[], unsigned int readLen)
int sensorDataReady(void)
int numBytesReadComPort(ComPortHandle comPort)
void registerWriteByte(unsigned char winNumber, unsigned char regAddr, unsigned char regByte, unsigned int verbose)
unsigned short registerRead16(unsigned char winNumber, unsigned char regAddr, unsigned int verbose)
int writeComPort(ComPortHandle comPort, unsigned char *bytesToWrite, int size)
static unsigned char data[256]
void populateEpsonData(struct EpsonOptions options, struct EpsonData *epson_data)
int sensorDataReadBurstNOptions(struct EpsonOptions options, struct EpsonData *epson_data)
int readComPort(ComPortHandle comPort, unsigned char *bytes, int bytesToRead)
int sensorDataReadyOptions(struct EpsonOptions options)
void seDelayMS(uint32_t millis)
const unsigned char UART_DELIMITER