mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2025-05-17 08:08:32 -04:00
Fix zraw assignment issue that was preventing touch press-and-hold from working
This commit is contained in:
parent
b3a7e34d1b
commit
e6fa6f935b
14
touch.cpp
14
touch.cpp
@ -6,7 +6,7 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
constexpr int16_t Z_THRESHOLD = 400;
|
constexpr int16_t Z_THRESHOLD = 400;
|
||||||
constexpr uint8_t MSEC_THRESHOLD = 3;
|
constexpr uint8_t MSEC_THRESHOLD = 3;//Max sample rate is 125kHz, but we'll limit ourselves conservatively
|
||||||
|
|
||||||
constexpr uint8_t START_COMMAND = 1 << 7;
|
constexpr uint8_t START_COMMAND = 1 << 7;
|
||||||
constexpr uint8_t CHANNEL_Y = 1 << 4;
|
constexpr uint8_t CHANNEL_Y = 1 << 4;
|
||||||
@ -58,8 +58,6 @@ uint16_t touchReadChannel(uint8_t channel_command){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void touch_update(){
|
void touch_update(){
|
||||||
zraw = 0;//Default value to report
|
|
||||||
|
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if (now - msraw < MSEC_THRESHOLD){
|
if (now - msraw < MSEC_THRESHOLD){
|
||||||
return;
|
return;
|
||||||
@ -73,12 +71,13 @@ void touch_update(){
|
|||||||
int16_t z2 = touchReadChannel(MEASURE_Z2);//~4095 when not pressed, decreases with pressure
|
int16_t z2 = touchReadChannel(MEASURE_Z2);//~4095 when not pressed, decreases with pressure
|
||||||
z += (4095 - z2);
|
z += (4095 - z2);
|
||||||
//Serial.print(F("z1:"));Serial.print(z1);Serial.print(F(" z2:"));Serial.print(z2);Serial.print(F(" z:"));Serial.println(z);
|
//Serial.print(F("z1:"));Serial.print(z1);Serial.print(F(" z2:"));Serial.print(z2);Serial.print(F(" z:"));Serial.println(z);
|
||||||
if (z < Z_THRESHOLD) {
|
|
||||||
|
zraw = z;
|
||||||
|
if (zraw < Z_THRESHOLD) {//Don't bother reading x/y if we're not being touched
|
||||||
digitalWrite(PIN_TOUCH_CS, HIGH);
|
digitalWrite(PIN_TOUCH_CS, HIGH);
|
||||||
SPI.endTransaction();
|
SPI.endTransaction();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
zraw = z;
|
|
||||||
|
|
||||||
// make 3 x-y measurements
|
// make 3 x-y measurements
|
||||||
int16_t data[6];
|
int16_t data[6];
|
||||||
@ -88,14 +87,13 @@ void touch_update(){
|
|||||||
data[3] = touchReadChannel(MEASURE_Y);
|
data[3] = touchReadChannel(MEASURE_Y);
|
||||||
data[4] = touchReadChannel(MEASURE_X);
|
data[4] = touchReadChannel(MEASURE_X);
|
||||||
data[5] = touchReadChannel(MEASURE_Y & ~POWER_ADC_REF);//Turn off sensor
|
data[5] = touchReadChannel(MEASURE_Y & ~POWER_ADC_REF);//Turn off sensor
|
||||||
|
|
||||||
digitalWrite(PIN_TOUCH_CS, HIGH);
|
digitalWrite(PIN_TOUCH_CS, HIGH);
|
||||||
SPI.endTransaction();
|
SPI.endTransaction();
|
||||||
|
|
||||||
int16_t x = touch_besttwoavg( data[0], data[2], data[4] );
|
int16_t x = touch_besttwoavg( data[0], data[2], data[4] );
|
||||||
int16_t y = touch_besttwoavg( data[1], data[3], data[5] );
|
int16_t y = touch_besttwoavg( data[1], data[3], data[5] );
|
||||||
|
|
||||||
//Serial.printf(" %d,%d", x, y);
|
|
||||||
//Serial.println();
|
|
||||||
msraw = now; // good read completed, set wait
|
msraw = now; // good read completed, set wait
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case 0:
|
case 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user