62#ifndef SENSOR_SHUTDOWN
63#define SENSOR_SHUTDOWN 48
67#define SENSOR_FPD_INT 18
83#if SENSOR_SHUTDOWN != -1
93#if SENSOR_FPD_INT != -1
105 Serial.println(
"PAW-A350 sensor initialization failed!");
107 Serial.println(
"Ensure sensor is connected and I2C wiring is correct");
113 Serial.println(
" initialized successfully");
117 Serial.println(
"Software reset failed!");
120 Serial.println(
"Software reset successful");
122 Serial.println(
"\n========== ID Test ==========");
125 Serial.print(
"Product ID: 0x");
126 Serial.print(pid, HEX);
127 Serial.print(
" (expected 0x88)");
128 Serial.println(pid == 0x88 ?
" [OK]" :
" [FAIL]");
129 Serial.print(
"Revision ID: 0x");
130 Serial.println(rev, HEX);
132 Serial.println(
"\n========== CPI Test ==========");
134 Serial.print(
"Set CPI 125: ");
135 Serial.println(rslt ?
"OK" :
"FAILED");
136 Serial.print(
"Get CPI: ");
141 Serial.print(
"Set CPI 250: ");
142 Serial.println(rslt ?
"OK" :
"FAILED");
143 Serial.print(
"Get CPI: ");
148 Serial.print(
"Set CPI 500: ");
149 Serial.println(rslt ?
"OK" :
"FAILED");
150 Serial.print(
"Get CPI: ");
155 Serial.print(
"Set CPI 750: ");
156 Serial.println(rslt ?
"OK" :
"FAILED");
157 Serial.print(
"Get CPI: ");
162 Serial.print(
"Set CPI 1000: ");
163 Serial.println(rslt ?
"OK" :
"FAILED");
164 Serial.print(
"Get CPI: ");
169 Serial.print(
"Set CPI 1250: ");
170 Serial.println(rslt ?
"OK" :
"FAILED");
171 Serial.print(
"Get CPI: ");
175 Serial.println(
"\n========== Power Management Test ==========");
176 Serial.println(
"-- Run Downshift --");
178 Serial.print(
"Set RunDownshift(8): ");
179 Serial.println(rslt ?
"OK" :
"FAILED");
180 Serial.print(
"Get RunDownshift: ");
183 Serial.print(
"Get RunDownshiftMs: ");
188 Serial.print(
"Set RunDownshift(4): ");
189 Serial.println(rslt ?
"OK" :
"FAILED");
191 Serial.println(
"-- Rest1 Period --");
193 Serial.print(
"Set Rest1Period(9): ");
194 Serial.println(rslt ?
"OK" :
"FAILED");
195 Serial.print(
"Get Rest1Period: ");
198 Serial.print(
"Get Rest1PeriodMs: ");
203 Serial.print(
"Set Rest1Period(1): ");
204 Serial.println(rslt ?
"OK" :
"FAILED");
206 Serial.println(
"-- Rest1 Downshift --");
208 Serial.print(
"Set Rest1Downshift(50): ");
209 Serial.println(rslt ?
"OK" :
"FAILED");
210 Serial.print(
"Get Rest1Downshift: ");
215 Serial.print(
"Set Rest1Downshift(31): ");
216 Serial.println(rslt ?
"OK" :
"FAILED");
218 Serial.println(
"-- Rest2 Period --");
220 Serial.print(
"Set Rest2Period(19): ");
221 Serial.println(rslt ?
"OK" :
"FAILED");
222 Serial.print(
"Get Rest2Period: ");
225 Serial.print(
"Get Rest2PeriodMs: ");
230 Serial.print(
"Set Rest2Period(9): ");
231 Serial.println(rslt ?
"OK" :
"FAILED");
233 Serial.println(
"-- Rest2 Downshift --");
235 Serial.print(
"Set Rest2Downshift(100): ");
236 Serial.println(rslt ?
"OK" :
"FAILED");
237 Serial.print(
"Get Rest2Downshift: ");
242 Serial.print(
"Set Rest2Downshift(47): ");
243 Serial.println(rslt ?
"OK" :
"FAILED");
245 Serial.println(
"-- Rest3 Period --");
247 Serial.print(
"Set Rest3Period(99): ");
248 Serial.println(rslt ?
"OK" :
"FAILED");
249 Serial.print(
"Get Rest3Period: ");
252 Serial.print(
"Get Rest3PeriodMs: ");
257 Serial.print(
"Set Rest3Period(49): ");
258 Serial.println(rslt ?
"OK" :
"FAILED");
260 Serial.println(
"\n========== LED Control Test ==========");
262 Serial.print(
"Set LedOn(true): ");
263 Serial.println(rslt ?
"OK" :
"FAILED");
264 Serial.print(
"Get LedOn: ");
269 Serial.print(
"Set LedOn(false): ");
270 Serial.println(rslt ?
"OK" :
"FAILED");
271 Serial.print(
"Get LedOn: ");
275 Serial.println(
"-- LED Drive Current --");
277 Serial.print(
"Set LedDriveCurrent(0=13mA): ");
278 Serial.println(rslt ?
"OK" :
"FAILED");
279 Serial.print(
"Get LedDriveCurrent: ");
284 Serial.print(
"Set LedDriveCurrent(2=9.6mA): ");
285 Serial.println(rslt ?
"OK" :
"FAILED");
286 Serial.print(
"Get LedDriveCurrent: ");
291 Serial.print(
"Set LedDriveCurrent(7=27mA): ");
292 Serial.println(rslt ?
"OK" :
"FAILED");
293 Serial.print(
"Get LedDriveCurrent: ");
297 Serial.println(
"\n========== Shutter Test ==========");
299 Serial.print(
"Set ShutterMax(2000): ");
300 Serial.println(rslt ?
"OK" :
"FAILED");
301 Serial.print(
"Get ShutterMax: ");
306 Serial.print(
"Set ShutterMax(2929): ");
307 Serial.println(rslt ?
"OK" :
"FAILED");
308 Serial.print(
"Get ShutterMax: ");
312 Serial.println(
"\n========== Motion Interrupt Test ==========");
313 for (
int i = 0;
i <= 7;
i++) {
315 Serial.print(
"Set threshold(");
318 Serial.print(rslt ?
"OK" :
"FAILED");
319 Serial.print(
" Get: ");
324 Serial.println(
"\n========== Power Timing Summary ==========");
325 Serial.print(
"Run downshift: ");
327 Serial.println(
" ms");
328 Serial.print(
"Rest1 period: ");
330 Serial.println(
" ms");
331 Serial.print(
"Rest1 downshift: ");
333 Serial.println(
" s");
334 Serial.print(
"Rest2 period: ");
336 Serial.println(
" ms");
337 Serial.print(
"Rest2 downshift: ");
339 Serial.println(
" min");
340 Serial.print(
"Rest3 period: ");
342 Serial.println(
" ms");
347 Serial.println(
"\n========== Motion Detection Started ==========");
348 Serial.println(
"Move finger across sensor to detect motion");
349 Serial.println(
"------------------------------------------");
354 uint32_t currentTime = millis();
355 static uint32_t lastPrintTime = 0;
356 static int32_t cumulativeX = 0;
357 static int32_t cumulativeY = 0;
359#if SENSOR_FPD_INT != -1
360 static uint32_t proximityTriggerPrintInterval = 0;
363 if (millis() - proximityTriggerPrintInterval >= 1000) {
364 Serial.println(
"Finger proximity sensor triggered.");
365 proximityTriggerPrintInterval = millis();
381 if (currentTime - lastPrintTime >= 100) {
382 float inchesX = (float)cumulativeX / 1000.0f;
383 float inchesY = (float)cumulativeY / 1000.0f;
385 Serial.print(
"Motion: DX=");
387 Serial.print(
", DY=");
389 Serial.print(
", CumX=");
390 Serial.print(cumulativeX);
391 Serial.print(
", CumY=");
392 Serial.print(cumulativeY);
393 Serial.print(
", InchX=");
394 Serial.print(inchesX, 3);
395 Serial.print(
", InchY=");
396 Serial.print(inchesY, 3);
397 Serial.print(
", Time=");
398 Serial.println(currentTime);
400 lastPrintTime = currentTime;
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
PAW-A350 Optical Finger Navigation Sensor Driver.
uint32_t getRest2PeriodMs() const
Get Rest2 period in milliseconds.
bool checkMotion(MotionStatus &status)
Check motion status.
bool getLedOn() const
Get LED always-on status.
uint32_t getRest1PeriodMs() const
Get Rest1 period in milliseconds.
int getProductID() const
Get Product ID.
int getRest2DownshiftTime() const
Get Rest2 to Rest3 downshift time.
bool getMotionData(MotionData &data)
Get motion delta data.
bool setLedDriveCurrent(uint8_t current)
Set LED drive current.
int getRest1DownshiftTime() const
Get Rest1 to Rest2 downshift time.
int getRevisionID() const
Get Revision ID.
int getRest1Period() const
Get Rest1 frame period.
bool setRest1Period(uint8_t period)
Set Rest1 frame period.
@ CPI_125
125 CPI - Lowest resolution, largest range
@ CPI_500
500 CPI - Default resolution
@ CPI_1000
1000 CPI - Recommended for most applications
@ CPI_1250
1250 CPI - Highest resolution
bool setMotionInterruptThreshold(uint8_t threshold)
Set motion interrupt threshold.
uint32_t getRest2DownshiftTimeMs() const
Get Rest2 downshift time in milliseconds.
uint32_t getRunDownshiftTimeMs() const
Get Run downshift time in milliseconds.
int getRest2Period() const
Get Rest2 frame period.
int getRunDownshiftTime() const
Get Run to Rest1 downshift time.
CpiResolution getCpi() const
Get current CPI resolution.
bool setRest3Period(uint8_t period)
Set Rest3 frame period.
bool setLedOn(bool enable)
Enable/disable LED always-on mode.
int getRest3Period() const
Get Rest3 frame period.
const char * getChipName() const
Get chip name.
MotionStatus
Motion Detection Status.
@ MOTION_DETECTED
Motion occurred, data ready for reading.
int getMotionInterruptThreshold() const
Get motion interrupt threshold.
bool setShutterMax(uint16_t value)
Set shutter maximum open time.
bool setRest2Period(uint8_t period)
Set Rest2 frame period.
int getShutterMax() const
Get shutter maximum open time.
uint32_t getRest3PeriodMs() const
Get Rest3 period in milliseconds.
bool setRunDownshiftTime(uint8_t rd)
Set Run to Rest1 downshift time.
bool setRest2DownshiftTime(uint8_t r2d)
Set Rest2 to Rest3 downshift time.
bool setRest1DownshiftTime(uint8_t r1d)
Set Rest1 to Rest2 downshift time.
bool setCpi(CpiResolution cpi)
Set CPI resolution.
int getLedDriveCurrent() const
Get LED drive current setting.
uint32_t getRest1DownshiftTimeMs() const
Get Rest1 downshift time in milliseconds.
bool softReset()
Perform software reset.
volatile bool fingerStateChanged
volatile bool motionIrqTriggered
int8_t delta_x
X-axis movement (-128 to +127 counts)
int8_t delta_y
Y-axis movement (-128 to +127 counts)