You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

401 lines
19 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "opticFlowADNS.h"
  2. #include <wiringPi.h>
  3. #define STB_IMAGE_IMPLEMENTATION
  4. #define STB_IMAGE_WRITE_IMPLEMENTATION
  5. #include "../../../../data/stbi/stb_image.h"
  6. #include "../../../../data/stbi/stb_image_write.h"
  7. static const uint8_t SROM[1986]={
  8. 0xe6,0xff,0x40,0x22,0x86,0xaa,0x9f,0x73,0xdc,0x34,0x5f,0x1d,0x0d,0x05,0xe2,0xae,
  9. 0x5c,0xe7,0x5e,0x67,0x2f,0xd2,0x45,0xaa,0xb7,0x2d,0xf9,0x71,0xc0,0xe2,0x89,0x8f,
  10. 0x18,0xc0,0x50,0xb1,0x4c,0x5b,0x1e,0xb3,0x53,0x32,0x56,0x3a,0x14,0xe7,0x64,0x58,
  11. 0x41,0x24,0x03,0x3c,0xc5,0x2a,0x9c,0x8c,0x06,0xa7,0xa2,0x1f,0x23,0xf7,0x64,0xe6,
  12. 0x1b,0x50,0x97,0x3a,0x8a,0x86,0x16,0x4a,0xf5,0x77,0x5b,0x28,0x5d,0xa6,0xe0,0xcf,
  13. 0xc1,0x4a,0x28,0x62,0xfb,0x85,0x09,0x80,0x07,0xce,0x11,0x59,0xd4,0x89,0xcf,0xc1,
  14. 0x42,0x1d,0x05,0xea,0xa2,0x47,0x2e,0x0f,0xa1,0x10,0x0c,0xb4,0xe1,0x3f,0x95,0x70,
  15. 0x6d,0x4d,0xc0,0xce,0x8b,0x49,0x46,0x6e,0xfd,0x77,0x84,0x7e,0x62,0x0a,0x5d,0xaa,
  16. 0xc7,0x5d,0xa7,0x64,0x8d,0xc6,0x17,0x0d,0x44,0x6a,0xdc,0x56,0xae,0xa2,0x35,0xd0,
  17. 0xd9,0xdb,0xa7,0x68,0xc1,0xa5,0xcb,0xdb,0xda,0xdf,0xe9,0x65,0xb9,0x55,0x49,0xf0,
  18. 0x8f,0xe8,0x6e,0x4b,0xca,0xfc,0xe4,0x14,0x91,0x7a,0xaf,0x59,0x74,0x54,0x11,0x69,
  19. 0xf1,0xce,0x80,0xc0,0xd1,0x99,0x40,0x81,0x36,0x20,0x48,0x69,0x92,0xb1,0x44,0xdc,
  20. 0x97,0x4f,0x0e,0x95,0xc3,0x27,0x23,0xcf,0x7a,0xcd,0xe8,0x33,0x1b,0x12,0x9f,0xde,
  21. 0x2f,0x60,0x04,0x05,0x43,0x80,0x6b,0x0c,0xa1,0x72,0x26,0x36,0x46,0x51,0xbd,0x6c,
  22. 0xa2,0x4b,0x93,0x4b,0x3e,0x9b,0x5a,0x60,0xd8,0x23,0xa5,0x37,0x6b,0x04,0x37,0x11,
  23. 0xa8,0x32,0xec,0x1b,0x0b,0x06,0x6e,0x59,0xe8,0xf7,0x6c,0x26,0x03,0xb7,0xf2,0xec,
  24. 0x97,0x9d,0xc9,0x74,0x65,0xf3,0x90,0x58,0xa7,0x36,0x7b,0x6f,0xe8,0x31,0x05,0xfe,
  25. 0x04,0x9a,0xa4,0x73,0xa7,0xcf,0x27,0x78,0x8f,0xdc,0xd3,0xc6,0x14,0x55,0x76,0xa1,
  26. 0x24,0xcc,0xb0,0x38,0x53,0x7f,0x7b,0xf8,0x23,0xd7,0x09,0xd7,0xee,0xb8,0x19,0x1d,
  27. 0x0a,0x9a,0x70,0xdd,0xd8,0x5e,0x70,0x6f,0xd4,0xe9,0x2c,0x23,0x44,0xe0,0x3e,0xa7,
  28. 0x7d,0x31,0xf4,0x79,0xd0,0x40,0xfe,0x8e,0x8f,0x01,0xbc,0x4e,0x7f,0xbd,0x16,0xde,
  29. 0x9b,0xd5,0xcb,0xf5,0x18,0xb0,0x2a,0x00,0x31,0x26,0x89,0x4b,0x62,0x14,0x95,0x21,
  30. 0x45,0x2a,0x6a,0x99,0x38,0x8e,0xf3,0xad,0x25,0xfd,0xd0,0x1d,0x4a,0x91,0xf6,0xb7,
  31. 0x71,0x01,0x5a,0xcd,0xc1,0x99,0x50,0xad,0x77,0x55,0x95,0xfd,0x88,0x0e,0xde,0xeb,
  32. 0xb6,0x54,0xe1,0x8d,0xfd,0x6d,0x02,0x3d,0x00,0x15,0x75,0x43,0x88,0x17,0x04,0x15,
  33. 0x39,0x95,0xaa,0x25,0x40,0x67,0x91,0x9b,0x7e,0x1d,0x6b,0xf2,0xaa,0x73,0x8f,0xf3,
  34. 0x8f,0x75,0x0c,0x55,0x1a,0x41,0x8c,0xab,0xab,0x79,0xf8,0xc8,0x91,0xc2,0x70,0xe0,
  35. 0xca,0x2a,0x8b,0xde,0x97,0x1c,0xcc,0xc7,0xa5,0x8f,0x55,0x9f,0x08,0x0d,0xe8,0x89,
  36. 0x90,0xf9,0xe2,0xa1,0x87,0xb6,0x25,0xa0,0x5a,0x71,0xc5,0x28,0x6e,0x17,0xef,0xb2,
  37. 0x58,0x8c,0xc6,0xe2,0xcf,0x26,0x93,0x29,0x63,0x59,0xbc,0x71,0x8e,0xe0,0x91,0x61,
  38. 0x06,0xb0,0x65,0x07,0x51,0x45,0x2e,0xa3,0xa7,0x7c,0x75,0x6b,0x57,0x36,0x70,0xb2,
  39. 0xbc,0xe4,0x08,0x6b,0xe2,0x8c,0x44,0x06,0x39,0x11,0xe0,0xd7,0x9c,0x13,0x4b,0x09,
  40. 0xdc,0x16,0x9a,0xda,0x20,0x64,0xd5,0x8a,0xe5,0x4b,0x58,0x69,0x6c,0x96,0x05,0x07,
  41. 0x03,0xd2,0x2d,0xce,0xbb,0x4c,0x88,0xe2,0x64,0x05,0xa4,0x48,0x41,0xeb,0x15,0xd8,
  42. 0x42,0xaa,0xd5,0x83,0x52,0x79,0xcf,0xa5,0x3b,0x54,0x56,0xa2,0xe2,0xcb,0xf3,0xf2,
  43. 0xcb,0xf2,0x17,0x02,0x6b,0xff,0x32,0x27,0x4d,0xbb,0xe7,0x65,0x7d,0x88,0x36,0xad,
  44. 0x66,0x64,0x8b,0x1a,0x65,0xee,0xa2,0x0c,0xc3,0xde,0xce,0x7e,0xd7,0x4d,0xe2,0xd7,
  45. 0x5c,0xc1,0xd6,0xc3,0xe2,0x91,0x31,0x5d,0xaf,0x9c,0x93,0xb8,0x4a,0x83,0x22,0x07,
  46. 0x62,0x17,0xe8,0x73,0x06,0x8f,0xff,0x9e,0x24,0xd9,0xf7,0x11,0xdb,0x0f,0xbd,0x5c,
  47. 0xda,0x93,0x7f,0x96,0xd1,0x98,0xf8,0x2b,0x8c,0x77,0xfc,0xc3,0xc4,0x97,0x5d,0x74,
  48. 0x3a,0xa4,0x42,0xf5,0x97,0xe9,0x81,0x73,0x71,0xf3,0x81,0x94,0x47,0x96,0x91,0x60,
  49. 0x6e,0x8f,0x0d,0xf2,0xa4,0x62,0x1e,0x58,0xcf,0x03,0x7c,0x31,0x5b,0xa8,0x24,0x1b,
  50. 0xc9,0x31,0x30,0x07,0xdd,0xaa,0x31,0x86,0x55,0x93,0x42,0xec,0x17,0xca,0xdc,0x20,
  51. 0x2a,0x60,0x2d,0x4e,0xce,0xae,0xa4,0x66,0x48,0x09,0x7a,0xa5,0x4d,0x4d,0xdd,0xc2,
  52. 0xb3,0x85,0x1a,0x6f,0x0c,0x27,0xa8,0x5d,0xf8,0x2e,0xde,0xa3,0xde,0xf4,0xe8,0xaa,
  53. 0x64,0xa7,0x69,0x9a,0xf8,0x78,0xba,0x73,0x8a,0xfd,0xee,0x06,0x72,0x5d,0xf2,0xe4,
  54. 0x90,0xf7,0xa0,0x46,0xe5,0x06,0x44,0xe3,0xc1,0xee,0x92,0x23,0xc2,0x7c,0xd1,0xd2,
  55. 0x31,0xba,0xeb,0x2f,0x16,0x4d,0xe2,0xf0,0xcf,0x98,0x38,0xbc,0x11,0x68,0xd7,0xc2,
  56. 0xeb,0x91,0xe6,0x34,0x60,0xd1,0x48,0x95,0x54,0x30,0x49,0xb3,0x30,0x8a,0x5a,0xb2,
  57. 0xec,0x14,0x41,0xe9,0xf4,0x84,0x46,0xea,0x31,0x5a,0xbc,0x29,0xb9,0xa1,0xc5,0x2c,
  58. 0x07,0x16,0xfd,0x90,0x5f,0x95,0x41,0xdc,0xf2,0xc3,0x6e,0x57,0xf0,0xea,0x0f,0xdc,
  59. 0xf0,0x58,0x5c,0x83,0x59,0x8a,0xff,0xe2,0xc9,0x33,0x5a,0xfc,0xde,0x4f,0x42,0x89,
  60. 0xbe,0x66,0xfe,0x27,0x93,0x94,0x2a,0xfb,0xca,0xd5,0x78,0x79,0x4a,0x64,0x71,0xb0,
  61. 0xb2,0xda,0x84,0x2c,0xd6,0x16,0xf3,0x79,0xfc,0x31,0x89,0x13,0xb8,0x39,0x2b,0x37,
  62. 0x5c,0xd3,0x1e,0xb6,0xfa,0x4a,0x79,0x62,0x9c,0x86,0xb6,0x22,0x00,0xcc,0xc6,0x05,
  63. 0x8c,0x86,0x98,0xd5,0x61,0x11,0xc2,0x67,0x06,0x8a,0x14,0x34,0xe9,0xd3,0x0a,0xae,
  64. 0x45,0x50,0x52,0x23,0x43,0xd5,0x6d,0x1f,0x45,0x7c,0x91,0xe5,0x2b,0x2d,0x2c,0xef,
  65. 0xbf,0x70,0x3a,0x0a,0x8c,0x50,0xc1,0xf4,0x21,0x0c,0x1e,0x34,0xc5,0xe3,0xad,0x7c,
  66. 0x94,0x87,0x49,0x96,0x58,0x91,0x8c,0xf9,0x26,0xa6,0xb6,0x72,0x0e,0xad,0x36,0x75,
  67. 0x38,0x0e,0x84,0x40,0xa1,0x60,0xc2,0xeb,0xd0,0xa8,0xbd,0x13,0x8d,0x3c,0x14,0x87,
  68. 0x49,0x96,0x48,0x4d,0x9f,0x21,0x4c,0xc2,0xf6,0xce,0x6c,0xd9,0x5a,0x2f,0x55,0x40,
  69. 0x47,0xd4,0x8c,0x7d,0x9b,0xbf,0xff,0xbe,0x88,0x06,0x7e,0x72,0x96,0xd3,0x66,0x0c,
  70. 0x9c,0x29,0x62,0xaf,0xb1,0xd8,0x32,0x84,0x19,0x08,0x44,0xac,0xdc,0x80,0x03,0x47,
  71. 0x18,0x8e,0xb5,0x2d,0xde,0x6a,0x2a,0xcd,0x41,0x82,0x8c,0x19,0x78,0xc8,0x08,0xa8,
  72. 0x42,0x01,0x1f,0x9b,0x73,0xab,0x71,0x42,0x99,0x97,0x75,0x44,0xf3,0x7c,0x42,0x47,
  73. 0x89,0x5b,0xb1,0xb1,0x34,0xe1,0x73,0xf2,0x60,0x68,0xc6,0x25,0x3b,0x12,0xdb,0x9e,
  74. 0x1f,0x90,0x88,0xb6,0x9b,0x49,0xa0,0xa6,0x9e,0x0e,0xb7,0x0c,0x42,0xb4,0x62,0x4a,
  75. 0x0f,0x5c,0x59,0xc2,0x83,0xd9,0x53,0xea,0x4e,0x5e,0xf0,0x8c,0x9d,0xb1,0xe1,0x1c,
  76. 0xa6,0x7f,0x07,0x76,0x39,0x8c,0x4f,0xc0,0x10,0x8f,0xaf,0xf1,0x53,0xe8,0x40,0x0e,
  77. 0x8c,0x96,0x9d,0x95,0x7a,0x5b,0x07,0x80,0xb1,0xac,0xe9,0x6f,0xd1,0xb2,0xc7,0x36,
  78. 0x96,0x07,0xf0,0xcc,0x08,0x9e,0x8d,0x94,0x99,0x9d,0x8b,0xb6,0x8e,0x26,0x9b,0x7b,
  79. 0xd8,0xe3,0x8e,0x79,0x43,0x29,0xc2,0x0a,0x84,0x89,0x4b,0xa5,0x1b,0x9e,0x87,0x79,
  80. 0x90,0xce,0x0e,0x81,0xb5,0xd0,0x11,0x83,0xb8,0xf7,0x1f,0xc4,0x14,0xca,0x11,0xb2,
  81. 0xea,0x12,0xdd,0xb3,0xe0,0xf5,0x57,0xed,0x17,0x2e,0x44,0x0f,0x8e,0xbe,0xa6,0xaf,
  82. 0xdf,0xe9,0xcb,0x3b,0x70,0x12,0xe2,0x55,0x67,0x67,0x5e,0x13,0x76,0x2d,0x71,0x07,
  83. 0x9e,0x7c,0xed,0xc9,0xe5,0x7f,0x04,0xe4,0x58,0x1f,0x6e,0x73,0x57,0xe0,0x71,0x43,
  84. 0xd9,0xf4,0x44,0x08,0x80,0x8e,0xad,0xbd,0x11,0x4c,0xfa,0x43,0x40,0xb2,0x40,0x95,
  85. 0xd8,0x8d,0x19,0x85,0x4d,0x89,0x14,0xfb,0x29,0x58,0x35,0xed,0x83,0x8b,0x61,0x35,
  86. 0x3c,0xd6,0x18,0xaa,0xe0,0xad,0x73,0x11,0x24,0x61,0x69,0x7b,0x14,0x56,0xf9,0x95,
  87. 0x48,0xfc,0x02,0xe9,0xf7,0xf1,0x28,0x15,0x4c,0xa0,0x73,0xc5,0x29,0x7d,0xab,0x4c,
  88. 0x67,0xd9,0xc5,0xd0,0x86,0xec,0x38,0xb9,0xa8,0x21,0xf4,0x53,0x78,0x78,0x3c,0xc6,
  89. 0xfb,0x12,0xe5,0xb3,0x94,0x37,0x7e,0x19,0x53,0xc1,0x75,0x03,0x57,0xab,0x59,0x2a,
  90. 0xcc,0x9a,0x60,0x34,0x08,0x8f,0x1e,0x36,0xec,0x89,0xb8,0x27,0xdc,0x8d,0x3d,0x2d,
  91. 0xbd,0x3f,0x5e,0x54,0x12,0x5f,0x6a,0x2c,0xfc,0x17,0x9a,0x92,0xc0,0x38,0x7f,0x7c,
  92. 0x67,0x37,0x47,0x8e,0x0e,0x1d,0x95,0x2c,0x10,0x0d,0x73,0xcd,0x9d,0x56,0x2c,0x68,
  93. 0x5b,0x05,0x2f,0xf5,0x07,0x5d,0x78,0x29,0xf6,0xbb,0x22,0xb8,0x58,0x8c,0x85,0x89,
  94. 0xe2,0x89,0x1c,0xd1,0x83,0x0f,0x8d,0x2e,0x4f,0xe8,0xff,0x6c,0x3f,0x99,0x4d,0xa7,
  95. 0xca,0x15,0xa9,0x59,0xea,0x33,0x25,0xff,0x80,0xaf,0x88,0x6e,0x93,0x0d,0xab,0x61,
  96. 0x00,0x18,0x11,0x9a,0x67,0xda,0x42,0x83,0xf8,0xf7,0x8d,0x19,0x3c,0xe4,0x36,0x64,
  97. 0x69,0xf0,0x07,0x55,0x7f,0x1f,0x23,0xbf,0x03,0x55,0xb0,0x5c,0x08,0x84,0x4b,0xc1,
  98. 0x0a,0xb9,0x53,0x75,0x9a,0x09,0x0b,0x37,0x55,0x63,0x9c,0xa5,0x7f,0x62,0xab,0x34,
  99. 0x1e,0xb4,0x24,0x48,0x83,0x57,0x93,0xff,0x1f,0x08,0x03,0x5c,0xe6,0xb6,0x6f,0x9b,
  100. 0x98,0x97,0x69,0x97,0xdb,0x67,0xc9,0xd7,0x84,0x66,0xc9,0xb6,0x9f,0x40,0x07,0x4b,
  101. 0x93,0x95,0x6d,0x9f,0x65,0xe6,0xcf,0xba,0x9d,0x70,0xa7,0x0b,0x2f,0x95,0x4c,0xdd,
  102. 0x1e,0xcc,0xfc,0x9c,0x35,0x89,0x70,0xa5,0x66,0xcc,0x1b,0x73,0xd8,0xf6,0x88,0x55,
  103. 0xb7,0x8f,0x7a,0x90,0xc0,0xba,0x35,0x2f,0xac,0x03,0x4c,0x7c,0x74,0x49,0xa7,0xc5,
  104. 0xb5,0x0b,0x26,0x09,0x66,0xbb,0xf0,0x1e,0x19,0x96,0xbc,0xc1,0x3c,0x2f,0x0e,0x36,
  105. 0x31,0x2b,0x04,0x3e,0x6a,0x4f,0x39,0x7f,0xeb,0x05,0x74,0x53,0xdf,0x67,0xac,0xb6,
  106. 0x5c,0xe1,0xe5,0xc7,0x5f,0x25,0x34,0xd2,0xe3,0x83,0x62,0x33,0xe6,0x10,0x8d,0xa4,
  107. 0x59,0x1d,0x36,0xc8,0xe9,0xbf,0xf8,0x0e,0x0d,0xb5,0x5a,0xef,0x77,0x10,0x10,0x6e,
  108. 0xb1,0xe7,0x0c,0xc7,0x7d,0x37,0x1d,0x17,0x67,0xa7,0x2e,0xbe,0x56,0x27,0x38,0x03,
  109. 0xbb,0x3a,0x0b,0x11,0x16,0x82,0xb7,0x22,0x64,0xb1,0x42,0x07,0x05,0x60,0xb6,0xfe,
  110. 0xa0,0x4c,0x27,0x68,0xa6,0xc2,0x46,0x33,0x05,0x07,0xdc,0x26,0x69,0xd7,0xda,0x87,
  111. 0x6a,0x70,0x91,0xf9,0x90,0x65,0x35,0xab,0x2c,0xf7,0xe2,0x20,0xb3,0xdb,0x6c,0xa2,
  112. 0xb6,0xd7,0x8f,0x77,0xed,0x55,0x82,0x6a,0x25,0xd2,0xa4,0xa3,0x47,0x0d,0x6b,0x4e,
  113. 0x19,0x77,0xb2,0x04,0x6a,0x70,0x47,0x19,0x73,0x82,0x45,0x51,0xc2,0xc1,0xa1,0x5d,
  114. 0xa7,0xd5,0x98,0x7e,0xd1,0x01,0x44,0x64,0xb2,0xeb,0x94,0x0c,0x8e,0x68,0xaf,0xc7,
  115. 0x61,0x31,0x15,0xe6,0x21,0xc1,0x76,0x43,0x77,0x56,0xa2,0xd6,0xcb,0x7a,0x7d,0x73,
  116. 0xd2,0xea,0xd8,0x35,0xfb,0x2c,0x5c,0x38,0xe8,0x4c,0x89,0x9c,0x9d,0x8f,0x6c,0x42,
  117. 0x88,0x80,0x98,0x6c,0xc9,0x3d,0x6a,0x6c,0xbe,0xdd,0xfc,0xd4,0x15,0x68,0xf1,0xc6,
  118. 0xf4,0x41,0x7f,0x27,0x4f,0xf3,0x91,0x0f,0x88,0xa7,0x3a,0xba,0x45,0x32,0x44,0xe5,
  119. 0xed,0xd7,0x20,0x64,0xbc,0xb6,0x61,0x21,0x5a,0x0a,0x52,0x88,0x56,0x79,0x73,0x41,
  120. 0xf0,0x3a,0x71,0x60,0x58,0x0d,0x0b,0xb9,0x58,0x1f,0x07,0xb0,0x07,0xe2,0x02,0xb0,
  121. 0xe7,0x44,0x1b,0x8d,0xf8,0x5f,0x26,0xf1,0xf3,0x28,0x40,0x38,0x74,0x6e,0xfb,0xda,
  122. 0x2b,0xb1,0x03,0x03,0x5c,0x34,0x55,0x12,0x05,0x65,0xfd,0xb6,0xfd,0xe0,0xd5,0xe4,
  123. 0xb9,0xca,0x75,0x64,0xef,0xd3,0x6f,0xb6,0x58,0xfe,0xf2,0x41,0x9a,0x6b,0xf1,0xef,
  124. 0x7e,0xe5,0x29,0xb3,0xf5,0x30,0x47,0x0a,0x8c,0xa5,0x5b,0x19,0x19,0xbe,0x64,0x76,
  125. 0x8b,0x1b,0xf7,0xd6,0x2a,0xdc,0x2b,0xcc,0x9a,0x99,0x8b,0x8a,0x05,0x84,0xf9,0x4a,
  126. 0x70,0x64,0xef,0xb2,0xbc,0x32,0x05,0xee,0x68,0xc0,0x7d,0x42,0x66,0x44,0xde,0x70,
  127. 0x32,0x5b,0xa3,0xe9,0xa3,0xdf,0xbd,0xd3,0xe0,0xcd,0x73,0xaf,0x4b,0x39,0x5c,0x3e,
  128. 0x64,0x57,0xe8,0xbc,0x9f,0x4a,0x17,0x8d,0x89,0xa9,0x43,0x29,0x3a,0xfe,0xe4,0x76,
  129. 0xaa,0x59,0x55,0xde,0x39,0xfc,0x4a,0x2f,0x4f,0x31,0x78,0x5c,0xde,0xd8,0x69,0x98,
  130. 0x06,0xa2,0x43,0xa2,0xbc,0xf2,0xa4,0x4d,0x04,0x6f,0xb3,0xd0,0xaf,0xd5,0xf2,0xa8,
  131. 0xc4,0xd8,0x92,0xa7,0x36,0xe2,0xe9,0xdf,0x6d,0x84,0xa9,0x36,0x5f,0x20,0x51,0x0d,
  132. 0x00,0x88};
  133. #define LOG( X ) m_pLog->Log( "OPFLOW", this, X )
  134. #define LOG_ERROR( X ) m_pLog->Log( "OPFLOW", this, _LOG_ERROR, X )
  135. opticFlow::opticFlow( config_setting_t *Settings, PATHFINDER_DBC *DBC ):basicThread(){
  136. m_pLog = basicLogCollection::getInstance();
  137. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "OPTIC_FLOW" );
  138. m_pBLOG = objectPathfinderBinaryLog::getInstance();
  139. m_pDBC = DBC;
  140. m_pBus = NULL;
  141. m_bWM = OF_WM_PICTURES;
  142. };
  143. opticFlow::~opticFlow(){
  144. waitThreadEnd( true );
  145. if( m_pBus != NULL ) delete( m_pBus );
  146. };
  147. // https://github.com/x75/adsn3080-emd/blob/master/ADNS3080-getmotion.c
  148. bool opticFlow::create(){
  149. uint8_t prodID;
  150. uint8_t revID;
  151. char tBuffer[128];
  152. m_pBus = new spiPort( "/dev/spidev0.0", 500000 );
  153. if( m_pBus == NULL ){
  154. LOG_ERROR("Failed to open the SPI bus.");
  155. return false;
  156. };
  157. prodID = m_pBus->read8( OF_SROM_PRODUCT_ID );
  158. usleep(10);
  159. revID = m_pBus->read8( OF_SROM_REVISION_ID );
  160. sprintf( tBuffer, "ADNS3080 ProductID: %d Rev. %d", prodID, revID );
  161. LOG( tBuffer );
  162. if( prodID != 0x17 ){
  163. LOG_ERROR("SPI communication failed");
  164. return false;
  165. } else {
  166. LOG("Load SROM");
  167. if( ! uploadSRAM() ) {
  168. LOG_ERROR("Loading failure");
  169. return false;
  170. };
  171. m_nConfigB = m_pBus->read8( OF_SROM_CONFIG_BITS );
  172. m_nConfigE = m_pBus->read8( OF_SROM_EXTEND_CONFIG );
  173. //Apply config
  174. m_nConfigB |= OF_REG_CB_RES;
  175. m_pBus->write8( OF_SROM_CONFIG_BITS, m_nConfigB );
  176. SLEEP( 10 );
  177. m_nConfigB = m_pBus->read8( OF_SROM_CONFIG_BITS );
  178. sprintf( tBuffer, "Current Config: 0x%02X 0x%02X", m_nConfigB, m_nConfigE );
  179. LOG( tBuffer );
  180. #ifdef DEBUG
  181. if( ( OF_REG_CB_NLED & m_nConfigB ) == OF_REG_CB_NLED ) {
  182. LOG("Shutter mode On (LED only on when illumination is required)");
  183. } else {
  184. LOG("Shutter mode Off (LED always on)");
  185. };
  186. if( ( OF_REG_CB_STEST & m_nConfigB ) == OF_REG_CB_STEST ) {
  187. LOG("Perform all System Tests");
  188. } else {
  189. LOG("No Tests");
  190. };
  191. if( ( OF_REG_CB_RES & m_nConfigB ) == OF_REG_CB_RES ) {
  192. LOG("Resolution 1600 DPI");
  193. } else {
  194. LOG("Resolution 400 DPI");
  195. };
  196. if( ( OF_REG_ECB_BUSY & m_nConfigE ) == OF_REG_ECB_BUSY ) {
  197. LOG("Write to the registers BUSY");
  198. } else {
  199. LOG("Writing to the registers is allowed");
  200. };
  201. if( ( OF_REG_ECB_NPU & m_nConfigE ) == OF_REG_ECB_NPU ) {
  202. LOG("Enable serial port pull-up");
  203. } else {
  204. LOG("Disable serial port pull-up");
  205. };
  206. if( ( OF_REG_ECB_NAGC & m_nConfigE ) == OF_REG_ECB_NAGC ) {
  207. LOG("AGC is disabled");
  208. } else {
  209. LOG("AGC is active");
  210. };
  211. if( ( OF_REG_ECB_FFR & m_nConfigE ) == OF_REG_ECB_FFR ) {
  212. LOG("Fixed frame rate");
  213. } else {
  214. LOG("Automatic frame rate");
  215. };
  216. #endif
  217. if( m_pDBC != NULL ) {
  218. m_pDBC->setOpfMode( 1 );
  219. };
  220. readBurstPixels();
  221. };
  222. return init();
  223. };
  224. void opticFlow::m_fThreadProc( void ){
  225. uint32_t pic_idx = 0;
  226. m_bThreadStatus = TH_WORKING;
  227. while( m_bThreadStatus < TH_ENDED ){
  228. switch( m_bWM ) {
  229. case OF_WM_PICTURES:{
  230. if( readBurstPixels( pic_idx, false ) ) pic_idx++;
  231. break;
  232. };
  233. case OF_WM_MOVEMENT:{
  234. PF_TIMESTAMP ts;
  235. if( readBurstMotion() ) {
  236. getPFTS(&ts);
  237. m_sEvent.seconds = ts.seconds;
  238. m_sEvent.milliseconds = ts.milliseconds;
  239. m_sEvent.bFLAGS = m_sMotion.bFLAGS;
  240. m_sEvent.dX = m_sMotion.dX;
  241. m_sEvent.dY = m_sMotion.dY;
  242. m_sEvent.bSurfaceQuality = m_sMotion.bSurfaceQuality;
  243. m_sEvent.bMaxPixel = m_sMotion.bMaxPixel;
  244. if( m_pBLOG!= NULL ) {
  245. m_pBLOG->registerOPF( &m_sEvent );
  246. };
  247. if( ( m_sMotion.bFLAGS & OF_MO_FLG_MD )== OF_MO_FLG_MD ){
  248. if( m_pDBC != NULL ) {
  249. m_pDBC->updateOPF_MOV( &ts, &m_sMotion );
  250. };
  251. };
  252. };
  253. break;
  254. };
  255. case OF_WM_SWITCH2MOV:{
  256. if( uploadSRAM() ) {
  257. m_bWM = OF_WM_MOVEMENT;
  258. m_pDBC->setOpfMode( 0 );
  259. } else {
  260. m_bWM = OF_WM_PICTURES;
  261. };
  262. break;
  263. };
  264. case OF_WM_SWITCH2PIC:{
  265. if( readBurstPixels() ){
  266. m_bWM = OF_WM_PICTURES;
  267. m_pDBC->setOpfMode( 1 );
  268. } else {
  269. m_bWM = OF_WM_MOVEMENT;
  270. };
  271. break;
  272. };
  273. };
  274. SLEEP(100);
  275. };
  276. };
  277. bool opticFlow::resetChip(){
  278. digitalWrite( OF_RESET_PIN, 1 );
  279. usleep(100);
  280. digitalWrite( OF_RESET_PIN, 0 );
  281. usleep(35000);
  282. return true;
  283. };
  284. bool opticFlow::resetMotion(){
  285. if( m_pBus == NULL )return false;
  286. m_pBus->write8( OF_SROM_MOTION_CLR, 0xFF );
  287. return true;
  288. };
  289. bool opticFlow::setMode( uint8_t mode ){
  290. if( m_pBus == NULL )return false;
  291. if( m_bWM == mode ) return true;
  292. if( mode == OF_WM_PICTURES ) {
  293. m_bWM = OF_WM_SWITCH2PIC;
  294. return true;
  295. };
  296. if( mode == OF_WM_MOVEMENT ) {
  297. m_bWM = OF_WM_SWITCH2MOV;
  298. return true;
  299. };
  300. return false;
  301. };
  302. bool opticFlow::uploadSRAM(){
  303. if( m_pBus == NULL )return false;
  304. resetChip();
  305. m_pBus->write8( 0x20, 0x44 );
  306. m_pBus->write8( 0x23, 0x07 );
  307. m_pBus->write8( 0x24, 0x88 );
  308. usleep( 10000 );
  309. m_pBus->write8( OF_SROM_ENABLE, 0x18 );
  310. m_pBus->writeMZ( OF_SROM_LOAD, (uint8_t *)&SROM, 1986 );
  311. usleep( 200 );
  312. m_pBus->write8( OF_SROM_ENABLE, 0xA1 );
  313. usleep( 10000 );
  314. uint8_t dL, dH, stt;
  315. uint16_t tCS;
  316. dL = m_pBus->read8( OF_SROM_DATA_OUT_LB );
  317. dH = m_pBus->read8( OF_SROM_DATA_OUT_HB );
  318. tCS = dH;
  319. tCS = ( tCS << 8 ) | dL;
  320. #ifdef DEBUG
  321. char tBuff[64];
  322. sprintf( tBuff, "SROM CS=0x%04X Must be: 0x%04X", tCS, OF_SROM_CS );
  323. LOG( tBuff );
  324. #endif
  325. if( tCS != OF_SROM_CS ) return false;
  326. m_pBus->write8( OF_SROM_OBSERVATION, 0x00 );
  327. usleep( 10000 );
  328. stt = m_pBus->read8( OF_SROM_OBSERVATION );
  329. #ifdef DEBUG
  330. sprintf( tBuff, "SROM Observation: 0x%02X", stt );
  331. LOG( tBuff );
  332. #endif
  333. return true;
  334. };
  335. bool opticFlow::readBurstMotion(){
  336. if( m_pBus == NULL )return false;
  337. //memset(&m_sMotion, 0, sizeof(OPF_MOTION));
  338. return m_pBus->readMZ( OF_SROM_MOTION_BURST, (uint8_t *)&m_sMotion, sizeof(OPF_MOTION));
  339. };
  340. bool opticFlow::readBurstPixels( uint32_t idx, bool wm_srom ){
  341. uint8_t fBuffer[900];
  342. PF_TIMESTAMP * tTS = NULL;
  343. if( m_pBus == NULL ) return false;
  344. if( m_pBus->write8( OF_SROM_FRAME_CAP, 0x83 ) ){
  345. tTS = getPFTS();
  346. if( tTS != NULL ){
  347. usleep( 1510 );
  348. if( m_pBus->readMZ( OF_SROM_PIXEL_BURST, (uint8_t *)fBuffer, 900 ) ){
  349. for( int i = 0; i < 900; i++ ) {
  350. fBuffer[i] = ( fBuffer[i] & 0x3f ) << 2;
  351. };
  352. if( m_pDBC == NULL ){
  353. char tBuff[64];
  354. sprintf( tBuff, "pic_%05d.png", idx );
  355. stbi_write_png( tBuff, 30, 30, 1, (const void *)fBuffer, 30);
  356. } else {
  357. int olen;
  358. uint8_t * tPtr;
  359. tPtr = stbi_write_png_to_mem( fBuffer, 30, 30, 30, 1, &olen );
  360. if( tPtr!= NULL ) {
  361. m_pDBC->updateOPF_PIC( tTS, tPtr, olen );
  362. free( tPtr );
  363. };
  364. };
  365. free( tTS );
  366. resetChip();
  367. if( wm_srom ) return uploadSRAM();
  368. return true;
  369. };
  370. };
  371. free( tTS );
  372. };
  373. return false;
  374. };
  375. bool opticFlow::isDead(){
  376. return false;
  377. };
  378. #undef LOG
  379. #undef LOG_ERROR