For this, i am connecting 3 buttons to the esp32 TOUCH pins.
Code: Select all
touchAttachInterrupt(T0, gotLeftClick, 15);
touchAttachInterrupt(T5, gotMiddleClick, 25);
touchAttachInterrupt(T3, gotRightClick, 15);
Code: Select all
volatile bool midleClickDetected = false;
void gotLeftClick(){
buttons |= 0x01 ;
}
void gotRightClick(){
buttons |= 0x02 ;
}
void gotMiddleClick(){
midleClickDetected = true ;
}
it all goes bad.
Firstly, no buttons work.
secondly, after some time, the program just crashes and stops working all together (nothing in the serial monitor).
Here is the function in which I send the clicks:
Code: Select all
void getDisplacement () {
timeInMillis = millis() - start ;
if (timeInMillis >= 35) {
prevLcState = false ;
mpu.dmpGetQuaternion(&q, fifoBuffer);
dmpGetYawPitchRoll(q_a , &q, &gravity);
double x = cos(q_a[0]) * cos(q_a[2]);
double y = sin(q_a[0]) * cos(q_a[2]);
double z = sin(q_a[2]);
double t = 2000/x;
x = t*x;
y = t*y;
z = t*z;
z+=2040;
if (abs(z) > 4095)
z = 4095;
y+=2040;
if (abs(y) > 4095)
y = 4095;
if (z < 0) z = 0 ;
if (y < 0) y = 0 ;
int16_t scroll = 0;
if (midleClickDetected) {
scroll = z-2040;
}
uint8_t val[] = {
(uint8_t)buttons,
lowByte((uint16_t)y) ,
highByte((uint16_t)y) ,
lowByte((uint16_t)z) ,
highByte((uint16_t)z),
highByte((uint16_t)z),
highByte(scroll) <<3};
input->setValue(val, 6);
input->notify();
buttons = 0 ;
midleClickDetected = false ;
// //mouse.move((char)y , (char) z);
start = millis() ;
// movement_end_check();
}
}