#include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/portmacro.h" #include #include "esp_err.h" #include "emu.h" #include "tmeconfig.h" #include "mpu6050.h" #include "mpumouse.h" portMUX_TYPE dxdyMux=portMUX_INITIALIZER_UNLOCKED; static int dx, dy, btn; void mpuMouseGetDxDyBtn(int *pDx, int *pDy, int *pBtn) { printf("Mouse: %d %d\n", dx, dy); portENTER_CRITICAL(&dxdyMux); *pDx=dx; *pDy=dy; *pBtn=0; dx=0; dy=0; portEXIT_CRITICAL(&dxdyMux); } #define RECAL_SAMPS 32 static int recal[RECAL_SAMPS][2]; static int recalPos=0; static int idleAx=0, idleAy=0; static int curDx, curDy; //Add sample to correction static void addToCorr(int ax, int ay) { recalPos++; if (recalPos>=RECAL_SAMPS) recalPos=0; recal[recalPos][0]=ax; recal[recalPos][1]=ay; } #define DIV_NOMOTION 5000 static void checkCorr() { int avgax=0; int avgay=0; for (int i=0; i=10) { calCtr=0; checkCorr(); } vTaskDelay(1); } }