diff --git a/examples/absolute_mode/absolute_mode.ino b/examples/absolute_mode/absolute_mode.ino index 57917c0..6e84f8b 100644 --- a/examples/absolute_mode/absolute_mode.ino +++ b/examples/absolute_mode/absolute_mode.ino @@ -16,6 +16,15 @@ PinnacleTouchSPI trackpad(DR_PIN, SS_PIN); // an object to hold data reported by the Cirque trackpad AbsoluteReport data; +#if DR_PIN != PINNACLE_SW_DR +// track the interrupts with our own IRQ flag +volatile bool isDataReady = false; + +void interruptHandler() { + isDataReady = true; +} +#endif // using DR_PIN + void setup() { Serial.begin(115200); while (!Serial) { @@ -30,6 +39,10 @@ void setup() { Serial.println(F("CirquePinnacle/examples/absolute_mode")); trackpad.setDataMode(PINNACLE_ABSOLUTE); trackpad.absoluteModeConfig(1); // set count of z-idle packets to 1 +#if DR_PIN != PINNACLE_SW_DR + // pinMode() is already called by trackpad.begin() + attachInterrupt(digitalPinToInterrupt(DR_PIN), interruptHandler, FALLING); +#endif // using DR_PIN Serial.println(F("\n*** Enter 'M' to measure and print raw data.")); Serial.println(F("*** Enter 'T' to measure and print trigonometric calculations.\n")); Serial.println(F("Touch the trackpad to see the data.")); @@ -43,14 +56,20 @@ raw data (false) or trigonometry data (true) */ bool onlyShowTrigVals = false; -#ifndef M_PI +#if defined(M_PI) && !defined(PI) #define PI M_PI -#else +#endif +#ifndef PI #define PI 3.14159 #endif void loop() { +#if DR_PIN == PINNACLE_SW_DR // not using DR_PIN if (trackpad.available()) { +#else // using interruptHandler() + if (isDataReady) { + isDataReady = false; // reset our IRQ flag +#endif // using DR_PIN trackpad.read(&data); // datasheet recommends clamping the axes value to reliable range diff --git a/examples/anymeas_mode/anymeas_mode.ino b/examples/anymeas_mode/anymeas_mode.ino index 5277356..fbc6d6e 100644 --- a/examples/anymeas_mode/anymeas_mode.ino +++ b/examples/anymeas_mode/anymeas_mode.ino @@ -48,6 +48,18 @@ void compensate() { } } +// track the interrupts with our own IRQ flag +volatile bool isDataReady = false; + +// a flag to control iteration of our loop() +bool waitingForInterrupt = false; +// the index number used to iterate through our vectorDeterminants array used in loop() +unsigned int vectorIndex = 0; + +void interruptHandler() { + isDataReady = true; +} + void setup() { Serial.begin(115200); while (!Serial) { @@ -63,20 +75,36 @@ void setup() { trackpad.setDataMode(PINNACLE_ANYMEAS); trackpad.anymeasModeConfig(); compensate(); + // pinMode() is already called by trackpad.begin() + attachInterrupt(digitalPinToInterrupt(DR_PIN), interruptHandler, FALLING); Serial.println(F("starting in 5 seconds...")); delay(5000); } void loop() { - for (uint8_t i = 0; i < variousVectors_size; i++) { - int16_t measurement = trackpad.measureAdc(vectorDeterminants[i].toggle, - vectorDeterminants[i].polarity); - measurement -= compensations[i]; + if (!isDataReady && !waitingForInterrupt) { + trackpad.startMeasureAdc( + vectorDeterminants[vectorIndex].toggle, + vectorDeterminants[vectorIndex].polarity); + waitingForInterrupt = true; + } else if (isDataReady) { + isDataReady = false; // reset our IRQ flag + waitingForInterrupt = false; // allow iteration to continue + + int16_t measurement = trackpad.getMeasureAdc(); + measurement -= compensations[vectorIndex]; Serial.print(F("meas")); - Serial.print(i); + Serial.print(vectorIndex); Serial.print(F(":")); Serial.print(measurement); Serial.print(F(" \t")); + + // increment our loop iterator + if (vectorIndex < (variousVectors_size - 1)) { + vectorIndex++; + } else { + vectorIndex = 0; + Serial.println(); + } } - Serial.println(); } diff --git a/examples/relative_mode/relative_mode.ino b/examples/relative_mode/relative_mode.ino index ca84274..9180c26 100644 --- a/examples/relative_mode/relative_mode.ino +++ b/examples/relative_mode/relative_mode.ino @@ -15,6 +15,15 @@ PinnacleTouchSPI trackpad(DR_PIN, SS_PIN); // an object to hold data reported by the Cirque trackpad RelativeReport data; +#if DR_PIN != PINNACLE_SW_DR +// track the interrupts with our own IRQ flag +volatile bool isDataReady = false; + +void interruptHandler() { + isDataReady = true; +} +#endif // using DR_PIN + void setup() { Serial.begin(115200); while (!Serial) { @@ -29,11 +38,21 @@ void setup() { Serial.println(F("CirquePinnacle/examples/relative_mode")); trackpad.setDataMode(PINNACLE_RELATIVE); trackpad.relativeModeConfig(); // uses default config +#if DR_PIN != PINNACLE_SW_DR + // pinMode() is already called by trackpad.begin() + attachInterrupt(digitalPinToInterrupt(DR_PIN), interruptHandler, FALLING); +#endif // using DR_PIN Serial.println(F("Touch the trackpad to see the data.")); } void loop() { + +#if DR_PIN == PINNACLE_SW_DR // not using DR_PIN if (trackpad.available()) { +#else // using interruptHandler() + if (isDataReady) { + isDataReady = false; // reset our IRQ flag +#endif // using DR_PIN trackpad.read(&data); Serial.print(F("Left:")); Serial.print(data.buttons & 1); diff --git a/examples/usb_mouse/usb_mouse.ino b/examples/usb_mouse/usb_mouse.ino index 089a22f..aa293ff 100644 --- a/examples/usb_mouse/usb_mouse.ino +++ b/examples/usb_mouse/usb_mouse.ino @@ -12,6 +12,15 @@ PinnacleTouchSPI trackpad(DR_PIN, SS_PIN); // an object to hold data reported by the Cirque trackpad RelativeReport data; +#if DR_PIN != PINNACLE_SW_DR +// track the interrupts with our own IRQ flag +volatile bool isDataReady = false; + +void interruptHandler() { + isDataReady = true; +} +#endif // using DR_PIN + const uint32_t interval = 750; // milliseconds used to blink LED uint32_t lastLedChange = 0; // millis() since last digitalWrite() bool ledState = false; // last state sent to digitalWrite() @@ -31,7 +40,10 @@ void setup() { trackpad.setDataMode(PINNACLE_RELATIVE); // ensure mouse mode is enabled // tell the Pinnacle ASIC to rotate the orientation of the axis data by +90 degrees trackpad.relativeModeConfig(true, true); // (enable taps, rotate90) - +#if DR_PIN != PINNACLE_SW_DR + // pinMode() is already called by trackpad.begin() + attachInterrupt(digitalPinToInterrupt(DR_PIN), interruptHandler, FALLING); +#endif // using DR_PIN digitalWrite(LED, LOW); lastLedChange = millis(); @@ -39,7 +51,12 @@ void setup() { void loop() { - if (trackpad.available()) { // is there new data? +#if DR_PIN == PINNACLE_SW_DR // not using DR_PIN + if (trackpad.available()) { +#else // using interruptHandler() + if (isDataReady) { + isDataReady = false; // reset our IRQ flag +#endif // using DR_PIN // save buttons' previous state before getting updates uint8_t prevButtonStates = data.buttons; // for edge detection