Go Down

Topic: [HELP] Mouse Double-Click with an ATtiny85 ? (Read 1 time) previous topic - next topic

80TCS

Dec 14, 2016, 02:02 pm Last Edit: Dec 14, 2016, 02:53 pm by 80TCS
I don't even know where to start...  :smiley-confuse:

First, my issue is that I pretty much have no experience with coding other than looking through some source codes from games plugins (.sma) some years back (I guess that was pawn or something... )

What I want to achieve it's to hardware mod a mouse to include a Mouse Double-Click function on a single push of a button with an ATtiny85 which I've bought specifically for this purpose few days ago. I just can't live without a dedicated Double-Click Mouse button any more since I've used the first A4Tech mouse with this feature. And I don't want to be dependent of additional software on my PC to do it. I just want to have that feature on the mouse itself so I can take the mouse to another PC and not needing to install drivers or 3rd party programs.

I'm currently using a Logitech G300S and it has enough buttons so I could use (unassign) one of them for being "assigned" as the Double-Click button. The mouse also has 3 profiles and some RGB light strips (no PWM I think, as it's just 7 solid colors, no fading, etc. and shaking the mouse fast enough doesn't make the LED appear like it's "blinking")

What I'd like to do it's to use 3 pins from the Tiny85 to check the state (color) of the RGB LED and for the color teal (Profile 1) to activate the Double-Clicking "function". The RGB LED is a common anode.

Next, a 4th pin (preferably Pin1/RST - already connected to the on-board LED) should be an output as an indicator of the mode/profile 1 being active. Something like a beacon (double blink - 25ms/75ms/25ms) at about 2~3 seconds interval.

A 5th pin should be an input for the Mouse Button I'll press for the Double_Click (in my case, that will be "G5"/Forward/Mouse Button 5) I don't know yet if my mouse MCU it's a pullup/pulldown on the buttons inputs (I'll figure that out when I'll open it for the final installation)

