LibDriver PMW3901MB
Loading...
Searching...
No Matches
driver_pmw3901mb_read_test.c
Go to the documentation of this file.
1
36
38
39static pmw3901mb_handle_t gs_handle;
40
50uint8_t pmw3901mb_read_test(float height_m, uint32_t times)
51{
52 uint8_t res;
54
55 /* link interface function */
66
67 /* get information */
68 res = pmw3901mb_info(&info);
69 if (res != 0)
70 {
71 pmw3901mb_interface_debug_print("pmw3901mb: get info failed.\n");
72
73 return 1;
74 }
75 else
76 {
77 /* print chip info */
78 pmw3901mb_interface_debug_print("pmw3901mb: chip is %s.\n", info.chip_name);
79 pmw3901mb_interface_debug_print("pmw3901mb: manufacturer is %s.\n", info.manufacturer_name);
80 pmw3901mb_interface_debug_print("pmw3901mb: interface is %s.\n", info.interface);
81 pmw3901mb_interface_debug_print("pmw3901mb: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
82 pmw3901mb_interface_debug_print("pmw3901mb: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
83 pmw3901mb_interface_debug_print("pmw3901mb: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
84 pmw3901mb_interface_debug_print("pmw3901mb: max current is %0.2fmA.\n", info.max_current_ma);
85 pmw3901mb_interface_debug_print("pmw3901mb: max temperature is %0.1fC.\n", info.temperature_max);
86 pmw3901mb_interface_debug_print("pmw3901mb: min temperature is %0.1fC.\n", info.temperature_min);
87 }
88
89 /* start the read test */
90 pmw3901mb_interface_debug_print("pmw3901mb: start the read test.\n");
91
92 /* init pmw3901mb */
93 res = pmw3901mb_init(&gs_handle);
94 if (res != 0)
95 {
96 pmw3901mb_interface_debug_print("pmw3901mb: init failed.\n");
97
98 return 1;
99 }
100
101 /* chip power up */
102 res = pmw3901mb_power_up(&gs_handle);
103 if (res != 0)
104 {
105 pmw3901mb_interface_debug_print("pmw3901mb: power up failed.\n");
106 (void)pmw3901mb_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set optimum performance */
112 res = pmw3901mb_set_optimum_performance(&gs_handle);
113 if (res != 0)
114 {
115 pmw3901mb_interface_debug_print("pmw3901mb: set optimum performance failed.\n");
116 (void)pmw3901mb_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* wait */
122 while (times != 0)
123 {
124 float delta_x;
125 float delta_y;
126 pmw3901mb_motion_t motion;
127
128 start:
129
130 /* burst read */
131 res = pmw3901mb_burst_read(&gs_handle, &motion);
132 if (res != 0)
133 {
134 pmw3901mb_interface_debug_print("pmw3901mb: burst read failed.\n");
135
136 return 1;
137 }
138
139 /* check the result */
140 if (motion.is_valid == 1)
141 {
142 /* convert the delta x */
143 res = pmw3901mb_delta_raw_to_delta_cm(&gs_handle, motion.delta_x, height_m, (float *)&delta_x);
144 if (res != 0)
145 {
146 pmw3901mb_interface_debug_print("pmw3901mb: delta raw to delta cm failed.\n");
147
148 return 1;
149 }
150
151 /* convert the delta y */
152 res = pmw3901mb_delta_raw_to_delta_cm(&gs_handle, motion.delta_y, height_m, (float *)&delta_y);
153 if (res != 0)
154 {
155 pmw3901mb_interface_debug_print("pmw3901mb: delta raw to delta cm failed.\n");
156
157 return 1;
158 }
159
160 /* print the result */
161 pmw3901mb_interface_debug_print("pmw3901mb: delta_x: %0.3fcm delta_y: %0.3fcm.\n", delta_x, delta_y);
162 pmw3901mb_interface_debug_print("pmw3901mb: raw_average is 0x%02X.\n", motion.raw_average);
163 pmw3901mb_interface_debug_print("pmw3901mb: raw_max is 0x%02X.\n", motion.raw_max);
164 pmw3901mb_interface_debug_print("pmw3901mb: raw_min is 0x%02X.\n", motion.raw_min);
165 pmw3901mb_interface_debug_print("pmw3901mb: observation is 0x%02X.\n", motion.observation);
166 pmw3901mb_interface_debug_print("pmw3901mb: shutter is 0x%04X.\n", motion.shutter);
167 pmw3901mb_interface_debug_print("pmw3901mb: surface quality is 0x%04X.\n", motion.surface_quality);
168 }
169 else
170 {
172
173 goto start;
174 }
175
176 times--;
177 }
178
179 /* finish the read test */
180 pmw3901mb_interface_debug_print("pmw3901mb: finish the read test.\n");
181 (void)pmw3901mb_deinit(&gs_handle);
182
183 return 0;
184}
driver pmw3901mb read test header file
uint8_t pmw3901mb_init(pmw3901mb_handle_t *handle)
initialize the chip
struct pmw3901mb_handle_s pmw3901mb_handle_t
pmw3901mb handle structure definition
struct pmw3901mb_info_s pmw3901mb_info_t
pmw3901mb information structure definition
uint8_t pmw3901mb_set_optimum_performance(pmw3901mb_handle_t *handle)
set the optimum performance
uint8_t pmw3901mb_power_up(pmw3901mb_handle_t *handle)
power up the chip
uint8_t pmw3901mb_info(pmw3901mb_info_t *info)
get chip's information
struct pmw3901mb_motion_s pmw3901mb_motion_t
pmw3901mb motion structure definition
uint8_t pmw3901mb_delta_raw_to_delta_cm(pmw3901mb_handle_t *handle, int16_t raw, float height_m, float *cm)
convert the delta raw to the delta cm
uint8_t pmw3901mb_deinit(pmw3901mb_handle_t *handle)
close the chip
uint8_t pmw3901mb_burst_read(pmw3901mb_handle_t *handle, pmw3901mb_motion_t *motion)
burst read data
void pmw3901mb_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t pmw3901mb_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t pmw3901mb_interface_spi_deinit(void)
interface spi bus deinit
uint8_t pmw3901mb_interface_reset_gpio_write(uint8_t data)
interface reset gpio write
uint8_t pmw3901mb_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t pmw3901mb_interface_spi_init(void)
interface spi bus init
uint8_t pmw3901mb_interface_reset_gpio_deinit(void)
interface reset gpio deinit
void pmw3901mb_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t pmw3901mb_interface_reset_gpio_init(void)
interface reset gpio init
uint8_t pmw3901mb_read_test(float height_m, uint32_t times)
read test