BOOL getCalibValue(int mouseNb, CALIB_MOTION_MOUSE *motion) { uint8 notReceived; //wait answer during max one tick if(uart_GetDataSize(mice[mouseNb].uart) >= sizeof(CALIB_MOTION_MOUSE)) { notReceived = uart_Get(mice[mouseNb].uart, (uint8*)&(motion->code), sizeof(motion->code), 1); if(notReceived == 0) { if(motion->code != DELTA_MOTION) { if((mice[mouseNb].nbUnkError++ % 100)==0) { //LOG_ERROR2("Mouse %d : Unknown message (0x%02X) !", mouseNb, motion->code); } return FALSE; } } else { //LOG_ERROR1("Mouse %d : Time'd out !", mouseNb); return FALSE; } //wait for the rest of mouse message during max one tick notReceived = uart_Get(mice[mouseNb].uart, ((uint8*)motion)+1, sizeof(CALIB_MOTION_MOUSE)-1, 1); if(notReceived == 0) { if(computeCalibChecksum(motion) != motion->checksum) { //LOG_ERROR1("Mouse %d : checksum error !", mouseNb); return FALSE; } else { /*if(motion->deltaX.i != 0 || motion->deltaY.i != 0) { LOG_DEBUG3("M%d: %d,%d", mouseNb, motion->deltaX.i, motion->deltaY.i); }*/ mice[mouseNb].error = 0; return TRUE; } } else { //LOG_ERROR1("Mouse %d : Time'd out !", mouseNb); return FALSE; } } return FALSE; }
//------------------------------------------------------------------- //External Functions //------------------------------------------------------------------- sys_res vk321x_Init() { p_dev_uart pUart; #if VK321X_LOCK_ENABLE rt_sem_init(&vk321x_sem, "vk321x", 1, RT_IPC_FLAG_FIFO); #endif sys_GpioConf(&tbl_bspVk321x[0]); sys_GpioConf(&tbl_bspVk321x[1]); for (pUart = dev_Uart; pUart < ARR_ENDADR(dev_Uart); pUart++) if (pUart->def->type == UART_T_VK321X) vk321x_uart_dev[pUart->def->id] = pUart; while ((vk321x_port = uart_Get(VK321X_COMID, 1000)) == NULL); vk321x_Reset(); return irq_ExtRegister(VK321X_INTID, tbl_bspVk321x[1].port, tbl_bspVk321x[1].pin, IRQ_TRIGGER_FALLING, vk321x_ItHandler, IRQ_MODE_HALF); }
BOOL getValue(int mouseNb, MOTION_MOUSE *motion) { uint8 notReceived; //verify nb of bytes in the uart stack if(uart_GetDataSize(mice[mouseNb].uart) >= sizeof(MOTION_MOUSE)) { //wait answer during max one tick notReceived = uart_Get(mice[mouseNb].uart, (uint8*)&motion->code, sizeof(motion->code), 1); if(notReceived == 0) { if(motion->code != X_Y_MOTION) { if((mice[mouseNb].nbUnkError++ % 100)==0) { LOG_ERROR2("M%d : Unknown message = %ld", mouseNb, mice[mouseNb].nbUnkError); } mice[mouseNb].error++; return FALSE; } } else { LOG_ERROR1("Mouse %d : Time'd out ???", mouseNb); mice[mouseNb].error++; return FALSE; } //wait for the rest of mouse message during max one tick notReceived = uart_Get(mice[mouseNb].uart, ((uint8*)motion)+1, sizeof(MOTION_MOUSE)-1, 1); if(notReceived == 0) { if(computeChecksum(motion) != motion->checksum) { if((mice[mouseNb].nbCksmError++ % 100)==0) { LOG_ERROR2("M%d: Checksum error= %ld", mouseNb, mice[mouseNb].nbCksmError); } mice[mouseNb].error++; return FALSE; } else { //quick integrity verification if((fabs(motion->X.f) >= 5000.0f) || (fabs(motion->Y.f) >= 5000.0f)) { LOG_DEBUG3("M%d: %4.2g, %4.2g", mouseNb, motion->X.f, motion->Y.f); return FALSE; } mice[mouseNb].error = 0; return TRUE; } } else { LOG_ERROR1("Mouse %d : Time'd out ???", mouseNb); mice[mouseNb].error++; return FALSE; } } return FALSE; }