And finally, the 6th pin should be the output to my Mouse Button 1 (and hopefully my mouse doesn't do a huge debounce on that button... )


So far I've started mocking this up...

Code: [Select]
// Set the desired ATtiny pins configureation
void setup() {
  pinMode(1, OUTPUT);         // Onboard LED / Mode Enabled LED
  pinMode(2, OUTPUT);         // To Mouse Button [1]
  pinMode(3, INPUT);          // From Mouse Button [5]
  pinMode(5, INPUT);          // From RGB LED [R]
  pinMode(6, INPUT);          // From RGB LED [G]
  pinMode(7, INPUT);          // From RGB LED [B]
}

// Check if the desired profile is active
bool isProfile(bool profile) {
  if(digitalRead(5) == HIGH && digitalRead(6) == LOW && digitalRead(7) == LOW) {
    isProfile = true
  }
  return profile;
}

// Activate LED "beacon" when the desired Profile is active
while(isProfile) == true {
  digitalWrite(1, HIGH);    // Turn the LED On
  delay(25);                // Wait 25ms
  digitalWrite(1, LOW);     // Turn the LED Off
  delay(50);                // Wait 50ms
  digitalWrite(1, HIGH);    // Turn the LED On
  delay(25);                // Wait 25ms
  digitalWrite(1, LOW);     // Turn the LED Off
  delay(2900);              // Wait 2900ms
}

bool buttonReleased = true;

// Double Click & Hold Mouse Button [1] when Mouse Button [5] is pressed
void loop() {
  while(isProfile) == true {
    if(digitalRead(3) == HIGH && buttonReleased == true) {
      digitalWrite(2, HIGH);              // Mouse Button 1 High
      delay(20);                          // Wait 20ms
      digitalWrite(2, LOW);               // Mouse Button 1 Low
      delay(20);                          // Wait 20ms
      digitalWrite(2, HIGH);              // Mouse Button 1 High
      delay(20);                          // Wait 20ms
      if(digitalRead(3) == LOW) {
        digitalWrite(1, LOW);             // Mouse Button 1 Low
      }
      else buttonReleased = true;
    }
    else {
      digitalWrite(2, HIGH);              // Mouse Button 1 High
      buttonReleased = false;
    }
  }
}


Well... soon enough I've realized that I didn't had a clue of what the heck I was doing...  :o

Basically I am trying to make a 20ms Click High > 20ms Click Low > 20ms Click High +keep high until I let the button go. That would be a "Double-Click & Hold"; pretty much what I couldn't do in Logitech Gaming Software among other nags... On the A4Tech mice I could just send this macro to the on-board memory and be done:

Code: [Select]
<Root>
 <DefaultMacro>
 <Major></Major>
 <Description></Description>
 <Comment></Comment>
 <GUIOption>
 <RepeatType>1</RepeatType>
 </GUIOption>
 <KeyUp>
 <Syntax></Syntax>
 </KeyUp>
 <KeyDown>
 <Syntax>
//   It is your new script below.
//-------------------
//there are three ways to create the script.
//1. Insert functions from top and left panels.
//2. Record both mouse and keyboard movements using record button.
//3. Input with either keyboard panel below or your actual keyboard.
LeftDown 1
Delay 20 ms
LeftUp 1
Delay 20 ms
LeftDown 1
Delay 20 ms
IfKey 7 1 13</Syntax>
 </KeyDown>
 <Software></Software>
 </DefaultMacro>
</Root>


EDIT: I'm wondering If it's possible to tap onto MISO/MOSI lines of the mouse MCU in order to read some bytes and figure the desired Profile (1)... ? That way it would be profile color agnostic (as I can set any color to any profile... ) Maybe even figuring the current CPI level (there are 3 CPI steps available per profile) and make a CPI step indicator with another Tiny85 and 3 LED's...

80TCS

I think I'm getting Closer...  :smiley-confuse: ?

Code: [Select]
// Set the desired ATtiny pins configureation
void setup() {
  pinMode(1, OUTPUT);                       // Onboard LED / Mode Enabled LED
  pinMode(2, OUTPUT);                       // To Mouse Button [1]
  pinMode(3, INPUT);                        // From Mouse Button [5]
  pinMode(5, INPUT);                        // From RGB LED [R]
  pinMode(6, INPUT);                        // From RGB LED [G]
  pinMode(7, INPUT);                        // From RGB LED [B]
}

// Check if the desired profile is active
bool isProfile(bool profile) {
  if(digitalRead(5) == HIGH && digitalRead(6) == LOW && digitalRead(7) == LOW) {
    profile = true;
  }
  else {
    profile = false;
  }
  return isProfile;
}

bool wasButtonReleased = true;

// Double Click & Hold Mouse Button [1] when Mouse Button [5] is pressed
void loop() {
  while(isProfile) {
    // Activate LED "beacon" when the desired Profile is active
    digitalWrite(1, HIGH);                  // Turn the LED On
    delay(25);                              // Wait 25ms
    digitalWrite(1, LOW);                   // Turn the LED Off
    delay(50);                              // Wait 50ms
    digitalWrite(1, HIGH);                  // Turn the LED On
    delay(25);                              // Wait 25ms
    digitalWrite(1, LOW);                   // Turn the LED Off
    delay(2900);                            // Wait 2900ms
   
    if(digitalRead(3) == HIGH) {
      if(wasButtonReleased == true) {
        digitalWrite(2, HIGH);              // Mouse Button 1 High
        delay(20);                          // Wait 20ms
        digitalWrite(2, LOW);               // Mouse Button 1 Low
        delay(20);                          // Wait 20ms
        digitalWrite(2, HIGH);              // Mouse Button 1 High
        delay(20);                          // Wait 20ms
        wasButtonReleased = false;
      }
    }
    else {
      digitalWrite(2, LOW);                 // Mouse Button 1 Low
      wasButtonReleased = true;
    }
  }
}


Still have no clue what I'm doing...

Go Up