Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

64 lines
1.6KB

  1. float gx, gy, gz;
  2. uint16_t xc, yc;
  3. uint8_t isTouch;
  4. int16_t xc_old, yc_old;
  5. void printAngles(){
  6. //test function calls
  7. float gx, gy, gz;
  8. getAccel(ax, ay, az);
  9. Serial.printf("Accel-g's: %f, %f, %f\n", ax, ay, az);
  10. getGyro(gx, gy, gz);
  11. Serial.printf("Gyro-deg/sec: %f, %f, %f\n", gx, gy, gz);
  12. getAngles(pitch, roll);
  13. Serial.printf("Pitch/Roll: %f, %f\n", pitch, roll);
  14. getCoords(xc, yc, isTouch);
  15. }
  16. void getCoords(uint16_t &xc, uint16_t &yc, uint8_t &isTouch){
  17. //uint8_t finger = 0; //only getting finger 1
  18. uint8_t Id = 0;
  19. // Trackpad touch 1: id, active, x, y
  20. xc = ((psAxis[37] & 0x0f) << 8) | psAxis[36];
  21. yc = psAxis[38] << 4 | ((psAxis[37] & 0xf0) >> 4),
  22. isTouch = psAxis[35] >> 7;
  23. if(xc != xc_old || yc != yc_old){
  24. Serial.printf("Touch: %d, %d, %d, %d\n", psAxis[33], isTouch, xc, yc);
  25. xc_old = xc;
  26. yc_old = yc;
  27. }
  28. }
  29. void getAccel( float &ax, float &ay, float &az){
  30. int accelx = (int16_t)(psAxis[20]<<8) | psAxis[19];
  31. int accelz = (int16_t)(psAxis[22]<<8) | psAxis[21];
  32. int accely = (int16_t)(psAxis[24]<<8) | psAxis[23];
  33. ax = (float) accelx/8192;
  34. ay = (float) accely/8192;
  35. az = (float) accelz/8192;
  36. }
  37. void getAngles(float &p, float &r){
  38. getAccel( ax, ay, az);
  39. p = (atan2f(ay, az) + PI) * RAD_TO_DEG;
  40. r = (atan2f(ax, az) + PI) * RAD_TO_DEG;
  41. }
  42. void getGyro(float &gx, float &gy, float &gz){
  43. int gyroy = (int16_t)(psAxis[14]<<8) | psAxis[13];
  44. int gyroz = (int16_t)(psAxis[16]<<8) | psAxis[15];
  45. int gyrox = (int16_t)(psAxis[18]<<8) | psAxis[17];
  46. gx = (float) gyrox * RAD_TO_DEG/1024;
  47. gy = (float) gyroy * RAD_TO_DEG/1024;
  48. gz = (float) gyroz * RAD_TO_DEG/1024;
  49. }